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 - tween/Tween.js, line 17
Members
-
game :Phaser.Game
-
A reference to the currently running Game.
- Source - tween/Tween.js, line 29
-
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.
- Default Value:
- false
- Source - tween/Tween.js, line 181
-
onComplete :Phaser.Signal
-
The onComplete event is fired when the Tween completes. Does not fire if the Tween is set to loop.
- Source - tween/Tween.js, line 175
-
onLoop :Phaser.Signal
-
The onLoop event is fired if the Tween loops.
- Source - tween/Tween.js, line 170
-
onStart :Phaser.Signal
-
The onStart event is fired when the Tween begins.
- Source - tween/Tween.js, line 165
-
pendingDelete :boolean
-
If this tween is ready to be deleted by the TweenManager.
- Default Value:
- false
- Source - tween/Tween.js, line 160
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.
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 558
-
delay(amount) → {Phaser.Tween}
-
Sets a delay time before this tween will start.
Parameters:
Name Type Description amountnumber The amount of the delay in ms.
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 478
-
easing(easing) → {Phaser.Tween}
-
Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
Parameters:
Name Type Description easingfunction The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 529
-
from(properties, duration, ease, autoStart, delay, repeat, yoyo) → {Phaser.Tween}
-
Sets this tween to be a
fromtween on the properties given. Afromtween starts at the given value and tweens to the current values. For example a Sprite with anxcoordinate of 100 could be tweened fromx: 200by giving a properties object of{ x: 200 }.Parameters:
Name Type Argument Default Description propertiesobject Properties you want to tween from.
durationnumber <optional>
1000 Duration of this tween in ms.
easefunction <optional>
null Easing function. If not set it will default to Phaser.Easing.Linear.None.
autoStartboolean <optional>
false Whether this tween will start automatically or not.
delaynumber <optional>
0 Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
repeatnumber <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.
yoyoboolean <optional>
false A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead.
Returns:
This Tween object.
- Source - tween/Tween.js, line 261
-
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 frameRatenumber <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.
dataarray <optional>
If given the generated data will be appended to this array, otherwise a new array will be returned.
Returns:
array -An array of tweened values.
- Source - tween/Tween.js, line 340
-
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 interpolationfunction The interpolation function to use (Phaser.Math.linearInterpolation by default)
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 543
-
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();
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 572
-
onUpdateCallback(callback, callbackContext) → {Phaser.Tween}
-
Sets a callback to be fired each time this tween updates.
Parameters:
Name Type Description callbackfunction The callback to invoke each time this tween is updated.
callbackContextobject The context in which to call the onUpdate callback.
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 591
-
pause()
-
Pauses the tween.
- Source - tween/Tween.js, line 608
-
repeat(times) → {Phaser.Tween}
-
Sets the number of times this tween will repeat.
Parameters:
Name Type Description timesnumber How many times to repeat.
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 493
-
resume()
-
Resumes a paused tween.
- Source - tween/Tween.js, line 636
-
start() → {Phaser.Tween}
-
Starts the tween running. Can also be called by the autoStart parameter of
Tween.to.Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 289
-
stop() → {Phaser.Tween}
-
Stops the tween if running and removes it from the TweenManager. If called directly and there are any
onCompletecallbacks or events they are not dispatched.Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 458
-
to(properties, duration, ease, autoStart, delay, repeat, yoyo) → {Phaser.Tween}
-
Sets this tween to be a
totween on the properties given. Atotween starts at the current value and tweens to the destination value given. For example a Sprite with anxcoordinate of 100 could be tweened tox200 by giving a properties object of{ x: 200 }.Parameters:
Name Type Argument Default Description propertiesobject The properties you want to tween, such as
Sprite.xorSound.volume. Given as a JavaScript object.durationnumber <optional>
1000 Duration of this tween in ms.
easefunction <optional>
null Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden at will.
autoStartboolean <optional>
false Whether this tween will start automatically or not.
delaynumber <optional>
0 Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
repeatnumber <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.
yoyoboolean <optional>
false A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead.
Returns:
This Tween object.
- Source - tween/Tween.js, line 187
-
update(time) → {boolean}
-
Core tween update function called by the TweenManager. Does not need to be invoked directly.
Parameters:
Name Type Description timenumber A timestamp passed in by the TweenManager.
Returns:
boolean -false if the tween has completed and should be deleted from the manager, otherwise true (still active).
- Source - tween/Tween.js, line 672
-
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 yoyoboolean Set to true to yoyo this tween.
Returns:
This tween. Useful for method chaining.
- Source - tween/Tween.js, line 508