Rob Tarr Posted April 28, 2015 Share Posted April 28, 2015 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 More sharing options...
rich Posted April 28, 2015 Share Posted April 28, 2015 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 More sharing options...
Rob Tarr Posted April 30, 2015 Author Share Posted April 30, 2015 Will passing `true` for `killOnComplete` not remove the sprite when it's done with the animation? What is meant by "parent sprite" in "If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed." Link to comment Share on other sites More sharing options...
Recommended Posts