Skip to content

Commit 3852c9c

Browse files
committed
BitmapText can take a contents array now. Also fixed scroll rect.
1 parent 798ffa9 commit 3852c9c

4 files changed

Lines changed: 35 additions & 31 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'ae3fbaf0-4bdc-11e7-8d01-0d1ecc83299a'
2+
build: 'b5751ca0-4be3-11e7-b9b3-d158ff787407'
33
};
44
module.exports = CHECKSUM;

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var DynamicBitmapText = new Class({
1313
Components.BlendMode,
1414
Components.Origin,
1515
Components.RenderTarget,
16-
Components.Size,
1716
Components.Texture,
1817
Components.Transform,
1918
Components.Visible,
@@ -31,21 +30,30 @@ var DynamicBitmapText = new Class({
3130

3231
this.fontData = this.state.sys.cache.bitmapFont.get(font);
3332

34-
this.text = text;
33+
this.text = (Array.isArray(text)) ? text.join('\n') : text;
3534

3635
this.fontSize = size || this.fontData.size;
3736

38-
this._scrollX = 0;
39-
this._scrollY = 0;
40-
this._maxWidth = 0;
41-
this._maxHeight = 0;
37+
this.scrollX = 0;
38+
this.scrollY = 0;
39+
40+
this.width = 0;
41+
this.height = 0;
4242

4343
this.displayCallback;
4444

4545
this.setTexture(font);
4646
this.setPosition(x, y);
4747
},
4848

49+
setSize: function (width, height)
50+
{
51+
this.width = width;
52+
this.height = height;
53+
54+
return this;
55+
},
56+
4957
setDisplayCallback: function (callback)
5058
{
5159
this.displayCallback = callback;
@@ -67,30 +75,16 @@ var DynamicBitmapText = new Class({
6775
return this;
6876
},
6977

70-
setMaxWidth: function (value)
71-
{
72-
this._maxWidth = value;
73-
74-
return this;
75-
},
76-
77-
setMaxHeight: function (value)
78-
{
79-
this._maxHeight = value;
80-
81-
return this;
82-
},
83-
8478
setScrollX: function (value)
8579
{
86-
this._scrollX = value;
80+
this.scrollX = value;
8781

8882
return this;
8983
},
9084

9185
setScrollY: function (value)
9286
{
93-
this._scrollY = value;
87+
this.scrollY = value;
9488

9589
return this;
9690
},

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

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

73-
var currentX;
74-
var currentY;
73+
if (src.width > 0 && src.height > 0)
74+
{
75+
ctx.save();
76+
ctx.beginPath();
77+
ctx.rect(0, 0, src.width, src.height);
78+
ctx.clip();
79+
ctx.closePath();
80+
}
7581

7682
for (var index = 0; index < textLength; ++index)
7783
{
@@ -103,8 +109,10 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
103109
glyphW = glyph.width;
104110
glyphH = glyph.height;
105111

106-
x = indexCount + glyph.xOffset + xAdvance;
107-
y = glyph.yOffset + yAdvance;
112+
x = (indexCount + glyph.xOffset + xAdvance) - src.scrollX;
113+
y = (glyph.yOffset + yAdvance) - src.scrollY;
114+
115+
// This could be optimized so that it doesn't even bother drawing it if the x/y is out of range
108116

109117
if (lastGlyph !== null)
110118
{
@@ -122,9 +130,6 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
122130
rotation = output.rotation;
123131
}
124132

125-
// Scroll clipping
126-
x -= src._scrollX;
127-
128133
x *= scale;
129134
y *= scale;
130135

@@ -149,6 +154,11 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
149154
lastCharCode = charCode;
150155
}
151156

157+
if (src.width > 0 && src.height > 0)
158+
{
159+
ctx.restore();
160+
}
161+
152162
ctx.restore();
153163
};
154164

v3/src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var BitmapText = new Class({
3434
this.font = font;
3535
this.fontData = this.state.sys.cache.bitmapFont.get(font);
3636

37-
this.text = text;
37+
this.text = (Array.isArray(text)) ? text.join('\n') : text;
3838

3939
this.fontSize = size || this.fontData.size;
4040

0 commit comments

Comments
 (0)