多平台响应键盘事件!(适用于Cocos2dx 3.0 alpha以上版本)
来源:互联网 发布:ios本地播放软件 编辑:程序博客网 时间:2024/06/06 02:20
Hello everyone! For a week I’ve been looking on how to make a keyboard work!
I managed to figure it out and I want to share my knowledge with you!
So, before we get started - this tutorial only works on Cocos2d-x 3.0alpha and later.
We will start by making two functions in the scene we want keyboard on.
They will be:
首先在需要键盘处理事件的场景中文件中添加如下两个函数。
These functions will be called when we press/release a key on the keyboard.
Next we need a listener to look for the keyboard we will create it like so (I did it in the init function)
当键盘按下时会调用上面这两的函数。
接下来在init()方法中添加如下代码来监听键盘事件。
This code creates a keyboard listener and then setting what functions will be called when the key is pressed or released.
Now Our program can detect keyboard! Wait… How do I know what key is pressed? It is simple! Let me show you:
然后就可以在最上面的两个方法中添加keyCode的判定了。
This piece of code will check what is the key-code of the key that was pressed. The list of key-codes is inside the EventKeyboard class. To use a keycode you just type:
EventKeyboard::KeyCode::KEY_**whatever key** - you will usually get a list of available keys to chose from.
Well, I think that’s it! Enjoy!
- 多平台响应键盘事件!(适用于Cocos2dx 3.0 alpha以上版本)
- 多平台响应键盘事件!(适用于Cocos2dx 3.0 alpha以上版本)
- cocos2dx 3.0以上版本的触摸事件
- cocos2dx 响应windows键盘事件
- cocos2dx 弹出键盘无法响应键盘外的触摸事件
- Cocos2dx 3.0 以上版本 集成 MFC
- cocos2dx 2.2.x版本和3.0以上版本创建项目
- cocos2dx 2.0以上版本修改
- Datagrid键盘事件响应(二)
- winform键盘事件的响应(C#)
- CDialog响应键盘事件
- MFC 键盘响应事件
- 响应键盘事件
- javascript键盘事件响应
- Android键盘响应事件
- 响应键盘回车键事件
- C#响应键盘事件
- qt响应键盘事件
- 黑马程序员一在hashSet集合中比较对象需要覆盖的两个方法hashCode(),equlas()
- 【jQuery】一个跟随鼠标运动的图层
- 【我的问题】ubuntu下的android开发问题:模拟器无法打开 2-bit Linux Android emulator binaries are DEPRECATED,
- JRE与JVM、JDK的区别
- GZU Monthly, December 2014
- 多平台响应键盘事件!(适用于Cocos2dx 3.0 alpha以上版本)
- 嵌入式程序中的回调函数
- 初识Linux(三)--常用命令
- IE8 访问https安全证书错误;导航阻止 解决办法 《转》
- GIMP使用 二 实现图片的抓图,裁剪,取色
- 2014年语音聊天室软件最新排行榜
- Python os模块简介
- C++ 浮点数(double、float)如何定义NaN、正无穷、负无穷,以及如何判断是否是NaN
- 每天一个linux命令(46):vmstat命令