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- 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— togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as tweener from "tweener"
- 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,
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):tweenease(easing_function: easing_function, from: number, to: number, time: number | undefined, time_elapsed: number): numberis_active(tween:tween): booleancancel(tween?:tween| undefined): booleanis_paused(tween:tween): booleanset_pause(tween:tween, is_paused: boolean)
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 usefrom:number— The starting value to tween fromto:number— The target value to tween totime:number | undefined— The duration of the tween in seconds, default is 1callback:(value: number, is_end: boolean, time_elapsed: number, time_total: number) => void— The callback function to call on each updateupdate_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_functionfrom:numberto:numbertime:number | undefined— The duration of the tween in seconds, default is 1time_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 bytweenfunction
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 bytweenfunction
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 bytweenfunction
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 bytweenfunctionis_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