mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Update WeightedRandomize() to support index arrays
This commit is contained in:
parent
15c45bda0e
commit
e128733f02
1 changed files with 4 additions and 2 deletions
|
@ -48,8 +48,10 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
|
|||
sum += weightedIndexes[j].weight;
|
||||
if (rand <= sum)
|
||||
{
|
||||
randomIndex = weightedIndexes[j].index;
|
||||
break;
|
||||
var chosen = weightedIndexes[j].index
|
||||
randomIndex = Array.isArray(chosen)
|
||||
? chosen[Math.floor(Math.random() * chosen.length)]
|
||||
: chosen
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue