Hi all, I have a group where, I want 2 types of blocks to be generated from left to right or vice versa not really important, my randomization seems to work fine, but the problem is they only changes if I refresh the game, but if I run it as it is, it will always be the same kind of block until I refresh, any ideas?
createOnebloque: function(){
this.bloquecs = ["bloqueSprite","bloquelSprite"]; //////Here are the 2 sprites
this.bloquesr = this.bloquecs[Math.floor(Math.random()*2)]; ///Here I randomize but only works when I refresh.
this.bloque = this.game.add.group();
this.bloque.createMultiple(5, this.bloquesr);
this.bloque.setAll('anchor.x', 0.5);
this.bloque.setAll('anchor.y', 0.5);
this.bloque.setAll('outOfBoundsKill', true);
this.bloque.setAll('checkWorldBounds', true);
},
makeBloques: function(){
this.bloques = this.bloque.getFirstExists(false);
if (this.bloques) {
this.bloques.reset(1440, 1400);
this.game.physics.arcade.enable(this.bloques);
this.bloques.enableBody = true;
this.bloques.body.immovable = true;
this.bloques.body.velocity.x = -2000;
}
},
This below goes on the create funtion:
this.game.physics.arcade.collide(this.bullets, this.bloque, this.collisionBulletBloque, null, this);