Tween Complete Delay

This example demonstrates how to use the completeDelay property to pause for a set duration after a tween finishes its movement before triggering the completion event.

Tween Complete Delay, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    constructor()
    {
        super();
    }

    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('block', 'assets/sprites/block.png');
    }

    create ()
    {
        this.marker = this.add.image(100, 300, 'block').setAlpha(0.3);
        this.image = this.add.image(100, 300, 'block');

        this.moveBlock();
    }

    resetBlock()
    {
        this.tweens.add({
            targets: this.image,
            x: 100,
            duration: 1000,
            ease: 'Power2',
            completeDelay: 2000,
            onComplete: function () {
                this.moveBlock();
            }.bind(this),
        });
    }

    moveBlock()
    {
        this.tweens.add({
            targets: this.image,
            x: 700,
            duration: 1000,
            ease: 'Power2',
            completeDelay: 2000,
            onComplete: function () {
                this.resetBlock();
            }.bind(this),
        });
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'game-container',
    scene: Example
};

var game = new Phaser.Game(config);

More in Tweens58 examples