Fix Text UV updates.

Previously, Text didn't update the TextureSource dimensions,
so its UVs were identical to resolution.
They should have been normalized to the 0-1 range.
It used `MultiPipeline.batchTexture` to render, which accommodated
these UVs.
These changes update the dimensions when Text changes its canvas size,
and this makes normalized UVs available.
This commit is contained in:
Ben Richards 2024-05-01 15:58:45 +12:00
parent 48d1164c16
commit 3140edf0c3
2 changed files with 27 additions and 0 deletions

View file

@ -1303,6 +1303,12 @@ var Text = new Class({
this.frame.setSize(w, h);
// Resizing the canvas changes the size of the texture source.
// Because this is a dedicated texture for this Text object,
// we know this is a simple resize.
this.frame.source.updateSize(w, h);
this.frame.updateUVs();
// Because resizing the canvas resets the context
style.syncFont(canvas, context);

View file

@ -338,6 +338,27 @@ var TextureSource = new Class({
}
},
/**
* Updates the dimensions of this Texture Source.
* This is called automatically by game systems which manage textures,
* such as Text, which renders to a dedicated canvas that changes size.
*
* @method Phaser.Textures.TextureSource#updateSize
* @since 3.90.0
* @param {number} width - The new width of the source image.
* @param {number} height - The new height of the source image.
*/
updateSize: function (width, height)
{
if (this.width === width && this.height === height)
{
return;
}
this.width = width;
this.height = height;
this.isPowerOf2 = IsSizePowerOfTwo(width, height);
},
/**
* Destroys this Texture Source and nulls the references.
*