×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.821 | Released: 23 May 2012, 2:01am | What's New | Download Now

Sprite Sheets

Overview

Sprite sheets are 2D animations packed as multiple frames into a single texture image. This allows a much more efficient use of texture memory, which is highly limited on mobile devices, and also minimizes loading time.

Corona supports two types of sprite sheets: those whose animation frames are all sized and positioned uniformly, and those whose frames have non-uniform sizes and positions. In the former case, you simply provide Corona with the width and height of each frame in the sprite sheet image file to create a new internal representation of the sprite sheet. The JungleScene sample project that ships with Corona SDK, is an example of a sprite sheet with uniformly-sized frames

In the other case, the positions and sizes of individual frames within the sprite sheet are described by an external data file that can be exported from several sprite sheet generator tools (such as Zwoptex or TexturePacker). Corona lets you easily create an internal sprite sheet object from a sprite sheet image and its accompanying data file. The HorseAnimation sample project contains frames with non-uniform sizes and positions.

More Information

For more information see Advanced Animation Using Sprites.

Replies

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gammabeam
User offline. Last seen 40 weeks 4 days ago. Offline
Joined: 9 Nov 2010

This is awesome! Just what I needed!
Thanks Corona Dev Dudes!

hima
User offline. Last seen 1 year 1 week ago. Offline
Joined: 8 Apr 2010

I don't quite understand the use of this. I tried it and it's really confusing. Could you please provide more example?

Also, will there be anyway to refer to a frame with a frame's name? This is more useful than refering to the frame by number and Zwoptex already generate a frame's name for you.

Ninja Pig Studios's picture
Ninja Pig Studios
User offline. Last seen 10 hours 30 min ago. Offline
Joined: 26 Jan 2011

Is there anyway you guys can make a Youtube video on these Sprite codes? I would love to learn and tis isn't that straight forward.

llamachiselme
User offline. Last seen 5 weeks 5 days ago. Offline
Joined: 21 Jan 2011

I've managed to get this partly working.

When you do sprite.add the second and third sprite sheets need to be referenced by advancing the starting frame to where your sprite sheet is.

So in the above example, to access the different elements you would put

sprite.add( spriteSet2, "oddSheet1",1,5, 1000, 0 ) --
sprite.add( spriteSet2, "oddSheet2",6,3, 1000, 0 ) -- Start frame is 6 to go past the 5 frames in first oddSheet
sprite.add( spriteSet2, "evenSheet",9,4, 1000, 0 ) -- Start frame is 9 to go past the 8 frames in first two oddSheets

Then to access

local instance1 = sprite.newSprite( spriteSet2 )
instance1:prepare("oddSheet2") -- Start on the second animation
instance1:play()

Then to change animation

instance1:prepare("evenAnimation") -- Change to third animation
instance1:play()

etc etc

At least thats what I've found out through trial and error, is this correct? I've no idea and I couldn't find anything else in the docs

The only thing is I seems to get 1 frame of the first sheet when I first start the animation, but only once.

This means you can't start it on the second sheet, but can change sheets seamlessly after its going.