Phaser 3 - 如何在使用 accelerateTo 移动后停止游戏对象

Phaser 3 - How to Stop gameObject after moving with accelerateTo

我正在尝试为使用 accelerateTo 方法发牌的套牌创建动画。 Phaser 的文档说游戏对象在到达目标坐标后不会停止移动。没有解释如何在对象到达目的地后实际停止该对象。

function preload () {
    this.load.image('back', '../static/deck/flipo.png')
};

function create () {
  card = this.physics.add.image(500,500, 'back')
  this.physics.accelerateTo(card, 126, 160, 60, 1)
};

这可以让卡片沿着路径移动,但我怎样才能让它停下来?我猜我可以使用不可见的对撞机对象,但我更喜欢使用更干净的解决方案。

您可以在 update 函数中检查它的位置,以及它是否达到所需的 xy 位置。你可以setVelocity(0)来阻止它。

但老实说,因为您只想将卡片从一个地方移动到另一个地方,我认为使用 tween 是最好和最简单的选择。您还可以在补间上设置 onCompleteCallback

var tween = this.tweens.add({
    targets: card,
    x: 120,
    y: 160,
    ease: 'Power1',
    duration: 3000
});

这是simple tween example.