Options
All
  • Public
  • Public/Protected
  • All
Menu

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 Tween.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

Index

Constructors

constructor

  • new Tween<Target>(object: Target, group?: Group): Tween<Target>
  • 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 Group.shared

    Returns Tween<Target>

Methods

chain

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

    Parameters

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

      tweens to be started when this tween ends

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

delay

  • delay(amount: number): 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 Tween.repeatDelay

    This will only work before calling Tween.start.

    Parameters

    • amount: number

      the delay for this tween.

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

duration

  • duration(d: number): Tween<Target>
  • Sets the duration for this tween in miliseconds.

    Parameters

    • d: number

      The duration for this tween in miliseconds.

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

dynamicTo

  • dynamicTo(properties: RecursivePartial<Target>, duration?: number): Tween<Target>
  • dynamicTo(properties: any, duration?: number): 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 Tween.to.

    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 Tween.duration will be needed.

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

  • Parameters

    • properties: any
    • Optional duration: number

    Returns Tween<Target>

easing

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

    You can use the functions inside the Easing object.

    Parameters

    • easingFunction: EasingFunction

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

end

  • end(endChainedTweens?: boolean): Tween<Target>
  • Fastforwards this tween to the end by triggering an update with an infinite value. This will work even on paused tweens.

    Parameters

    • endChainedTweens: boolean = false

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

from

  • Writes the starting values of the tween.

    Starting values generated from Tween.start will be overwritten.

    Parameters

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

  • Parameters

    • properties: any

    Returns Tween<Target>

getGroup

getId

  • getId(): number
  • 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 number

    returns the id for this tween.

getTimescale

  • getTimescale(): 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 number

    returns the timescale for this tween.

group

  • Sets the Group for this tween.

    Parameters

    • group: Group

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

interpolation

  • 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.

    Parameters

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

isPaused

  • isPaused(): boolean
  • A tween can only be paused if it was playing.

    Returns boolean

    returns true if this tween is paused.

isPlaying

  • isPlaying(): 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 Tween.isPaused.

    Returns boolean

    returns true if this tween is playing.

onAfterDelay

  • onAfterDelay(callback: (object: Target, tween: Tween<Target>) => void): Tween<Target>
  • Sets the onAfterDelay callback. This will be called when the delay is over.

    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>

    returns this tween for daisy chaining methods.

onComplete

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

    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>

    returns this tween for daisy chaining methods.

onRepeat

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

    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>

    returns this tween for daisy chaining methods.

onStart

  • onStart(callback: (object: Target, tween: Tween<Target>) => void): Tween<Target>
  • Sets the onStart callback. This will be called as soon as you call Tween.start.

    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>

    returns this tween for daisy chaining methods.

onStop

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

    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>

    returns this tween for daisy chaining methods.

onUpdate

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

    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>

    returns this tween for daisy chaining methods.

pause

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

repeat

  • repeat(times?: number): Tween<Target>
  • Sets the number of times this tween will loop

    Parameters

    • times: number = Infinity

      the number of loops. For endless loops use Infinity

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

repeatDelay

  • repeatDelay(amount: number): 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 Tween.delay

    Parameters

    • amount: number

      the repeat delay for this tween.

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

reset

  • experimental

    Clears the starting and loop starting values.

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

restart

  • restart(delay?: number): Tween<Target>
  • experimental

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

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

    Parameters

    • Optional delay: number

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

resume

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

rewind

  • experimental

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

safetyCheck

  • safetyCheck(safetyCheckFunction: (target: Target) => boolean): 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.

    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>

    returns this tween for daisy chaining methods.

skip

  • skip(amount: number, resetCurrentLoop?: boolean): Tween<Target>
  • experimental

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

    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>

    returns this tween for daisy chaining methods.

start

  • start(delay?: number): 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 Tween.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 Tween.restart

    Parameters

    • Optional delay: number

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

startChainedTweens

  • startChainedTweens(stopThis?: boolean): Tween<Target>
  • experimental

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

    Parameters

    • stopThis: boolean = false

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

stop

  • Stops this tween

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

stopChainedTweens

  • stopChainedTweens(): Tween<Target>
  • experimental

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

timescale

  • timescale(multiplier: number): 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.

    Parameters

    • multiplier: number

      the timescale value for this tween.

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

to

  • 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 Tween.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 Tween.interpolation

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

    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 Tween.duration will be needed.

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

  • Parameters

    • properties: any
    • Optional duration: number

    Returns Tween<Target>

update

  • update(deltaTime: number, preserve?: boolean): boolean
  • Updates this tween

    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

    returns true if the tween hasn't finished yet.

yoyo

  • yoyo(yoyo?: boolean): Tween<Target>
  • Sets if this tween should yoyo (reflect) itself when repeating.

    Parameters

    • yoyo: boolean = true

      the yoyo value for this tween.

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

yoyoEasing

  • 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.

    Parameters

    • easingFunction: EasingFunction

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

    Returns Tween<Target>

    returns this tween for daisy chaining methods.

Generated using TypeDoc