Merge pull request #1176 from knoxHuang/v1.3

update KEY API
This commit is contained in:
Jare Guo
2016-10-09 17:55:49 +08:00
committed by GitHub
2 changed files with 361 additions and 18 deletions
File diff suppressed because it is too large Load Diff
+16 -7
View File
@@ -1,9 +1,18 @@
-----
cc.eventManager.addListener({
event: cc.EventListener.KEYBOARD,
onKeyPressed: function(keyCode, event){
if (cc.KEY["a"] == keyCode) {
cc.log("A is pressed");
cc.Class({
extends: cc.Component,
onLoad: function () {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
},
destroy () {
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
},
onKeyDown: function (event) {
switch(event.keyCode) {
case cc.KEY['0']:
console.log('Press a key');
break;
}
}
}, this);
});