我如何反转 Phaser 补间?

How do i reverse a Phaser tween?

在 Phaser 中,我使用补间动画在单击按钮时移动精灵。

var tween = this.game.add.tween(sprite)
    .to({ y: destinationY) }, 400, Phaser.Easing.Bounce.InOut));
tween.start();

如何恢复补间动画,以便在我单击另一个按钮时精灵返回到其原始位置?

要在单击按钮时反转补间,只需让您的按钮 运行 有一个补间即可。 :)

在您的特定情况下,除了您现在保存的 destinationY 之外,这可能还涉及保存 originalY

然后 运行 您的新补间具有该值。

您现有按钮的类似内容:

// Save the sprites current position first to originalY.
var tween = this.game.add.tween(sprite)
    .to({ y: destinationY) }, 400, Phaser.Easing.Bounce.InOut));
tween.start();

然后在您的新按钮中使用它。

var tween = this.game.add.tween(sprite)
    .to({ y: originalY) }, 400, Phaser.Easing.Bounce.InOut));
tween.start();