Jump to content

Groups Design Pattern flawed


wilbertom
 Share

Recommended Posts

Hey guys. I have been learning Phaser as my first attempt to do game development. So far it is great. I only have one issue.

 

Reading http://blog.lessmilk.com/how-to-make-flappy-bird-in-html5-1/ I learned about using dead group items to add objects to the game. Code can better explain:

this.pipes = game.add.group();  this.pipes.createMultiple(20, 'pipe');  // later onadd_one_pipe: function(x, y) {      // Get the first dead pipe of our group    var pipe = this.pipes.getFirstDead();    // Set the new position of the pipe    pipe.reset(x, y);    // Add velocity to the pipe to make it move left    pipe.body.velocity.x = -200;     // Kill the pipe when it's no longer visible     pipe.outOfBoundsKill = true;},

I refactored this to my first attempt at a game, but I'm having problems. Whenever a user leaves the screen and then comes back, the screen is bombarded with items. At first I thought that maybe it was just the wrong way to implement it. But in the Phaser example http://examples.phaser.io/_site/view_full.html?d=games&f=invaders.js&t=invaders the same thing happens. If you play for a little while. Leave the tab or open the js console and cause the game to stop playing(I think when requestAnimationFrame stops), all the bullets fire at you.

 

This gets worse with the more time you play. I think the more group items that are revived(with getFirstDead()) and then paused, the worse it is.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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