Module anim
Animation library.
This library gives you functions to animate a variable from one value to another.
You can group and chain multiple animations, for instance grouping two animations that
animate the x and y positions of an object.
How anim interpolates between the two values are set by animation styles such as linear, quadIn etc.
To load do the following.
anim = require 'anim/anim'
function love.update(dt)
anim:update(dt)
end
Release: 2010-02-26 Version 1
Functions
anim.chain:new (...) | Creates an animation chain that plays multiple animations one after another. |
anim.chain:onFinish (...) | Callback function when the last animation in the chain finishes |
anim.chain:pause () | Pauses the animation chain |
anim.chain:play () | Plays/resumes the animation chain. |
anim.group:new (...) | Creates an animation group which can hold individual animations. |
anim.group:onFinish () | Callback function when all the animations in the group have finished |
anim.group:pause () | Pauses all the animations in the group |
anim.group:play () | Plays/resumes all the animations in the group together |
anim.group:reverse () | Reverses all the animations in the group |
anim.group:setTime (time) | Sets the time period of every animation in the group |
anim:easy (table, key, start, finish, time, style) | Convenience function for anim:new(). |
anim:finish () | Finish the animation. |
anim:moveTo (object, x, y, time, style, delay) | Animates an object from it's current position to another. |
anim:new (anim_table) | Create a new animation instance. |
anim:onFinish () | Callback function when the animation is finished. |
anim:onPause () | Callback function when anim:pause() is called |
anim:onPlay () | Callback function when anim:play() is called |
anim:pause () | Pause the animation. |
anim:play () | Plays or resumes the animation |
anim:reverse () | Reverse the animation. |
anim:update (dt) | Updates all animations, use inside love.update(). |
Tables
anim_table | An animation table |
styles | List of animation styles you can use. |
Examples
Sliding text | Animate text to slide in from offscreen. |
Functions
- anim.chain:new ( ... )
-
Creates an animation chain that plays multiple animations one after another.
Parameters
-
...
a list of animations to chain, in order.
Return value:
table: an animation chain.
-
...
- anim.chain:onFinish ( ... )
-
Callback function when the last animation in the chain finishes
- anim.chain:pause ( )
-
Pauses the animation chain
- anim.chain:play ( )
-
Plays/resumes the animation chain.
- anim.group:new ( ... )
-
Creates an animation group which can hold individual animations.
Parameters
-
...
multiple animations to group.
Return value:
table: an animation group.
-
...
- anim.group:onFinish ( )
-
Callback function when all the animations in the group have finished
- anim.group:pause ( )
-
Pauses all the animations in the group
- anim.group:play ( )
-
Plays/resumes all the animations in the group together
- anim.group:reverse ( )
-
Reverses all the animations in the group
- anim.group:setTime ( time )
-
Sets the time period of every animation in the group
Parameters
-
time :number
time in seconds.
-
time :number
- anim:easy ( table, key, start, finish, time, style )
-
Convenience function for anim:new(). Creates an animation instance.
The animation will automatically play.Parameters
-
table :table
The table holding the value you wish to animate. -
key :string
The key's value you wish to animate. -
start :number
The starting value. -
finish :number
The finishing value. -
time :number
The time it takes for the animation to complete. (In seconds) -
style :string
The style of the animation.
Return value:
table: An animation instance.
See also:
-
table :table
- anim:finish ( )
-
Finish the animation. (Instantaneus)
- anim:moveTo ( object, x, y, time, style, delay )
-
Animates an object from it's current position to another.
The object must have x and y keys!
The animation will automatically play.Parameters
-
object :table
An object with 'x' and 'y' keys. -
x :number
The target x position. -
y :number
The target y position. -
time :number
The time it takes for the animation to complete. (In seconds) -
style :string
The style of the animation. -
delay :number
The time it waits before starting the animation. (In seconds)
Return value:
table: An animation instance.
See also:
-
object :table
- anim:new ( anim_table )
-
Create a new animation instance.
Parameters
-
anim_table
A table of animation paremeters.
Usage:
new_animation = anim:new{
table = myTable,
key = 'x_position',
start = 12,
finish = 120,
time = 4,
style = 'linear'
}
Return value:
table: An animation instance you can call anim methods on.
See also:
-
anim_table
- anim:onFinish ( )
-
Callback function when the animation is finished.
Usage:
new_anim = anim:new( anim_table )
function new_anim:onFinish()
print('animation finished')
end
- anim:onPause ( )
-
Callback function when anim:pause() is called
See also:
- anim:onPlay ( )
-
Callback function when anim:play() is called
See also:
- anim:pause ( )
-
Pause the animation.
- anim:play ( )
-
Plays or resumes the animation
- anim:reverse ( )
-
Reverse the animation.
- anim:update ( dt )
-
Updates all animations, use inside love.update().
Parameters
-
dt :number
delta time
-
dt :number
Tables
- anim_table
- An animation table
Fields
- table The table to pass to the anim object
- key The key to animate. (table[key] will be animated).
- start The value the animation starts at. (if nil current table[key] value will be used).
- finish The value the animation finishes at. (if nil current table[key] value will be used).
- time The time it takes for the animation to complete. (in seconds, default 1).
- delay The time it takes for the animation to start after calling anim:play(). (in seconds, default 0).
- style The style of the animation. (a string, default 'linear'). See style.
- styleargs Some styles such as 'elastic' can take extra parameters in the form of a table {arg1,arg2}.
- styles
- List of animation styles you can use.
Fields
- linear
- quartIn
- quartOut
- quartInOut
- quadIn
- quadOut
- quadInOut
- expoIn
- expoOut
- expoInOut
- elastic
Examples
- Sliding text
-
Here's how:
anim = require 'anim/anim'
function love.load()
text = { x = -100, str = 'Woo!' }
new_anim = anim:new{
table = text,
key = 'x',
start = -100
finish = 100,
time = 2,
style = 'quadInOut'
}
new_anim:play()
end
function love.update(dt)
anim:update(dt)
end
function love.draw()
love.graphics.print(text.str, text.x, 100)
end