Skip to content

Commit a4577e2

Browse files
committed
The GetBitmapTextSize function has a new boolean parameter updateOrigin, which will adjust the origin of the parent BitmapText if set, based on the new bounds calculations.
1 parent a682b83 commit a4577e2

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

src/gameobjects/bitmaptext/GetBitmapTextSize.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
* @private
2020
*
2121
* @param {(Phaser.GameObjects.DynamicBitmapText|Phaser.GameObjects.BitmapText)} src - The BitmapText to calculate the bounds values for.
22-
* @param {boolean} [round] - Whether to round the positions to the nearest integer.
22+
* @param {boolean} [round=false] - Whether to round the positions to the nearest integer.
23+
* @param {boolean} [updateOrigin=false] - Whether to update the origin of the BitmapText after bounds calculations?
2324
* @param {object} [out] - Object to store the results in, to save constant object creation. If not provided an empty object is returned.
2425
*
2526
* @return {Phaser.Types.GameObjects.BitmapText.BitmapTextSize} The calculated bounds values of the BitmapText.
2627
*/
27-
var GetBitmapTextSize = function (src, round, out)
28+
var GetBitmapTextSize = function (src, round, updateOrigin, out)
2829
{
30+
if (updateOrigin === undefined) { updateOrigin = false; }
31+
2932
if (out === undefined)
3033
{
3134
out = {
@@ -385,6 +388,16 @@ var GetBitmapTextSize = function (src, round, out)
385388
w: glyph.width * scale,
386389
h: glyph.height * scale,
387390
line: currentLine,
391+
isTinted: false,
392+
tintEffect: 0,
393+
tintTL: 0,
394+
tintTR: 0,
395+
tintBL: 0,
396+
tintBR: 0,
397+
alphaTL: 1,
398+
alphaTR: 1,
399+
alphaBL: 1,
400+
alphaBR: 1,
388401
glyph: glyph
389402
});
390403

@@ -446,8 +459,9 @@ var GetBitmapTextSize = function (src, round, out)
446459
local.width = bw * scale;
447460
local.height = bh * scale;
448461

449-
global.x = (src.x - src.displayOriginX) + (bx * sx);
450-
global.y = (src.y - src.displayOriginY) + (by * sy);
462+
global.x = (src.x - src._displayOriginX) + (bx * sx);
463+
global.y = (src.y - src._displayOriginY) + (by * sy);
464+
451465
global.width = bw * sx;
452466
global.height = bh * sy;
453467

@@ -471,6 +485,21 @@ var GetBitmapTextSize = function (src, round, out)
471485
lines.longest = Math.ceil(longestLine);
472486
}
473487

488+
if (updateOrigin)
489+
{
490+
src._displayOriginX = src.originX * global.width;
491+
src._displayOriginY = src.originY * global.height;
492+
493+
global.x = (src.x - src._displayOriginX) + (bx * sx);
494+
global.y = (src.y - src._displayOriginY) + (by * sy);
495+
496+
if (round)
497+
{
498+
global.x = Math.ceil(global.x);
499+
global.y = Math.ceil(global.y);
500+
}
501+
}
502+
474503
out.words = words;
475504
out.characters = characters;
476505
out.lines.height = lineHeight;

src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,9 @@ var BitmapText = new Class({
373373

374374
if (this._dirty || round || this.scaleX !== bounds.scaleX || this.scaleY !== bounds.scaleY)
375375
{
376-
this._dirty = false;
377-
378-
GetBitmapTextSize(this, round, bounds);
376+
GetBitmapTextSize(this, round, true, bounds);
379377

380-
this.updateDisplayOrigin();
378+
this._dirty = false;
381379
}
382380

383381
return bounds;
@@ -443,8 +441,12 @@ var BitmapText = new Class({
443441
*/
444442
updateDisplayOrigin: function ()
445443
{
446-
this._displayOriginX = this.originX * this.width;
447-
this._displayOriginY = this.originY * this.height;
444+
this._dirty = true;
445+
446+
this.getTextBounds(false);
447+
448+
// this._displayOriginX = this.originX * this.width;
449+
// this._displayOriginY = this.originY * this.height;
448450

449451
return this;
450452
},
@@ -482,7 +484,7 @@ var BitmapText = new Class({
482484

483485
this.setTexture(entry.texture, entry.frame);
484486

485-
GetBitmapTextSize(this, false, this._bounds);
487+
GetBitmapTextSize(this, false, true, this._bounds);
486488
}
487489
}
488490

0 commit comments

Comments
 (0)