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.
For more information see Advanced Animation Using Sprites.
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.
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.
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.
This is awesome! Just what I needed!
Thanks Corona Dev Dudes!