mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
New features added.
This commit is contained in:
parent
0fc9c3f4ad
commit
6648543446
3 changed files with 55 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
||||||
var CHECKSUM = {
|
var CHECKSUM = {
|
||||||
build: '24668b80-fe14-11e6-9463-35f4273cae70'
|
build: 'e143e9e0-fe97-11e6-b242-774fc1dcf72c'
|
||||||
};
|
};
|
||||||
module.exports = CHECKSUM;
|
module.exports = CHECKSUM;
|
|
@ -31,8 +31,30 @@ var BitmapText = new Class({
|
||||||
|
|
||||||
this.fontSize = size;
|
this.fontSize = size;
|
||||||
|
|
||||||
|
// Setting these will enable the Size component to work
|
||||||
|
// then anchorX etc will work too
|
||||||
|
// this.frame.realWidth = 0;
|
||||||
|
// this.frame.realHeight = 0;
|
||||||
|
|
||||||
|
this.displayCallback;
|
||||||
|
|
||||||
this.setTexture(font);
|
this.setTexture(font);
|
||||||
this.setPosition(x, y);
|
this.setPosition(x, y);
|
||||||
|
},
|
||||||
|
|
||||||
|
setDisplayCallback: function (callback)
|
||||||
|
{
|
||||||
|
this.displayCallback = callback;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
|
setText: function (text)
|
||||||
|
{
|
||||||
|
// this._text = text;
|
||||||
|
// this.dirty = true;
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,15 +10,14 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
||||||
|
|
||||||
var textureFrame = src.frame;
|
var textureFrame = src.frame;
|
||||||
|
|
||||||
|
var displayCallback = src.displayCallback;
|
||||||
|
|
||||||
var cameraScrollX = camera.scrollX;
|
var cameraScrollX = camera.scrollX;
|
||||||
var cameraScrollY = camera.scrollY;
|
var cameraScrollY = camera.scrollY;
|
||||||
|
|
||||||
var chars = src.fontData.chars;
|
var chars = src.fontData.chars;
|
||||||
var lineHeight = src.fontData.lineHeight;
|
var lineHeight = src.fontData.lineHeight;
|
||||||
|
|
||||||
var srcX = src.x;
|
|
||||||
var srcY = src.y;
|
|
||||||
|
|
||||||
var xAdvance = 0;
|
var xAdvance = 0;
|
||||||
var yAdvance = 0;
|
var yAdvance = 0;
|
||||||
|
|
||||||
|
@ -43,8 +42,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
||||||
var textureX = textureFrame.cutX;
|
var textureX = textureFrame.cutX;
|
||||||
var textureY = textureFrame.cutY;
|
var textureY = textureFrame.cutY;
|
||||||
|
|
||||||
var scaleX = src.scaleX * (src.fontSize / src.fontData.size);
|
var rotation = 0;
|
||||||
var scaleY = src.scaleY * (src.fontSize / src.fontData.size);
|
var scale = (src.fontSize / src.fontData.size);
|
||||||
|
|
||||||
// Blend Mode
|
// Blend Mode
|
||||||
if (renderer.currentBlendMode !== src.blendMode)
|
if (renderer.currentBlendMode !== src.blendMode)
|
||||||
|
@ -66,8 +65,17 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
||||||
renderer.currentScaleMode = src.scaleMode;
|
renderer.currentScaleMode = src.scaleMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(src.x, src.y);
|
||||||
|
ctx.rotate(src.rotation);
|
||||||
|
ctx.scale(src.scaleX, src.scaleY);
|
||||||
|
|
||||||
for (var index = 0; index < textLength; ++index)
|
for (var index = 0; index < textLength; ++index)
|
||||||
{
|
{
|
||||||
|
// Reset the scale (in case the callback changed it)
|
||||||
|
scale = (src.fontSize / src.fontData.size);
|
||||||
|
rotation = 0;
|
||||||
|
|
||||||
charCode = text.charCodeAt(index);
|
charCode = text.charCodeAt(index);
|
||||||
|
|
||||||
if (charCode === 10)
|
if (charCode === 10)
|
||||||
|
@ -92,8 +100,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
||||||
glyphW = glyph.width;
|
glyphW = glyph.width;
|
||||||
glyphH = glyph.height;
|
glyphH = glyph.height;
|
||||||
|
|
||||||
x = srcX + indexCount + glyph.xOffset + xAdvance;
|
x = indexCount + glyph.xOffset + xAdvance;
|
||||||
y = srcY + glyph.yOffset + yAdvance;
|
y = glyph.yOffset + yAdvance;
|
||||||
|
|
||||||
if (lastGlyph !== null)
|
if (lastGlyph !== null)
|
||||||
{
|
{
|
||||||
|
@ -101,15 +109,26 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
||||||
x += (kerningOffset !== undefined) ? kerningOffset : 0;
|
x += (kerningOffset !== undefined) ? kerningOffset : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
x *= scaleX;
|
if (displayCallback)
|
||||||
y *= scaleY;
|
{
|
||||||
|
var output = displayCallback({ index: index, charCode: charCode, x: x, y: y, scale: scale, rotation: 0 });
|
||||||
|
|
||||||
|
x = output.x;
|
||||||
|
y = output.y;
|
||||||
|
scale = output.scale;
|
||||||
|
rotation = output.rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
x *= scale;
|
||||||
|
y *= scale;
|
||||||
|
|
||||||
x -= cameraScrollX;
|
x -= cameraScrollX;
|
||||||
y -= cameraScrollY;
|
y -= cameraScrollY;
|
||||||
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.translate(x, y);
|
ctx.translate(x, y);
|
||||||
ctx.scale(scaleX, scaleY);
|
ctx.rotate(rotation);
|
||||||
|
ctx.scale(scale, scale);
|
||||||
ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
|
ctx.drawImage(image, glyphX, glyphY, glyphW, glyphH, 0, 0, glyphW, glyphH);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
|
||||||
|
@ -118,6 +137,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
||||||
lastGlyph = glyph;
|
lastGlyph = glyph;
|
||||||
lastCharCode = charCode;
|
lastCharCode = charCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.restore();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = BitmapTextCanvasRenderer;
|
module.exports = BitmapTextCanvasRenderer;
|
||||||
|
|
Loading…
Reference in a new issue