litecoinDude Posted October 1, 2013 Share Posted October 1, 2013 Hello everyone! I'm totally new to game development.I started playing around with Phaser and came to the Motion Demo in the physics section from the examples. I modified the alien sprite physics that it seems some bombs are dropping from the sky ;-) My Question is, why it´s starting to lag as soon as i add more aliens? Maybe 600-800 In the bunny demo from pixijs i can add thousands of bunnys and still have 60fpshttp://www.goodboydigital.com/pixijs/bunnymark/ This is my Code(function () { var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update}); function preload() { game.load.image('baddie', 'assets/sprites/space-baddie.png'); game.load.tilemap('level1', 'assets/games/starstruck/tiles-1.png', 'assets/games/starstruck/level1.json', null, Phaser.Tilemap.JSON); } var aliens; var map; function create() { map = game.add.tilemap(0, 0, 'level1'); map.setCollisionRange(1, 12, true, true, true, true); map.setCollisionRange(18, 47, true, true, true, true); map.setCollisionRange(53, 69, true, true, true, true); aliens = game.add.group(); for (var i = 0; i < 50; i++) { var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie'); s.name = 'alien' + s; s.body.bounce.y = 0.3; s.body.velocity.x=100; s.body.gravity.y = 15; aliens.add(s); // aliens.push(s); } } function update() { game.physics.collide(aliens, map,collisionHandler, null, this); if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { for (var i = 0; i < 50; i++) { var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie'); s.name = 'alien' + s; s.body.bounce.y = 0.3; s.body.velocity.x=100; s.body.gravity.y = 15; aliens.add(s); // aliens.push(s); } } } function collisionHandler(aliens,map){ }})();thanks for any tipps and the cool framework!!! Link to comment Share on other sites More sharing options...
Chris Posted October 1, 2013 Share Posted October 1, 2013 I'm sorry - just a quick question: Wouldn't this line:s.name = 'alien' + s;ALWAYS set the name to 'alien[object:object]', since you basically add the whole object to the string 'alien' ?! Link to comment Share on other sites More sharing options...
litecoinDude Posted October 2, 2013 Author Share Posted October 2, 2013 Hi Chris, Yes you are right, but this is taken from the Motion example, and has no influence on the performance Link to comment Share on other sites More sharing options...
Recommended Posts