Skip to content

animation

Animation module: tweens numeric properties over time.

lua
local anim = basalt.use("animation")
anim.to(label, { x = 20, y = 5 }, 0.5, "easeOut", function(el) ... end)
label:animate({ x = 20 }, 0.5)          -- sugar added to Element

Standalone module: drives itself through a basalt.schedule coroutine (sleep-based, ~20 fps) and touches no core files.

Fields

FieldTypeDescription
easingstable<string, fun(t: number): number>Registered easing functions

Methods

animation.to(el, props, duration, easing, onDone)

Tweens the given numeric properties to their target values.

  • el (table) The element to animate

  • props (table) Target values, e.g.

  • duration (number, optional) Seconds, default 0.3

  • easing (string, optional) "linear", "easeIn", "easeOut" or "easeInOut"

  • onDone (function, optional) Called with the element after completion

  • returns handle (table) Handle with :cancel()

Element:animate(props, duration, easing, onDone)

Sugar on Element: el:animate({x = 20}, 0.5, "easeOut", onDone) Fluent element shortcut for animation.to().

  • props (table) Target property values

  • duration (number, optional) Seconds, default 0.3

  • easing (string, optional) Easing name

  • onDone (function, optional) Completion callback

  • returns handle (table) Cancellable animation handle

Last updated:

Released under the MIT License.