在Laya开发过程中需要监听键盘按下或抬起事件,处理其他事情。
onUpdate() { if (Laya.KeyBoardManager.hasKeyDown(Laya.Keyboard.A)) { this.rig.setVelocity({ x: -10, y: this.rig.linearVelocity.y }); } else if (Laya.KeyBoardManager.hasKeyDown(Laya.Keyboard.D)) { this.rig.setVelocity({ x: 10, y: this.rig.linearVelocity.y }); } } onKeyDown(e) { //console.log(e.nativeEvent.key+".........2"); if (e.nativeEvent.key == " " && this.canJump) { this.canJump = false; this.rig.setVelocity({ x: this.rig.linearVelocity.x, y: -13 }); } } onKeyPress(e) { console.log(e.nativeEvent.key+".........1"); if(e.nativeEvent.key == "a") { } }
请赞赏
朋友,创作不易;为犒赏小编的辛勤劳动,请她喝杯咖啡吧!
给她赞赏,您将财运亨通