Skip to content

Commit 64dafcc

Browse files
committed
Fixed width and height properties for Dynamic Bitmap Text
1 parent d6fb8d7 commit 64dafcc

3 files changed

Lines changed: 52 additions & 13 deletions

File tree

v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ var DynamicBitmapText = new Class({
4848
this.scrollX = 0;
4949
this.scrollY = 0;
5050

51-
this.width = 0;
52-
this.height = 0;
51+
this.cropWidth = 0;
52+
this.cropHeight = 0;
5353

5454
this.displayCallback;
5555
},
5656

5757
setSize: function (width, height)
5858
{
59-
this.width = width;
60-
this.height = height;
59+
this.cropWidth = width;
60+
this.cropHeight = height;
6161

6262
return this;
6363
},
@@ -112,12 +112,51 @@ var DynamicBitmapText = new Class({
112112
// }
113113
// }
114114

115-
getTextBounds: function ()
115+
getTextBounds: function (round)
116116
{
117117
// local = the BitmapText based on fontSize and 0x0 coords
118118
// global = the BitmapText, taking into account scale and world position
119119

120-
return GetBitmapTextSize(this);
120+
this._bounds = GetBitmapTextSize(this, round);
121+
122+
return this._bounds;
123+
},
124+
125+
width: {
126+
127+
get: function ()
128+
{
129+
this.getTextBounds(false);
130+
return this._bounds.global.width;
131+
}
132+
133+
},
134+
135+
height: {
136+
137+
get: function ()
138+
{
139+
this.getTextBounds(false);
140+
return this._bounds.global.height;
141+
}
142+
143+
},
144+
145+
toJSON: function ()
146+
{
147+
var out = Components.ToJSON(this);
148+
149+
// Extra data is added here
150+
151+
var data = {
152+
font: this.font,
153+
text: this.text,
154+
fontSize: this.fontSize
155+
};
156+
157+
out.data = data;
158+
159+
return out;
121160
}
122161

123162
});

v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCanvasRenderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
7070
ctx.rotate(src.rotation);
7171
ctx.scale(src.scaleX, src.scaleY);
7272

73-
if (src.width > 0 && src.height > 0)
73+
if (src.cropWidth > 0 && src.cropHeight > 0)
7474
{
7575
ctx.save();
7676
ctx.beginPath();
77-
ctx.rect(0, 0, src.width, src.height);
77+
ctx.rect(0, 0, src.cropWidth, src.cropHeight);
7878
ctx.clip();
7979
ctx.closePath();
8080
}
@@ -154,7 +154,7 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
154154
lastCharCode = charCode;
155155
}
156156

157-
if (src.width > 0 && src.height > 0)
157+
if (src.cropWidth > 0 && src.cropHeight > 0)
158158
{
159159
ctx.restore();
160160
}

v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextWebGLRenderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
9494

9595
var gl = renderer.gl;
9696

97-
if (gameObject.width > 0 && gameObject.height > 0)
97+
if (gameObject.cropWidth > 0 && gameObject.cropHeight > 0)
9898
{
9999
if (renderer.currentRenderer !== null)
100100
{
@@ -106,8 +106,8 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
106106
gl.enable(gl.SCISSOR_TEST);
107107
}
108108

109-
var sw = gameObject.width * gameObject.scaleX;
110-
var sh = gameObject.height * gameObject.scaleY;
109+
var sw = gameObject.cropWidth * gameObject.scaleX;
110+
var sh = gameObject.cropHeight * gameObject.scaleY;
111111

112112
gl.scissor(gameObject.x, gl.drawingBufferHeight - gameObject.y - sh, sw, sh);
113113
}
@@ -255,7 +255,7 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
255255
lastCharCode = charCode;
256256
}
257257

258-
if (gameObject.width > 0 && gameObject.height > 0)
258+
if (gameObject.cropWidth > 0 && gameObject.cropHeight > 0)
259259
{
260260
spriteBatch.flush();
261261

0 commit comments

Comments
 (0)