Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Tween

A Tween animates numeric properties of objects. It uses different transition functions to give the animations various styles.

The primary use of this class is to do standard animations like movement, fading, rotation, etc. But there are no limits on what to animate; as long as the property you want to animate is numeric (int, uint, Number), the tween can handle it. For a list of available Transition types, look at the "Transitions" class.

Here is an example of a tween that moves an object to the right, rotates it, and fades it out:

tween:Tween = new Tween(object, 2.0, Transitions.EASE_IN_OUT); tween.animate("x", object.x + 50); tween.animate("rotation", deg2rad(45)); tween.fadeTo(0); // equivalent to 'animate("alpha", 0)' Starling.juggler.add(tween);

Note that the object is added to a juggler at the end of this sample. That's because a tween will only be executed if its "advanceTime" method is executed regularly - the juggler will do that for you, and will remove the tween when it is finished.

@see Juggler @see Transitions

Hierarchy

Implements

Index

Constructors

constructor

  • new Tween(target: any, time: number, transition?: any): Tween
  • Creates a tween with a target, duration (in seconds) and a transition function.

    Parameters

    • target: any

      the object that you want to animate

    • time: number

      the duration of the Tween (in seconds)

    • Optional transition: any

      can be either a String (e.g. one of the constants defined in the Transitions class) or a function. Look up the 'Transitions' class for a documentation about the required signature.

    Returns Tween

Properties

currentTime

currentTime: number

The time that has passed since the tween was created (in seconds).

delay

delay: number

The delay before the tween is started (in seconds). @default 0

isComplete

isComplete: boolean

Indicates if the tween is finished.

nextTween

nextTween: Tween

Another tween that will be started (i.e. added to the same juggler) as soon as this tween is completed.

onComplete

onComplete: Function

A that will be called when the tween is complete.

onCompleteArgs

onCompleteArgs: Array<any>

The arguments that will be passed to the 'onComplete' function.

onRepeat

onRepeat: Function

A that will be called each time the tween finishes one repetition (except the last, which will trigger 'onComplete').

onRepeatArgs

onRepeatArgs: Array<any>

The arguments that will be passed to the 'onRepeat' function.

onStart

onStart: Function

A that will be called when the tween starts (after a possible delay).

onStartArgs

onStartArgs: Array<any>

The arguments that will be passed to the 'onStart' function.

onUpdate

onUpdate: Function

A that will be called each time the tween is advanced.

onUpdateArgs

onUpdateArgs: Array<any>

The arguments that will be passed to the 'onUpdate' function.

progress

progress: number

The current progress between 0 and 1, as calculated by the transition function.

repeatCount

repeatCount: number

The number of times the tween will be executed. Set to '0' to tween indefinitely. @default 1

repeatDelay

repeatDelay: number

The amount of time to wait between repeat cycles (in seconds). @default 0

reverse

reverse: boolean

Indicates if the tween should be reversed when it is repeating. If enabled, every second repetition will be reversed. @default false

roundToInt

roundToInt: boolean

Indicates if the numeric values should be cast to Integers. @default false

target

target: any

The target object that is animated.

totalTime

totalTime: number

The total time the tween will take per repetition (in seconds).

transition

transition: string

The transition method used for the animation. @see Transitions

transitionFunc

transitionFunc: function

The actual transition used for the animation.

Type declaration

    • (number: any): number
    • Parameters

      • number: any

      Returns number

Methods

addEventListener

  • addEventListener(type: string, listener: Function): void

advanceTime

  • advanceTime(time: number): void

animate

  • animate(property: string, endValue: number): void
  • Animates the property of the target to a certain value. You can call this method multiple times on one tween.

    Some property types are handled in a special way:

    • If the property contains the string color or Color, it will be treated as an unsigned integer with a color value (e.g. 0xff0000 for red). Each color channel will be animated individually.
    • The same happens if you append the string #rgb to the name.
    • If you append #rad, the property is treated as an angle in radians, making sure it always uses the shortest possible arc for the rotation.
    • The string #deg does the same for angles in degrees.

    Parameters

    • property: string
    • endValue: number

    Returns void

animatesProperty

  • animatesProperty(property: string): boolean

dispatchEvent

  • dispatchEvent(event: Event): void
  • Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.

    Parameters

    Returns void

dispatchEventWith

  • dispatchEventWith(type: string, bubbles?: boolean, data?: any): void

fadeTo

  • fadeTo(alpha: number): void

getEndValue

  • getEndValue(property: string): number
  • The end value a certain property is animated to. Throws an ArgumentError if the property is not being animated.

    Parameters

    • property: string

    Returns number

Protected get_currentTime

  • get_currentTime(): number

Protected get_delay

  • get_delay(): number

Protected get_isComplete

  • get_isComplete(): boolean

Protected get_nextTween

Protected get_onComplete

  • get_onComplete(): Function

Protected get_onCompleteArgs

  • get_onCompleteArgs(): Array<any>

Protected get_onRepeat

  • get_onRepeat(): Function

Protected get_onRepeatArgs

  • get_onRepeatArgs(): Array<any>

Protected get_onStart

  • get_onStart(): Function

Protected get_onStartArgs

  • get_onStartArgs(): Array<any>

Protected get_onUpdate

  • get_onUpdate(): Function

Protected get_onUpdateArgs

  • get_onUpdateArgs(): Array<any>

Protected get_progress

  • get_progress(): number

Protected get_repeatCount

  • get_repeatCount(): number

Protected get_repeatDelay

  • get_repeatDelay(): number

Protected get_reverse

  • get_reverse(): boolean

Protected get_roundToInt

  • get_roundToInt(): boolean

Protected get_target

  • get_target(): any

Protected get_totalTime

  • get_totalTime(): number

Protected get_transition

  • get_transition(): string

Protected get_transitionFunc

  • get_transitionFunc(): function

hasEventListener

  • hasEventListener(type: string, listener?: any): boolean

moveTo

  • moveTo(x: number, y: number): void

removeEventListener

  • removeEventListener(type: string, listener: Function): void

removeEventListeners

  • removeEventListeners(type?: string): void

reset

  • reset(target: any, time: number, transition?: any): Tween

rotateTo

  • rotateTo(angle: number, type?: string): void
  • Animates the 'rotation' property of an object to a certain target value, using the smallest possible arc. 'type' may be either 'rad' or 'deg', depending on the unit of measurement.

    Parameters

    • angle: number
    • Optional type: string

    Returns void

scaleTo

  • scaleTo(factor: number): void

Protected set_delay

  • set_delay(value: number): number

Protected set_nextTween

Protected set_onComplete

  • set_onComplete(value: Function): Function

Protected set_onCompleteArgs

  • set_onCompleteArgs(value: Array<any>): Array<any>

Protected set_onRepeat

  • set_onRepeat(value: Function): Function

Protected set_onRepeatArgs

  • set_onRepeatArgs(value: Array<any>): Array<any>

Protected set_onStart

  • set_onStart(value: Function): Function

Protected set_onStartArgs

  • set_onStartArgs(value: Array<any>): Array<any>

Protected set_onUpdate

  • set_onUpdate(value: Function): Function

Protected set_onUpdateArgs

  • set_onUpdateArgs(value: Array<any>): Array<any>

Protected set_repeatCount

  • set_repeatCount(value: number): number

Protected set_repeatDelay

  • set_repeatDelay(value: number): number

Protected set_reverse

  • set_reverse(value: boolean): boolean

Protected set_roundToInt

  • set_roundToInt(value: boolean): boolean

Protected set_transition

  • set_transition(value: string): string

Protected set_transitionFunc

  • set_transitionFunc(value: function): function
  • Parameters

    • value: function
        • (number: any): number
        • Parameters

          • number: any

          Returns number

    Returns function

      • (number: any): number
      • Parameters

        • number: any

        Returns number

Generated using TypeDoc