2016-10-05 00:09:23 +00:00
|
|
|
|
2016-10-04 21:36:07 +00:00
|
|
|
/**
|
|
|
|
* Note that 'this' in all functions here refer to the owning object.
|
|
|
|
* For example the Group, Stage, Sprite, etc. because the render function
|
|
|
|
* here is mapped to the prototype for the game object.
|
|
|
|
*/
|
|
|
|
Phaser.Renderer.Canvas.GameObjects.Text = {
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
TYPES: [
|
2016-10-08 02:05:42 +00:00
|
|
|
Phaser.GameObjects.Text.prototype
|
2016-10-05 00:09:23 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
render: function (renderer, src)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
if (src.dirty)
|
2016-10-04 21:47:05 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
src.updateText();
|
|
|
|
src.dirty = false;
|
2016-10-04 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 21:36:07 +00:00
|
|
|
// If the sprite is not visible or the alpha is 0 then no need to render this element
|
2016-10-05 00:09:23 +00:00
|
|
|
if (!src.visible || src.alpha === 0 || !src.renderable)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add back in: || src.texture.crop.width <= 0 || src.texture.crop.height <= 0
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
var wt = src.worldTransform;
|
2016-10-04 21:36:07 +00:00
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
if (src.blendMode !== renderer.currentBlendMode)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
renderer.currentBlendMode = src.blendMode;
|
2016-10-04 21:36:07 +00:00
|
|
|
renderer.context.globalCompositeOperation = Phaser.blendModesCanvas[renderer.currentBlendMode];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the texture can be rendered
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
if (src._mask)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
renderer.pushMask(src._mask);
|
2016-10-04 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
var resolution = src.texture.baseTexture.resolution / renderer.game.resolution;
|
2016-10-04 21:36:07 +00:00
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
renderer.context.globalAlpha = src.worldAlpha;
|
2016-10-04 21:36:07 +00:00
|
|
|
|
|
|
|
// If smoothingEnabled is supported and we need to change the smoothing property for src texture
|
2016-10-05 00:09:23 +00:00
|
|
|
if (renderer.smoothProperty && renderer.currentScaleMode !== src.texture.baseTexture.scaleMode)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
renderer.currentScaleMode = src.texture.baseTexture.scaleMode;
|
2016-10-04 21:36:07 +00:00
|
|
|
renderer.context[renderer.smoothProperty] = (renderer.currentScaleMode === Phaser.scaleModes.LINEAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions
|
2016-10-05 00:09:23 +00:00
|
|
|
var dx = (src.texture.trim) ? src.texture.trim.x - src.anchor.x * src.texture.trim.width : src.anchor.x * -src.texture.frame.width;
|
|
|
|
var dy = (src.texture.trim) ? src.texture.trim.y - src.anchor.y * src.texture.trim.height : src.anchor.y * -src.texture.frame.height;
|
2016-10-04 21:36:07 +00:00
|
|
|
|
|
|
|
var tx = (wt.tx * renderer.game.resolution) + renderer.game.camera._shake.x;
|
|
|
|
var ty = (wt.ty * renderer.game.resolution) + renderer.game.camera._shake.y;
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
var cw = src.texture.crop.width;
|
|
|
|
var ch = src.texture.crop.height;
|
2016-10-04 21:36:07 +00:00
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
if (src.texture.rotated)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
|
|
|
var a = wt.a;
|
|
|
|
var b = wt.b;
|
|
|
|
var c = wt.c;
|
|
|
|
var d = wt.d;
|
|
|
|
var e = cw;
|
|
|
|
|
|
|
|
// Offset before rotating
|
|
|
|
tx = wt.c * ch + tx;
|
|
|
|
ty = wt.d * ch + ty;
|
|
|
|
|
|
|
|
// Rotate matrix by 90 degrees
|
|
|
|
// We use precalculated values for sine and cosine of rad(90)
|
|
|
|
wt.a = a * 6.123233995736766e-17 + -c;
|
|
|
|
wt.b = b * 6.123233995736766e-17 + -d;
|
|
|
|
wt.c = a + c * 6.123233995736766e-17;
|
|
|
|
wt.d = b + d * 6.123233995736766e-17;
|
|
|
|
|
|
|
|
// Update cropping dimensions.
|
|
|
|
cw = ch;
|
|
|
|
ch = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow for pixel rounding
|
|
|
|
if (renderer.roundPixels)
|
|
|
|
{
|
|
|
|
renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx | 0, ty | 0);
|
|
|
|
dx |= 0;
|
|
|
|
dy |= 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
renderer.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx, ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
dx /= resolution;
|
|
|
|
dy /= resolution;
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
if (src.tint !== 0xFFFFFF)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
if (src.texture.requiresReTint || src.cachedTint !== src.tint)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
src.tintedTexture = PIXI.CanvasTinter.getTintedTexture(src, src.tint);
|
2016-10-04 21:36:07 +00:00
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
src.cachedTint = src.tint;
|
|
|
|
src.texture.requiresReTint = false;
|
2016-10-04 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
renderer.context.drawImage(src.tintedTexture, 0, 0, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
2016-10-04 21:36:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
var cx = src.texture.crop.x;
|
|
|
|
var cy = src.texture.crop.y;
|
2016-10-04 21:36:07 +00:00
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
renderer.context.drawImage(src.texture.baseTexture.source, cx, cy, cw, ch, dx, dy, cw / resolution, ch / resolution);
|
2016-10-04 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
for (var i = 0; i < src.children.length; i++)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
2016-10-05 00:09:23 +00:00
|
|
|
var child = src.children[i];
|
|
|
|
child.render(renderer, child);
|
2016-10-04 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 00:09:23 +00:00
|
|
|
if (src._mask)
|
2016-10-04 21:36:07 +00:00
|
|
|
{
|
|
|
|
renderer.popMask();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|