Log In  

I'm working on this small animation library. It adds a straightforward way to animate an object's state.

Usage example:

Let's say there's a game object called "progress", representing a progress bar we want to animate:

progress={value=0}

we could animate the value rising from 0 to 100 by adding this to something that triggers the progress to start:

tween(progress,{value=100})

and in _update() we want to call the animate() function to keep updating the value, until it's duration has elapsed:

if has_animations(progress) then animate(progress) end

Demo

Cart #tweendemo-2 | 2021-02-21 | Code ▽ | Embed ▽ | No License
2

Configuration

There are some global variables you can override:

animate_default_duration=0.4
animate_default_easing=ease_quad_out
animate_key="__a" --which key should contain the tweening animation state

You can also add your own easing functions:

function my_easing(t)
 return t*t*t
end
add(animate_easings,my_easing)
ease_my_easing=#animate_easings

Arguments

tween(node,target,options)
  • node - table that contains the value that should be animated
  • target - table of the values that should be tweened
  • [options.duration] - how long the tween should play
  • [options.easing] - easing function (included easings: linear, quad_in, quad_out and quad_in_out)
  • [options.custom_time] - custom starting time

Tweens are removed automatically once the animation completes. Starting a new animation for a key with an active animation will overwrite the previous one, continuing animating from it's current value.

Download

The most recent version is available at https://github.com/thykka/pico-8-libs/blob/main/animate.lua

Changelog

  • v3
    • refactored & parametrized almost everything
    • animate_key() replaced by tween()
    • can now tween multiple values with one tween() call
P#87978 2021-02-21 18:35 ( Edited 2021-02-22 00:13)


[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-02-28 06:54 | 0.018s | 4194k | Q:26