How grids and animations work together
masteranim8 uses a two-step process to build animations:
- Create a Grid: A
Gridobject is used to divide a spritesheet into individual frames (Quads). It handles the math of calculating where each frame is located based on dimensions and borders. - Create an Animation: An
Animationobject is created by passing it a collection of frames (retrieved from aGrid) and timing information.
This separation allows you to reuse the same Grid to create multiple different animations (e.g., a 'walk' animation and an 'idle' animation) from the same spritesheet.
local anim8 = require 'anim8'
local image = love.graphics.newImage('path/to/image.png')
-- 1. Create the grid
local g = anim8.newGrid(32, 32, image:getWidth(), image:getHeight())
-- 2. Create the animation using frames from the grid
local animation = anim8.newAnimation(g('1-8', 1), 0.1)