Hello everyone
I get stuck by stopping the tween applied to a sprite and trying to applied another tween to the same sprite.
Here is a simplyfied example of my problem (using a example in phaser.io)
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#2d2d2d',
parent: 'phaser-example',
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('block', 'assets/sprites/block.png');
}
function create ()
{
var image = this.add.image(100, 300, 'block');
var tween = this.tweens.add({
targets: image,
x: 700,
delay: 1000,
duration: 6000,
ease: 'Power2'
});
this.input.on('pointerdown', function () {
tween.stop();//tween.destroy() doesn't work
tween = this.tweens.add({
targets: image,
y:0,
delay: 1000,
duration: 6000,
ease: 'Power2'
});
});
}
the first tween works well, but the game freezes when clicking on mouse button, failling to apply the second tween.
Does someone have an idea about how to do ?
Glad you solved it, but it’s worth adding that you do not need:
this.scene = scene;
In your Block Game Object, because it extends Sprite and the call to super() will do that automatically. That line of code is basically just repeating something that has already happened.