【发布时间】:2016-05-14 00:23:37
【问题描述】:
我有一个组,我希望从左到右生成两种类型的块,反之亦然。这并不重要。我的随机化似乎工作正常,但问题是它们只有在我刷新游戏时才会改变。但是,如果我按原样运行它,在我刷新之前它始终是同一种块。我该如何解决这个问题?
createOnebloque: function () {
this.bloquecs = ["bloqueSprite", "bloquelSprite"]; ////// Here are the 2 sprites
this.bloquesr = this.bloquecs[Math.floor(Math.random() * 2)]; /// Here I randomize, but it 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.game.physics.arcade.collide(this.bullets, this.bloque, this.collisionBulletBloque, null, this);
【问题讨论】:
标签: phaser-framework