Jump to content

Low fps... is my game so advanced?


Ulbast
 Share

Recommended Posts

Hi guys, my game was working fine, fluently, etc and I was expanding it. It's platform, where a lot of bullets are flying, also many spikes hang from the upper platforms. Now, when I add more spikes and more bullets, when the turrets shot them, the game drastically slows. Is too many object there? And what can I do to make it faster again?

Creating spikes:

    function create_spikes ( x , y , number, angle, vertical) {
        for (i=0; i < number; ++k, i++)
        {
        if ( vertical != 'yes' ) {
        spikes[k] = game.add.sprite((x+i)*16, y*16, 'kolec');
        }
        else
        spikes[k] = game.add.sprite(x*16, (y+i)*16, 'kolec'); 
        
            
            
        game.physics.enable(spikes[k], Phaser.Physics.ARCADE);
        spikes.enableBody = true;
            
        if ( angle==180 )
        spikes[k].body.setSize(12, 8, -14, -16);
        else
        spikes[k].body.setSize(12, 8, 4, 8);
            
        spikes[k].body.allowGravity = false;
        spikes[k].angle=angle;
        }
    }


//ENEMY BULLETS
    ebullets = game.add.group();
    ebullets.enableBody = true;
    ebullets.physicsBodyType = Phaser.Physics.ARCADE;
    game.physics.enable(ebullets, Phaser.Physics.ARCADE);
    ebullets.createMultiple(50, 'enemy_bullet');
    ebullets.setAll('checkWorldBounds', true);
    ebullets.setAll('outOfBoundsKill', true);

//ENEMY SHOOTING
function enemy_shooting (enemy,type,direction) {
        
        if ( type == 'mortar' && enemy.alive==true) {

            
        nextFire = game.time.now + fireRate;
        var ebullet = ebullets.getFirstDead();
        ebullet.reset(enemy.body.x-20, enemy.body.y-20);
        ebullet.body.velocity.y=-200;
        if ( player.body.x <= enemy.body.x )
            ebullet.body.velocity.x=-200;
        else
            ebullet.body.velocity.x=200;

        }

 

Link to comment
Share on other sites

By increasing amount, as I suspected, its even worse, the game runs slower, because it has more objects to handle...

Bullets are killed with collision with objects, like this:

function resetBullet (bullet) {

    bullet.kill();
    

}

game.physics.arcade.overlap(bullet, sth, resetBullet);

 

Link to comment
Share on other sites

Creating objects while running? As my hero is copying himself every sec. or stth like that?

Everything was working perfectly, since more objects come to life. Now when I'm removing a few bullets, everything goes faster. But it sounds ridiculous if this little amount of objects can slow the whole system...

Link to comment
Share on other sites

Usually when games are slow with many objects, the pool is too small. Try it with no pool, i.e. create a new object every time you need it :)
The amount of objects itself is not very relevant (as long as they don't all have different textures). 10000 objects with the same texture will pretty much render just as fast as 1 object... 

Link to comment
Share on other sites

When the bullet leaves the screen, in next second eventually it collide with wall and die. In addition, checkworldbounds is set true. The shooting look like this:

//CREATE

//ENEMY BULLETS
    ebullets = game.add.group();
    ebullets.enableBody = true;
    ebullets.physicsBodyType = Phaser.Physics.ARCADE;
    game.physics.enable(ebullets, Phaser.Physics.ARCADE);
    ebullets.createMultiple(50, 'enemy_bullet');
    ebullets.setAll('checkWorldBounds', true);
    ebullets.setAll('outOfBoundsKill', true);
    ebullets.forEach(function(bullet){
          bullet.body.collideWorldBounds = true;
      bullet.body.bounce.set(1)});


turret13 = game.add.sprite(145*16, 61*16, 'turret');
    object_create_properties(turret13,'turret');
    
    turret14 = game.add.sprite(145*16, 67*16, 'turret');
    object_create_properties(turret14,'turret');
    
    turret15 = game.add.sprite(145*16, 71*16, 'turret');
    object_create_properties(turret15,'turret');


//TIMER
game.time.events.loop(1000, turrets_shot, this); //turrets shooting


//IN FUNCTIONS:

function turrets_shot() {
         enemy_shooting(turret13,'turret');
         enemy_shooting(turret14,'turret');
         enemy_shooting(turret15,'turret');
         
         
}

function enemy_shooting (enemy,type,direction) {
    if ( type == 'turret' ) {

        
        nextFire = game.time.now + fireRate;
        var ebullet = ebullets.getFirstDead();
        ebullet.reset(enemy.body.x+4, enemy.body.y+16);
        ebullet.body.velocity.y=0;
        ebullet.body.allowGravity = true;
        
    }
}

 

Link to comment
Share on other sites

21 hours ago, Milton said:

This means you are doing something wrong. Increasing a pool should not slow anything down, only eat some memory.
Maybe you're not returning your objects back to the pool. Put your game online somewhere so we can have a look.

Actually the pool size has a big hit on performance - noticed this with my last game. Not crazy amounts even - 20 vs 40 objects made a significant hole in fps (-10, -15 fps). To be fair the sprites where 200x200px or bigger and my pc rig it's slow (which is good because I can catch perfomance drops quite easily :D ). This hapened even though I used every optimization trick in the book - they were images not sprites, I killed them when they were off screen, etc. - probably had to do with PIXI having to deal with lots of texture data or something, don't know for sure and maybe it was solved in Phaser 2.7

Solution - don't use a pool. With phaser 2.6 perfomance it's better with instantiating and destroying a large number of images/sprites.

Link to comment
Share on other sites

  • 3 months later...
On 4/17/2017 at 6:52 AM, scheffgames said:

Actually the pool size has a big hit on performance - noticed this with my last game. Not crazy amounts even - 20 vs 40 objects made a significant hole in fps (-10, -15 fps). To be fair the sprites where 200x200px or bigger and my pc rig it's slow (which is good because I can catch perfomance drops quite easily :D ). This hapened even though I used every optimization trick in the book - they were images not sprites, I killed them when they were off screen, etc. - probably had to do with PIXI having to deal with lots of texture data or something, don't know for sure and maybe it was solved in Phaser 2.7

That seems unlikely.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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