所以我试着让这段代码工作,但无论我怎么努力,它仍然无法工作。我的目标是让我的精灵使用光标移动,但它不起作用。同样出于某种原因,如果我的精灵依赖于此:
gameState.cursors.this.input.keyboard.
createCursorKeys();
我知道我的代码是错误的,但我不知道如何修复它,它就在下面:
if (gameState.cursors.left.isDown) {
gameState.player.setVelocityX(-160);
} else if (gameState.cursors.right.isDown) {
gameState.player.setVelocityX(160);
} else {
gameState.player.setVelocityX(0);
}
}
再次感谢堆叠社区!
应该是gameState.cursors = this.input.keyboard.createCursorKeys();
,以便正确分配它们。这是假设gameState
是一个全局变量,可以从当前范围中看到。