【转】Key Presses
FROM:http://lazyfoo.net/tutorials/SDL/04_key_presses/index.php
Key Presses
Last Updated 6/11/19
Xing out the window is just one of the events SDL is capable of handling. Another type of input used heavily in games is the keyboard. In this tutorial we're going to make different images appear depending on which key you press.
//Key press surfaces constants
enum KeyPressSurfaces
{
KEY_PRESS_SURFACE_DEFAULT,
KEY_PRESS_SURFACE_UP,
KEY_PRESS_SURFACE_DOWN,
KEY_PRESS_SURFACE_LEFT,
KEY_PRESS_SURFACE_RIGHT,
KEY_PRESS_SURFACE_TOTAL
};
One bad habit beginning programmers have is using abritary numbers instead of symbolic constants. For example they'll have 1 mean main menu, 2 mean options, etc which is fine for small programs. When you're dealing with thousands of lines of code (which video games usually do), having a line that says "if( option == 1 )" will produce much more headaches than using "if( option == MAIN_MENU )".
//Starts up SDL and creates window
bool init(); //Loads media
bool loadMedia(); //Frees media and shuts down SDL
void close(); //Loads individual image
SDL_Surface* loadSurface( std::string path ); //The window we'll be rendering to
SDL_Window* gWindow = NULL; //The surface contained by the window
SDL_Surface* gScreenSurface = NULL; //The images that correspond to a keypress
SDL_Surface* gKeyPressSurfaces[ KEY_PRESS_SURFACE_TOTAL ]; //Current displayed image
SDL_Surface* gCurrentSurface = NULL;
【转】Key Presses的更多相关文章
- Android按键事件处理流程 -- KeyEvent
刚接触Android开发的时候,对touch.key事件的处理总是一知半解,一会是Activity里的方法,一会是各种View 中的,自己始终不清楚到底哪个在先哪个在后,总之对整个处理流程没能很好的把 ...
- IP-Address TextBox
http://www.codeproject.com/Articles/4693/IP-Address-TextBox 可以下载试用效果.个人感觉功能很强大,但输入时让人不太舒服.可以参考. ntro ...
- 词频统计_输入到文件_update
/* 输入文件见337.in.txt 输出文件见338.out.txt */ #include <iostream> #include <cctype> #include &l ...
- SDL1.2学习
http://wenku.baidu.com/view/c953c0878762caaedd33d4d8.html 一.安装: sudo apt-get install libsdl1.2-dev l ...
- 自定义View(7)官方教程:自定义View(含onMeasure),自定义一个Layout(混合组件),重写一个现有组件
Custom Components In this document The Basic Approach Fully Customized Components Compound Controls ...
- Fast-paced Multiplayer
http://www.gabrielgambetta.com/fpm1.html —————————————————————————————————————————————————————— Fast ...
- [翻译.每月一译.每日一段]Exploring Fonts with DirectWrite and Modern C++
Windows with C++ Exploring Fonts with DirectWrite and Modern C++ Kenny Kerr DirectWrite is an incred ...
- Android Audio Play Out Channel
1: 7嘴8舌 扬声器, 耳机, 和听筒 就是通过: audiomanager.setmode(AudioManager.MODE_IN_COMMUNICATION)audiomanager.setS ...
- js大小写锁判断
<html> <head> <title>CapsLock Demo</title> <script src="http://ajax. ...
随机推荐
- 刷题[GKCTF2020]
[GKCTF2020]CheckIN 解题思路 打开直接是源码: <title>Check_In</title> <?php highlight_file(__FILE_ ...
- Linux的MySQL安装方法
第一种: APT方式安装 在ubuntu系统的apt软件仓库中,默认存在MySQL数据库 在用户模式下使用命令: apt/apt-get install mysql-server mysql-cli ...
- android.widget.TextView.setText() on a null object reference
错误描述 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView. ...
- Spring Boot第四弹,一文教你如何无感知切换日志框架?
持续原创输出,点击上方蓝字关注我吧 目录 前言 Spring Boot 版本 什么是日志门面? 如何做到无感知切换? 如何切换? 引入依赖 指定配置文件 日志如何配置? 总结 前言 首先要感谢一下读者 ...
- Python-如何拆分含有多种分隔符的字符串?
案例: 把某个字符串依据分隔符拆分,该字符包含不同的多种分隔符,如下 s = '12;;7.osjd;.jshdjdknx+' 其中 ; . + 是分隔符 有哪些解决方案? 方法1:通过str.spl ...
- Django-Scrapy生成后端json接口
Django-Scrapy生成后端json接口: 网上的关于django-scrapy的介绍比较少,该博客只在本人查资料的过程中学习的,如果不对之处,希望指出改正: 以后的博客可能不会再出关于djan ...
- DoModal 函数的用法
转载:https://blog.csdn.net/mpp_king/article/details/79707728 https://www.cnblog ...
- 【Excel技巧】用IF函数进行等级评定
如果下面给出一份"2月份语文成绩考核表",那么如何对成绩进行等级评定呢. 等级评定规则: 总分(100分) A级(91-100) B级(81-90) C级(71-80) D级(70 ...
- JavaScript写秒表
1.HTML部分 <div id="div1"> <span id="hour">00</span> <span> ...
- spring框架bean注入
今天学习了spring框架,刚刚入门简单的了解了spring并学习了bean的注入IOC:IOC(Inversion of Control,控制反转)不是什么技术,而是一种设计思想.它的目的是指导我们 ...