The BitmapText.setFont method will now set the texture, size and alignment even if the same font key has been given as is already in use. Fix #6740

This commit is contained in:
Richard Davey 2024-02-19 14:41:53 +00:00
parent 76903fcdb9
commit a9012b19b4

View file

@ -783,7 +783,7 @@ var BitmapText = new Class({
/**
* Changes the font this BitmapText is using to render.
*
* The new texture is loaded and applied to the BitmapText. The existing test, size and alignment are preserved,
* The new texture is loaded and applied to the BitmapText. The existing text, size and alignment are preserved,
* unless overridden via the arguments.
*
* @method Phaser.GameObjects.BitmapText#setFont
@ -800,22 +800,19 @@ var BitmapText = new Class({
if (size === undefined) { size = this._fontSize; }
if (align === undefined) { align = this._align; }
if (key !== this.font)
var entry = this.scene.sys.cache.bitmapFont.get(key);
if (entry)
{
var entry = this.scene.sys.cache.bitmapFont.get(key);
this.font = key;
this.fontData = entry.data;
this._fontSize = size;
this._align = align;
this.fromAtlas = entry.fromAtlas === true;
if (entry)
{
this.font = key;
this.fontData = entry.data;
this._fontSize = size;
this._align = align;
this.fromAtlas = entry.fromAtlas === true;
this.setTexture(entry.texture, entry.frame);
this.setTexture(entry.texture, entry.frame);
GetBitmapTextSize(this, false, true, this._bounds);
}
GetBitmapTextSize(this, false, true, this._bounds);
}
return this;