Skip to content
FloatingBanana edited this page Dec 28, 2022 · 17 revisions

Introduction

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.

Example

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

Functions

Constructors

animation.newAnimation(imageList, speed, range)

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.


General

All setters returns itself, so you can chain functions.

object:update(dt)

Updates the animation.

dt (number): Delta time.


object:draw(...)

Draws the animation.

... (mixed): The same arguments you would pass to love.graphics.draw(), except the first (texture) argument.


object:play()

Plays the animation. If animation has ended, then the animation will play from start. Returns self (table).


object:pause()

Pauses the animation. Returns self (table).


object:stop()

Pauses the animation and go back to the fist frame. Returns self (table).


object:setLoop(state)

Loops the animation. Returns self (table).

state (boolean): True if animation can be looped, false otherwise.


object:setRewind(state)

Rewind the animation. Returns self (table).

state (boolean): True to rewind animation, false to play normally.


object:setFrame(frame)

Jumps animation to a specific frame. Returns self (table).

frame (number): The frame to jump to.


object:setSpeed(speed)

Defines the animation speed in FPS. Returns self (table).

speed (number): The speed of animation.


object:setRange(range)

Defines the range of animation. Returns self (table).

range (number): The range of animation.


object:isPlaying()

returns whether the animation is playing or not (boolean).


object:isLooping()

returns whether the animation is looping or not (boolean).


object:isRewinding()

returns whether the animation is rewinding or not (boolean).


object:getFrame()

returns the current animation frame (number).


object:getSpeed()

returns the animation speed (number)


object:getRange()

returns the animation range (number).


object:setImage(image, frame)

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.


object:setAllImages(sequence)

Changes the animation sequence. Returns self (table).

sequence (table): A table containing a sequence of drawable objects.


object:getImage(frame)

returns a specific image frame (texture).

frame (number or nil): The selected frame. Defaults to current frame.


object:getAllImages()

Returns all images in the animation (table).


object.onComplete = function(self) end

Calls a function when animation ends, even if animation is looping.


object.onFrameChange = function(self) end

Calls a function when the frame is changed.