Skip to content

Commit 4fd2524

Browse files
committed
Text.setStyle has a new argument update which will optionally automatically call updateText after setting the new style (thanks @staff0rd phaserjs#2478)
1 parent f34b567 commit 4fd2524

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
351351
* The Arcade Physics overlap method would return false if two bodies were overlapping but neither had any velocity (i.e. they were embedded into each other)
352352
* PIXI.defaultRenderer is now set to `null` in Game.destroy, allowing it to be reset if a new Game instance is created on the same page (thanks @xtforgame ##2474)
353353
* BitmapData.drawGroupProxy is now capable of iterating through Sprites that have children, and also now uses the world positions for drawing instead. This change updates the functionality of BitmapData.drawGroup.
354+
* Text.setStyle has a new argument `update` which will optionally automatically call `updateText` after setting the new style (thanks @staff0rd #2478)
354355

355356
### Bug Fixes
356357

src/gameobjects/Text.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,12 @@ Phaser.Text.prototype.setShadow = function (x, y, color, blur, shadowStroke, sha
287287
* @param {number} [style.wordWrapWidth=100] - The width in pixels at which text will wrap.
288288
* @param {number} [style.maxLines=0] - The maximum number of lines to be shown for wrapped text.
289289
* @param {number|array} [style.tabs=0] - The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop.
290+
* @param {boolean} [update=false] - Immediately update the Text object after setting the new style? Or wait for the next frame.
290291
* @return {Phaser.Text} This Text instance.
291292
*/
292-
Phaser.Text.prototype.setStyle = function (style) {
293+
Phaser.Text.prototype.setStyle = function (style, update) {
294+
295+
if (update === undefined) { update = false; }
293296

294297
style = style || {};
295298
style.font = style.font || 'bold 20pt Arial';
@@ -343,6 +346,11 @@ Phaser.Text.prototype.setStyle = function (style) {
343346
this.style = style;
344347
this.dirty = true;
345348

349+
if (update)
350+
{
351+
this.updateText();
352+
}
353+
346354
return this;
347355

348356
};

typescript/phaser.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="pixi.d.ts" />
22
/// <reference path="p2.d.ts" />
33

4-
// Type definitions for Phaser 2.4.8 - 29th April 2016
4+
// Type definitions for Phaser 2.4.8 - 16th May 2016
55
// Project: https://github.com/photonstorm/phaser
66

77
declare module "phaser" {
@@ -4827,7 +4827,7 @@ declare module Phaser {
48274827
preUpdate(): void;
48284828
renderTabLine(line: string, x: number, y: number, fill?: boolean): void;
48294829
setShadow(x?: number, y?: number, color?: any, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.Text;
4830-
setStyle(style?: PhaserTextStyle): Phaser.Text;
4830+
setStyle(style?: PhaserTextStyle, update?: boolean): Phaser.Text;
48314831
setText(text: string): Phaser.Text;
48324832
setTextBounds(x?: number, y?: number, width?: number, height?: number): Phaser.Text;
48334833
update(): void;

0 commit comments

Comments
 (0)