Class Tween<Target>

A Tween is basically an animation command. For example: Go from here to there in this amount of time.

Tweens won't start by themselves. Remeber to call start when you want your tweens to start!

Most methods will return the same object to allow for daisy chaining.

Type Parameters

  • Target

    of the tween

Hierarchy

  • Tween

Constructors

  • Creates an instance of tween.

    Type Parameters

    • Target

    Parameters

    • object: Target

      The target object which properties you want to animate

    • Optional group: Group

      The Group this new Tween will belong to. If none is provided it will default to the static shared

    Returns Tween<Target>

Methods

  • Adds tweens to be called when this tween ends. The tweens here will be called all at the same time.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • Rest ...tweens: Tween<any>[]

      tweens to be started when this tween ends

    Returns Tween<Target>

  • Sets the delay for this tween.

    This will only be applied at the start of the tween. For delaying the repeating of a tween, see repeatDelay

    This will only work before calling start.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • amount: number

      the delay for this tween.

    Returns Tween<Target>

  • Sets the duration for this tween in miliseconds.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • d: number

      The duration for this tween in miliseconds.

    Returns Tween<Target>

  • Set the final values for the target object's properties by reference. This will store a reference to the properties object allowing you to change the final values while the tween is running. If you want the tween to make a copy of the final values use to.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • properties: RecursivePartial<Target>

      final values for the target object.

    • Optional duration: number

      if given it will be used as the duration in miliseconds. if not, a call to duration will be needed.

    Returns Tween<Target>

  • Parameters

    • properties: any
    • Optional duration: number

    Returns Tween<Target>

  • Sets the easing function to interpolate the starting values with the final values.

    You can use the functions inside the Easing object.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • easingFunction: EasingFunction

      a function that takes a number between 0 and 1 and returns another number between 0 and 1

    Returns Tween<Target>

  • Fastforwards this tween to the end by triggering an update with an infinite value. This will work even on paused tweens.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • endChainedTweens: boolean = false

    Returns Tween<Target>

  • Writes the starting values of the tween.

    Starting values generated from start will be overwritten.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    Returns Tween<Target>

  • Parameters

    • properties: any

    Returns Tween<Target>

  • Gets the id for this tween. A tween id is a number that increases perpetually with each tween created. It is used inside Group to keep track of tweens

    Returns

    returns the id for this tween.

    Returns number

  • Gets the timescale for this tween. The timescale is a factor by which each deltatime is multiplied, allowing to speed up or slow down the tween.

    Returns

    returns the timescale for this tween.

    Returns number

  • Sets the Group for this tween.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • group: Group

      the group for this tween. If undefined or null is given, the group will default to shared.

    Returns Tween<Target>

  • Sets the easing function to interpolate the starting values with the final values when the final value is an array of objects. Use this to create bezier curves or interpolate colors.

    You can use the functions inside the Interpolation object.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    Returns Tween<Target>

  • A tween can only be paused if it was playing.

    Returns

    returns true if this tween is paused.

    Returns boolean

  • A tween is playing when it has been started but hasn't ended yet. This has nothing to do with pausing. For that see isPaused.

    Returns

    returns true if this tween is playing.

    Returns boolean

  • Sets the onAfterDelay callback. This will be called when the delay is over.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • callback: ((object: Target, tween: Tween<Target>) => void)

      the function to call on start. It will recieve the target object and this tween as a parameter.

        • (object: Target, tween: Tween<Target>): void
        • Parameters

          • object: Target
          • tween: Tween<Target>

          Returns void

    Returns Tween<Target>

  • Sets the onComplete callback

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • callback: ((object: Target, tween: Tween<Target>) => void)

      the function to call on complete. It will recieve the target object and this tween as a parameter.

        • (object: Target, tween: Tween<Target>): void
        • Parameters

          • object: Target
          • tween: Tween<Target>

          Returns void

    Returns Tween<Target>

  • Sets the onRepeat callback

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • callback: ((object: Target, repeatCount: number, tweenRef: Tween<Target>) => void)

      the function to call on repeat. It will recieve the target object and this tween as a parameter.

        • (object: Target, repeatCount: number, tweenRef: Tween<Target>): void
        • Parameters

          • object: Target
          • repeatCount: number
          • tweenRef: Tween<Target>

          Returns void

    Returns Tween<Target>

  • Sets the onStart callback. This will be called as soon as you call start.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • callback: ((object: Target, tween: Tween<Target>) => void)

      the function to call on start. It will recieve the target object and this tween as a parameter.

        • (object: Target, tween: Tween<Target>): void
        • Parameters

          • object: Target
          • tween: Tween<Target>

          Returns void

    Returns Tween<Target>

  • Sets the onStop callback

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • callback: ((object: Target, tween: Tween<Target>) => void)

      the function to call on stop. It will recieve the target object and this tween as a parameter.

        • (object: Target, tween: Tween<Target>): void
        • Parameters

          • object: Target
          • tween: Tween<Target>

          Returns void

    Returns Tween<Target>

  • Sets the onStart callback

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • callback: ((object: Target, elapsed: number, tween: Tween<Target>) => void)

      the function to call on start. It will recieve the target object, this tween, and a number between 0 and 1 determining the progress as a parameter.

        • (object: Target, elapsed: number, tween: Tween<Target>): void
        • Parameters

          • object: Target
          • elapsed: number
          • tween: Tween<Target>

          Returns void

    Returns Tween<Target>

  • Pauses this tween. Does nothing is if the tween was already paused or wasn't playing. Paused tweens ignore all update calls.

    Returns

    returns this tween for daisy chaining methods.

    Returns Tween<Target>

  • Sets the number of times this tween will loop

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • times: number = Infinity

      the number of loops. For endless loops use Infinity

    Returns Tween<Target>

  • Sets the repeat delay for this tween.

    This will only be applied at the start of every repeat. For delaying only the start, see delay

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • amount: number

      the repeat delay for this tween.

    Returns Tween<Target>

  • Experimental

    Clears the starting and loop starting values.

    Starting values will be cleared!. This function will erase all values created from from and/or start

    Returns

    returns this tween for daisy chaining methods.

    Returns Tween<Target>

  • Experimental

    Forces a tween to restart. Starting values for the animation will be stored at this moment. This literally calls reset and then start.

    Starting values will be cleared!. This function will erase all values created from from and/or start

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • Optional delay: number

      if given it will be used as the delay in miliseconds.

    Returns Tween<Target>

  • Resumes this tween. Does nothing if the tween wasn't paused nor running.

    Returns

    returns this tween for daisy chaining methods.

    Returns Tween<Target>

  • Experimental

    Stops the tween and sets the values to the starting ones.

    Returns

    returns this tween for daisy chaining methods.

    Returns Tween<Target>

  • Experimental

    Sets the safety check function to test if the tweening object is still valid. If the function returns a non-truthy value, the tween will skip the update loop.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • safetyCheckFunction: ((target: Target) => boolean)

      a function that takes the target object for this tween and returns true if the object is still valid.

        • (target: Target): boolean
        • Parameters

          • target: Target

          Returns boolean

    Returns Tween<Target>

  • Experimental

    Skips forward the in the repeats of this tween by triggering a biiiiig update. Think of this as a less agressive end.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • amount: number

      The amount of repeats to skip.

    • resetCurrentLoop: boolean = false

      If true, the time will become zero and the object will return to the initial value in the next update.

    Returns Tween<Target>

  • Tweens won't start by themselves when created. Call this to start the tween. Starting values for the animation will be stored at this moment.

    This function can't overwrite the starting values set by from

    You can call this method on a finished tween to restart it without changing the starting values. To restart a tween and reset the starting values use restart

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • Optional delay: number

      if given it will be used as the delay in miliseconds.

    Returns Tween<Target>

  • Experimental

    Starts all tweens chained to this tween. To chain a tween see chain.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • stopThis: boolean = false

      If true, this tween will be stopped before it starts the chained tweens.

    Returns Tween<Target>

  • Stops this tween

    Returns

    returns this tween for daisy chaining methods.

    Returns Tween<Target>

  • Experimental

    Stops tweens chained to this tween. To chain a tween see chain.

    Returns

    returns this tween for daisy chaining methods.

    Returns Tween<Target>

  • Sets the timescale for this tween. The deltaTime inside the update will be multiplied by this value allowing to speed up or slow down the flow of time.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • multiplier: number

      the timescale value for this tween.

    Returns Tween<Target>

  • Set the final values for the target object's properties by copy. This will try to create a deep copy of the properties parameter. If you want the tween to keep a reference to the final values use dynamicTo.

    If an array value is provided for a value that originally wasn't an array, it will be interpreted as an interpolable curve and the values inside the array will be interpolated using the function provided in interpolation

    If a string value that starts with either + or -is provided it will be taken as a relative value to the start value.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • properties: RecursivePartial<Target>

      final values for the target object.

    • Optional duration: number

      if given it will be used as the duration in miliseconds. if not, a call to duration will be needed.

    Returns Tween<Target>

  • Parameters

    • properties: any
    • Optional duration: number

    Returns Tween<Target>

  • Updates this tween

    Returns

    returns true if the tween hasn't finished yet.

    Parameters

    • deltaTime: number

      the amount of time that passed since last update in miliseconds

    • preserve: boolean = false

      Prevent the removal of stopped, paused, finished or non started tweens from their group.

    Returns boolean

  • Sets if this tween should yoyo (reflect) itself when repeating.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • yoyo: boolean = true

      the yoyo value for this tween.

    Returns Tween<Target>

  • Experimental

    Sets the easing function to interpolate the starting values with the final values on the way back due to a yoyo tween.

    You can use the functions inside the Easing object.

    Returns

    returns this tween for daisy chaining methods.

    Parameters

    • easingFunction: EasingFunction

      a function that takes a number between 0 and 1 and returns another number between 0 and 1

    Returns Tween<Target>

Generated using TypeDoc