Use the Tween class to animate the properties of a display object like x, y, scaleX, scaleY, alpha, rotation etc. The animation starts with the current value of the property and ends at a given target or delta value.

Use one of the predefined Transition functions to control the progress of the animation (linear, easeInQuadratic, easeInCubic, ...). If none of the predefined Transition functions fulfills your needs you can also define your own function (see TransitionFunction).

Examples:

var tween = new Tween(mySprite, 1.0, Transition.easeInCubic);
tween.delay = 0.5;
tween.animate.alpha.to(0.0);  // target value = 0.0
tween.animate.x.by(10.0);     // delta value = 10.0;
tween.animate.y.by(-10.0);    // delta value = -10.0;
tween.onComplete = () => print('completed');
stage.juggler.add(tween);

var sawtooth = Tween(mySprite, 1.0, (r) => (r * 4).remainder(1.0);
sawtooth.animate.y.to(10);
stage.juggler.add(sawtooth);

stage.juggler.addTween(mySprite, 1.0, Transition.easeInCubic)
  ..delay = 0.5
  ..animate.alpha.to(0.0);
Implements
  • Animatable

Constructors

Tween(TweenObject tweenObject, num time, [ TransitionFunction transition = Transition.linear ])

Creates a new Tween for the specified TweenObject with a duration of time seconds.

Properties

animate TweenPropertyAccessor2D

Accessor for 2D properties like x, y, rotation, alpha and others which can be animated with this tween. Works for all display objects.

read-only
animate3D TweenPropertyAccessor3D

Accessor for 3D properties like offsetZ, rotationZ and others which can be animated with this tween. Works for all 3D display objects.

read-only
currentTime → num

The current time of this Tween.

read-only
delay → num

The delay this Tween waits until it starts animating.

read / write
hashCode → int

Get a hash code for this object.

read-only, inherited
isComplete → bool

Indicates if this Tween is completed.

read-only
onComplete

The function that is called when this Tween is completed.

write-only
onStart

The function that is called when this Tween starts.

write-only
onUpdate

The function that is called every time this Tween updates the properties of the TweenObject.

write-only
roundToInt → bool

Specifies if the values should be rounded to an integer.

read / write
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited
totalTime → num

The total time of this Tween.

read-only
tweenObject TweenObject

The object that is tweened.

read-only

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

advanceTime(num time) → bool

This method is called by the Juggler with the time past since the last call.

complete() → void

Advances this Tween to its end state.

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() → String

Returns a string representation of this object.

inherited