Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

how can I set a sprite frame based on "name" (and not index) - i.e. SpriteObject:setFrame( frameIndex )
Started by greg886 Jul 24 2012 03:38 PM

3 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

greg886

[GLOBAL: userInfoPane.html]
greg886
  • Contributor

  • 913 posts
  • Corona SDK

How can I do a SpriteObject:setFrame but then pass the "name" of the sprite frame I want not the index?

Background
* Have a spritesheet and lua file generated by TexturePacker
* in the lua file there is the use of "name", however when I set the frame I have to pass the index
* the actual sprites within the texture file are out of order too, so it's not as if the 2nd sprite image I added in TexturePacker to be included is actually 2nd in the lua file

currSprite:setFrame(spriteIndex)

local SpriteSheet = {}
SpriteSheet.getSpriteSheetData = function ()
	return {
		frames = {
			{
				name = "1.png",
				spriteColorRect = { x = 20, y = 9, width = 12, height = 26 },
				textureRect = { x = 114, y = 64, width = 12, height = 26 },
				spriteSourceSize = { width = 50, height = 50 },
				spriteTrimmed = true,
				textureRotated = false
			},
			{
				name = "10",
				spriteColorRect = { x = 4, y = 6, width = 36, height = 30 },
				textureRect = { x = 2, y = 66, width = 36, height = 30 },
				spriteSourceSize = { width = 50, height = 50 },
				spriteTrimmed = true,
				textureRotated = false
			},


uid: 140210 topic_id: 29024 reply_id: 329024


[TOPIC: post.html]
#2

danedwar

[GLOBAL: userInfoPane.html]
danedwar
  • Enthusiast

  • 47 posts
  • Corona SDK

You can use the function that is provided in your texturepacker generate .lua file

function SheetInfo:getFrameIndex(name)
    return self.frameIndex[name];
end

You just need to pass the name to this function and it will return the index something like

SpriteObject:setFrame(mysheetInfo:getFrameIndex("theframename"))
uid: 77943 topic_id: 29024 reply_id: 117148


[TOPIC: post.html]
#3

greg886

[GLOBAL: userInfoPane.html]
greg886
  • Contributor

  • 913 posts
  • Corona SDK

oh, I'm using TexturePacker 3 (3.0.0b10) and I don't see in the data file (*.lua) a "getFrameIndex" method defined anywhere?
uid: 140210 topic_id: 29024 reply_id: 117149


[TOPIC: post.html]
#4

davidcondolora

[GLOBAL: userInfoPane.html]
davidcondolora
  • Contributor

  • 171 posts
  • Corona SDK

@greg886: The "getFrameIndex" method should be at the bottom of your texturePacker-generated LUA file, just below the "getSheet" method. 




[topic_controls]
[/topic_controls]