Sprite.lua
Jump to navigation
Jump to search
sprite.lua is a library for creating high-level animated custom sprites with movement abilities. It requires LunaLua v0.7.1.
Installation
Copy the sprite.lua file in the LuaScriptsLib folder.
How to use and Examples
To enable the sprite library for a specific level, add this line to lunadll.lua:
local SpriteAPI = loadAPI("sprite");
This will load the Sprite API.
Creating an animated sprite from multiple images
First of all you want load your images in a table:
local myImages = {
Graphics.loadImage(Misc.resolveFile("frame1.png")),
Graphics.loadImage(Misc.resolveFile("frame2.png")),
Graphics.loadImage(Misc.resolveFile("frame3.png"))
}
local myAnimationSet = SpriteAPI.animationFromImages(myImages)
local mySprite = SpriteAPI.sprite(myAnimationSet, SpriteAPI.COOR_CAMERA, 100, 100)
mySprite:show()
This is the easiest way to get an animated sprite. But you will see that the animation goes insanely fast. To fix that you can add this line:
mySprite:setFrameSpeed(8)
With this line only every 8 frames a frameswitch is happening.