Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Randomly display group


kopi3310
 Share

Recommended Posts

Currently I'm working on a project like flappy bird using Phaser. The pipe is replace with several combination of picture, as picture here post-8228-0-82489300-1397765608.png.

 

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

 Share

  • Recently Browsing   0 members

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