Skip to Content
defold-typescript libraries
Insality

Insality/defold-tweener/tweener

A tweener module to manage tweening operations. Tween functions are based on the Defold timer.delay function. Use tweener.tween to create a tween, and tweener.ease to get the result of an easing function. You can track the final call of tween by last parameter of the callback function.

  • GitHub: Insality/defold-tweener — pinned to 6
    1. This repo publishes no stable release. Pick a tag from Insality/defold-tweener tags and add its Source code (zip) URL — for the pinned tag, https://github.com/Insality/defold-tweener/archive/refs/tags/6.zip — to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as tweener from "tweener"

Functions

tween(easing_function: easing_function, from: number, to: number, time: number | undefined, callback: (value: number, is_end: boolean, time_elapsed: number, time_total: number) => void, update_delta_time?: number | undefined): tween

Starts a tweening operation. Return a tween object to manage the tween.

Parameters

  • easing_function: easing_function — The easing function to use
  • from: number — The starting value to tween from
  • to: number — The target value to tween to
  • time: number | undefined — The duration of the tween in seconds, default is 1
  • callback: (value: number, is_end: boolean, time_elapsed: number, time_total: number) => void — The callback function to call on each update
  • update_delta_time?: number | undefined — Default is 1/60, the time between updates

Returns

  • tween — A new created tween state

ease(easing_function: easing_function, from: number, to: number, time: number | undefined, time_elapsed: number): number

Returns the result of an easing function.

Parameters

  • easing_function: easing_function
  • from: number
  • to: number
  • time: number | undefined — The duration of the tween in seconds, default is 1
  • time_elapsed: number — current time [0 .. t - from]

Returns

  • number — The result of easing

is_active(tween: tween): boolean

Check if a tween exists

Parameters

  • tween: tween — the tween handle returned by tween function

Returns

  • boolean — if the tween is active, false if the tween finished

cancel(tween?: tween | undefined): boolean

Cancel a previous running tween.

Parameters

  • tween?: tween | undefined — the tween handle returned by tween function

Returns

  • boolean — if the tween was active, false if the tween is already cancelled / complete

is_paused(tween: tween): boolean

Check if a tween is paused

Parameters

  • tween: tween — the tween handle returned by tween function

Returns

  • boolean — true if the tween is active and paused, false if the tween is running

set_pause(tween: tween, is_paused: boolean)

Sets the pause on a running tween.

Parameters

  • tween: tween — the tween handle returned by tween function
  • is_paused: boolean — the tween paused state

Types

tween

tween.timer_id: number

The timer id handle from the timer.delay function

tween.is_paused: boolean

Whether the tween is paused

On this page