kosmoskolio Posted August 15, 2016 Share Posted August 15, 2016 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 More sharing options...
charlie_says Posted August 16, 2016 Share Posted August 16, 2016 In the past I've used: this.hero[i].animations.currentAnim.frame Hope that helps. Link to comment Share on other sites More sharing options...
kosmoskolio Posted August 16, 2016 Author Share Posted August 16, 2016 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 More sharing options...
3ddy Posted August 16, 2016 Share Posted August 16, 2016 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. kosmoskolio 1 Link to comment Share on other sites More sharing options...
kosmoskolio Posted August 16, 2016 Author Share Posted August 16, 2016 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 More sharing options...
charlie_says Posted August 16, 2016 Share Posted August 16, 2016 sorry @kosmoskolio (although, glad you've found a solution) my other suggestion would be, although it's less optimal, would be to create separate graphics for all the frames so they have a unique index. kosmoskolio 1 Link to comment Share on other sites More sharing options...
stupot Posted August 16, 2016 Share Posted August 16, 2016 try: this.hero[i].defaultAnim._frameIndex Link to comment Share on other sites More sharing options...
Recommended Posts