How to reverse spritesheet animation direction?

Hi all, I have the code below which animates four images contained in a spritesheet when the image is touched, starting with image 1 and stopping on image 4.

What I really would like to do would be to start with image 4 showing on the screen and, when it’s tapped, start the animation backwards so that it ends with image 1.

Thanks in advance for any advice,

Laddsa

[code]
require(“sprite”)
display.setStatusBar(display.HiddenStatusBar)

function touchimage (event)
if (event.phase ==“began”) then
event.target:prepare(“forward”)
event.target:play()
end
end

local data = require(“images”).getSpriteSheetData()
local sheet = sprite.newSpriteSheetFromData(“images.png”,data)

local myimage = sprite.newSpriteSet(sheet,1,4)
sprite.add( myimage, “forward”, 1 ,4, 350, 1)

local card = sprite.newSprite(myimage)
card.x = 60
card.y = 100

myimage:addEventListener( “touch”, touchimage)
[/code] [import]uid: 25313 topic_id: 9741 reply_id: 309741[/import]

I believe [lua]sprite.add( myimage, “forward”, 4 ,-4, 350, 1)[/lua] should do the trick. I remember seeing something about it in the docs but it’s a pain in the ass to check on a smartphone. [import]uid: 51516 topic_id: 9741 reply_id: 35497[/import]

Hi many thanks for the code - I tried it, but unfortunately got the following error message: ‘sequence frames must be inside the sheet’.

I also checked the API refernce area of the website just now and it gives the same line of code too, so am surprised that it didn’t work.

Might be a problem with my spritesheet, I’ll recreate it and try again!

Best wishes,

Laddsa
[import]uid: 25313 topic_id: 9741 reply_id: 35505[/import]

Actually use your code “sprite.add( myimage, “forward”, 1 ,4, 350, 1)” but change the code to “sprite.add( myimage, “forward”, 1 ,4, 350, -1)” for one time back and forth or “sprite.add( myimage, “forward”, 1 ,4, 350, -2)” for continuous back and forth. [import]uid: 24502 topic_id: 9741 reply_id: 35521[/import]

Thanks tomchristman24447,

That’s close to what I would like as it plays the direction backwards when it gets to the last image frame, but ideally what I require is just the animation starting at image 4 and going backwards when it’s tapped. Do you think this is possible?

Best wishes,

Laddsa [import]uid: 25313 topic_id: 9741 reply_id: 35535[/import]

It might be easier to modify the sprite sheet to include the images backward at the end. [import]uid: 24502 topic_id: 9741 reply_id: 35556[/import]

Ah yes, good idea, I think that’s the best way to proceed.

Many thanks,

Laddsa [import]uid: 25313 topic_id: 9741 reply_id: 35634[/import]

So at the moment, there is no way of reversing the order of the animation through code? [import]uid: 70056 topic_id: 9741 reply_id: 57433[/import]