mirror of
https://github.com/photonstorm/phaser
synced 2024-11-15 17:28:18 +00:00
parseList support added.
This commit is contained in:
parent
2e447ec01d
commit
3066f60f11
1 changed files with 56 additions and 0 deletions
|
@ -793,6 +793,62 @@ Phaser.Text.prototype.setText = function (text) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* The text to be displayed by this Text object.
|
||||
* Use a \n to insert a carriage return and split the text.
|
||||
* The text will be rendered with any style currently set.
|
||||
*
|
||||
* @method Phaser.Text#parseList
|
||||
* @param {array} list - X
|
||||
* @return {Phaser.Text} This Text instance.
|
||||
*/
|
||||
Phaser.Text.prototype.parseList = function (list) {
|
||||
|
||||
// list can be either an array containing strings, or an array containing arrays.
|
||||
// If a multi-dim array then each new array equals a new line in the text.
|
||||
//
|
||||
// [ 'a', 'b', 'c' ] = "a\tb\tc";
|
||||
//
|
||||
// [
|
||||
// [ 'a', 'b', 'c' ],
|
||||
// [ 'd', 'e', 'f']
|
||||
// ] = "a\tb\tc\nd\te\tf";
|
||||
|
||||
if (!Array.isArray(list))
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
var s = "";
|
||||
|
||||
for (var i = 0; i < list.length; i++)
|
||||
{
|
||||
if (Array.isArray(list[i]))
|
||||
{
|
||||
s += list[i].join("\t");
|
||||
|
||||
if (i < list.length - 1)
|
||||
{
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s += list[i] + "\t";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(s);
|
||||
|
||||
this.text = s;
|
||||
this.dirty = true;
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The Text Bounds is a rectangular region that you control the dimensions of into which the Text object itself is positioned,
|
||||
* regardless of the number of lines in the text, the font size or any other attribute.
|
||||
|
|
Loading…
Reference in a new issue