Xylops Posted August 3, 2016 Share Posted August 3, 2016 Hi everyone Currently i'm building a game about drilling oil from the ground. The stage that im in right now is creating the ground and the driller. Here is an example image The way that I create this effect is by using group. When ever the white dot collide with the brown mud, the driller will kill the mud they collide. Size of the mud is about 5 x 5 px so in order to fill up the whole screen i use a 2 for loop to create hundreds of mud sprite under one single group. var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render }); function preload(){ game.load.image('mud', 'img/mud.png'); game.load.image('driller', 'img/square.png'); game.time.advancedTiming = true; } function create(){ floorLevel = 100; dirt = game.add.group(); dirt.enableBody = true; dirt.physicalBodyType = Phaser.Physics.ARCADE; for(var j = floorLevel; j < game.world.height; j = j+5 ){ for (var i = 0; i < game.world.width; i=i+5){ var mud = dirt.create(i, j, 'mud'); } } driller = game.add.sprite(100,50, 'driller'); game.physics.enable(driller,Phaser.Physics.ARCADE); drillerTween = game.add.tween(driller).to({x:400, y:300}, 3000); drillerTween.start(); } function update(){ game.physics.arcade.overlap(driller, dirt, function collisionHandler(driller, mud){ mud.kill(); }); } function render(){ game.debug.text('FPS: ' + (game.time.fps || '--') , 2, 14, "#00ff00"); } Here comes the problem, when trying to run this game it was REALLY laggy. In a PC local environment, the FPS was about 15-20. But when i export it to my mobile through CocoonJS, the FPS drops down to 2-3 fps. I've try to come up with a solutions by increase the size of the mud so less sprite would need to be create and handle by the CPU. But i'd want to avoid this method to not expose that much background to the players. I've also done some research on the tileMap. I realized that it is possible to have an collision event on the with the tiles, but is it possible to kill that tiles when collide??? QUESTIONS: So Are there any kind of way to improve my FPS?? Really appreciate for the time to read and Thank You. Link to comment Share on other sites More sharing options...
Milton Posted August 3, 2016 Share Posted August 3, 2016 Your ground should be just 1 bitmap (sprite), not hundreds. If you 'kill' mud, update the bitmap. You should only need 2 sprites in the whole game. Link to comment Share on other sites More sharing options...
Xylops Posted August 3, 2016 Author Share Posted August 3, 2016 O....that points me into a totally new directions, I'll do some research about it as i don't know much about bitmap Thanks for the solution and quick reply @Milton Link to comment Share on other sites More sharing options...
Recommended Posts