Jump to content

Sprite Animation Issues


Rob Tarr
 Share

Recommended Posts

I'm trying to get a feel for Phaser, writing a simple game where two tanks drive around to random points and will damage each other when they collide. I wanted to add an animation to the collision, but the sprite animation leaves every frame on the page, and then doesn't go away when I'm done. I put the code on Codepen (http://codepen.io/robtarr/pen/LVEgrW), but the animation there seems to completely break everything so I commented it out. Any help would be greatly appreciated.

 

 

Thanks,

Rob

Link to comment
Share on other sites

What you're doing in the code is creating a new sprite, assigning and animation to it and then playing it. This is fine, but no-where do you then remove the sprite once the animation has complete, so over time it's going to build up these sprites all over the place.

 

You ideally ought to pool the explosion sprites, like in the Phaser Examples for Invaders and Tanks, then grab the first dead explosion, position it and play it. You can find code for this on the web site. Alternatively you could use the animation onComplete event, listen for this and then destroy the explosion sprite when it happens. Personally I'd pool them though.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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