PRSoluções Posted April 23, 2016 Share Posted April 23, 2016 Hi, I think that i have a memory leak on animation. Every explosion i create 10 explosion objects, and after some time it is growing a lot, see (521 childrens): https://www.dropbox.com/s/pq1hwyixvsunrnt/Screenshot%202016-04-22%2021.09.46.png?dl=0 My code to add animation is: var effect6 = this.groups.underPlayer.create((o.x * GameApp.TILE_SIZE) + (GameApp.TILE_SIZE / 2), (o.y * GameApp.TILE_SIZE) + (GameApp.TILE_SIZE / 2), 'bombFlameSpritesheet001'); effect6.animations.add('default', [, 1, 2, 3, 4], 12); effect6.anchor.set(0.5, 0.5); effect6.play('default', 12, false, true); I have defined TRUE to destroy on finish. Link to comment Share on other sites More sharing options...
PRSoluções Posted April 23, 2016 Author Share Posted April 23, 2016 The sprite is killed, but not destroyed. Have any advantage with it? My problem is solved if i change Phaser source code to: if (this.killOnComplete) { this._parent.destroy(); } There is any method to destroy old animation sprites and remove from three? Thanks. Link to comment Share on other sites More sharing options...
VitaZheltyakov Posted April 23, 2016 Share Posted April 23, 2016 This is a bad practice. If the sprite is attached events, this will result in an error Link to comment Share on other sites More sharing options...
PRSoluções Posted April 23, 2016 Author Share Posted April 23, 2016 Yes, im using: var effect6 = this.groups.underPlayer.getFirstExists(false, true, (o.x * GameApp.TILE_SIZE) + (GameApp.TILE_SIZE / 2), (o.y * GameApp.TILE_SIZE) + (GameApp.TILE_SIZE / 2), 'bombFlameSpritesheet001'); effect6.animations.add('default', [, 1, 2, 3, 4], 12); effect6.anchor.set(0.5, 0.5); effect6.play('default', 12, false, true); But i dont know if is a good practice. Link to comment Share on other sites More sharing options...
drhayes Posted April 23, 2016 Share Posted April 23, 2016 There's a difference between "kill", which is what the last argument to Sprite.play does, and "destroy", which is what your code snippet that you added does. "kill" makes it ready for being used again, while "destroy" removes it from the game entirely, never to be seen again. Link to comment Share on other sites More sharing options...
PRSoluções Posted April 23, 2016 Author Share Posted April 23, 2016 I know. Because this i dont create, i get first avaliable. Link to comment Share on other sites More sharing options...
drhayes Posted April 24, 2016 Share Posted April 24, 2016 I don't understand: you don't want it to create that many objects, but you keep calling create? Why not re-use those explosion objects instead of creating and destroying them? Link to comment Share on other sites More sharing options...
PRSoluções Posted April 24, 2016 Author Share Posted April 24, 2016 I only want know if getFirstExists is the correct way. Link to comment Share on other sites More sharing options...
drhayes Posted April 26, 2016 Share Posted April 26, 2016 I think so, yes. getFirstExists will only work if there are a few non-destroyed sprites in your group. You can create a bunch in the group first. Later, your code can do "getFirstExists" to pull them out. Link to comment Share on other sites More sharing options...
Recommended Posts