Ulbast Posted April 12, 2017 Share Posted April 12, 2017 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 More sharing options...
Aquarius Posted April 12, 2017 Share Posted April 12, 2017 Maybe increazing your bullet pull will help you. ebullets.createMultiple(50, 'enemy_bullet'); => ebullets.createMultiple(200, 'enemy_bullet'); How bullets "dies" ? Are you sure that you just hide them ? Link to comment Share on other sites More sharing options...
Ulbast Posted April 12, 2017 Author Share Posted April 12, 2017 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 More sharing options...
Milton Posted April 12, 2017 Share Posted April 12, 2017 Hmm, that doesn't make sense. It only handles live objects. Even if you had a pool of 10000 it wouldn't matter... Just make sure you don't create objects while running. Link to comment Share on other sites More sharing options...
Ulbast Posted April 12, 2017 Author Share Posted April 12, 2017 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 More sharing options...
Milton Posted April 12, 2017 Share Posted April 12, 2017 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... samme 1 Link to comment Share on other sites More sharing options...
Ulbast Posted April 16, 2017 Author Share Posted April 16, 2017 When I'm increasing the pool, the game goes slower and slower. Any other ideas? Link to comment Share on other sites More sharing options...
Milton Posted April 16, 2017 Share Posted April 16, 2017 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. samme 1 Link to comment Share on other sites More sharing options...
Drakira Posted April 16, 2017 Share Posted April 16, 2017 You've stated that bullets are killed with collision with objects, but have you set it to that bullets die automatically if you miss the enemy and the bullet leaves the screen? Link to comment Share on other sites More sharing options...
Ulbast Posted April 17, 2017 Author Share Posted April 17, 2017 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 More sharing options...
samid737 Posted April 17, 2017 Share Posted April 17, 2017 checkWorldBounds can be expensive if you have many objects: https://phaser.io/docs/2.3.0/Phaser.Component.InWorld.html#checkWorldBounds Maybe you can disable that feature and test if it makes any difference in performane. If it does try to make your own custom walls that destroy the bullets on collision? Link to comment Share on other sites More sharing options...
scheffgames Posted April 17, 2017 Share Posted April 17, 2017 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 ). 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. Arcanorum 1 Link to comment Share on other sites More sharing options...
Ulbast Posted April 17, 2017 Author Share Posted April 17, 2017 Deleting the checkWorldBounds make game a lot faster, thanks a lot! Link to comment Share on other sites More sharing options...
Milton Posted April 17, 2017 Share Posted April 17, 2017 23 minutes ago, scheffgames said: Solution - don't use a pool. With phaser 2.6 perfomance it's better with instantiating and destroying a large number of images/sprites. That's just insane. @rich? Link to comment Share on other sites More sharing options...
samme Posted August 6, 2017 Share Posted August 6, 2017 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 ). 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 More sharing options...
Arcanorum Posted August 7, 2017 Share Posted August 7, 2017 @Ulbast You could use https://phaser.io/docs/2.6.2/Phaser.Sprite.html#lifespan as an alternative to checkWorldBounds. Link to comment Share on other sites More sharing options...
Recommended Posts