Javascript 当精灵';s移动停止在相位器3中
发布此文章以分享我如何解决此问题。我到处都找遍了,似乎找不到有效的解决办法 问题(我的版本)-我有一个精灵将成为我游戏中的玩家。我有一个向左跑和向右跑的动画。这些动画设置为“循环”,因此当速度增加时,播放器将显示为正在运行我希望播放器的动画在停止移动后立即停止我的实现Javascript 当精灵';s移动停止在相位器3中,javascript,animation,phaser-framework,Javascript,Animation,Phaser Framework,发布此文章以分享我如何解决此问题。我到处都找遍了,似乎找不到有效的解决办法 问题(我的版本)-我有一个精灵将成为我游戏中的玩家。我有一个向左跑和向右跑的动画。这些动画设置为“循环”,因此当速度增加时,播放器将显示为正在运行我希望播放器的动画在停止移动后立即停止我的实现 update() { //If right arrowkey is pressed if (this.arrowKeys.right._justDown) { //Move
update() {
//If right arrowkey is pressed
if (this.arrowKeys.right._justDown) {
//Move player
this.hero.setVelocityX(5);
//Play your animation animation
this.hero.anims.play('yourAnim', true);
};
//This will run every time the animation "repeats", meaning it has gone through all of its frames. Make sure your animation is set to loop!
this.hero.on("animationupdate", () => {
//If the player has stopped moving
if (this.hero.body.velocity.x < 0.5 && this.hero.body.velocity.x > -0.5) {
//Stop the animation
this.hero.anims.stop();
}
});
}
update(){
//如果按下向右箭头键
如果(此箭头键为右。\仅向下){
//移动播放器
这个.hero.setVelocityX(5);
//播放动画
这个。英雄。动画。游戏('yourAnim',真的);
};
//这将在每次动画“重复”时运行,这意味着它已通过其所有帧。请确保您的动画设置为循环!
this.hero.on(“animationupdate”,()=>{
//如果玩家停止移动
if(this.hero.body.velocity.x<0.5&&this.hero.body.velocity.x>-0.5){
//停止动画
这个.hero.anims.stop();
}
});
}
格式有点不好。几乎可以肯定,有一种稍微快一点的方法可以做到这一点。但这是我现在的实现,我只是想分享一下,以防其他人也有同样的问题!请随意评论一个更好的解决方案或任何问题我遇到过这样的问题,您可能不再需要解决方案,但其他人可能需要。我使用JustDown启动动画,使用JustUp进入空闲状态。更新中的代码:
if(Phaser.Input.Keyboard.JustDown(downKey)){
gamePiece.anims.play("down");
}
if(Phaser.Input.Keyboard.JustUp(downKey)){
gamePiece.anims.play("spin");
}
在您的情况下,它将停止动画而不是空闲动画