-
Notifications
You must be signed in to change notification settings - Fork 0
animation.lua
There's a lot of good sprite sheet animation libraries, but if you want the traditional frame-by-frame animation then this library may help you.
local Animation = require "grove.animation"
local sequence = nil
function love.load()
local imageList = {}
for i = 1, 20 do
imageList[i] = love.graphics.newImage("images/image"..i..".png")
end
sequence = Animation(imageList, 20, 20)
--Play animation
sequence:setLoop(true):play() --You can chain functions
end
function love.draw()
sequence:draw(300, 100)
end
function love.update(dt)
sequence:update(dt)
end
Create an animation using an image sequence. Returns a sequence animation object.
imageList
(table): A table containing a sequence of drawable objects.
speed
(number): The speed of animation in FPS. Defaults to 30.
range
(number): The range of animation. Defaults to #imageList
.
All setters returns itself, so you can chain functions.
Updates the animation.
dt
(number): Delta time.
Draws the animation.
...
(mixed): The same arguments you would pass to love.graphics.draw(), except the first (texture) argument.
Plays the animation. If animation has ended, then the animation will play from start. Returns self (table).
Pauses the animation. Returns self (table).
Pauses the animation and go back to the fist frame. Returns self (table).
Loops the animation. Returns self (table).
state
(boolean): True if animation can be looped, false otherwise.
Rewind the animation. Returns self (table).
state
(boolean): True to rewind animation, false to play normally.
Jumps animation to a specific frame. Returns self (table).
frame
(number): The frame to jump to.
Defines the animation speed in FPS. Returns self (table).
speed
(number): The speed of animation.
Defines the range of animation. Returns self (table).
range
(number): The range of animation.
returns whether the animation is playing or not (boolean).
returns whether the animation is looping or not (boolean).
returns whether the animation is rewinding or not (boolean).
returns the current animation frame (number).
returns the animation speed (number)
returns the animation range (number).
Changes a specific frame image. Returns self (table).
image
(texture): The image to be placed.
frame
(number or nil): The frame to be changed. Defaults to current frame.
Changes the animation sequence. Returns self (table).
sequence
(table): A table containing a sequence of drawable objects.
returns a specific image frame (texture).
frame
(number or nil): The selected frame. Defaults to current frame.
Returns all images in the animation (table).
Calls a function when animation ends, even if animation is looping.
Calls a function when the frame is changed.