Tweener
Tweener - is a single file Lua module for the Defold game engine. It provides a way to handle manual tweening in your game.
Features
- Tweening: Create tweens for any action your want.
- Easing Functions: Provides a set of easing functions for different types of easings.
- Custom Update Frequency: Option to define update frequency for the tween.
- Callbacks: Callbacks for each tween update.
Setup
See the Defold-Tweener repository on Github for the Setup, Documentation, API and Use Cases
Usage
You can use Tweener to animate scoring text, for example:
This animation can be created using the following code:
tweener.tween(tween_function, from, to, time, callback, [dt])
tweener.tween(gui.EASING_OUTCIRC, 0, 9999, 2.4, function(value, is_final_call)
gui.set_text(text_score, "Score: " .. math.floor(value))
if is_final_call then
gui.set_scale(text_score, vmath.vector3(1.25, 1.25, 1))
gui.animate(text_score, "scale", vmath.vector3(1, 1, 1), gui.EASING_OUTBOUNCE, 0.5)
end
end)
You can obtain the value of the tween at any point in time with the tweener.ease
function:
tweener.ease(tween_function, from, to, time, time_elapsed)
tweener.ease(gui.EASING_OUTSINE, 0, 100, 1, 0) -- Returns 0
tweener.ease(gui.EASING_OUTSINE, 0, 100, 1, 0.25) -- Returns 38.268343236509
tweener.ease(gui.EASING_OUTSINE, 0, 100, 1, 0.5) -- Returns 70.710678118655
tweener.ease(gui.EASING_OUTSINE, 0, 100, 1, 0.75) -- Returns 92.387953251129
tweener.ease(gui.EASING_OUTSINE, 0, 100, 1, 1) -- Returns 100