jjwallace Posted May 31, 2017 Share Posted May 31, 2017 I have a fish game and i add fish and remove them using destroy. The game gets slower as more and more fish are eaten and removed and added again. Is there a way to destroy the prototype and everything inside? I checked memory leaks and it seems its the CPU that is having trouble not memory Link to comment Share on other sites More sharing options...
samid737 Posted May 31, 2017 Share Posted May 31, 2017 Im not an expert on this, so im also interested to know what is going on. Maybe its the destroy function call itself that builds up processing time (if there are alot of fish, lot of garbage collection)? Are there any functions you apply to each fish right before they are destroyed / just after they are added to the game? This topic contains some more info related to your case: Link to comment Share on other sites More sharing options...
jjwallace Posted June 1, 2017 Author Share Posted June 1, 2017 So what i found is that after my fish is eaten (alive=false) he falls to the bottom and off the screen (active=false) so i found even after deleteing the sprite the object is being push farther and farther along the Y. This causes the drawable area or something larger and larger and so i was able to stop the prototype from making these calculations. I still wana destroy it if i can. I tried setting it to null but it hates that. Link to comment Share on other sites More sharing options...
samid737 Posted June 1, 2017 Share Posted June 1, 2017 You could add some flag inside your prototype function that idles the execution. Maybe some boolean/flag property i.e. fish.isDead=true and add onDestroy to distpatch that signal? Link to comment Share on other sites More sharing options...
jjwallace Posted June 1, 2017 Author Share Posted June 1, 2017 Very interesting, that is kinda what i have now without the onDestroy. I wish there was a way to completely obliterate it though. Link to comment Share on other sites More sharing options...
Odk Posted June 1, 2017 Share Posted June 1, 2017 Is there any reason that you want to destroy fish object? Normally to reduce cost of spawning new object you create group of fish objects, set them all to dead state. When you need to spawn new fish just call: https://photonstorm.github.io/phaser-ce/Phaser.Group.html#getFirstDead set x,y coordinates, etc and make fish alive again. With this way you will only need as many fish objects as maximum you want on screen at once. Creating new sprite cost resources, try to avoid it if possible. Link to comment Share on other sites More sharing options...
Arcanorum Posted June 1, 2017 Share Posted June 1, 2017 ^ To note, if you wish to research further, this concept is called object pooling and is a must have for any game where you are reusing the same kinds of things a lot. Link to comment Share on other sites More sharing options...
Recommended Posts