mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +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 = {
|
||||
build: '24668b80-fe14-11e6-9463-35f4273cae70'
|
||||
build: 'e143e9e0-fe97-11e6-b242-774fc1dcf72c'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -31,8 +31,30 @@ var BitmapText = new Class({
|
|||
|
||||
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.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 displayCallback = src.displayCallback;
|
||||
|
||||
var cameraScrollX = camera.scrollX;
|
||||
var cameraScrollY = camera.scrollY;
|
||||
|
||||
var chars = src.fontData.chars;
|
||||
var lineHeight = src.fontData.lineHeight;
|
||||
|
||||
var srcX = src.x;
|
||||
var srcY = src.y;
|
||||
|
||||
var xAdvance = 0;
|
||||
var yAdvance = 0;
|
||||
|
||||
|
@ -43,8 +42,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
var textureX = textureFrame.cutX;
|
||||
var textureY = textureFrame.cutY;
|
||||
|
||||
var scaleX = src.scaleX * (src.fontSize / src.fontData.size);
|
||||
var scaleY = src.scaleY * (src.fontSize / src.fontData.size);
|
||||
var rotation = 0;
|
||||
var scale = (src.fontSize / src.fontData.size);
|
||||
|
||||
// Blend Mode
|
||||
if (renderer.currentBlendMode !== src.blendMode)
|
||||
|
@ -66,8 +65,17 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
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)
|
||||
{
|
||||
// Reset the scale (in case the callback changed it)
|
||||
scale = (src.fontSize / src.fontData.size);
|
||||
rotation = 0;
|
||||
|
||||
charCode = text.charCodeAt(index);
|
||||
|
||||
if (charCode === 10)
|
||||
|
@ -92,8 +100,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
|
||||
x = srcX + indexCount + glyph.xOffset + xAdvance;
|
||||
y = srcY + glyph.yOffset + yAdvance;
|
||||
x = indexCount + glyph.xOffset + xAdvance;
|
||||
y = glyph.yOffset + yAdvance;
|
||||
|
||||
if (lastGlyph !== null)
|
||||
{
|
||||
|
@ -101,15 +109,26 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
x += (kerningOffset !== undefined) ? kerningOffset : 0;
|
||||
}
|
||||
|
||||
x *= scaleX;
|
||||
y *= scaleY;
|
||||
if (displayCallback)
|
||||
{
|
||||
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;
|
||||
y -= cameraScrollY;
|
||||
|
||||
ctx.save();
|
||||
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.restore();
|
||||
|
||||
|
@ -118,6 +137,8 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
|
|||
lastGlyph = glyph;
|
||||
lastCharCode = charCode;
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
};
|
||||
|
||||
module.exports = BitmapTextCanvasRenderer;
|
||||
|
|
Loading…
Reference in a new issue