ScrollZone back in under the new renderer with new demos

This commit is contained in:
Richard Davey
2013-05-30 05:34:35 +01:00
parent f2054f8a2a
commit ce1523585f
28 changed files with 1582 additions and 349 deletions
+116
View File
@@ -1,5 +1,6 @@
/// <reference path="../Game.ts" />
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="../gameobjects/ScrollZone.ts" />
/// <reference path="../cameras/Camera.ts" />
/// <reference path="IRenderer.ts" />
@@ -199,6 +200,121 @@ module Phaser {
}
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool {
// Render checks (needs inCamera check added)
if (scrollZone.scale.x == 0 || scrollZone.scale.y == 0 || scrollZone.texture.alpha < 0.1)
{
return false;
}
// Reset our temp vars
this._ga = -1;
this._sx = 0;
this._sy = 0;
this._sw = scrollZone.frameBounds.width;
this._sh = scrollZone.frameBounds.height;
this._fx = scrollZone.scale.x;
this._fy = scrollZone.scale.y;
this._sin = 0;
this._cos = 1;
this._dx = (camera.scaledX * scrollZone.scrollFactor.x) + scrollZone.frameBounds.x - (camera.worldView.x * scrollZone.scrollFactor.x);
this._dy = (camera.scaledY * scrollZone.scrollFactor.y) + scrollZone.frameBounds.y - (camera.worldView.y * scrollZone.scrollFactor.y);
this._dw = scrollZone.frameBounds.width;
this._dh = scrollZone.frameBounds.height;
// Alpha
if (scrollZone.texture.alpha !== 1)
{
this._ga = scrollZone.texture.context.globalAlpha;
scrollZone.texture.context.globalAlpha = scrollZone.texture.alpha;
}
// Sprite Flip X
if (scrollZone.texture.flippedX)
{
this._fx = -scrollZone.scale.x;
}
// Sprite Flip Y
if (scrollZone.texture.flippedY)
{
this._fy = -scrollZone.scale.y;
}
// Rotation and Flipped
if (scrollZone.modified)
{
if (scrollZone.texture.renderRotation == true && (scrollZone.rotation !== 0 || scrollZone.rotationOffset !== 0))
{
this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.rotationOffset + scrollZone.rotation));
this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.rotationOffset + scrollZone.rotation));
}
// setTransform(a, b, c, d, e, f);
// a = scale x
// b = skew x
// c = skew y
// d = scale y
// e = translate x
// f = translate y
scrollZone.texture.context.save();
scrollZone.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + scrollZone.skew.x, -(this._sin * this._fy) + scrollZone.skew.y, this._cos * this._fy, this._dx, this._dy);
this._dx = -scrollZone.origin.x;
this._dy = -scrollZone.origin.y;
}
else
{
if (!scrollZone.origin.equals(0))
{
this._dx -= scrollZone.origin.x;
this._dy -= scrollZone.origin.y;
}
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
this._sw = Math.round(this._sw);
this._sh = Math.round(this._sh);
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
for (var i = 0; i < scrollZone.regions.length; i++)
{
if (scrollZone.texture.isDynamic)
{
scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
}
else
{
scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
}
}
if (scrollZone.modified)
{
scrollZone.texture.context.restore();
}
//if (this.renderDebug)
//{
// this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
//this.collisionMask.render(camera, cameraOffsetX, cameraOffsetY);
//}
if (this._ga > -1)
{
scrollZone.texture.context.globalAlpha = this._ga;
}
return true;
}
}
}
+3 -9
View File
@@ -18,18 +18,12 @@ module Phaser {
public render() {}
public renderSprite(camera: Camera, sprite: Sprite): bool {
// Render checks (needs inCamera check added)
if (sprite.scale.x == 0 || sprite.scale.y == 0 || sprite.texture.alpha < 0.1)
{
return false;
}
return true;
}
// Add Tilemap, ScrollZone, etc?
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool {
return true;
}
}
+1
View File
@@ -6,6 +6,7 @@ module Phaser {
render();
renderSprite(camera: Camera, sprite: Sprite): bool;
renderScrollZone(camera: Camera, sprite: ScrollZone): bool;
}