new Tween(object, game, manager)
Tween constructor Create a new <code>Tween</code>.
Parameters:
Name | Type | Description |
---|---|---|
object |
object | Target object will be affected by this tween. |
game |
Phaser.Game | Current game instance. |
manager |
Phaser.TweenManager | The TweenManager responsible for looking after this Tween. |
- Source:
Members
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game.
-
isRunning
-
- Default Value:
- false
- Source:
Properties:
Name Type Description isRunning
boolean If the tween is running this is set to true, otherwise false. Tweens that are in a delayed state, waiting to start, are considered as being running.
-
onComplete
-
- Source:
Properties:
Name Type Description onComplete
Phaser.Signal The onComplete event is fired when the Tween completes. Does not fire if the Tween is set to loop.
-
onLoop
-
- Source:
Properties:
Name Type Description onLoop
Phaser.Signal The onLoop event is fired if the Tween loops.
-
onStart
-
- Source:
Properties:
Name Type Description onStart
Phaser.Signal The onStart event is fired when the Tween begins.
-
pendingDelete
-
- Default Value:
- false
- Source:
Properties:
Name Type Description pendingDelete
boolean If this tween is ready to be deleted by the TweenManager.
Methods
-
chain() → {Phaser.Tween}
-
You can chain tweens together by passing a reference to the chain function. This enables one tween to call another on completion. You can pass as many tweens as you like to this function, they will each be chained in sequence.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
delay(amount) → {Phaser.Tween}
-
Sets a delay time before this tween will start.
Parameters:
Name Type Description amount
number The amount of the delay in ms.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
easing(easing) → {Phaser.Tween}
-
Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
Parameters:
Name Type Description easing
function The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
generateData(frameRate, data) → {array}
-
This will generate an array populated with the tweened object values from start to end. It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and similar functions. It ignores delay and repeat counts and any chained tweens. Just one play through of tween data is returned, including yoyo if set.
Parameters:
Name Type Argument Default Description frameRate
number <optional>
60 The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates.
data
array <optional>
If given the generated data will be appended to this array, otherwise a new array will be returned.
- Source:
Returns:
An array of tweened values.
- Type
- array
-
interpolation(interpolation) → {Phaser.Tween}
-
Set interpolation function the tween will use, by default it uses Phaser.Math.linearInterpolation. Also available: Phaser.Math.bezierInterpolation and Phaser.Math.catmullRomInterpolation.
Parameters:
Name Type Description interpolation
function The interpolation function to use (Phaser.Math.linearInterpolation by default)
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
loop() → {Phaser.Tween}
-
Loop a chain of tweens
Usage: game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None, true) .to({ y: 300 }, 1000, Phaser.Easing.Linear.None) .to({ x: 0 }, 1000, Phaser.Easing.Linear.None) .to({ y: 0 }, 1000, Phaser.Easing.Linear.None) .loop();
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
onUpdateCallback(callback) → {Phaser.Tween}
-
Sets a callback to be fired each time this tween updates. Note: callback will be called in the context of the global scope.
Parameters:
Name Type Description callback
function The callback to invoke each time this tween is updated.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
pause()
-
Pauses the tween.
- Source:
-
repeat(times) → {Phaser.Tween}
-
Sets the number of times this tween will repeat.
Parameters:
Name Type Description times
number How many times to repeat.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
resume()
-
Resumes a paused tween.
- Source:
-
start() → {Phaser.Tween}
-
Starts the tween running. Can also be called by the autoStart parameter of Tween.to.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
stop() → {Phaser.Tween}
-
Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween
-
to(properties, duration, ease, autoStart, delay, repeat, yoyo) → {Phaser.Tween}
-
Configure the Tween
Parameters:
Name Type Argument Default Description properties
object Properties you want to tween.
duration
number <optional>
1000 Duration of this tween in ms.
ease
function <optional>
null Easing function. If not set it will default to Phaser.Easing.Linear.None.
autoStart
boolean <optional>
false Whether this tween will start automatically or not.
delay
number <optional>
0 Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
repeat
number <optional>
0 Should the tween automatically restart once complete? If you want it to run forever set as Number.MAX_VALUE. This ignores any chained tweens.
yoyo
boolean <optional>
false A tween that yoyos will reverse itself when it completes.
- Source:
Returns:
This Tween object.
- Type
- Phaser.Tween
-
update(time) → {boolean}
-
Core tween update function called by the TweenManager. Does not need to be invoked directly.
Parameters:
Name Type Description time
number A timestamp passed in by the TweenManager.
- Source:
Returns:
false if the tween has completed and should be deleted from the manager, otherwise true (still active).
- Type
- boolean
-
yoyo(yoyo) → {Phaser.Tween}
-
A tween that has yoyo set to true will run through from start to finish, then reverse from finish to start. Used in combination with repeat you can create endless loops.
Parameters:
Name Type Description yoyo
boolean Set to true to yoyo this tween.
- Source:
Returns:
Itself.
- Type
- Phaser.Tween