mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
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
This commit is contained in:
parent
1025362781
commit
9a2a0ad45f
1 changed files with 22 additions and 3 deletions
|
@ -399,6 +399,8 @@ var TextStyle = new Class({
|
|||
else
|
||||
{
|
||||
this._font = font;
|
||||
|
||||
this.setFont(font, false);
|
||||
}
|
||||
|
||||
// Allow for 'fill' to be used in place of 'color'
|
||||
|
@ -515,11 +517,14 @@ var TextStyle = new Class({
|
|||
* @since 3.0.0
|
||||
*
|
||||
* @param {(string|object)} font - The font family or font settings to set.
|
||||
* @param {boolean} [updateText=true] - Whether to update the text immediately.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Text} The parent Text object.
|
||||
*/
|
||||
setFont: function (font)
|
||||
setFont: function (font, updateText)
|
||||
{
|
||||
if (updateText === undefined) { updateText = true; }
|
||||
|
||||
var fontFamily = font;
|
||||
var fontSize = '';
|
||||
var fontStyle = '';
|
||||
|
@ -530,14 +535,28 @@ var TextStyle = new Class({
|
|||
fontSize = GetValue(font, 'fontSize', '16px');
|
||||
fontStyle = GetValue(font, 'fontStyle', '');
|
||||
}
|
||||
else
|
||||
{
|
||||
var fontSplit = font.split(' ');
|
||||
var i = 0;
|
||||
if (fontSplit.length > 2)
|
||||
{
|
||||
this.fontStyle = fontSplit[i++];
|
||||
}
|
||||
this.fontSize = fontSplit[i++] || this.fontSize;
|
||||
this.fontFamily = fontSplit[i++] || this.fontFamily;
|
||||
}
|
||||
|
||||
if (fontFamily !== this.fontFamily || fontSize !== this.fontSize || fontStyle !== this.fontStyle)
|
||||
{
|
||||
this.fontFamily = fontFamily;
|
||||
this.fontSize = fontSize;
|
||||
this.fontStyle = fontStyle;
|
||||
|
||||
this.update(true);
|
||||
|
||||
if (updateText)
|
||||
{
|
||||
this.update(true);
|
||||
}
|
||||
}
|
||||
|
||||
return this.parent;
|
||||
|
|
Loading…
Reference in a new issue