Nikow Posted May 20, 2015 Share Posted May 20, 2015 Hi, I'm creating an infinite space shooter with background parallax and infinite scroll.There are planets and asteroids wich are created in game randomly . If i let the game on, many minutes after it began, fps are shutting down sooo fast, and after many minutes again, the game is running with 0 fps... Do you know what is the problem ? All of the groups have :planetes.setAll('checkWorldBounds', true);planetes.setAll('outOfBoundsKill', true);so i d'ont understand.... Thank for all Link to comment Share on other sites More sharing options...
drhayes Posted May 20, 2015 Share Posted May 20, 2015 checkWorldBounds and outOfBoundsKill can be kind of expensive, but I'm wondering about your planets. From the documentation of Sprite.kill: Note that killing a Game Object is a way for you to quickly recycle it in an object pool, it doesn't destroy the object or free it up from memory. I wonder if those planets you're randomly creating are still hanging around? As in, you should probably make a few at the beginning of the game then re-use them when they're dead instead of making more? Phaser.Group#getFirstDead is a great way of recycling display objects like sprites if they're already in a group (like your group "planetes"). Link to comment Share on other sites More sharing options...
Nikow Posted May 21, 2015 Author Share Posted May 21, 2015 Hi ! I will look at this ! 'getFirstDead' seems to be a good way. If .kill a sprite doesn't free it from memory, how can i do that ? Link to comment Share on other sites More sharing options...
Skeptron Posted May 21, 2015 Share Posted May 21, 2015 That's a good question! Is the JS keyword delete enough? Link to comment Share on other sites More sharing options...
Tom Atom Posted May 21, 2015 Share Posted May 21, 2015 Hi, to destroy game object like sprite, call destroy() on it... But, if you know you will one planet destroy and other generate in the same time, then this is not good idea. It is better then call kill() and revive it as drhayes suggested. Read this tutorial by Rich: http://www.photonstorm.com/phaser/phaser-coding-tips-7 Link to comment Share on other sites More sharing options...
Nikow Posted May 21, 2015 Author Share Posted May 21, 2015 Hi ! I just add in ma extanding class : if(this.y > game.height+300) { this.destroy(); }It's works perfectly, but i'm looking for your link, to do this with the better way Link to comment Share on other sites More sharing options...
drhayes Posted May 21, 2015 Share Posted May 21, 2015 If .kill a sprite doesn't free it from memory, how can i do that ? That's a good question! Is the JS keyword delete enough? Nope! JavaScript uses a garbage collector that handles all the memory management for you. It periodically runs when it detects that it can reclaim memory. When it does it looks for data that isn't being referred to from your code. The GC also, catastrophically for us JS gamedevs, "pauses the world" while it does so which would look like your game skipping frames. Certain JS coding styles (e.g. making and throwing away lots of arrays or objects) can wake the beast and cause it to scoop up all the garbage. That's what Rich is talking about when he mentions "object pooling" and using kill vs. destroy. The delete operator is used for deleting properties off of JS objects. You're *usually* better off setting those properties to null instead of deleting them. Most JS interpreters will inflict a performance penalty for switching properties around like that. Link to comment Share on other sites More sharing options...
Recommended Posts