Play animations in a row

Hi everybody!
Im working on some tool, that will allow me to import animations for displayObjects from xml file.

now, the main loop for playing animation looks this way(tweak exmple from http://developer.anscamobile.com/content/animation#comment-42405):
[lua]frameInc = 1
pass = function()
if frameInc frameInc = frameInc + 1
transition.to(self.image, {time=self.Animation.TimePerFrame, onComplete=pass, x= self.image.x + v.Frames[frameInc].Pos[1], y= self.image.y + v.Frames[frameInc].Pos[2] … etc)
end
end
pass()[/lua]
it loops thgough the frames and move sprite in series.
everything works like a charm… BUT :slight_smile:
if i want play animation few times in a row, by calling
obj:play(animFile)
obj:play(animFile)
obj:play(animFile)
it start all function simultaneously and sprite moves strange.
And i want it to plays in order. one by one.
Can somebody help me, please?Maybe, i choose wrong technique to play animation at all? [import]uid: 41345 topic_id: 12761 reply_id: 312761[/import]

Now I haven’t tested this and I’m a little groggy after a long day, but I believe this should work - try it and let me know, if it doesn’t I shall take a good look at it in the morning :slight_smile:

[lua]local function multiPass (event)
frameInc = 1
pass = function()
if frameInc frameInc = frameInc + 1
transition.to(self.image, {time=self.Animation.TimePerFrame, onComplete=pass, x= self.image.x + v.Frames[frameInc].Pos[1], y= self.image.y + v.Frames[frameInc].Pos[2] … etc)
end
end
pass()
end
timer.performWithDelay(5000, multiPass, 10)[/lua]

That would call it 10 times, 5 seconds apart. You’d want to change the 5000 to however long it takes to complete the full cycle. As in, if it takes 10 seconds, do 10,000.

Peach :slight_smile: [import]uid: 52491 topic_id: 12761 reply_id: 46945[/import]

Thanks for answer, Peach! But i did it that way too) i even wrote the function that returned animation duration for me, so i could run performWithDelay with delay equal to animation duration. But i am looking for solving case in which a few animation(maybe different) can spawn in short period of time. And i want them play in a row, one by one…
[import]uid: 41345 topic_id: 12761 reply_id: 46969[/import]

maybe, i need dispatch event or checking somehow if object plays animation at some point of time and wait till it ends before starting new [import]uid: 41345 topic_id: 12761 reply_id: 46970[/import]