Jump to content

delay between animations


pranadevil
 Share

Recommended Posts

hi buddies,

 

 

again me, i just wanna ask u all if in phaser we can have a delay between animations frames?

 

 

any example?  i just wanna introduce a little delay between each frame and then when the animation is complete lauch an event.

 

 

thanks in advance. ;)

 

 

 

the main issue is when you need to call a function when a condition is reached in the uptime function.

example:

 

//inside uptime function

 

 

if(a <B)

{

   //  call a function

    this.launchRocket();

 

}

 

// so uptime function will call the launchRocket function many times ??

Link to comment
Share on other sites

I'm not sure I completely understand what you are asking.  I'm guessing that by "uptime" function you mean "update".  Beyond that, I'm still not quite sure what you wish to do.

 

However, I can say that yes, the update function is going to fire very frequently - up to 60 times per second.  There is already a built-in delay between every time it fires.  There are ways to pause and turn it off, but that is almost certainly not the right way to do what you want to do.  You can indeed call functions from inside update, but they will be called a lot and not far between.  Such functions need to do as little as possible.   Also, if you want the function to only fire under certain conditions, you need to put in an "if" check, which you appear to be doing - but the "if check" itself will execute every time.

 

Here is something that might help.  Inside an "if check" in the update function, you can start a tween.  This gives you an animation whose rate does not need to parallel the animation update loop.  

 

Alternatively, you can manage the flight of a rocket by changing the X and Y properties of the rocket sprite by just a little bit each time in the update function.  Or, you can apply properties to the physics body of the sprite (if you are using physics) that will give it direction without you having to fiddle with it in update every call.

Link to comment
Share on other sites

ok thanks for answering,

 

what i want t reach is... imagine two sprites one moving using the keyboard arrows, the other is static.

im checking in the update function when both are separated by for example 100, using a fuction that check the distance between them. when they are close each other i want to play an animation (both of them are spritesheets in frame 0) so i want to play the animation and X second after that disappear the static sprite to relocate it in other position. think about a cat hunting a mouse when the cat is very close to the mouse it gonna take it and eat it, then the mouse gonna appear somewhere else in the world.

 

my issue is, i can calculate the distance between them and check in the update function when is equal to 10. using a if clause.

i boot the animation but because im using a function called relocate mouse, the uptime function call it several times and then the chaos of mice is unleash.

Link to comment
Share on other sites

I'm not sure what the animation needs to do, but it seems fairly straightforward to do what you want.

 

Each update you check how close the sprites are by comparing x and y values of each sprite.  If they are close enough, run your animation routine... here's the part I am not sure what is needed.  You COULD define a tween for it and give it an onComplete call back function.  That function would reset the x and y position of the static sprite.

 

I should say up front that I am no Phaser expert yet, someone else may have better suggestions.

Link to comment
Share on other sites

im not agree with you, cause your answer is from someone who really knows phaser  :)  :)  :)  :)  thanks for sharing your wisdom and your time!!

while i was waiting for your reply i read a bit and found exactly what you have described !!

 

now i want to know how to start a frame change (of a spritesheet) with a tween and thats all 

Link to comment
Share on other sites

You can stop and restart a tween.  I'm not certain about pause, but it should be in the docs.  You could just make two separate tweens - first part and second part for that matter.

 

As far as starting an animation at a certain from from a tween... if you already know how to start an animation with a certain frame (and this of course is possible) then you could do as I suggested before.  In the onComplete function, start the animation at a certain frame.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...