The time to start working with spritesheets has come for me and I have a hard time mastering them.
I am using TexturePacker, but I guess it’s the same with Zwoptex.
According to the documentation you have to follow these steps for setting up an animation of “mysprite” that has 8 frames:
[lua]require “sprite”
local mysprite = sprite.newSpriteSheetFromData( “out.png”, require(“out”).getSpriteSheetData() )
local spriteSet = sprite.newSpriteSet(mysprite,1,8)
sprite.add(spriteSet,“myAnimation1”,1,8,1000,0)
local spriteInstance = sprite.newSprite(spriteSet)
spriteInstance:setReferencePoint(display.BottomRightReferencePoint)
spriteInstance.x = 200
spriteInstance.y = 200
spriteInstance:prepare(“myAnimation1”)
spriteInstance:play()[/lua]
However, I am not interested on animations at all. I would like to give Corona a SpriteSheet from TexturePacker that includes several 1-frame character sprites and call them by name. TexturePacker reads the image files that I have in my assets folder and keep this information in the spritesheet.lua file for Corona.
So, using spritesheets, how would I setup and display a single-framed sprite that has been stored to image “seeker.png” and is included to “out.png” spritesheet that TexturePacker makes? Isn’t there a way to retrieve the sprite by image name from the container spritesheet?
… I have managed to display the sprite using:
[lua]require “sprite”
local mysprite = sprite.newSpriteSheetFromData( “out.png”, require(“out”).getSpriteSheetData() )
local spriteSet = sprite.newSpriteSet(mysprite,4,1) --desired sprite has is indexed 4th in out.lua
local spriteInstance = sprite.newSprite(spriteSet)
spriteInstance:setReferencePoint(display.BottomRightReferencePoint)
spriteInstance.x = 200
spriteInstance.y = 200[/lua]
…but I suspect there is a shorter way to do this and by using image names instead of arithmetic indexes. Isn’t there?
From documentation :
“In either case, creating a new sprite sheet object does not actually result in anything being added to the display list. To do that you need to create a sprite (and optionally sprite sets) from your sprite sheet object.”
EDIT: I found a solution to get sprites by image names. So the question is whether a spriteSet is indeed necessary or not, for a single-framed sprite. [import]uid: 7356 topic_id: 2636 reply_id: 8985[/import]