Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rameshvarun/hump.timer.actions
Composable actions, powered by Hump.Timer.
https://github.com/rameshvarun/hump.timer.actions
love2d lua
Last synced: about 2 months ago
JSON representation
Composable actions, powered by Hump.Timer.
- Host: GitHub
- URL: https://github.com/rameshvarun/hump.timer.actions
- Owner: rameshvarun
- License: mit
- Created: 2016-01-16T01:19:22.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T17:42:41.000Z (almost 2 years ago)
- Last Synced: 2024-12-21T19:05:24.513Z (about 2 months ago)
- Topics: love2d, lua
- Language: Lua
- Homepage: https://blog.varunramesh.net/posts/composable-animations/
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hump.timer.actions
[![Lua](https://github.com/rameshvarun/hump.timer.actions/actions/workflows/lua.yml/badge.svg)](https://github.com/rameshvarun/hump.timer.actions/actions/workflows/lua.yml)
Composable actions, powered by [hump.timer](https://hump.readthedocs.org/en/latest/timer.html). Inspired by [LibGDX actions](https://github.com/libgdx/libgdx/wiki/Scene2d#actions). Represents a `monoid`. This approach also lends itself to manipulation by higher order functions (similar to parser combinators).
## Example
```lua
local Actions = require "actions"
local Timer = require "hump.timer"local objectA = {val = 0}, objectB = {val = 0}
local action = Actions.Sequence(
Actions.Print("Started action..."),
Actions.Wait(3),
Actions.Print("3 seconds passed..."),
Actions.Parallel(
Actions.Tween(3.0, objectA, {val=10}, 'linear'),
Actions.Tween(2.0, objectB, {val=10}, 'linear')
)
)--[[ Play the action by calling it as a function.
The first argument is the Hump.Timer object used to run
events, and the second argument is a continuation to
be run on the completion of the action. ]]--
action(Timer, function()
print("Continuation...")
end)
```## Documentation
### Action Primitives
These functions return actions that, when played, will do something.
#### `Actions.Empty()`
An empty 'identity' action which does nothing.
#### `Actions.Wait(duration)`
An action which waits for the provided amount of seconds.
#### `Actions.Do(func)`
An action which invokes the provided function, then continues.
#### `Actions.Print(func)`
An action which prints to the console.
#### `Actions.Tween(duration, subject, target, method, ...)`
Tweens an object. See [Timer.tween](https://hump.readthedocs.org/en/latest/timer.html#Timer.tween) for more details.### Combinators
Combinators take in actions, compose them, and return new actions that can be further composed.
#### `Actions.Sequence(...)`
Takes in a variable number of actions, and returns a new action which plays them all in sequence.
#### `Actions.Parallel(...)`
Takes in a variable number of actions, and returns a new action which plays them all in parallel. The continuation is invoked when### Creating a Custom Action Primitive
Part of what makes this approach effective is that you can create your own Action primitives. Here are some examples.```lua
function Actions.PlaySource(source)
return function(timer, cont)
love.audio.play(source)
cont()
end
endfunction Actions.DestroyEntity(entity)
return function(timer, cont)
entity:destroy()
cont()
end
end
```