Jump to content

Big problem > LAGG > Need help.


Nikow
 Share

Recommended Posts

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

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

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

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

 Share

  • Recently Browsing   0 members

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