Sprite sheets are 2D animations compiled to multiple frames into a single texture image. This is an efficient way to save on texture memory. It is beneficial for mobile devices and minimizes loading time.
The following line makes the sprite features available under the sprite namespace:
require "sprite"
sprite.newSpriteSheet
: The function creates a new sprite sheet.spriteSheet = sprite.newSpriteSheet("myImage.png", frameWidth, frameHeight) -- the width/height of each animation in the sprite sheet
For example, the number of frames in the sprite sheet is assumed to be
floor(imageWidth/frameWidth) * floor(imageHeight/frameHeight)
. The first frame is placed at the top-left position and reads left to right and follows the next row if applicable. The following sprite sheet has 5 frames that are 128 x 128 pixels each. The sprite sheet image altogether is 384 x 256 pixels. If it were to be integrated in Corona, a sample method would be displayed as follows:spriteSheet...