我正在使用Phaser 3中的用户输入制作角色动画(使用纹理图谱),我遇到了一个问题,当我释放相应的箭头按钮时,动画没有停止.我试过一些策略,有些只是部分奏效.下面的代码是我使用的,它在所有方面都按照预期工作,除了释放相应的箭头键后动画没有停止.也许我需要逻辑与停止动画一旦键被解除?有什么建议吗?谢谢!
一百零二 Sprite Sheet animation with arrow keys.
update() {
this.hero.setVelocity(0,0);
if (this.cursors.up.isDown) {
this.hero.anims.play('walkUp', true);
this.hero.setVelocityY(-200);
}
else if (this.cursors.down.isDown) {
this.hero.anims.play('walkDown', true)
this.hero.setVelocityY(200);
}
if (this.cursors.left.isDown) {
this.hero.anims.play('walkLeft', true)
this.hero.setVelocityX(-200);
}
else if (this.cursors.right.isDown) {
this.hero.anims.play('walkRight', true)
this.hero.setVelocityX(200);
}
}