标签:c++ cocos2d 游戏 开发人员 cocos2d-js
Cocos2d-JS中的键盘事件与触摸事件不同,它没有空间方面信息。键盘事件不仅可以响应键盘,还可以响应设备的菜单。onEnter: function () { this._super(); cc.log("HelloWorld onEnter"); cc.eventManager.addListener({ ① event: cc.EventListener.KEYBOARD, ② onKeyPressed: function(keyCode, event){ ③ cc.log("Key with keycode " + keyCode + " pressed"); }, onKeyReleased: function(keyCode, event){ ④ cc.log("Key with keycode " + keyCode + " released"); } }, this); }, onExit: function () { this._super(); cc.log("HelloWorld onExit"); cc.eventManager.removeListeners(cc.EventListener.KEYBOARD); ⑤ }上述代码第①行cc.eventManager.addListener是通过快捷方式注册事件监听器对象。第②行代码是设置键盘事件cc.EventListener.KEYBOARD。第③行代码是设置键盘按下属性onKeyPressed,其中的参数keyCode是按下的键编号。第④行代码是设置键盘抬起属性onKeyReleased。
JS: Key with keycode 124 released JS: Key with keycode 124 pressed JS: Key with keycode 139 pressed JS: Key with keycode 139 released JS: Key with keycode 124 released JS: Key with keycode 139 pressed JS: Key with keycode 124 pressed JS: Key with keycode 139 released JS: Key with keycode 124 released JS: Key with keycode 139 pressed JS: Key with keycode 124 pressed JS: Key with keycode 139 released JS: Key with keycode 124 released
《Cocos2d-x实战 JS卷》现已上线,各大商店均已开售:
京东:http://item.
标签:c++ cocos2d 游戏 开发人员 cocos2d-js
原文地址:http://blog.csdn.net/tonny_guan/article/details/44810903