Moving more rendering functionality over.

This commit is contained in:
Richard Davey 2016-10-04 00:58:52 +01:00
parent 0142997787
commit d55cc215ee
2 changed files with 98 additions and 1 deletions

View file

@ -82,7 +82,7 @@ Phaser.Image.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
* @method Phaser.Image#preUpdate
* @memberof Phaser.Image
*/
Phaser.Image.prototype.preUpdate = function() {
Phaser.Image.prototype.preUpdate = function () {
if (!this.preUpdateInWorld())
{

View file

@ -0,0 +1,97 @@
/**
* 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.Container = {
render: function (renderer)
{
if (!this.visible || this.alpha <= 0 || !this.children.length)
{
return;
}
var context = renderer.context;
context.globalAlpha = this.worldAlpha;
this.displayObjectUpdateTransform();
var transform = this.worldTransform;
var isRotated = true;
for (var i = 0; i < this.children.length; i++)
{
var child = this.children[i];
if (!child.visible)
{
continue;
}
var texture = child.texture;
var frame = texture.frame;
context.globalAlpha = this.worldAlpha * child.alpha;
if (child.rotation % Phaser.Math.PI2 === 0)
{
// If rotation === 0 we can avoid setTransform
if (isRotated)
{
context.setTransform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty);
isRotated = false;
}
context.drawImage(
texture.baseTexture.source,
frame.x,
frame.y,
frame.width,
frame.height,
((child.anchor.x) * (-frame.width * child.scale.x) + child.position.x + 0.5 + renderSession.shakeX) | 0,
((child.anchor.y) * (-frame.height * child.scale.y) + child.position.y + 0.5 + renderSession.shakeY) | 0,
frame.width * child.scale.x,
frame.height * child.scale.y);
}
else
{
if (!isRotated)
{
isRotated = true;
}
child.displayObjectUpdateTransform();
var childTransform = child.worldTransform;
var tx = (childTransform.tx * renderSession.resolution) + renderSession.shakeX;
var ty = (childTransform.ty * renderSession.resolution) + renderSession.shakeY;
// allow for trimming
if (renderer.roundPixels)
{
context.setTransform(childTransform.a, childTransform.b, childTransform.c, childTransform.d, tx | 0, ty | 0);
}
else
{
context.setTransform(childTransform.a, childTransform.b, childTransform.c, childTransform.d, tx, ty);
}
context.drawImage(
texture.baseTexture.source,
frame.x,
frame.y,
frame.width,
frame.height,
((child.anchor.x) * (-frame.width) + 0.5) | 0,
((child.anchor.y) * (-frame.height) + 0.5) | 0,
frame.width,
frame.height);
}
}
}
};