mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 22:18:29 +00:00
Previously, changing a Text object by setting its text
property directly wouldn't change the text being rendered as using setText
was the expected way to change what was being displayed. Internally the text
property has been renamed to _text
and flagged as private, and a new getter / setter for text
has been added, which hands over to the setText
method, meaning you can now use both ways of setting the text. Fix #3919
This commit is contained in:
parent
54dbdce1c7
commit
27c3cc30ac
2 changed files with 32 additions and 9 deletions
|
@ -63,6 +63,7 @@ The Text Game Object has been given an internal overhaul to make it more flexibl
|
|||
* Text now keeps a reference to the renderer in the `renderer` property.
|
||||
* The `canvasTexture` property has been removed.
|
||||
* Text now has internal `texture` and `frame` properties. These replace the old `canvasTexture` but perform the same task, while allowing for texture cropping and much smaller renderer code.
|
||||
* Previously, changing a Text object by setting its `text` property directly wouldn't change the text being rendered as using `setText` was the expected way to change what was being displayed. Internally the `text` property has been renamed to `_text` and flagged as private, and a new getter / setter for `text` has been added, which hands over to the `setText` method, meaning you can now use both ways of setting the text. Fix #3919 (thanks @hackhat @samid737)
|
||||
|
||||
### Tile Sprite Object New Features and Updates
|
||||
|
||||
|
|
|
@ -146,11 +146,12 @@ var Text = new Class({
|
|||
/**
|
||||
* The text to display.
|
||||
*
|
||||
* @name Phaser.GameObjects.Text#text
|
||||
* @name Phaser.GameObjects.Text#_text
|
||||
* @type {string}
|
||||
* @since 3.0.0
|
||||
* @private
|
||||
* @since 3.12.0
|
||||
*/
|
||||
this.text = '';
|
||||
this._text = '';
|
||||
|
||||
/**
|
||||
* Specify a padding value which is added to the line width and height when calculating the Text size.
|
||||
|
@ -520,7 +521,7 @@ var Text = new Class({
|
|||
*/
|
||||
getWrappedText: function (text)
|
||||
{
|
||||
if (text === undefined) { text = this.text; }
|
||||
if (text === undefined) { text = this._text; }
|
||||
|
||||
this.style.syncFont(this.canvas, this.context);
|
||||
|
||||
|
@ -553,9 +554,9 @@ var Text = new Class({
|
|||
value = value.join('\n');
|
||||
}
|
||||
|
||||
if (value !== this.text)
|
||||
if (value !== this._text)
|
||||
{
|
||||
this.text = value.toString();
|
||||
this._text = value.toString();
|
||||
|
||||
this.updateText();
|
||||
}
|
||||
|
@ -1003,11 +1004,11 @@ var Text = new Class({
|
|||
|
||||
style.syncFont(canvas, context);
|
||||
|
||||
var outputText = this.text;
|
||||
var outputText = this._text;
|
||||
|
||||
if (style.wordWrapWidth || style.wordWrapCallback)
|
||||
{
|
||||
outputText = this.runWordWrap(this.text);
|
||||
outputText = this.runWordWrap(this._text);
|
||||
}
|
||||
|
||||
// Split text into lines
|
||||
|
@ -1143,6 +1144,27 @@ var Text = new Class({
|
|||
return this.style.getTextMetrics();
|
||||
},
|
||||
|
||||
/**
|
||||
* The text string being rendered by this Text Game Object.
|
||||
*
|
||||
* @name Phaser.GameObjects.Text#text
|
||||
* @type {string}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
text: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._text;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.setText(value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Build a JSON representation of the Text object.
|
||||
*
|
||||
|
@ -1159,7 +1181,7 @@ var Text = new Class({
|
|||
|
||||
var data = {
|
||||
autoRound: this.autoRound,
|
||||
text: this.text,
|
||||
text: this._text,
|
||||
style: this.style.toJSON(),
|
||||
padding: {
|
||||
left: this.padding.left,
|
||||
|
|
Loading…
Add table
Reference in a new issue