kopi3310 Posted April 17, 2014 Share Posted April 17, 2014 Currently I'm working on a project like flappy bird using Phaser. The pipe is replace with several combination of picture, as picture here . I use Math.random to display the moving object every 2 second but its not proper. Below is my code for example. If I have 10 set of object then I need to create 10 statement: ... add_red_ribbon: function(x, y) { var add_red_ribbon= this.red_ribbon.getFirstDead(); add_red_ribbon.reset(x, y); add_red_ribbon.body.velocity.x = -200; add_red_ribbon.outOfBoundsKill = true; }, add_small_flag: function(x, y) { var add_small_flag= this.small_flag.getFirstDead(); add_small_flag.reset(x, y); add_small_flag.body.velocity.x = -200; add_small_flag.outOfBoundsKill = true; },... var random = Math.floor((Math.random()*2) + 1); if (random == 1){this.red_ribbon(700, 0); this.add_small_flag(700, 430);}else if(random == 2){this.yellow_ribbon(700, 0);this.guy(700, 258);}... Is there any better way to accomplish this? One more problem is its overlap each time its display, how to fix this. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts