2

有人可以帮我让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;
       }
   }

}

它不会工作,任何帮助将不胜感激。

4

1 回答 1

2

抱歉,有人在 slack 上为我解决了这个问题。我不得不用“npm run-script build”编译它。在那之后它起作用了。

于 2018-04-16T15:23:34.867 回答