@@ -392,14 +392,11 @@ var TextStyle = new Class({
392392 // Allow for 'font' override
393393 var font = GetValue ( style , 'font' , null ) ;
394394
395- if ( font = == null )
395+ if ( font ! == null )
396396 {
397- this . _font = [ this . fontStyle , this . fontSize , this . fontFamily ] . join ( ' ' ) . trim ( ) ;
398- }
399- else
400- {
401- this . _font = font ;
397+ this . setFont ( font , false ) ;
402398 }
399+ this . _font = [ this . fontStyle , this . fontSize , this . fontFamily ] . join ( ' ' ) . trim ( ) ;
403400
404401 // Allow for 'fill' to be used in place of 'color'
405402 var fill = GetValue ( style , 'fill' , null ) ;
@@ -515,11 +512,14 @@ var TextStyle = new Class({
515512 * @since 3.0.0
516513 *
517514 * @param {(string|object) } font - The font family or font settings to set.
515+ * @param {boolean } [updateText=true] - Whether to update the text immediately.
518516 *
519517 * @return {Phaser.GameObjects.Text } The parent Text object.
520518 */
521- setFont : function ( font )
519+ setFont : function ( font , updateText )
522520 {
521+ if ( updateText === undefined ) { updateText = true ; }
522+
523523 var fontFamily = font ;
524524 var fontSize = '' ;
525525 var fontStyle = '' ;
@@ -530,14 +530,25 @@ var TextStyle = new Class({
530530 fontSize = GetValue ( font , 'fontSize' , '16px' ) ;
531531 fontStyle = GetValue ( font , 'fontStyle' , '' ) ;
532532 }
533+ else
534+ {
535+ var fontSplit = font . split ( ' ' ) ;
536+ var i = 0 ;
537+ this . fontStyle = fontSplit . length > 2 ? fontSplit [ i ++ ] : '' ;
538+ this . fontSize = fontSplit [ i ++ ] || '16px' ;
539+ this . fontFamily = fontSplit [ i ++ ] || 'Courier' ;
540+ }
533541
534542 if ( fontFamily !== this . fontFamily || fontSize !== this . fontSize || fontStyle !== this . fontStyle )
535543 {
536544 this . fontFamily = fontFamily ;
537545 this . fontSize = fontSize ;
538546 this . fontStyle = fontStyle ;
539-
540- this . update ( true ) ;
547+
548+ if ( updateText )
549+ {
550+ this . update ( true ) ;
551+ }
541552 }
542553
543554 return this . parent ;
0 commit comments