Jump to content

getFirstDead doesn't choose from the beginning?


DELETE THIS ACC PLS
 Share

Recommended Posts

Hello,

 

While working on my new up-coming open-source flappy bird clone I noticed that after reaching the second pipe, the game freezes.

I followed Thomas Palef's tutorial on making a Flappy bird game with Phaser 1.1.5 and It works like a charm.

While adding the same code to Phaser 2.0.7 I had many bugs and fixed some with the help of this forum but the way how pipes are spawned doesn't work.

 

Here's some code so you can understand how pipes are working:

/* line 27 */ var pipe;~~ Create function ~~/* line 65 */ this.pipes = game.add.group();/* line 66 */ this.pipes.createMultiple(20, 'pipe');/* line 67 */ this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this);~~ Hit_Pipe ~~/* line 103 */ hit_pipe: function() {/* line 104 */    if (box.alive === false) {/* line 105 */         return;/* line 106 */     }/* line 107 */     pipe.body.moves = false;/* line 108 */     box.alive = false;/* line 109 */     this.game.time.events.remove(this.timer);/* line 110 */     this.pipes.forEachAlive(function(p){/* line 111 */         p.body.velocity.x = 0;/* line 112 */         p.body.velocity.y = 0;/* line 113 */     }, this);/* line 114 */ },~~ Add_One_Pipe ~~/* line 124 */ add_one_pipe: function(x, y) {/* line 125 */     console.log(this.pipes.getFirstDead());/* line 126 */         pipe = this.pipes.getFirstDead();/* line 127 */         pipe.reset(x, y);/* line 128 */         game.physics.enable(pipe, Phaser.Physics.ARCADE);/* line 129 */         pipe.scale.setTo(0.8, 0.8);/* line 130 */         pipe.body.velocity.setTo(-200, 0);/* line 131 */         pipe.body.bounce.set(0);/* line 132 */         pipe.outOfBoundsKill = true;/* line 133 */ },~~ Add_Row_Of_Pipes ~~/* line 135 */ add_row_of_pipes: function() {/* line 136 */     var hole = Math.floor(Math.random()*5)+1;/* line 137 */     for (var i = 0; i < 10; i++)/* line 138 */         if (i != hole && i != hole +1) {/* line 139 */             this.add_one_pipe(400, i*60+5);/* line 140 */         }/* line 141 */ }

You can test the game here : Flappy Box

While passing the second pipe with console opened, You'll see what pipe becomes (null in this case)

I want it to restart choosing from the 20 pipes that are already created. Worked in 1.1.5

 

Thanks in advance.

Link to comment
Share on other sites

Your pipes are not dead, so getting first dead does not work. Sprite.outOfBoundsKill does not kill if Sprite.checkWorldBounds = false, which is default, so just set checkWorldBounds = true.

add_one_pipe: function(x, y) {  console.log(this.pipes.getFirstDead());  pipe = this.pipes.getFirstDead();  pipe.reset(x, y);  game.physics.enable(pipe, Phaser.Physics.ARCADE);  pipe.scale.setTo(0.8, 0.8);  pipe.body.velocity.setTo(-200, 0);  pipe.body.bounce.set(0);  pipe.checkWorldBounds = true; // Add this line  pipe.outOfBoundsKill = true;},
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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