代码如下:
const {ccclass, property} = cc._decorator;
@ccclass
export default class player extends cc.Component {
@property(cc.Node)
transtage: cc.Node = null;
// LIFE-CYCLE CALLBACKS:
onLoad () {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeydown,this);
}
onDestroy(){
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeydown,this);
}
start () {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeydown,this);
}
onKeydown(event){
switch(event.keyCode){
case cc.macro.KEY.left:
this.transtage.x -= 22;
break;
case cc.macro.KEY.up:
this.transtage.y += 22;
break;
case cc.macro.KEY.right:
this.transtage.x += 22;
break;
case cc.macro.KEY.down:
this.transtage.y -= 22;
break;
case cc.macro.KEY.a:
this.span(this.transtage);
break;
case cc.macro.KEY.s:
this.mirrow(this.transtage);
break;
case cc.macro.KEY.space:
this.settage();
break;
}
}
// update (dt) {}
settage(){}
mirrow(node:cc.Node){
var action = cc.flipX(true);
node.runAction(action);
}
span(node:cc.Node){
var action = cc.rotateTo(0.1,90);
node.runAction(action);
}
}
测试过键盘监听一直有效,但是动作都只执行一次,是咋回事