Assigning tags to individual spritesheet frames

I have a multi frame animation using a spritesheet. When the animation stops I would like to reference the current frame by a name. Lets just call it “Frame A”, “Frame B”, and “Frame C”

Now I could just look at sprite.currentFrame and because I created the animation I know which .currentFrame number is “Frame A”.

However I am in a situation where the animation has many “Frame A”, “Frame B”, and “Frame C” all mixed in a crazy order.

Without having to write my code to check if sprite.currentFrame == 1 or 3 or 8 or 15 or 16 or 19…
I would like to say if sprite.currentFrame.tag == “Frame A”

Does anyone here see a way I could accomplish this?

Thanks! [import]uid: 9187 topic_id: 3716 reply_id: 303716[/import]

You should be using sequences instead of animating by frame.

[lua]local spriteSheet = sprite.newSpriteSheetFromData(
“textures/sfinnRun.png”,
require(“textures/sfinnRun”).getSpriteSheetData()
)
spriteFinn = sprite.newSpriteSet(spriteSheet, 1, 20)
sprite.add( spriteFinn, “run”, 1, 8, 1000, 0)
sprite.add( spriteFinn, “stand”, 9, 1, 1000, 0)
sprite.add( spriteFinn, “standStun”, 10, 1, 1, 0)
sprite.add( spriteFinn, “crouch”, 11, 2, 100, 0)
sprite.add( spriteFinn, “crouchStun”, 12, 1, 1, 0)
sprite.add( spriteFinn, “die”, 13, 4, 400, 1)
sprite.add( spriteFinn, “cast”, 17, 1, 400, 0)
sprite.add( spriteFinn, “attack1”, 17, 5, 300, 1)

si = sprite.newSprite(spriteFinn)[/lua]

Then I could use an if statement on the sprite:
[lua]if (si.sequence == “attack1”) then
–Do something.
end[/lua] [import]uid: 11024 topic_id: 3716 reply_id: 11314[/import]

Sorry I wasn’t clear.

I am using sequences. Building on your example.

local spriteSheet = sprite.newSpriteSheetFromData(  
 "textures/framesABC.png",  
 require("textures/framesABC").getSpriteSheetData()  
)  
framesABC = sprite.newSpriteSet(spriteSheet, 1, 60)  
sprite.add( framesABC, "fast", 1, 60, 2000, 0)  
  
abcAnimation = sprite.newSprite(framesABC)  
abcAnimation:prepare("fast")  
abcAnimation:play()  

Notice there are 60 frames in my animation, however I only really have 3 frames (A,B,and C) that are being referenced multiple times in a very specific order inside my spriteSheetData file.

abcAnimation:pause()  

Now I want to see which frame I am on. A, B, or C with out having to reference abcAnimation.currentFrame against my specific order of 60.

If only the frames could be tagged where no matter where in the sequence it lies, abcAnimation.currentFrame.tag would equal “Frame A” or B or C.

I hope I’m explaining correctly. Thanks for your help.
[import]uid: 9187 topic_id: 3716 reply_id: 11317[/import]

I guess there’s presently no real way around it if that’s how you’re going about it. I don’t think Corona has frame-naming functions like Flash. You’re pretty much stuck making a function.

[lua]if (metaInfo:frameTag(abcAnimation.currentFrame()) == “Frame A”) then
–do
end[/lua]

[lua]function metaInfo:frameTag(thisFrame)
if (thisFrame == 33) then
return “Frame A”
elseif (thisFrame == 46) then
return “Frame B”
end
end[/lua] [import]uid: 11024 topic_id: 3716 reply_id: 11318[/import]

Yea that’s what I am doing now. I was hoping to find an easier way because changing one frame in my sequence means having to adjust all the numbers in my tagging function. [import]uid: 9187 topic_id: 3716 reply_id: 11319[/import]