mirror of
https://github.com/photonstorm/phaser
synced 2024-11-25 06:00:41 +00:00
Merge pull request #6537 from jorbascrumps/feat-use-seeded-random-for-tilemap-weighted-randomize
Updates `Tilemaps.Components.WeightedRandomize` to use seeded random value
This commit is contained in:
commit
b27e4d3744
1 changed files with 3 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
var GetTilesWithin = require('./GetTilesWithin');
|
||||
var MATH = require('../../math');
|
||||
|
||||
/**
|
||||
* Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the
|
||||
|
@ -51,7 +52,7 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
|
|||
|
||||
for (i = 0; i < tiles.length; i++)
|
||||
{
|
||||
var rand = Math.random() * weightTotal;
|
||||
var rand = MATH.RND.frac() * weightTotal;
|
||||
var sum = 0;
|
||||
var randomIndex = -1;
|
||||
|
||||
|
@ -64,7 +65,7 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
|
|||
var chosen = weightedIndexes[j].index;
|
||||
|
||||
randomIndex = Array.isArray(chosen)
|
||||
? chosen[Math.floor(Math.random() * chosen.length)]
|
||||
? chosen[Math.floor(MATH.RND.frac() * chosen.length)]
|
||||
: chosen;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue