Skip to content

Timeline

Introduction

Schedule events to happen at specific times in the future, built-in object of phaser.

  • Author: Richard Davey

Usage

Create timeline

var timeline = scene.add.timeline([    
    {
        at: 0,
        in:
        from:

        set: {
            key: value,
        },

        tween: {
            targets: gameObject,
            alpha: 1,
            ease: 'Linear',       // 'Cubic', 'Elastic', 'Bounce', 'Back'
            duration: 1000,
            repeat: 0,            // -1: infinity
            yoyo: false
        },

        run(target){ },

        sound: '',

        event: '',

        // target: this,

        // once: false,
        // stop: false,
    },

    // ...
])
  • Time
    • at : Absolute delay time after starting in ms.
    • in : Absolute delay time after current time in ms.
    • from : Relative delay time after previous event in ms
  • Actions :
    • set : A key-value object of properties to set on the target.
    • tween : tween config
    • run : A function which will be called when the Event fires.
      function(target) {
      
      }
      
    • sound :
      • A string : A key from the Sound Manager to play
      • A config object for a sound to play when the Event fires.
        {
            key,
            config
        }
        
    • event : String-based event name to emit when the Event fires. The event is emitted from the Timeline instance.
      timeline.on(eventName);
      
    • target : The scope (this object) with which to invoke the run.
  • Control
    • once : If set, the Event will be removed from the Timeline when it fires.
    • stop : If set, the Timeline will stop and enter a complete state when this Event fires, even if there are other events after it.

The Timeline always starts paused.

Start

timeline.play();

Restart

timeline.play(true);

Stop

timeline.stop();

Pause / Resume

timeline.pause();
// timeline.paused = true;
timeline.resume();
// timeline.paused = false;

Is playing

Timeline is currently playing, not paused or not complete.

var isPlaying = timeline.isPlaying()

Add event

timeline.add(config);

or

timeline.add([config0, config1, ...]);

Clear all events

timeline.clear();

Destroy

Also remove updating.

timeline.destroy();