有人可以帮我让ponggame演示中的球拍横向移动吗?我添加了键绑定:
this.controls = new KeyboardControls(this);
this.controls.bindKey('up', 'up', { repeat: true } );
this.controls.bindKey('down', 'down', { repeat: true } );
this.controls.bindKey('left', 'left', { repeat: true } );
this.controls.bindKey('right', 'right', { repeat: true } );
我还更改了游戏引擎: processInput(inputData, playerId) {
super.processInput(inputData, playerId);
// get the player paddle tied to the player socket
let playerPaddle = this.world.queryObject({ playerId });
if (playerPaddle) {
if (inputData.input === 'up') {
playerPaddle.position.y -= 5;
} else if (inputData.input === 'down') {
console.log('you are moving down');
playerPaddle.position.y += 5;
} else if (inputData.input === 'left') {
console.log('you are moving left?');
playerPaddle.position.x -= 5;
} else if (inputData.input === 'right') {
console.log('you are moving left?');
playerPaddle.isMovingDown = true;
}
}
}
它不会工作,任何帮助将不胜感激。