Easy Sprite!
This module is a forked version and spiritual successor of SimpleSprite by @0bBinary. With added quality of life changes and bugfixes.
This has been designed with the intent to be as lightweight as possible, non-intrusive and easily expandable.
I’m also developing a game which utilizes this module, so I will personally maintain it.
Features:
- It abstracts (simplifies) the grid math used in Sprite Sheets so you don’t have to deal with it.
- Allows you to flip images!, save space in your sprite sheet for left-right animations.
- Comes bundled with a module that allows you to set custom playback (fps) for your spritesheets
- The library is strictly typed, it’s unlikely you will need to look at the API.
- Lightweight, in total it’s around ~200 lines of code
- Can be used from Server or Client
Differences from SimpleSprite
- No restrictions to sizing your ImageLabel object, can use either scale or offset
- No naming of cells
- No lists (replaced by SpriteSequencer)
- Animation Playback speed based on fps rather than waitLength
- Only ImageLabel support.
Usage:
This only has two objects: SpriteSheets and Sequences
local EasySprite, SpriteSequence = require(pathToEasySprite), require(pathToSpriteSequencer)
--lets create our spritesheet:
local mySpriteSheet = EasySprite.new(
ImageLabel,
'rbxassetid://00000000000', --assetId of the texture
Vector2.new(700, 700), --pixel dimensions of the texture (width, height)
Vector2.new(100, 100) --pixel cell size (width, height)
)
mySpriteSheet.display(1) --displays the first cell (counted from left to right)
mySpriteSheet.flip() --flips the spritesheet horizontally
--[[ now lets playback our sprite sheet!
create a sequence from cell 1 to 10 ]]
local mySequence = SpriteSequence.fromRange(mySpriteSheet, 1, 10)
mySequence.play(framesPerSecond, isLooping)
task.wait(5)
mySequence.stop()
API:
EasySprite.luau
--creates spritesheet
handler.new(ImageLabel, assetId: string, imgSize: Vector2, cellSize: Vector2)
SpriteSheet.display(cell: number) --shows cell at position
SpriteSheet.flip() --flips cell horizontally
SpriteSheet.isFlipped(): boolean --true if currently flipped
SpriteSheet.extend(spritesheet2) --appends all cells to the end of SpriteSheet
SpriteSheet.totalCells --the total cells in the sheet
SpriteSheet.currentCell --currently displaying cell
SpriteSequencer.luau
--creates sequence from list of cells
handler.new(spritesheet, cells: {number}): Sequence
--creates sequence from range
handler.fromRange(spritesheet, from: number, to: number): Sequence
Sequence.play(fps: number, looping: boolean): void
--[[NOTE: playing more than one sequence on a single image label
simply overwrites the previous one]]
Sequence.stop(): void
Sequence.isPlaying(): boolean
This is my first ever published resource, hope you enjoy!