Change :setSequence Spriteanimation

i tried removing mysprite = nil

and it works fine, step nr.2 is fixed , thanks Brent :slight_smile:

but its not behaving good for step nr.3

the code for step nr.3 works alone, but not after implementing this logic.

When i press the button setSequence(“three”) experience run normally but after its finished it calls sequence(“one”)

and there is no code that calls it

Hi @blablu1212,

Actually, there is code which calls “one” again. :slight_smile: Basically this is happening:

  1. You have set up a sprite event listener, and that refers to the function “myListener()” (this is fine).

  2. Within “myListener()”, you listen for the “ended” phase. (this is fine).

  3. The “ended” phase is triggered when any sequence finishes playing. So, when you play sequence “three”, it completes, and then the “myListener()” function plays “one” again.

Brent

Hi @Brent,

I really appreciate your help on this  :slight_smile:

 

Its true what you’re pointing out on nr (3)

So how i solved the issue is by setting what i want to achieve under “next” phase

if event.phase == "next" then self:removeEventListener( "sprite" ) self:setSequence("one") end 

This gets next frame = 2 , do you know how can i ask if frame=5 is ended ,to do all the logic?

 

I was looking at this link about event phases, tried to ask for next many times, but didnt work

http://docs.coronalabs.com/api/event/sprite/phase.html

Hi @blablu1212,

I assume you’ve seen the sprite guide, but in case you haven’t:

http://docs.coronalabs.com/guide/media/spriteAnimation/index.html

In any case, you’ll get much better control of everything if you use both the “event.phase” and “.sequence” of the sprite.

http://docs.coronalabs.com/api/type/SpriteObject/sequence.html

In this way, you can ask (for example), “If this sprite is currently on sequence three (sprite.sequence == 3) , and that sequence finished playing (ended phase), then (switch to another sequence, or stop, or restart the sequence, etc.)”.

Brent

Yeah i was looking around for something like obj.sequence ,i didn’t know its existence

i think this will work, need to try it :slight_smile:

Thanks so much @Brent!