Jump to content

Multiples particules, FPS gradually decreasing


bilboon
 Share

Recommended Posts

Hi, 

 

I did some tests with the sample rain effect which creates a lot of particules. My dev env : phaser-dev branch, latest chrome, linux. I used a modified version of the rain emitter (no loop, its stops after 100 particules emitted): i launched it 10, 20, 30 times... Game objects count is incrising and i quickly have thousands of inactive objects in game objects group. FPS is decreasing : starting from ~30/40 fps, it ends at ~ 15/20 fps, and fps is never upping after that even if there's no animation played.

 

Code of emitter:

var emitter = game.add.emitter(game.world.centerX, 0, 400);emitter.width = game.world.width;emitter.makeParticles('rain');emitter.maxParticleScale = 1.5;emitter.minParticleScale = 0.5;emitter.setYSpeed(500, 800);emitter.setXSpeed(-5, 5);emitter.minRotation = 0;emitter.maxRotation = 0;emitter.start(false, 600, 2, 100);

Is it a normal behavior ?

 

Must i systematically destroy emitter at the end of the animation ? Can i use the onComplete callback for that ?

 

May be the phaser preferred way is defining a pool of emitters and recycling them ? But if i have a lot of different effects, i will be facing the same issue with a majority of one shot effects in my pool.

 

Am i wrong, does somebody expreriencing the same problem or have advice / use case about that ?

 

Thanks a lot.

Link to comment
Share on other sites

Emitters are just groups with some extra functions on them to make using particles really simple.

Every time you run that code you have there, you are generating another 400 sprites. 

Every time you call makeParticles, the emitter does just that. It makes more particles.As you are not specifying how many to make, it is making the full 400 you set in the first line.

 

There is no real need to destroy the emitter once it is finished. Reusing emitters and their particles is simple.

Groups have functions for iterating over their children, such as forEach, that you can use to change the texture of the particles, or the frame of the particles, if that's how you doing things.

 

Maybe start looking at using one emitter per effect, but use a lower amount of particles for each one. If an effect only needs 10 particles, only give it 10.

Link to comment
Share on other sites

Ok thx a lot for the response. 

 

You say there's "no real need to destroy emitter", but the fps has decreased even if there's no animation played like if the old inactive emitter/particles had an incidence on phaser velocity.

 

Sample use case : blood effect, which can be used simulteany on different sprites (attack zone). If 5 sprites are shot at the same time, I need 5 "blood" emitters. Acquiring/releasing/creating emiter from a pool seems to me overcomplexe for a basic use case.

 

I gonna try to destroy everything to see if it makes difference.

Link to comment
Share on other sites

Or, instead of 5 blood emitters, use one. Have it emit particles, move the emit position and emit more, repeat until all effects are started.

 

 

EDIT:

Here is how I did that very thing, except I was emitting dust particles instead of blood.

//emitLocations is an array of objects {x:0, y:0, width:0}for ( var ii = 0; ii < emitLocations.length; ii++ ){    //Set the location to emit particles    emitters.dust.emitX = emitLocations[ii].x;    emitters.dust.emitY = emitLocations[ii].y;    emitters.dust.width = emitLocations[ii].width;    //Start will prepare the emitter to emit particles, but not actually do it...    emitters.dust.start(true, 1250, null, 6);    //Update is where the particles are assigned properties. As I am exploding things, all particles are emitted at once.    emitters.dust.update();}
Link to comment
Share on other sites

Thx a lot for this excellent use case ! Emitter usage is now much much clear. I adapted the max number of particules in my emitter to the max number of simultaneous displayed burst and created singleton emitter per effect. Inactive particles stayed in phaser but the fps is not dropping so quickly. I think i can live with that for the moment and later try to force old emitters GC if it's an issue.

 

May be it could be interesting to add a note about the "recycle pattern" in doc, cause it seems like a way to go in phaser (or maybe i am just a noob who didn't search very well).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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