Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

[SOLVED] Enumerating spritesheet data?
Started by mroberti Dec 09 2011 03:50 AM

No replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

mroberti

[GLOBAL: userInfoPane.html]
mroberti
  • Contributor

  • 308 posts
  • Corona SDK

Hello all!

This isn't necessarily a 'TexturePacker only' question, but here goes. TexturePacker outputs nice, neat SpriteSheet data:

local SpriteSheet = {}
SpriteSheet.getSpriteSheetData = function ()
	return {
		frames = {
			{
				name = "goblinarcher1.png",
				spriteColorRect = { x = 0, y = 0, width = 72, height = 68 },
				textureRect = { x = 363, y = 1254, width = 72, height = 68 },
				spriteSourceSize = { width = 72, height = 68 },
				spriteTrimmed = false,
				textureRotated = false
			},
			{
				name = "goblinarcher2.png",
				spriteColorRect = { x = 0, y = 0, width = 62, height = 75 },
				textureRect = { x = 749, y = 1209, width = 62, height = 75 },
				spriteSourceSize = { width = 62, height = 75 },
				spriteTrimmed = false,
				textureRotated = false
			},
			{
				name = "goblinarcher3.png",
				spriteColorRect = { x = 0, y = 0, width = 65, height = 66 },
				textureRect = { x = 505, y = 1445, width = 65, height = 66 },
				spriteSourceSize = { width = 65, height = 66 },
				spriteTrimmed = false,
				textureRotated = false
			},


is there a way I can enumerate through the above spritesheet data? I'd love to get a table with the 'name' variables and a matching frame# (that I could just add manually to a counter. Am I making sense? I just wanna avoid parsing the XML data to get what I want if I can help it.

End result I'd like to create a table with the data from the spritesheet like so:

1,goblinarcher1.png
2,goblinarcher2.png
3,goblinarcher3.png

etc. etc.

Appreciate any pointers!

Best,
Mario

[SOLVED!]

OK, where you get your spritesheet setup:
require ("sprite")
local sheetData = require "coronaTest"
local data = sheetData.getSpriteSheetData()
local spriteSheet = sprite.newSpriteSheetFromData( "coronaTest.png", data )
local spriteSet1 = sprite.newSpriteSet(spriteSheet, 1, 1)

you just use the 'data' variable like so:
	for i=1,#data.frames do
		print(i..","..data.frames[i].name)
	end
and do whatever you want from there.

Perfect!
uid: 11636 topic_id: 18897 reply_id: 318897



[topic_controls]
[/topic_controls]