Skip to content

Commit 8ae3493

Browse files
committed
setText updates
BitmapText.setText will check if the value given is falsey but not a zero and set to an empty string if so. BitmapText.setText will now cast the given value to a string before setting. BitmapText.setText will not change the text via `setText` unless the new text is different to the old one.
1 parent b447665 commit 8ae3493

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
### Updates
1212

1313
* AnimationComponent.play now calls `setSizeToFrame()` and `updateDisplayOrigin()` on the parent Game Object in order to catch situations where you've started playing an animation on a Game Object that uses a different size to the previously set frame.
14+
* Text.setText will check if the value given is falsey but not a zero and set to an empty string if so.
15+
* BitmapText.setText will check if the value given is falsey but not a zero and set to an empty string if so.
16+
* BitmapText.setText will now cast the given value to a string before setting.
17+
* BitmapText.setText will not change the text via `setText` unless the new text is different to the old one.
1418

1519
## Version 3.1.2 - 23rd February 2018
1620

src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,26 @@ var DynamicBitmapText = new Class({
226226
* @method Phaser.GameObjects.DynamicBitmapText#setText
227227
* @since 3.0.0
228228
*
229-
* @param {string|string[]} text - [description]
229+
* @param {string|string[]} value - The string, or array of strings, to be set as the content of this BitmapText.
230230
*
231231
* @return {Phaser.GameObjects.DynamicBitmapText} This Game Object.
232232
*/
233233
setText: function (value)
234234
{
235+
if (!value && value !== 0)
236+
{
237+
value = '';
238+
}
239+
235240
if (Array.isArray(value))
236241
{
237242
value = value.join('\n');
238243
}
239244

240-
this.text = value;
245+
if (value !== this.text)
246+
{
247+
this.text = value.toString();
248+
}
241249

242250
return this;
243251
},

src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,26 @@ var BitmapText = new Class({
145145
* @method Phaser.GameObjects.BitmapText#setText
146146
* @since 3.0.0
147147
*
148-
* @param {string|string[]} text - [description]
148+
* @param {string|string[]} value - The string, or array of strings, to be set as the content of this BitmapText.
149149
*
150150
* @return {Phaser.GameObjects.BitmapText} This Game Object.
151151
*/
152152
setText: function (value)
153153
{
154+
if (!value && value !== 0)
155+
{
156+
value = '';
157+
}
158+
154159
if (Array.isArray(value))
155160
{
156161
value = value.join('\n');
157162
}
158163

159-
this.text = value;
164+
if (value !== this.text)
165+
{
166+
this.text = value.toString();
167+
}
160168

161169
return this;
162170
},

0 commit comments

Comments
 (0)