mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
GetBitmapTextSize
, which is used internally in the BitmapText Game Objects, will now produce different bounds from the previous version. Previously, the bounds were tight against the letters in the text. However, this meant the bounds were not properly aligned with the origin of the BitmapText, and consequently you'd get different bounds if the text consisted of different characters. The bounds are now calculated purely based on the glyph data and letter spacing values. This will give a far more consistent overall experience, but it does mean if you were using the bounds to position text previously, you'll need to revisit that code again. See issue #3799 for more details (and to discuss this further if you wish)
This commit is contained in:
parent
17653fcf7d
commit
91a48c30c4
5 changed files with 18 additions and 26 deletions
|
@ -52,6 +52,7 @@ The Texture Tint Pipeline has been rewritten to tidy up hundreds of lines of dup
|
|||
* The `batchText` method has been removed from the `TextureTintPipeline` class, because it is now handled internally by the Game Object itself.
|
||||
* The `batchDynamicTilemapLayer` method has been removed from the `TextureTintPipeline` class, because it is now handled internally by the Game Object itself.
|
||||
* The `batchMesh` method has been removed from the `TextureTintPipeline` class, because it is now handled in the Mesh WebGL Renderer function.
|
||||
* The `batchBitmapText` method has been removed from the `TextureTintPipeline` class, because it is now handled in the BitmapText WebGL Renderer function.
|
||||
* The shader has a new attribute: `tintEffect`. This is a single FLOAT.
|
||||
* The vertex size has increased by 1 FLOAT to account for the extra shader attribute.
|
||||
|
||||
|
@ -110,6 +111,8 @@ There is a new Game Object Component called `TextureCrop`. It replaces the Textu
|
|||
* The TextureManager Sprite Sheet Parser will now throw a concise console warning if you specify invalid frame sizes that would result in no frames being generated (thanks @andygroff)
|
||||
* The `Quad` Game Object now has a new `setFrame` method that allows you to change the frame being rendered by the Quad, including using frames that are part of a texture atlas. Fix #3161 (thanks @halgorithm)
|
||||
* The `ScenePlugin` will now queue all of the following ops with the Scene Manager: `start`, `run`, `pause`, `resume`, `sleep`, `wake`, `switch` and `stop`. This means for all of these calls the Scene Manager will add the call into its queue and process it at the start of the next frame. This fixes #3812 and keeps things more predictable (thanks @Waclaw-I)
|
||||
* `GetBitmapTextSize`, which is used internally in the BitmapText Game Objects, will now produce different bounds from the previous version. Previously, the bounds were tight against the letters in the text. However, this meant the bounds were not properly aligned with the origin of the BitmapText, and consequently you'd get different bounds if the text consisted of different characters. The bounds are now calculated purely based on the glyph data and letter spacing values. This will give a far more consistent overall experience, but it does mean if you were using the bounds to position text previously, you'll need to revisit that code again. See issue #3799 for more details (and to discuss this further if you wish) (thanks @SBCGames)
|
||||
* `GetBitmapTextSize` and its exposed method `BitmapText.getTextBounds` now factor in the display origin of the BitmapText into the `global` position returned.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
|
|
@ -69,12 +69,9 @@ var GetBitmapTextSize = function (src, round)
|
|||
var xAdvance = 0;
|
||||
var yAdvance = 0;
|
||||
|
||||
var indexCount = 0;
|
||||
var charCode = 0;
|
||||
|
||||
var glyph = null;
|
||||
var glyphW = 0;
|
||||
var glyphH = 0;
|
||||
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
|
@ -89,7 +86,6 @@ var GetBitmapTextSize = function (src, round)
|
|||
if (charCode === 10)
|
||||
{
|
||||
xAdvance = 0;
|
||||
indexCount = 0;
|
||||
yAdvance += lineHeight;
|
||||
lastGlyph = null;
|
||||
continue;
|
||||
|
@ -102,11 +98,8 @@ var GetBitmapTextSize = function (src, round)
|
|||
continue;
|
||||
}
|
||||
|
||||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
|
||||
x = indexCount + glyph.xOffset + xAdvance;
|
||||
y = glyph.yOffset + yAdvance;
|
||||
x = xAdvance;
|
||||
y = yAdvance;
|
||||
|
||||
if (lastGlyph !== null)
|
||||
{
|
||||
|
@ -124,8 +117,8 @@ var GetBitmapTextSize = function (src, round)
|
|||
by = y;
|
||||
}
|
||||
|
||||
var gw = x + glyphW - bx;
|
||||
var gh = y + glyphH - by;
|
||||
var gw = x + glyph.xAdvance;
|
||||
var gh = y + lineHeight;
|
||||
|
||||
if (bw < gw)
|
||||
{
|
||||
|
@ -138,7 +131,6 @@ var GetBitmapTextSize = function (src, round)
|
|||
}
|
||||
|
||||
xAdvance += glyph.xAdvance + letterSpacing;
|
||||
indexCount += 1;
|
||||
lastGlyph = glyph;
|
||||
lastCharCode = charCode;
|
||||
}
|
||||
|
@ -155,8 +147,8 @@ var GetBitmapTextSize = function (src, round)
|
|||
height: bh * scale
|
||||
},
|
||||
global: {
|
||||
x: src.x + (bx * sx),
|
||||
y: src.y + (by * sy),
|
||||
x: (src.x - src.displayOriginX) + (bx * sx),
|
||||
y: (src.y - src.displayOriginY) + (by * sy),
|
||||
width: bw * sx,
|
||||
height: bh * sy
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ var BitmapText = new Class({
|
|||
*
|
||||
* Local size is based on just the font size and a [0, 0] position.
|
||||
*
|
||||
* Global size takes into account the Game Object's scale and world position.
|
||||
* Global size takes into account the Game Object's scale, world position and display origin.
|
||||
*
|
||||
* @method Phaser.GameObjects.BitmapText#getTextBounds
|
||||
* @since 3.0.0
|
||||
|
|
|
@ -40,7 +40,6 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
var xAdvance = 0;
|
||||
var yAdvance = 0;
|
||||
|
||||
var indexCount = 0;
|
||||
var charCode = 0;
|
||||
|
||||
var glyph = null;
|
||||
|
@ -123,7 +122,6 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
if (charCode === 10)
|
||||
{
|
||||
xAdvance = 0;
|
||||
indexCount = 0;
|
||||
yAdvance += lineHeight;
|
||||
lastGlyph = null;
|
||||
continue;
|
||||
|
@ -142,7 +140,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
|
||||
x = indexCount + glyph.xOffset + xAdvance;
|
||||
x = glyph.xOffset + xAdvance;
|
||||
y = glyph.yOffset + yAdvance;
|
||||
|
||||
if (lastGlyph !== null)
|
||||
|
@ -155,7 +153,6 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
y *= scale;
|
||||
|
||||
xAdvance += glyph.xAdvance + letterSpacing;
|
||||
indexCount += 1;
|
||||
lastGlyph = glyph;
|
||||
lastCharCode = charCode;
|
||||
|
||||
|
|
|
@ -79,7 +79,6 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
|
|||
|
||||
var xAdvance = 0;
|
||||
var yAdvance = 0;
|
||||
var indexCount = 0;
|
||||
var charCode = 0;
|
||||
var lastCharCode = 0;
|
||||
var letterSpacing = src.letterSpacing;
|
||||
|
@ -105,7 +104,6 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
|
|||
if (charCode === 10)
|
||||
{
|
||||
xAdvance = 0;
|
||||
indexCount = 0;
|
||||
yAdvance += lineHeight;
|
||||
lastGlyph = null;
|
||||
|
||||
|
@ -125,8 +123,8 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
|
|||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
|
||||
var x = (indexCount + glyph.xOffset + xAdvance) * scale;
|
||||
var y = (glyph.yOffset + yAdvance) * scale;
|
||||
var x = (glyph.xOffset + xAdvance) - src.displayOriginX;
|
||||
var y = (glyph.yOffset + yAdvance) - src.displayOriginY;
|
||||
|
||||
if (lastGlyph !== null)
|
||||
{
|
||||
|
@ -135,7 +133,6 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
|
|||
}
|
||||
|
||||
xAdvance += glyph.xAdvance + letterSpacing;
|
||||
indexCount++;
|
||||
lastGlyph = glyph;
|
||||
lastCharCode = charCode;
|
||||
|
||||
|
@ -145,13 +142,16 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
|
|||
continue;
|
||||
}
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
var u0 = glyphX / textureWidth;
|
||||
var v0 = glyphY / textureHeight;
|
||||
var u1 = (glyphX + glyphW) / textureWidth;
|
||||
var v1 = (glyphY + glyphH) / textureHeight;
|
||||
|
||||
var xw = x + glyphW * scale;
|
||||
var yh = y + glyphH * scale;
|
||||
var xw = x + (glyphW * scale);
|
||||
var yh = y + (glyphH * scale);
|
||||
|
||||
var tx0 = x * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
||||
var ty0 = x * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
||||
|
|
Loading…
Reference in a new issue