Phaser.ArrayUtils.numberArray now has optional prefix and suffix arguments, allowing you to do: numberArray(1, 4, 'Level ') and the Array will contain ["Level 1", "Level 2", "Level 3", "Level 4"].

This commit is contained in:
Richard Davey 2016-10-11 17:42:58 +01:00
parent 775dee029d
commit 591bf828a9
2 changed files with 33 additions and 6 deletions

View file

@ -357,6 +357,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* Device.css3D has been removed, and the function that tested it is no longer run.
* Device.isConsoleOpen has been removed. The function only worked on a very limited set of old browsers.
* Device.littleEndian has been removed, you can use Device.LITTLE_ENDIAN instead.
* Phaser.ArrayUtils.numberArray now has optional `prefix` and `suffix` arguments, allowing you to do: `numberArray(1, 4, 'Level ')` and the Array will contain `["Level 1", "Level 2", "Level 3", "Level 4"]`.
### Bug Fixes

View file

@ -260,25 +260,51 @@ Phaser.ArrayUtils = {
},
/**
* Create an array representing the inclusive range of numbers (usually integers) in `[start, end]`.
* Create an array representing the range of numbers (usually integers), between, and inclusive of,
* the given `start` and `end` arguments. For example:
*
* `var array = numberArray(2, 4); // array = [2, 3, 4]`
* `var array = numberArray(0, 9); // array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]`
*
* This is equivalent to `numberArrayStep(start, end, 1)`.
*
* You can optionally provide a prefix and / or suffix string. If given the array will contain
* strings, not integers. For example:
*
* `var array = numberArray(1, 4, 'Level '); // array = ["Level 1", "Level 2", "Level 3", "Level 4"]`
* `var array = numberArray(5, 7, 'HD-', '.png'); // array = ["HD-5.png", "HD-6.png", "HD-7.png"]`
*
* @method Phaser.ArrayUtils#numberArray
* @param {number} start - The minimum value the array starts with.
* @param {number} end - The maximum value the array contains.
* @return {number[]} The array of number values.
* @param {string} [prefix] - Optional prefix to place before the number. If provided the array will contain strings, not integers.
* @param {string} [suffix] - Optional suffix to place after the number. If provided the array will contain strings, not integers.
* @return {number[]|string[]} The array of number values, or strings if a prefix or suffix was provided.
*/
numberArray: function (start, end) {
numberArray: function (start, end, prefix, suffix)
{
var result = [];
for (var i = start; i <= end; i++)
{
result.push(i);
if (prefix || suffix)
{
var key = (prefix) ? prefix + i.toString() : i.toString();
if (suffix)
{
key = key.concat(suffix);
}
result.push(key);
}
else
{
result.push(i);
}
}
return result;
},
/**