Accessing the "name" in a spritesheet

I’m a Flash/Flex developer enjoying the productivity and fun of programming for Corona but I’m stuck on how to achieve the following:

I’ve created a sprite map using TexturePacker and I see that each of the frames in the descriptor file has a name (the same name as the original graphic). I want to create a single frame sprite using that name - in other words, I’m using a sprite sheet as a convenient way of storing lots of small images rather than having separate pngs.

Is there any way of accessing those frame names rather than having to use sprite numbers?

Kev [import]uid: 95579 topic_id: 16372 reply_id: 316372[/import]

I’ve implemented a workaround using a second table to index the spritesheet (assuming I’ve used “data” as the variable name for getSpriteSheetData());

local index={};
for n=1,#data.frames do
index[n]=data.frames[n].name
end
So now, when I need to pick out a sprite name, I search on the index table, return the index number of the matching name and use that to pull out the sprite from the sheet. A bit clunky but it works - I’d love to hear if there’s a better way! [import]uid: 95579 topic_id: 16372 reply_id: 61063[/import]

Or even better:

local index={};
for n=1,#data.frames do
index[data.frames[n].name]=n
end
Which creates a table indexed by the name of the graphic.

You can then do

local graphic=“tree.png”
sprite.add(set,“tree”,index[graphic],1,1000,1)

[import]uid: 95579 topic_id: 16372 reply_id: 61067[/import]

Hi kevin.partner,

Have you checked out Spriteloq? It’s purpose built to get your Flash graphics into Corona easier. I just pushed out a 1.3.0 update and we have a lower price point if you don’t need the premium support. http://www.loqheart.com/spriteloq/ We have quite a few developers that are really enjoying it.

There’s also extensive documention of the API that makes dealing with all the spritesheet stuff much easier.

http://www.loqheart.com/spriteloq/apidocs/files/loq_sprite-lua.html

[import]uid: 27183 topic_id: 16372 reply_id: 61140[/import]

Not sure how that helps with my problem of not being able to pull out sprites by name! [import]uid: 95579 topic_id: 16372 reply_id: 61143[/import]

You mentioned you’re a Flash/Flex developer, so I figured you might be interested in Spriteloq. Spriteloq’s API has the ability to pull out sprites by name.

Just trying to offer you an alternative to using TexturePacker. [import]uid: 27183 topic_id: 16372 reply_id: 61154[/import]

Kev,

Check out the SpriteGrabber lib from the code exchange, with it you can access sprites by names…

http://developer.anscamobile.com/code/spritegrabber-spritesheets-two-lines [import]uid: 10478 topic_id: 16372 reply_id: 61174[/import]