Skip to content

Commit a0c771d

Browse files
committed
Text.setText has a new optional argument immediate which will re-create the texture immediately upon call, rather than wait for the next render pass to do so (thanks @Scraft phaserjs#2594)
1 parent b24de1e commit a0c771d

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
330330
* The TilemapParser will now add more data when importing Image object types from Tiled. The extra data available is: image width, image height, and flags to see if the image is flipped either horizontally, vertically or diagonally (thanks @gotenxds #2564 #2554)
331331
* TilemapLayer.renderRegion has had an assignment to the obsolete `tileColor` property removed (thanks @cryptographer #2583)
332332
* Group.getFurthestFrom and Group.getClosestTo has a new optional argument: `callback`. This allows you to apply your own additional filtering to the distance checks, ultimately influencing the selected child (thanks @LoneStranger #2577)
333+
* Text.setText has a new optional argument `immediate` which will re-create the texture immediately upon call, rather than wait for the next render pass to do so (thanks @Scraft #2594)
333334

334335
### Bug Fixes
335336

src/gameobjects/Text.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,18 +1250,34 @@ Phaser.Text.prototype.componentsToFont = function (components) {
12501250
};
12511251

12521252
/**
1253-
* The text to be displayed by this Text object.
1254-
* Use a \n to insert a carriage return and split the text.
1255-
* The text will be rendered with any style currently set.
1256-
*
1257-
* @method Phaser.Text#setText
1258-
* @param {string} [text] - The text to be displayed. Set to an empty string to clear text that is already present.
1259-
* @return {Phaser.Text} This Text instance.
1260-
*/
1261-
Phaser.Text.prototype.setText = function (text) {
1253+
* The text to be displayed by this Text object.
1254+
* Use a \n to insert a carriage return and split the text.
1255+
* The text will be rendered with any style currently set.
1256+
*
1257+
* Use the optional `immediate` argument if you need the Text display to update immediately.
1258+
*
1259+
* If not it will re-create the texture of this Text object during the next time the render
1260+
* loop is called.
1261+
*
1262+
* @method Phaser.Text#setText
1263+
* @param {string} [text] - The text to be displayed. Set to an empty string to clear text that is already present.
1264+
* @param {boolean} [immediate=false] - Update the texture used by this Text object immediately (true) or automatically during the next render loop (false).
1265+
* @return {Phaser.Text} This Text instance.
1266+
*/
1267+
Phaser.Text.prototype.setText = function (text, immediate) {
1268+
1269+
if (immediate === undefined) { immediate = false; }
12621270

12631271
this.text = text.toString() || '';
1264-
this.dirty = true;
1272+
1273+
if (immediate)
1274+
{
1275+
this.updateText();
1276+
}
1277+
else
1278+
{
1279+
this.dirty = true;
1280+
}
12651281

12661282
return this;
12671283

typescript/phaser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4934,7 +4934,7 @@ declare module Phaser {
49344934
renderTabLine(line: string, x: number, y: number, fill?: boolean): void;
49354935
setShadow(x?: number, y?: number, color?: any, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.Text;
49364936
setStyle(style?: PhaserTextStyle, update?: boolean): Phaser.Text;
4937-
setText(text: string): Phaser.Text;
4937+
setText(text: string, immediate?: boolean): Phaser.Text;
49384938
setTextBounds(x?: number, y?: number, width?: number, height?: number): Phaser.Text;
49394939
update(): void;
49404940
updateFont(components: any): void;

0 commit comments

Comments
 (0)