mirror of
https://github.com/photonstorm/phaser
synced 2024-11-16 09:48:18 +00:00
GameObjects.Text.appendText
is a new method that will append the given text, or array of text, to the end of the content already stored in the Text object.
This commit is contained in:
parent
f96986a2e7
commit
e3afb1d159
1 changed files with 41 additions and 0 deletions
|
@ -615,6 +615,47 @@ var Text = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Appends the given text to the content already being displayed by this Text object.
|
||||
*
|
||||
* An array of strings will be joined with `\n` line breaks.
|
||||
*
|
||||
* @method Phaser.GameObjects.Text#appendText
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {(string|string[])} value - The string, or array of strings, to be appended to the existing content of this Text object.
|
||||
* @param {boolean} [addCR=true] - Insert a carriage-return before the string value.
|
||||
*
|
||||
* @return {this} This Text object.
|
||||
*/
|
||||
appendText: function (value, addCR)
|
||||
{
|
||||
if (addCR === undefined) { addCR = true; }
|
||||
|
||||
if (!value && value !== 0)
|
||||
{
|
||||
value = '';
|
||||
}
|
||||
|
||||
if (Array.isArray(value))
|
||||
{
|
||||
value = value.join('\n');
|
||||
}
|
||||
|
||||
value = value.toString();
|
||||
|
||||
var newText = this._text.concat((addCR) ? '\n' + value : value);
|
||||
|
||||
if (newText !== this._text)
|
||||
{
|
||||
this._text = newText;
|
||||
|
||||
this.updateText();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the text style.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue