🖼️ SPRITES#
The sprite
module allows you to load spritesheets and helps with animation.
Note
You can load 2 types of spritsheets:
1. If you have grid/strip like image, use col/rows to specify the number of columns and rows in the spritesheet.
2. Generate a spritesheet with Texture Packer using the ANTIRUINS exporter located in tools/texturepacker
. Read More
Sprite Structure#
A sprite is represented by a table with the following structure:
local SPRITE = {
frames = {}, -- table of frames
uvs = {}, -- table of UV coordinates
cFrame = 1, -- current frame
maxFrame = 1, -- maximum number of frames
direction = 1, -- animation direction
axis = {x=1, y=1}, -- axis for scaling
texture = {}, -- texture object
timer = {}, -- timer handle
stopAnimation = false, -- flag to stop animation
}
Functions#
Creates and returns a new sprite object.spritefile
is the path to the sprite data file. If you're using col/rows, set this to nil.
texture
is the texture object or path to the texture file.
OPTIONAL:col
and row
are specifiy the number of columns and rows in the spritesheet.
Returns a copy of the sprite object.
Draws the sprite at the specified x-y position.
frame
is the frame number to draw.OPTIONAL:
sX
and sY
are scaling factors.
Advances to the next frame in the animation.
Returns the current frame number.
Loops the animation from
startFrom
to endFrame
at the specified speed
.
Plays the animation from
startFrom
to endFrame
at the specified speed
.
Stops the current animation.
Sets the frame number.
Returns the current frame number.
Frees the texture data associated with the sprite.
Returns the width and height of the current sprite frame.