Skip to content

Commit 9a0b6c2

Browse files
committed
Text can now accept undefined or null as the text argument in the constructor and will cast it as an empty string.
1 parent 80540ea commit 9a0b6c2

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
262262
* TypeScript definitions fixes and updates (thanks @clark-stevenson @vrecluse)
263263
* JSDoc typo fixes (thanks )
264264
* VideoStream.active = false is used if the browser supports it, otherwise it falls back to VideoStream.stop.
265+
* Text can now accept `undefined` or `null` as the `text` argument in the constructor and will cast it as an empty string.
265266

266267
### Bug Fixes
267268

src/gameobjects/Text.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ Phaser.Text = function (game, x, y, text, style) {
4040

4141
x = x || 0;
4242
y = y || 0;
43-
text = text.toString() || '';
43+
44+
if (text === undefined || text === null)
45+
{
46+
text = '';
47+
}
48+
else
49+
{
50+
text = text.toString();
51+
}
52+
4453
style = style || {};
4554

4655
/**

0 commit comments

Comments
 (0)