Jump to content

An issue with animations


Zallin
 Share

Recommended Posts

So I`ve encountered the following problem. Say,  I create a number of sprites and add two animations to them.

var icon = game.add.sprite(x, y, 'icon name here', 3);icon.scale.x = icon.scale.y = iconScale;icon.animations.add('create', [0, 1, 2, 3], 12);icon.animations.add('kill', [4, 5, 6], 6);game.physics.arcade.enable(icon);

Later, I change the texture of some sprites 

icon.loadTexture(txt); //texture name defined beforeicon.reset(x, y); // new coordinates of the spritevar anim = icon.animations.getAnimation('create');anim.onComplete.add(callback, this);anim.play();

And here something strange happens : animation just stops at the first frame. Also, it does exist (anim var contains correct reference) and has property "isPlaying" set to true.

This thing happens only with the animation that is defined first, 'kill' animation works normally (if switch them, 'kill' anim won`t work and 'create' will do fine).

 

So I`m kind of frustrated with that behaviour, and I guess that the first animation is somehow overriden when I set new texture to a sprite.

I found that the issue could be solved by adding 'create' animation each time I want to play it : 

icon.loadTexture(txt);icon.reset(x, y); var anim = icon.animations.add('create', [0, 1, 2, 3], 12);anim.onComplete.add(callback, this);anim.play();

But this solution seems to be bad cause of perfomance concerns.

 

So why is this happening and how it could be effectively solved?

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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