Jump to content

currentFrame is undefined for second animation on the same sprite


Yerko
 Share

Recommended Posts

I'm trying to create a sprite with two animations. The first animation play constantly, and the second one after some events, then stop and the first keep playing.

I'm loading an atlas like this

game.load.atlas('girl', '../../spritesheet.png', '../../sprites.json')

where game is my Phaser.Game instance. Then I'm creating animations like this

girlSprite.animations.add('idle', window.Phaser.Animation.generateFrameNames('idle', 1, 16), 5, true)
girlSprite.animations.add('walk', window.Phaser.Animation.generateFrameNames('walk', 1, 20), 20, false)

where girlSprite is my character sprite. My animations run like this

girlSprite.animations.play('idle', 16, true)

// some events later

var idleAnimation = girlSprite.animations.getAnimation('idle')
var walkAnimation = girlSprite.animations.getAnimation('walk')

idleAnimation.paused = true
// girlSprite.animations.play('walk', 20, true)
girlSprite.animations.currentAnim = walkAnimation
girlSprite.animations.play('walk', 20, true)

This only pause my first animation and then throw an exception saying currentFrame is undefined. After that I debugged a little and found out that my girlSprite had the second animation with wrong frames defined, because when I created the second animations it used the frameData from the first animation and the currentFrame get never defined.

So, I'm a little lost. I'm doing it right? is there a better method to define multiple animations on the same sprite? Any help would be appreciated

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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