我已经帮你翻译了该内容:
我已经花了2-3个小时了,无法写出玩家移动逻辑。请帮我,好人啊。
```javascript
update() {
// 玩家左右移动
if (this.cursor.a.isDown && this.body.blocked.down) {
this.setVelocityX(-this.playerSpeed);
this.play("walk", true);
this.setFlipX(true);
} else if (this.cursor.d.isDown && this.body.blocked.down) {
this.setVelocityX(this.playerSpeed);
this.play("walk", true);
this.setFlipX(false);
} else {
this.setVelocityX(0);
this.play("idle", true);
}
// 玩家跳跃
if (Phaser.Input.Keyboard.JustDown(this.cursor.space) && this.body.blocked.down) {
this.setVelocityY(-this.jumpSpeed + 50);
}
// 玩家前进跳跃和后退跳跃
if (this.cursor.space.isDown && this.cursor.a.isDown && !this.body.blocked.down) {
this.setVelocityX(-this.playerSpeed);
}
if (this.cursor.space.isDown && this.cursor.d.isDown && !this.body.blocked.down) {
this.setVelocityX(this.playerSpeed);
}
}
}
export default Player;
评论 (0)