Skip to content

Commit d034f23

Browse files
committed
Tided up the renderer, optimized ParseXML a load, removed dead files.
1 parent 6fa10a3 commit d034f23

6 files changed

Lines changed: 65 additions & 183 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: '7d8aef10-ffa6-11e6-8da0-df16c1ad112f'
2+
build: '8a9ef8e0-ffb0-11e6-922a-fdf541bc229e'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/bitmaptext/BitmapText.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,41 @@ var BitmapText = new Class({
4646
return this;
4747
},
4848

49+
setFontSize: function (size)
50+
{
51+
this.fontSize = size;
52+
53+
return this;
54+
},
55+
4956
setText: function (text)
5057
{
5158
this.text = text;
5259

5360
return this;
5461
},
5562

63+
// {
64+
// local: {
65+
// x,
66+
// y,
67+
// width,
68+
// height
69+
// },
70+
// global: {
71+
// x,
72+
// y,
73+
// width,
74+
// height
75+
// }
76+
// }
77+
5678
getTextBounds: function ()
5779
{
58-
var size = GetBitmapTextSize(this);
80+
// local = the BitmapText based on fontSize and 0x0 coords
81+
// global = the BitmapText, taking into account scale and world position
5982

60-
return { x: this.x + size.x, y: this.y + size.y, width: size.width, height: size.height };
83+
return GetBitmapTextSize(this);
6184
}
6285

6386
});

v3/src/gameobjects/bitmaptext/BitmapTextCanvasRenderer.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
133133
// ctx.fillStyle = 'rgba(0,255,0,0.2)';
134134
// ctx.fillRect(0, 0, glyphW, glyphH);
135135

136-
// if (!window.bob)
137-
// {
138-
// window.bob = true;
139-
// console.log('xywh', x, y, glyphW, glyphH);
140-
// console.log('scaled', x * scale, y * scale, glyphW * scale, glyphH * scale);
141-
// }
142-
143136
ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
144137

145138
ctx.restore();

v3/src/gameobjects/bitmaptext/GetBitmapTextSize.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@ var GetBitmapTextSize = function (src)
44
var text = src.text;
55
var textLength = text.length;
66

7-
if (textLength === 0)
8-
{
9-
return {
10-
x: 0,
11-
y: 0,
12-
width: 0,
13-
height: 0
14-
};
15-
}
16-
177
var bx = Number.MAX_VALUE;
188
var by = Number.MAX_VALUE;
199
var bw = 0;
@@ -38,8 +28,6 @@ var GetBitmapTextSize = function (src)
3828
var lastGlyph = null;
3929
var lastCharCode = 0;
4030

41-
var scale = (src.fontSize / src.fontData.size);
42-
4331
for (var index = 0; index < textLength; ++index)
4432
{
4533
charCode = text.charCodeAt(index);
@@ -101,19 +89,23 @@ var GetBitmapTextSize = function (src)
10189
lastCharCode = charCode;
10290
}
10391

92+
var scale = (src.fontSize / src.fontData.size);
10493
var sx = scale * src.scaleX;
10594
var sy = scale * src.scaleY;
10695

107-
bx *= sx;
108-
by *= sy;
109-
bw *= sx;
110-
bh *= sy;
111-
11296
return {
113-
x: bx,
114-
y: by,
115-
width: bw,
116-
height: bh
97+
local: {
98+
x: bx * scale,
99+
y: by * scale,
100+
width: bw * scale,
101+
height: bh * scale
102+
},
103+
global: {
104+
x: src.x + (bx * sx),
105+
y: src.y + (by * sy),
106+
width: bw * sx,
107+
height: bh * sy
108+
}
117109
};
118110
};
119111

v3/src/gameobjects/bitmaptext/ParseXMLBitmapFont.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
function getValue (node, attribute)
2+
{
3+
return parseInt(node.getAttribute(attribute), 10);
4+
}
5+
16
var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame)
27
{
38
if (xSpacing === undefined) { xSpacing = 0; }
@@ -8,8 +13,8 @@ var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame)
813
var common = xml.getElementsByTagName('common')[0];
914

1015
data.font = info.getAttribute('face');
11-
data.size = parseInt(info.getAttribute('size'), 10);
12-
data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10) + ySpacing;
16+
data.size = getValue(info, 'size');
17+
data.lineHeight = getValue(common, 'lineHeight') + ySpacing;
1318
data.chars = {};
1419

1520
var letters = xml.getElementsByTagName('char');
@@ -19,17 +24,23 @@ var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame)
1924

2025
for (var i = 0; i < letters.length; i++)
2126
{
22-
var charCode = parseInt(letters[i].getAttribute('id'), 10);
27+
var node = letters[i];
28+
29+
var charCode = getValue(node, 'id');
30+
var gw = getValue(node, 'width');
31+
var gh = getValue(node, 'height');
2332

2433
data.chars[charCode] =
2534
{
26-
x: x + parseInt(letters[i].getAttribute('x'), 10),
27-
y: y + parseInt(letters[i].getAttribute('y'), 10),
28-
width: parseInt(letters[i].getAttribute('width'), 10),
29-
height: parseInt(letters[i].getAttribute('height'), 10),
30-
xOffset: parseInt(letters[i].getAttribute('xoffset'), 10),
31-
yOffset: parseInt(letters[i].getAttribute('yoffset'), 10),
32-
xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10) + xSpacing,
35+
x: x + getValue(node, 'x'),
36+
y: y + getValue(node, 'y'),
37+
width: gw,
38+
height: gh,
39+
centerX: Math.floor(gw / 2),
40+
centerY: Math.floor(gh / 2),
41+
xOffset: getValue(node, 'xoffset'),
42+
yOffset: getValue(node, 'yoffset'),
43+
xAdvance: getValue(node, 'xadvance') + xSpacing,
3344
kerning: {}
3445
};
3546
}
@@ -38,9 +49,11 @@ var ParseXMLBitmapFont = function (xml, xSpacing, ySpacing, frame)
3849

3950
for (i = 0; i < kernings.length; i++)
4051
{
41-
var first = parseInt(kernings[i].getAttribute('first'), 10);
42-
var second = parseInt(kernings[i].getAttribute('second'), 10);
43-
var amount = parseInt(kernings[i].getAttribute('amount'), 10);
52+
var kern = kernings[i];
53+
54+
var first = getValue(kern, 'first');
55+
var second = getValue(kern, 'second');
56+
var amount = getValue(kern, 'amount');
4457

4558
data.chars[second].kerning[first] = amount;
4659
}

v3/src/gameobjects/bitmaptext/_GetBitmapTextSize.js

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)