如何用长矛左右移动物体
How do I move objects side to side with lance
谁能帮我把 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;
}
}
}
它不会工作,任何帮助将不胜感激。
抱歉,有人在 slack 上帮我解决了。我不得不用 "npm run-script build" 编译它。之后就成功了。
谁能帮我把 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;
}
}
}
它不会工作,任何帮助将不胜感激。
抱歉,有人在 slack 上帮我解决了。我不得不用 "npm run-script build" 编译它。之后就成功了。