Chaining animation together not working

Hey, i’m completely new to Corona. I’m using Texture Packer to create sprite sets (but I believe that this is neither here nor there). I basically have some code that, would when the user presses a button, will run one animation. I want it to be able to run one animation followed by another one, but I am not able to get this to work. It basically will only run the second animation (or at least that is all I see).

  
local spriteSet = sprite.newSpriteSet(characterSheet, 1, 23)  
 sprite.add( spriteSet, "left\_turn", 1, 3, 1000, 0)  
 sprite.add( spriteSet, "right\_turn", 8, 1, 1000, 0)   
 sprite.add( spriteSet, "left\_move", 10, 7, 1000, 0)  
 sprite.add( spriteSet, "right\_move", 17, 7, 1000, 0)  
 sprite.add( spriteSet, "prone", 4, 1, 1, 0)  
  
-- move code...  
  
function leftArrow:touch(event)  
 motionx = -speed  
 motiony = 0   
 if dude.direction == "right" then -- "direction" is custom field, dude is facing right  
 dude:prepare("left\_turn")  
 dude:play() -- i'm not seeing this  
 dude:prepare("left\_move")  
 dude:play()  
 end   
end  
leftArrow:addEventListener("touch",leftArrow)  

Any help at all would be great. Ta [import]uid: 125022 topic_id: 29739 reply_id: 329739[/import]

Ok, you have to understand how Corona SDK works. It is not “linear” like you are thinking.

Any code that you write executes in-between screen frame updates that happen every 1/30th or 1/60th of a second. What you have to do is do the :prepare and leave it alone to run for the 1000 milliseconds that the animation has (or more, since it is looping). When you’re ready to change the animation, you do another :prepare. That has to happen either on a timer being fired, on an onComplete of a transition, or on a sprite listener. Then you again leave it alone to run.

What you have up there prepares the animation, *does not* give it time to run, immediately prepares another animation, then leaves it to play. You see why you’re seeing only the second one.

In general, a Corona program doesn’t start at the top, then executes to the bottom and stops, like a Fortran program would :slight_smile: You set things up the right way, then your various functions wait to be notified by various methods (timer, event listeners, transition onCompletes etc) that something happened, execute some code in response to the notification (quickly, not to slow down the action), then return and the wait continues. A lot of things (sprites animating, things moving during transitions, physics actions) happen by themselves during those “wait” times, without your code having to perform those things. Sometimes you have to do special animations in the space inbetween the video “frames” (that happen 30 or 60 times a second) - look at the Runtime “enterFrame” event listener documentation.

Often I find that a “state machine” model works well with the way Corona SDK is set up. [import]uid: 160496 topic_id: 29739 reply_id: 119359[/import]

thanks for the explanation. i’ll take a look and see what i can find :o) [import]uid: 125022 topic_id: 29739 reply_id: 119789[/import]

thanks for the explanation. i’ll take a look and see what i can find :o) [import]uid: 125022 topic_id: 29739 reply_id: 119789[/import]