Skip to content

Commit 9a2a0ad

Browse files
authored
TextStyle.setStyle & TextStyle.setFont now set fontSize, fontStyle & fontFamily when font is a string
TextStyle.setFont now sets fontFamily, fontSize, and fontStyle when "font" is a string. TextStyle.setStyle calls TextStyle.setFont when "font" is overridden. This fixes an issue where TextStyle.update(true) overrides TextStyle._font
1 parent 1025362 commit 9a2a0ad

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/gameobjects/text/TextStyle.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ var TextStyle = new Class({
399399
else
400400
{
401401
this._font = font;
402+
403+
this.setFont(font, false);
402404
}
403405

404406
// Allow for 'fill' to be used in place of 'color'
@@ -515,11 +517,14 @@ var TextStyle = new Class({
515517
* @since 3.0.0
516518
*
517519
* @param {(string|object)} font - The font family or font settings to set.
520+
* @param {boolean} [updateText=true] - Whether to update the text immediately.
518521
*
519522
* @return {Phaser.GameObjects.Text} The parent Text object.
520523
*/
521-
setFont: function (font)
524+
setFont: function (font, updateText)
522525
{
526+
if (updateText === undefined) { updateText = true; }
527+
523528
var fontFamily = font;
524529
var fontSize = '';
525530
var fontStyle = '';
@@ -530,14 +535,28 @@ var TextStyle = new Class({
530535
fontSize = GetValue(font, 'fontSize', '16px');
531536
fontStyle = GetValue(font, 'fontStyle', '');
532537
}
538+
else
539+
{
540+
var fontSplit = font.split(' ');
541+
var i = 0;
542+
if (fontSplit.length > 2)
543+
{
544+
this.fontStyle = fontSplit[i++];
545+
}
546+
this.fontSize = fontSplit[i++] || this.fontSize;
547+
this.fontFamily = fontSplit[i++] || this.fontFamily;
548+
}
533549

534550
if (fontFamily !== this.fontFamily || fontSize !== this.fontSize || fontStyle !== this.fontStyle)
535551
{
536552
this.fontFamily = fontFamily;
537553
this.fontSize = fontSize;
538554
this.fontStyle = fontStyle;
539-
540-
this.update(true);
555+
556+
if (updateText)
557+
{
558+
this.update(true);
559+
}
541560
}
542561

543562
return this.parent;

0 commit comments

Comments
 (0)