Jump to content

How to get current frame NUMBER (not index) - Phaser Animation


kosmoskolio
 Share

Recommended Posts

Hey guys :)

I've been working on a few cool little games with Phaser and I'have just stumbled upon a problem I can't seem to deal with on my own. Here's the deal:

var animationSequence = [0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 10, 10, 11, 11, 0, 0, 1, 1];
this.hero[i].defaultAnim = this.hero[i].animations.add('default', animationSequence);
this.hero[i].defaultAnim.play(5, true);

 

I am trying to find which is the current frame at the current time. 

If I use .frame or .currentFrame I get the frame INDEX and not the frame NUMBER . Meaning that on the last displayed frame of the animation I will not get 40 but 1. 

I've looked around the AnimationManager but couldn't find animation NUMBER anywhere.

 

I DO need the frame number :) I need to synchronize two actions - the state of the animation and a label and the code will be reused for different heroes so I would prefer to avoid a workaround :) 

 

Thanks in advance :)

Hopefully I will be able to share the games by mid September

Link to comment
Share on other sites

37 minutes ago, charlie_says said:

In the past I've used:


this.hero[i].animations.currentAnim.frame

Hope that helps.

Thanks :) but it doesn't solve the issue. With currentAnim.frame I get the INDEX of the currently displayed image. So if my animation is [0,1,0,1,2]  and I use currentAnim.frame in the update function it will return 0, 1, 0, 1, 2, 0, 1, 0, 1, 2 and so on.

While I need to get 1, 2, 3, 4, 5, 1, 2, 3, 4, 5

I am looking for a way to find how far the animation has progressed and not which is the currently displayed image.

 

 

 

Link to comment
Share on other sites

39 minutes ago, 3ddy said:

Maybe try to use http://phaser.io/docs/2.3.0/Phaser.Animation.html#onUpdate and create some counter. When counter reaches animation length then reset it and count again.

Thanks 3ddy! This did the trick :) 

It was lame on me to clearly see the problem and not try to fix it by creating the counter I needed :)

I will look around to see where can one request a new feature in Phaser. As I believe adding a frameNo would be quite easy.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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