Prevent sprite sequences from refreshing?

Hi!

I’m having a little problem with some animations, that keep refreshing.

If the sprite sequence is triggered by an enterFrame listener, the sprite sequence will refresh every frame

AKA it will not show anything but the first sprite in the sequence.

I need to find a way to prevent sprite sequence from playing again , if it has already started playing.

Check when the selected sequence is playing or something like that.

Any suggestions/ ideas?

Hope you use http://docs.coronalabs.com/api/library/display/newSprite.html because old sprite is depreciated.

Take a look at http://docs.coronalabs.com/api/type/SpriteObject/play.html. SpriteObject has play() method to which you can pass listener. In listener argument, event.phase can have phases as follows

  • “began” the sprite began playing
  • “ended” the sprite finished playing
  • “bounce” the sprite bounces from forward to backward while playing
  • “loop” the sprite loops from the beginning of the sequence
  • “next” the sprite plays a subsequent frame that’s none of the above phases

Seems like I can solve this problem by using SpriteObjects.

How exactly can I make them?

Corona docs article about SpriteObjects says that you can make them using display.newSprite().

I have a **local character = display.newSprite(sheet, animationData) **and I have assigned physics and everything to it.

How exactly do I make spriteObject with that?

do what?

Nevermind then…guess I already have the spriteObject created.

My sprite object is “char2sprite”.

and yes, animations are played like this:

char2sprite:setSequence(“name”)

char2sprite:play()

The problem is that certain animation keeps refreshing itself every frame.

Could I maybe remove the listener after the first frame? Just so that animation is triggered once per event phase.

Can I use timer.performWithDelay to remove the event listener from the function?

Ok…so I have stopped the sprite sequence from refreshing by using object.isPlaying.

If object.isPlaying is true, then remove event listener.

Now I must find a way to get that listener back, so the sprites will play the next time that event occurs.

Any suggestions on how to return the listener after it has been removed?

I had a lot of work for school this week, but today I took some time and did some progress on my game again.

It’s 2 o’clock in the morning right now, but I didn’t want to go to sleep until I solve this problem- and I did. Finally.

So…I have this sprite animation that is being played using enterFrame.

I used the spriteObj.isPlaying to check when the animation is playing.

And if it is playing, then removeEventListener  AKA stop refreshing the animation every damn frame.

Then I simply used another function to addEventListener back AKA return it, so that animation (mentioned above) could be triggered again, and NOT work only one time per app launched.

The way I explained it might sound a little confusing. Well…it’s my way of understanding it.

Hope you use http://docs.coronalabs.com/api/library/display/newSprite.html because old sprite is depreciated.

Take a look at http://docs.coronalabs.com/api/type/SpriteObject/play.html. SpriteObject has play() method to which you can pass listener. In listener argument, event.phase can have phases as follows

  • “began” the sprite began playing
  • “ended” the sprite finished playing
  • “bounce” the sprite bounces from forward to backward while playing
  • “loop” the sprite loops from the beginning of the sequence
  • “next” the sprite plays a subsequent frame that’s none of the above phases

Seems like I can solve this problem by using SpriteObjects.

How exactly can I make them?

Corona docs article about SpriteObjects says that you can make them using display.newSprite().

I have a **local character = display.newSprite(sheet, animationData) **and I have assigned physics and everything to it.

How exactly do I make spriteObject with that?

do what?

Nevermind then…guess I already have the spriteObject created.

My sprite object is “char2sprite”.

and yes, animations are played like this:

char2sprite:setSequence(“name”)

char2sprite:play()

The problem is that certain animation keeps refreshing itself every frame.

Could I maybe remove the listener after the first frame? Just so that animation is triggered once per event phase.

Can I use timer.performWithDelay to remove the event listener from the function?

Ok…so I have stopped the sprite sequence from refreshing by using object.isPlaying.

If object.isPlaying is true, then remove event listener.

Now I must find a way to get that listener back, so the sprites will play the next time that event occurs.

Any suggestions on how to return the listener after it has been removed?

I had a lot of work for school this week, but today I took some time and did some progress on my game again.

It’s 2 o’clock in the morning right now, but I didn’t want to go to sleep until I solve this problem- and I did. Finally.

So…I have this sprite animation that is being played using enterFrame.

I used the spriteObj.isPlaying to check when the animation is playing.

And if it is playing, then removeEventListener  AKA stop refreshing the animation every damn frame.

Then I simply used another function to addEventListener back AKA return it, so that animation (mentioned above) could be triggered again, and NOT work only one time per app launched.

The way I explained it might sound a little confusing. Well…it’s my way of understanding it.