Phaser 3 上的 moveToObject 精灵动画

moveToObject sprite animation on Phaser 3

我有一个可以点击指向移动的角色。我正在使用 MoveToObject 我想根据精灵移动的方向为精灵实现动画,类似于下面的代码片段

if (this.cursors.left.isDown)
{
    this.player.setVelocity(-speed, 0)
    this.player.play('left-walk', true)
}
else if (this.cursors.right.isDown)
{
    this.player.setVelocity(speed, 0)
    this.player.play('right-walk', true)
}
else if (this.cursors.up.isDown)
{
    this.player.setVelocity(0, -speed)
    this.player.play('up-walk', true)
}
else if (this.cursors.down.isDown)
{
    this.player.setVelocity(0, speed)
    this.player.play('down-walk', true)
}

我猜想得到精灵的当前角度,但我似乎无法让它发挥作用。谢谢

我已经解决了以下问题。谢谢!

 angles = Phaser.Math.Angle.BetweenPoints(avatar, target)
        var newAngles = Phaser.Math.RadToDeg(angles)
        console.log(newAngles)

        if (avatar.body.speed > 0)
        {
            if(newAngles <= -45 && newAngles >= -135) {
            avatar.anims.play('back', true)
            } else if (newAngles <= 45 && newAngles >= -45) {
                avatar.flipX = true
                avatar.anims.play('side', true)
            } else if (newAngles <= 135 && newAngles >= 45) {
                avatar.anims.play('front', true)
            } else if (newAngles <= 225 && newAngles >= 135) {
                avatar.flipX = false
                avatar.anims.play('side', true)
            }
            
            
            
            if (distance < 4)
            {
                avatar.anims.pause()
                avatar.body.reset(target.x, target.y);                
            }
        }