diff --git a/Phaser/Game.ts b/Phaser/Game.ts
index 7df89909..49e96bc9 100644
--- a/Phaser/Game.ts
+++ b/Phaser/Game.ts
@@ -1,9 +1,9 @@
-///
+///
///
///
-///
-///
-///
+///
+///
+///
///
///
///
diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj
index 8028b489..f699e104 100644
--- a/Phaser/Phaser.csproj
+++ b/Phaser/Phaser.csproj
@@ -87,27 +87,11 @@
Game.ts
-
-
CameraFX.ts
-
- Point.ts
-
-
-
- Polygon.ts
-
-
- Rectangle.ts
-
-
-
- Vec2.ts
-
DynamicTexture.ts
@@ -126,6 +110,22 @@
Tilemap.ts
+
+
+ Circle.ts
+
+
+
+ Line.ts
+
+
+
+ Point.ts
+
+
+
+ Rectangle.ts
+
GameMath.ts
@@ -144,6 +144,14 @@
+
+
+ Mat3.ts
+
+
+
+ Mat3Utils.ts
+
QuadTree.ts
@@ -152,6 +160,10 @@
LinkedList.ts
+
+
+ Vec2.ts
+
Motion.ts
@@ -200,15 +212,9 @@
RectangleUtils.ts
-
- Circle.ts
-
IntersectResult.ts
-
- Line.ts
-
Vec2Utils.ts
@@ -341,9 +347,7 @@
-
-
Group.ts
diff --git a/Phaser/World.ts b/Phaser/World.ts
index 0b1aabbf..6309e499 100644
--- a/Phaser/World.ts
+++ b/Phaser/World.ts
@@ -1,7 +1,7 @@
///
///
///
-///
+///
///
/**
diff --git a/Phaser/cameras/Camera.ts b/Phaser/cameras/Camera.ts
index b8badc77..0d873f81 100644
--- a/Phaser/cameras/Camera.ts
+++ b/Phaser/cameras/Camera.ts
@@ -1,7 +1,7 @@
///
-///
-///
-///
+///
+///
+///
///
///
///
diff --git a/Phaser/components/ScrollRegion.ts b/Phaser/components/ScrollRegion.ts
index aa75d28d..e8369dd7 100644
--- a/Phaser/components/ScrollRegion.ts
+++ b/Phaser/components/ScrollRegion.ts
@@ -1,6 +1,6 @@
///
-///
-///
+///
+///
/**
* Phaser - ScrollRegion
diff --git a/Phaser/components/Transform.ts b/Phaser/components/Transform.ts
index 70dd8f84..e56d1f0d 100644
--- a/Phaser/components/Transform.ts
+++ b/Phaser/components/Transform.ts
@@ -1,4 +1,5 @@
///
+///
/**
* Phaser - Components - Transform
@@ -17,6 +18,8 @@ module Phaser.Components {
this.game = parent.game;
this.parent = parent;
+ this.local = new Mat3;
+
this.scrollFactor = new Phaser.Vec2(1, 1);
this.origin = new Phaser.Vec2;
this.scale = new Phaser.Vec2(1, 1);
@@ -24,6 +27,77 @@ module Phaser.Components {
}
+ public local: Mat3;
+
+ private _sin: number;
+ private _cos: number;
+
+ public update() {
+
+ // 0 a = scale x
+ // 3 b = skew x
+ // 1 c = skew y
+ // 4 d = scale y
+ // 2 e = translate x
+ // 5 f = translate y
+
+ // Scale & Skew
+
+ // if (sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.transform.rotationOffset !== 0))
+
+ this._sin = 0;
+ this._cos = 1;
+
+ if (this.parent.texture.renderRotation)
+ {
+ this._sin = GameMath.sinA[this.rotation + this.rotationOffset];
+ this._cos = GameMath.cosA[this.rotation + this.rotationOffset];
+ }
+
+ if (this.parent.texture.flippedX)
+ {
+ //this.local.data[0] = GameMath.cosA[this.rotation + this.rotationOffset] * -this.scale.x;
+ //this.local.data[3] = (GameMath.sinA[this.rotation + this.rotationOffset] * -this.scale.x) + this.skew.x;
+ this.local.data[0] = this._cos * -this.scale.x;
+ this.local.data[3] = (this._sin * -this.scale.x) + this.skew.x;
+ }
+ else
+ {
+ //this.local.data[0] = GameMath.cosA[this.rotation + this.rotationOffset] * this.scale.x;
+ //this.local.data[3] = (GameMath.sinA[this.rotation + this.rotationOffset] * this.scale.x) + this.skew.x;
+ this.local.data[0] = this._cos * this.scale.x;
+ this.local.data[3] = (this._sin * this.scale.x) + this.skew.x;
+ }
+
+ if (this.parent.texture.flippedY)
+ {
+ //this.local.data[4] = GameMath.cosA[this.rotation + this.rotationOffset] * -this.scale.y;
+ //this.local.data[1] = -(GameMath.sinA[this.rotation + this.rotationOffset] * -this.scale.y) + this.skew.y;
+ this.local.data[4] = this._cos * -this.scale.y;
+ this.local.data[1] = -(this._sin * -this.scale.y) + this.skew.y;
+ }
+ else
+ {
+ //this.local.data[4] = GameMath.cosA[this.rotation + this.rotationOffset] * this.scale.y;
+ //this.local.data[1] = -(GameMath.sinA[this.rotation + this.rotationOffset] * this.scale.y) + this.skew.y;
+ this.local.data[4] = this._cos * this.scale.y;
+ this.local.data[1] = -(this._sin * this.scale.y) + this.skew.y;
+ }
+
+ // Translate
+ this.local.data[2] = this.parent.x;
+ this.local.data[5] = this.parent.y;
+
+ }
+
+ public get calculatedX(): number {
+ return this.origin.x * this.scale.x;
+ }
+
+ public get calculatedY(): number {
+ return this.origin.y * this.scale.y;
+ }
+
/**
* Reference to Phaser.Game
*/
@@ -50,7 +124,7 @@ module Phaser.Components {
public scrollFactor: Phaser.Vec2;
/**
- * The origin is the point around which scale and rotation takes place.
+ * The origin is the point around which scale and rotation takes place and defaults to the center of the sprite.
*/
public origin: Phaser.Vec2;
@@ -67,6 +141,20 @@ module Phaser.Components {
*/
public rotation: number = 0;
+ /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ public get centerX(): number {
+ return this.parent.width / 2;
+ }
+
+ /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ public get centerY(): number {
+ return this.parent.height / 2;
+ }
+
}
}
\ No newline at end of file
diff --git a/Phaser/core/Polygon.ts b/Phaser/core/Polygon.ts
deleted file mode 100644
index d1e851c4..00000000
--- a/Phaser/core/Polygon.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-///
-
-/**
-* Phaser - Polygon
-*
-*
-*/
-
-module Phaser {
-
- export class Polygon {
-
- /**
- *
- **/
- constructor(game: Game, points: Point[]) {
-
- this.game = game;
- this.context = game.stage.context;
-
- this.points = [];
-
- for (var i = 0; i < points.length; i++)
- {
- this.points.push(new Point().copyFrom(points[i]));
- }
-
- }
-
- public points: Point[];
- public game: Game;
- public context: CanvasRenderingContext2D;
-
- public render() {
-
- this.context.beginPath();
- this.context.strokeStyle = 'rgb(255,255,0)';
- this.context.moveTo(this.points[0].x, this.points[0].y);
-
- for (var i = 1; i < this.points.length; i++)
- {
- this.context.lineTo(this.points[i].x, this.points[i].y);
- }
-
- this.context.lineTo(this.points[0].x, this.points[0].y);
-
- this.context.stroke();
- this.context.closePath();
-
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/Phaser/gameobjects/ScrollZone.ts b/Phaser/gameobjects/ScrollZone.ts
index 2044a00d..aac49c72 100644
--- a/Phaser/gameobjects/ScrollZone.ts
+++ b/Phaser/gameobjects/ScrollZone.ts
@@ -1,5 +1,5 @@
///
-///
+///
///
/**
diff --git a/Phaser/gameobjects/Sprite.ts b/Phaser/gameobjects/Sprite.ts
index 001d59b1..3bf3d28e 100644
--- a/Phaser/gameobjects/Sprite.ts
+++ b/Phaser/gameobjects/Sprite.ts
@@ -1,6 +1,6 @@
///
-///
-///
+///
+///
///
///
///
@@ -40,11 +40,12 @@ module Phaser {
this.z = -1;
this.group = null;
- this.transform = new Phaser.Components.Transform(this);
+ // No dependencies
this.animations = new Phaser.Components.AnimationManager(this);
- this.texture = new Phaser.Components.Texture(this);
this.input = new Phaser.Components.Sprite.Input(this);
this.events = new Phaser.Components.Sprite.Events(this);
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
if (key !== null)
{
@@ -233,10 +234,14 @@ module Phaser {
*/
public preUpdate() {
+ this.transform.update();
+
//this.worldView.x = this.x * this.transform.scrollFactor.x;
//this.worldView.y = this.y * this.transform.scrollFactor.y;
- this.worldView.x = this.x - this.transform.origin.x;
- this.worldView.y = this.y - this.transform.origin.y;
+ this.worldView.x = this.x;
+ this.worldView.y = this.y;
+ //this.worldView.x = this.x - this.transform.origin.x;
+ //this.worldView.y = this.y - this.transform.origin.y;
this.worldView.width = this.width;
this.worldView.height = this.height;
diff --git a/Phaser/core/Circle.ts b/Phaser/geom/Circle.ts
similarity index 100%
rename from Phaser/core/Circle.ts
rename to Phaser/geom/Circle.ts
diff --git a/Phaser/core/Line.ts b/Phaser/geom/Line.ts
similarity index 100%
rename from Phaser/core/Line.ts
rename to Phaser/geom/Line.ts
diff --git a/Phaser/core/Point.ts b/Phaser/geom/Point.ts
similarity index 100%
rename from Phaser/core/Point.ts
rename to Phaser/geom/Point.ts
diff --git a/Phaser/core/Rectangle.ts b/Phaser/geom/Rectangle.ts
similarity index 100%
rename from Phaser/core/Rectangle.ts
rename to Phaser/geom/Rectangle.ts
diff --git a/Phaser/input/Pointer.ts b/Phaser/input/Pointer.ts
index e9afa9b3..7b89d213 100644
--- a/Phaser/input/Pointer.ts
+++ b/Phaser/input/Pointer.ts
@@ -1,5 +1,5 @@
///
-///
+///
/**
* Phaser - Pointer
diff --git a/Phaser/math/GameMath.ts b/Phaser/math/GameMath.ts
index 0c071772..c9afa8f4 100644
--- a/Phaser/math/GameMath.ts
+++ b/Phaser/math/GameMath.ts
@@ -12,11 +12,26 @@ module Phaser {
export class GameMath {
constructor(game: Game) {
+
this.game = game;
+
+ GameMath.sinA = [];
+ GameMath.cosA = [];
+
+ for (var i = 0; i < 360; i++)
+ {
+ GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
+ GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
+ }
}
public game: Game;
+ // Pre-calculated tables containing Math.sin(angle) and Math.cos(angle) from -180 to 180
+ // So sinA[sprite.rotation] would be the same as Math.sin(sprite.rotation) without a call to Math.sin
+ static sinA: number[];
+ static cosA: number[];
+
static PI: number = 3.141592653589793; //number pi
static PI_2: number = 1.5707963267948965; //PI / 2 OR 90 deg
static PI_4: number = 0.7853981633974483; //PI / 4 OR 45 deg
diff --git a/Phaser/math/Mat3.ts b/Phaser/math/Mat3.ts
new file mode 100644
index 00000000..9b37f7f2
--- /dev/null
+++ b/Phaser/math/Mat3.ts
@@ -0,0 +1,275 @@
+///
+
+/**
+* Phaser - Mat3
+*
+* A 3x3 Matrix
+*/
+
+module Phaser {
+
+ export class Mat3 {
+
+ /**
+ * Creates a new Mat3 object.
+ * @class Mat3
+ * @constructor
+ * @return {Mat3} This object
+ **/
+ constructor() {
+ this.data = [1, 0, 0, 0, 1, 0, 0, 0, 1];
+ }
+
+ // Temporary vars used for internal calculations
+ private _a00: number;
+ private _a01: number;
+ private _a02: number;
+ private _a10: number;
+ private _a11: number;
+ private _a12: number;
+ private _a20: number;
+ private _a21: number;
+ private _a22: number;
+
+ public data: number[];
+
+ public get a00(): number {
+ return this.data[0];
+ }
+
+ public set a00(value: number) {
+ this.data[0] = value;
+ }
+
+ public get a01(): number {
+ return this.data[1];
+ }
+
+ public set a01(value: number) {
+ this.data[1] = value;
+ }
+
+ public get a02(): number {
+ return this.data[2];
+ }
+
+ public set a02(value: number) {
+ this.data[2] = value;
+ }
+
+ public get a10(): number {
+ return this.data[3];
+ }
+
+ public set a10(value: number) {
+ this.data[3] = value;
+ }
+
+ public get a11(): number {
+ return this.data[4];
+ }
+
+ public set a11(value: number) {
+ this.data[4] = value;
+ }
+
+ public get a12(): number {
+ return this.data[5];
+ }
+
+ public set a12(value: number) {
+ this.data[5] = value;
+ }
+
+ public get a20(): number {
+ return this.data[6];
+ }
+
+ public set a20(value: number) {
+ this.data[6] = value;
+ }
+
+ public get a21(): number {
+ return this.data[7];
+ }
+
+ public set a21(value: number) {
+ this.data[7] = value;
+ }
+
+ public get a22(): number {
+ return this.data[8];
+ }
+
+ public set a22(value: number) {
+ this.data[8] = value;
+ }
+
+ /**
+ * Copies the values from one Mat3 into this Mat3.
+ * @method copyFromMat3
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ public copyFromMat3(source: Mat3): Mat3 {
+
+ this.data[0] = source.data[0];
+ this.data[1] = source.data[1];
+ this.data[2] = source.data[2];
+ this.data[3] = source.data[3];
+ this.data[4] = source.data[4];
+ this.data[5] = source.data[5];
+ this.data[6] = source.data[6];
+ this.data[7] = source.data[7];
+ this.data[8] = source.data[8];
+
+ return this;
+ }
+
+ /**
+ * Copies the upper-left 3x3 values into this Mat3.
+ * @method copyFromMat4
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ public copyFromMat4(source: any): Mat3 {
+
+ this.data[0] = source[0];
+ this.data[1] = source[1];
+ this.data[2] = source[2];
+ this.data[3] = source[4];
+ this.data[4] = source[5];
+ this.data[5] = source[6];
+ this.data[6] = source[8];
+ this.data[7] = source[9];
+ this.data[8] = source[10];
+
+ return this;
+ }
+
+ /**
+ * Clones this Mat3 into a new Mat3
+ * @param {Mat3} out The output Mat3, if none is given a new Mat3 object will be created.
+ * @return {Mat3} The new Mat3
+ **/
+ public clone(out?:Mat3 = new Phaser.Mat3): Mat3 {
+
+ out[0] = this.data[0];
+ out[1] = this.data[1];
+ out[2] = this.data[2];
+ out[3] = this.data[3];
+ out[4] = this.data[4];
+ out[5] = this.data[5];
+ out[6] = this.data[6];
+ out[7] = this.data[7];
+ out[8] = this.data[8];
+
+ return out;
+
+ }
+
+ /**
+ * Sets this Mat3 to the identity matrix.
+ * @method identity
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ public identity(): Mat3 {
+ return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ }
+
+ /**
+ * Translates this Mat3 by the given vector
+ **/
+ public translate(v:Phaser.Vec2): Mat3 {
+
+ this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
+ this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
+ this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
+
+ return this;
+
+ }
+
+ private setTemps() {
+
+ this._a00 = this.data[0];
+ this._a01 = this.data[1];
+ this._a02 = this.data[2];
+ this._a10 = this.data[3];
+ this._a11 = this.data[4];
+ this._a12 = this.data[5];
+ this._a20 = this.data[6];
+ this._a21 = this.data[7];
+ this._a22 = this.data[8];
+
+ }
+
+ /**
+ * Rotates this Mat3 by the given angle (given in radians)
+ **/
+ public rotate(rad:number): Mat3 {
+
+ this.setTemps();
+
+ var s = GameMath.sinA[rad];
+ var c = GameMath.cosA[rad];
+
+ this.data[0] = c * this._a00 + s * this._a10;
+ this.data[1] = c * this._a01 + s * this._a10;
+ this.data[2] = c * this._a02 + s * this._a12;
+
+ this.data[3] = c * this._a10 - s * this._a00;
+ this.data[4] = c * this._a11 - s * this._a01;
+ this.data[5] = c * this._a12 - s * this._a02;
+
+ return this;
+
+ }
+
+ /**
+ * Scales this Mat3 by the given vector
+ **/
+ public scale(v: Vec2): Mat3 {
+
+ this.data[0] = v.x * this.data[0];
+ this.data[1] = v.x * this.data[1];
+ this.data[2] = v.x * this.data[2];
+
+ this.data[3] = v.y * this.data[3];
+ this.data[4] = v.y * this.data[4];
+ this.data[5] = v.y * this.data[5];
+
+ return this;
+
+ }
+
+ public setTo(a00: number, a01: number, a02: number, a10: number, a11: number, a12: number, a20: number, a21: number, a22: number): Mat3 {
+
+ this.data[0] = a00;
+ this.data[1] = a01;
+ this.data[2] = a02;
+ this.data[3] = a10;
+ this.data[4] = a11;
+ this.data[5] = a12;
+ this.data[6] = a20;
+ this.data[7] = a21;
+ this.data[8] = a22;
+
+ return this;
+
+ }
+
+ /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ public toString(): string {
+ return '';
+ //return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/math/Mat3Utils.ts b/Phaser/math/Mat3Utils.ts
new file mode 100644
index 00000000..3808a5d2
--- /dev/null
+++ b/Phaser/math/Mat3Utils.ts
@@ -0,0 +1,189 @@
+///
+///
+///
+
+/**
+* Phaser - Mat3Utils
+*
+* A collection of methods useful for manipulating and performing operations on Mat3 objects.
+*
+*/
+
+module Phaser {
+
+ export class Mat3Utils {
+
+ /**
+ * Transpose the values of a Mat3
+ **/
+ static transpose(source:Phaser.Mat3, dest?:Phaser.Mat3 = null): Mat3 {
+
+ if (dest === null)
+ {
+ // Transpose ourselves
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a12 = source.data[5];
+
+ source.data[1] = source.data[3];
+ source.data[2] = source.data[6];
+ source.data[3] = a01;
+ source.data[5] = source.data[7];
+ source.data[6] = a02;
+ source.data[7] = a12;
+ }
+ else
+ {
+ source.data[0] = dest.data[0];
+ source.data[1] = dest.data[3];
+ source.data[2] = dest.data[6];
+ source.data[3] = dest.data[1];
+ source.data[4] = dest.data[4];
+ source.data[5] = dest.data[7];
+ source.data[6] = dest.data[2];
+ source.data[7] = dest.data[5];
+ source.data[8] = dest.data[8];
+ }
+
+ return source;
+
+ }
+
+ /**
+ * Inverts a Mat3
+ **/
+ static invert(source:Phaser.Mat3): Mat3 {
+
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+
+ var b01 = a22 * a11 - a12 * a21;
+ var b11 = -a22 * a10 + a12 * a20;
+ var b21 = a21 * a10 - a11 * a20;
+
+ // Determinant
+ var det = a00 * b01 + a01 * b11 + a02 * b21;
+
+ if (!det) {
+ return null;
+ }
+
+ det = 1.0 / det;
+
+ source.data[0] = b01 * det;
+ source.data[1] = (-a22 * a01 + a02 * a21) * det;
+ source.data[2] = (a12 * a01 - a02 * a11) * det;
+ source.data[3] = b11 * det;
+ source.data[4] = (a22 * a00 - a02 * a20) * det;
+ source.data[5] = (-a12 * a00 + a02 * a10) * det;
+ source.data[6] = b21 * det;
+ source.data[7] = (-a21 * a00 + a01 * a20) * det;
+ source.data[8] = (a11 * a00 - a01 * a10) * det;
+
+ return source;
+
+ }
+
+ /**
+ * Calculates the adjugate of a Mat3
+ **/
+ static adjoint(source:Phaser.Mat3): Mat3 {
+
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+
+ source.data[0] = (a11 * a22 - a12 * a21);
+ source.data[1] = (a02 * a21 - a01 * a22);
+ source.data[2] = (a01 * a12 - a02 * a11);
+ source.data[3] = (a12 * a20 - a10 * a22);
+ source.data[4] = (a00 * a22 - a02 * a20);
+ source.data[5] = (a02 * a10 - a00 * a12);
+ source.data[6] = (a10 * a21 - a11 * a20);
+ source.data[7] = (a01 * a20 - a00 * a21);
+ source.data[8] = (a00 * a11 - a01 * a10);
+
+ return source;
+
+ }
+
+ /**
+ * Calculates the adjugate of a Mat3
+ **/
+ static determinant(source:Phaser.Mat3): number {
+
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+
+ return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
+
+ }
+
+ /**
+ * Multiplies two Mat3s
+ **/
+ static multiply(source:Phaser.Mat3, b:Phaser.Mat3): Mat3 {
+
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+
+ var b00 = b.data[0];
+ var b01 = b.data[1];
+ var b02 = b.data[2];
+ var b10 = b.data[3];
+ var b11 = b.data[4];
+ var b12 = b.data[5];
+ var b20 = b.data[6];
+ var b21 = b.data[7];
+ var b22 = b.data[8];
+
+ source.data[0] = b00 * a00 + b01 * a10 + b02 * a20;
+ source.data[1] = b00 * a01 + b01 * a11 + b02 * a21;
+ source.data[2] = b00 * a02 + b01 * a12 + b02 * a22;
+
+ source.data[3] = b10 * a00 + b11 * a10 + b12 * a20;
+ source.data[4] = b10 * a01 + b11 * a11 + b12 * a21;
+ source.data[5] = b10 * a02 + b11 * a12 + b12 * a22;
+
+ source.data[6] = b20 * a00 + b21 * a10 + b22 * a20;
+ source.data[7] = b20 * a01 + b21 * a11 + b22 * a21;
+ source.data[8] = b20 * a02 + b21 * a12 + b22 * a22;
+
+ return source;
+
+ }
+
+ static fromQuaternion() { }
+ static normalFromMat4() { }
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/Phaser/math/QuadTree.ts b/Phaser/math/QuadTree.ts
index 1675a98c..738ab331 100644
--- a/Phaser/math/QuadTree.ts
+++ b/Phaser/math/QuadTree.ts
@@ -1,5 +1,5 @@
///
-///
+///
///
/**
diff --git a/Phaser/core/Vec2.ts b/Phaser/math/Vec2.ts
similarity index 98%
rename from Phaser/core/Vec2.ts
rename to Phaser/math/Vec2.ts
index e3118c35..637c78b6 100644
--- a/Phaser/core/Vec2.ts
+++ b/Phaser/math/Vec2.ts
@@ -3,7 +3,7 @@
/**
* Phaser - Vec2
*
-* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+* A Vector 2
*/
module Phaser {
diff --git a/Phaser/math/Vec2Utils.ts b/Phaser/math/Vec2Utils.ts
index b0f4f14a..3c093fca 100644
--- a/Phaser/math/Vec2Utils.ts
+++ b/Phaser/math/Vec2Utils.ts
@@ -1,5 +1,5 @@
///
-///
+///
/**
* Phaser - Vec2Utils
diff --git a/Phaser/physics/Body.ts b/Phaser/physics/Body.ts
index aaa547b1..a4b7a9f8 100644
--- a/Phaser/physics/Body.ts
+++ b/Phaser/physics/Body.ts
@@ -1,5 +1,5 @@
-///
-///
+///
+///
///
/**
diff --git a/Phaser/renderers/CanvasRenderer.ts b/Phaser/renderers/CanvasRenderer.ts
index cd5777d1..13d635bc 100644
--- a/Phaser/renderers/CanvasRenderer.ts
+++ b/Phaser/renderers/CanvasRenderer.ts
@@ -443,11 +443,10 @@ module Phaser {
if (sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false)
{
- return false;
+ //return false;
}
sprite.renderOrderID = this._count;
-
this._count++;
// Reset our temp vars
@@ -456,12 +455,8 @@ module Phaser {
this._sy = 0;
this._sw = sprite.texture.width;
this._sh = sprite.texture.height;
- this._fx = sprite.transform.scale.x;
- this._fy = sprite.transform.scale.y;
- this._sin = 0;
- this._cos = 1;
- this._dx = (camera.screenView.x * sprite.transform.scrollFactor.x) + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
- this._dy = (camera.screenView.y * sprite.transform.scrollFactor.y) + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
+ this._dx = camera.screenView.x + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
+ this._dy = camera.screenView.y + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
this._dw = sprite.texture.width;
this._dh = sprite.texture.height;
@@ -479,18 +474,6 @@ module Phaser {
sprite.texture.context.globalAlpha = sprite.texture.alpha;
}
- // Sprite Flip X
- if (sprite.texture.flippedX)
- {
- this._fx = -sprite.transform.scale.x;
- }
-
- // Sprite Flip Y
- if (sprite.texture.flippedY)
- {
- this._fy = -sprite.transform.scale.y;
- }
-
if (sprite.animations.currentFrame !== null)
{
this._sx = sprite.animations.currentFrame.x;
@@ -507,36 +490,26 @@ module Phaser {
}
}
- // Rotation and Flipped
if (sprite.modified)
{
- if (sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.transform.rotationOffset !== 0))
- {
- this._sin = Math.sin(sprite.game.math.degreesToRadians(sprite.transform.rotationOffset + sprite.rotation));
- this._cos = Math.cos(sprite.game.math.degreesToRadians(sprite.transform.rotationOffset + sprite.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
-
sprite.texture.context.save();
- sprite.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + sprite.transform.skew.x, -(this._sin * this._fy) + sprite.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
- this._dx = -sprite.transform.origin.x;
- this._dy = -sprite.transform.origin.y;
+ sprite.texture.context.setTransform(
+ sprite.transform.local.data[0], // scale x
+ sprite.transform.local.data[3], // skew x
+ sprite.transform.local.data[1], // skew y
+ sprite.transform.local.data[4], // scale y
+ this._dx, // translate x
+ this._dy // translate y
+ );
+
+ this._dx = sprite.transform.origin.x * -this._dw;
+ this._dy = sprite.transform.origin.y * -this._dh;
}
else
{
- if (!sprite.transform.origin.equals(0))
- {
- this._dx -= sprite.transform.origin.x;
- this._dy -= sprite.transform.origin.y;
- }
+ this._dx -= (this._dw * sprite.transform.origin.x);
+ this._dy -= (this._dh * sprite.transform.origin.y);
}
this._sx = Math.round(this._sx);
@@ -568,7 +541,7 @@ module Phaser {
this._dh // Destination Height (always same as Source Height unless scaled)
);
}
-
+
if (sprite.modified || sprite.texture.globalCompositeOperation)
{
sprite.texture.context.restore();
diff --git a/Phaser/utils/CircleUtils.ts b/Phaser/utils/CircleUtils.ts
index 51fa2005..35c26673 100644
--- a/Phaser/utils/CircleUtils.ts
+++ b/Phaser/utils/CircleUtils.ts
@@ -1,7 +1,7 @@
///
-///
-///
-///
+///
+///
+///
/**
* Phaser - CircleUtils
diff --git a/Phaser/utils/ColorUtils.ts b/Phaser/utils/ColorUtils.ts
index 426bff91..9f26ca8e 100644
--- a/Phaser/utils/ColorUtils.ts
+++ b/Phaser/utils/ColorUtils.ts
@@ -1,7 +1,7 @@
///
-///
-///
-///
+///
+///
+///
/**
* Phaser - ColorUtils
diff --git a/Phaser/utils/DebugUtils.ts b/Phaser/utils/DebugUtils.ts
index d27b0cb6..e1bf9039 100644
--- a/Phaser/utils/DebugUtils.ts
+++ b/Phaser/utils/DebugUtils.ts
@@ -1,7 +1,7 @@
///
-///
-///
-///
+///
+///
+///
///
///
diff --git a/Phaser/utils/PixelUtils.ts b/Phaser/utils/PixelUtils.ts
index 21ec835f..dfd1f8d3 100644
--- a/Phaser/utils/PixelUtils.ts
+++ b/Phaser/utils/PixelUtils.ts
@@ -1,7 +1,7 @@
///
-///
-///
-///
+///
+///
+///
/**
* Phaser - PixelUtils
diff --git a/Phaser/utils/PointUtils.ts b/Phaser/utils/PointUtils.ts
index f15cea4d..1431f215 100644
--- a/Phaser/utils/PointUtils.ts
+++ b/Phaser/utils/PointUtils.ts
@@ -1,5 +1,5 @@
///
-///
+///
/**
* Phaser - PointUtils
diff --git a/Phaser/utils/RectangleUtils.ts b/Phaser/utils/RectangleUtils.ts
index 7882f27b..180af7a3 100644
--- a/Phaser/utils/RectangleUtils.ts
+++ b/Phaser/utils/RectangleUtils.ts
@@ -1,6 +1,6 @@
///
-///
-///
+///
+///
/**
* Phaser - RectangleUtils
diff --git a/Phaser/utils/SpriteUtils.ts b/Phaser/utils/SpriteUtils.ts
index f3bd461d..7d8519bc 100644
--- a/Phaser/utils/SpriteUtils.ts
+++ b/Phaser/utils/SpriteUtils.ts
@@ -1,7 +1,7 @@
///
-///
-///
-///
+///
+///
+///
///
///
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 0c682e29..e26a5666 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -193,6 +193,10 @@
atlas 2.ts
+
+
+ origin 5.ts
+
tween loop 1.ts
diff --git a/Tests/phaser.js b/Tests/phaser.js
index a07d9581..79107e15 100644
--- a/Tests/phaser.js
+++ b/Tests/phaser.js
@@ -384,7 +384,7 @@ var __extends = this.__extends || function (d, b) {
d.prototype = new __();
};
///
-///
+///
///
/**
* Phaser - QuadTree
@@ -734,7 +734,7 @@ var Phaser;
/**
* Phaser - Vec2
*
-* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+* A Vector 2
*/
var Phaser;
(function (Phaser) {
@@ -1264,8 +1264,8 @@ var Phaser;
Phaser.Types = Types;
})(Phaser || (Phaser = {}));
///
-///
-///
+///
+///
/**
* Phaser - RectangleUtils
*
@@ -1455,9 +1455,9 @@ var Phaser;
Phaser.RectangleUtils = RectangleUtils;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
/**
* Phaser - ColorUtils
*
@@ -2797,9 +2797,263 @@ var Phaser;
})(Phaser.Components || (Phaser.Components = {}));
var Components = Phaser.Components;
})(Phaser || (Phaser = {}));
+///
+/**
+* Phaser - Mat3
+*
+* A 3x3 Matrix
+*/
+var Phaser;
+(function (Phaser) {
+ var Mat3 = (function () {
+ /**
+ * Creates a new Mat3 object.
+ * @class Mat3
+ * @constructor
+ * @return {Mat3} This object
+ **/
+ function Mat3() {
+ this.data = [
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1
+ ];
+ }
+ Object.defineProperty(Mat3.prototype, "a00", {
+ get: function () {
+ return this.data[0];
+ },
+ set: function (value) {
+ this.data[0] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a01", {
+ get: function () {
+ return this.data[1];
+ },
+ set: function (value) {
+ this.data[1] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a02", {
+ get: function () {
+ return this.data[2];
+ },
+ set: function (value) {
+ this.data[2] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a10", {
+ get: function () {
+ return this.data[3];
+ },
+ set: function (value) {
+ this.data[3] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a11", {
+ get: function () {
+ return this.data[4];
+ },
+ set: function (value) {
+ this.data[4] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a12", {
+ get: function () {
+ return this.data[5];
+ },
+ set: function (value) {
+ this.data[5] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a20", {
+ get: function () {
+ return this.data[6];
+ },
+ set: function (value) {
+ this.data[6] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a21", {
+ get: function () {
+ return this.data[7];
+ },
+ set: function (value) {
+ this.data[7] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a22", {
+ get: function () {
+ return this.data[8];
+ },
+ set: function (value) {
+ this.data[8] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Mat3.prototype.copyFromMat3 = /**
+ * Copies the values from one Mat3 into this Mat3.
+ * @method copyFromMat3
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function (source) {
+ this.data[0] = source.data[0];
+ this.data[1] = source.data[1];
+ this.data[2] = source.data[2];
+ this.data[3] = source.data[3];
+ this.data[4] = source.data[4];
+ this.data[5] = source.data[5];
+ this.data[6] = source.data[6];
+ this.data[7] = source.data[7];
+ this.data[8] = source.data[8];
+ return this;
+ };
+ Mat3.prototype.copyFromMat4 = /**
+ * Copies the upper-left 3x3 values into this Mat3.
+ * @method copyFromMat4
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function (source) {
+ this.data[0] = source[0];
+ this.data[1] = source[1];
+ this.data[2] = source[2];
+ this.data[3] = source[4];
+ this.data[4] = source[5];
+ this.data[5] = source[6];
+ this.data[6] = source[8];
+ this.data[7] = source[9];
+ this.data[8] = source[10];
+ return this;
+ };
+ Mat3.prototype.clone = /**
+ * Clones this Mat3 into a new Mat3
+ * @param {Mat3} out The output Mat3, if none is given a new Mat3 object will be created.
+ * @return {Mat3} The new Mat3
+ **/
+ function (out) {
+ if (typeof out === "undefined") { out = new Phaser.Mat3(); }
+ out[0] = this.data[0];
+ out[1] = this.data[1];
+ out[2] = this.data[2];
+ out[3] = this.data[3];
+ out[4] = this.data[4];
+ out[5] = this.data[5];
+ out[6] = this.data[6];
+ out[7] = this.data[7];
+ out[8] = this.data[8];
+ return out;
+ };
+ Mat3.prototype.identity = /**
+ * Sets this Mat3 to the identity matrix.
+ * @method identity
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function () {
+ return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ };
+ Mat3.prototype.translate = /**
+ * Translates this Mat3 by the given vector
+ **/
+ function (v) {
+ this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
+ this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
+ this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
+ return this;
+ };
+ Mat3.prototype.setTemps = function () {
+ this._a00 = this.data[0];
+ this._a01 = this.data[1];
+ this._a02 = this.data[2];
+ this._a10 = this.data[3];
+ this._a11 = this.data[4];
+ this._a12 = this.data[5];
+ this._a20 = this.data[6];
+ this._a21 = this.data[7];
+ this._a22 = this.data[8];
+ };
+ Mat3.prototype.rotate = /**
+ * Rotates this Mat3 by the given angle (given in radians)
+ **/
+ function (rad) {
+ this.setTemps();
+ var s = Phaser.GameMath.sinA[rad];
+ var c = Phaser.GameMath.cosA[rad];
+ this.data[0] = c * this._a00 + s * this._a10;
+ this.data[1] = c * this._a01 + s * this._a10;
+ this.data[2] = c * this._a02 + s * this._a12;
+ this.data[3] = c * this._a10 - s * this._a00;
+ this.data[4] = c * this._a11 - s * this._a01;
+ this.data[5] = c * this._a12 - s * this._a02;
+ return this;
+ };
+ Mat3.prototype.scale = /**
+ * Scales this Mat3 by the given vector
+ **/
+ function (v) {
+ this.data[0] = v.x * this.data[0];
+ this.data[1] = v.x * this.data[1];
+ this.data[2] = v.x * this.data[2];
+ this.data[3] = v.y * this.data[3];
+ this.data[4] = v.y * this.data[4];
+ this.data[5] = v.y * this.data[5];
+ return this;
+ };
+ Mat3.prototype.setTo = function (a00, a01, a02, a10, a11, a12, a20, a21, a22) {
+ this.data[0] = a00;
+ this.data[1] = a01;
+ this.data[2] = a02;
+ this.data[3] = a10;
+ this.data[4] = a11;
+ this.data[5] = a12;
+ this.data[6] = a20;
+ this.data[7] = a21;
+ this.data[8] = a22;
+ return this;
+ };
+ Mat3.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ function () {
+ return '';
+ //return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ };
+ return Mat3;
+ })();
+ Phaser.Mat3 = Mat3;
+})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
///
+ ///
/**
* Phaser - Components - Transform
*/
@@ -2823,11 +3077,87 @@ var Phaser;
this.rotation = 0;
this.game = parent.game;
this.parent = parent;
+ this.local = new Phaser.Mat3();
this.scrollFactor = new Phaser.Vec2(1, 1);
this.origin = new Phaser.Vec2();
this.scale = new Phaser.Vec2(1, 1);
this.skew = new Phaser.Vec2();
}
+ Transform.prototype.update = function () {
+ // 0 a = scale x
+ // 3 b = skew x
+ // 1 c = skew y
+ // 4 d = scale y
+ // 2 e = translate x
+ // 5 f = translate y
+ // Scale & Skew
+ // if (sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.transform.rotationOffset !== 0))
+ this._sin = 0;
+ this._cos = 1;
+ if(this.parent.texture.renderRotation) {
+ this._sin = Phaser.GameMath.sinA[this.rotation + this.rotationOffset];
+ this._cos = Phaser.GameMath.cosA[this.rotation + this.rotationOffset];
+ }
+ if(this.parent.texture.flippedX) {
+ //this.local.data[0] = GameMath.cosA[this.rotation + this.rotationOffset] * -this.scale.x;
+ //this.local.data[3] = (GameMath.sinA[this.rotation + this.rotationOffset] * -this.scale.x) + this.skew.x;
+ this.local.data[0] = this._cos * -this.scale.x;
+ this.local.data[3] = (this._sin * -this.scale.x) + this.skew.x;
+ } else {
+ //this.local.data[0] = GameMath.cosA[this.rotation + this.rotationOffset] * this.scale.x;
+ //this.local.data[3] = (GameMath.sinA[this.rotation + this.rotationOffset] * this.scale.x) + this.skew.x;
+ this.local.data[0] = this._cos * this.scale.x;
+ this.local.data[3] = (this._sin * this.scale.x) + this.skew.x;
+ }
+ if(this.parent.texture.flippedY) {
+ //this.local.data[4] = GameMath.cosA[this.rotation + this.rotationOffset] * -this.scale.y;
+ //this.local.data[1] = -(GameMath.sinA[this.rotation + this.rotationOffset] * -this.scale.y) + this.skew.y;
+ this.local.data[4] = this._cos * -this.scale.y;
+ this.local.data[1] = -(this._sin * -this.scale.y) + this.skew.y;
+ } else {
+ //this.local.data[4] = GameMath.cosA[this.rotation + this.rotationOffset] * this.scale.y;
+ //this.local.data[1] = -(GameMath.sinA[this.rotation + this.rotationOffset] * this.scale.y) + this.skew.y;
+ this.local.data[4] = this._cos * this.scale.y;
+ this.local.data[1] = -(this._sin * this.scale.y) + this.skew.y;
+ }
+ // Translate
+ this.local.data[2] = this.parent.x;
+ this.local.data[5] = this.parent.y;
+ };
+ Object.defineProperty(Transform.prototype, "calculatedX", {
+ get: function () {
+ return this.origin.x * this.scale.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "calculatedY", {
+ get: function () {
+ return this.origin.y * this.scale.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "centerX", {
+ get: /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ function () {
+ return this.parent.width / 2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "centerY", {
+ get: /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ function () {
+ return this.parent.height / 2;
+ },
+ enumerable: true,
+ configurable: true
+ });
return Transform;
})();
Components.Transform = Transform;
@@ -3412,7 +3742,7 @@ var Phaser;
var Components = Phaser.Components;
})(Phaser || (Phaser = {}));
///
-///
+///
/**
* Phaser - Vec2Utils
*
@@ -3707,8 +4037,8 @@ var Phaser;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
- ///
- ///
+ ///
+ ///
///
/**
* Phaser - Physics - Body
@@ -3938,8 +4268,8 @@ var Phaser;
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
///
-///
-///
+///
+///
///
///
///
@@ -3997,11 +4327,12 @@ var Phaser;
this.y = y;
this.z = -1;
this.group = null;
- this.transform = new Phaser.Components.Transform(this);
+ // No dependencies
this.animations = new Phaser.Components.AnimationManager(this);
- this.texture = new Phaser.Components.Texture(this);
this.input = new Phaser.Components.Sprite.Input(this);
this.events = new Phaser.Components.Sprite.Events(this);
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
if(key !== null) {
this.texture.loadImage(key, false);
} else {
@@ -4090,10 +4421,13 @@ var Phaser;
* Pre-update is called right before update() on each object in the game loop.
*/
function () {
+ this.transform.update();
//this.worldView.x = this.x * this.transform.scrollFactor.x;
//this.worldView.y = this.y * this.transform.scrollFactor.y;
- this.worldView.x = this.x - this.transform.origin.x;
- this.worldView.y = this.y - this.transform.origin.y;
+ this.worldView.x = this.x;
+ this.worldView.y = this.y;
+ //this.worldView.x = this.x - this.transform.origin.x;
+ //this.worldView.y = this.y - this.transform.origin.y;
this.worldView.width = this.width;
this.worldView.height = this.height;
if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
@@ -4183,9 +4517,9 @@ var Phaser;
Phaser.Sprite = Sprite;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
///
///
/**
@@ -6357,6 +6691,12 @@ var Phaser;
*/
this.globalSeed = Math.random();
this.game = game;
+ GameMath.sinA = [];
+ GameMath.cosA = [];
+ for(var i = 0; i < 360; i++) {
+ GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
+ GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
+ }
}
GameMath.PI = 3.141592653589793;
GameMath.PI_2 = 1.5707963267948965;
@@ -7626,9 +7966,9 @@ var Phaser;
Phaser.CameraFX = CameraFX;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
///
///
///
@@ -9164,8 +9504,8 @@ var Phaser;
Phaser.Emitter = Emitter;
})(Phaser || (Phaser = {}));
///
-///
-///
+///
+///
/**
* Phaser - ScrollRegion
*
@@ -9314,7 +9654,7 @@ var Phaser;
Phaser.ScrollRegion = ScrollRegion;
})(Phaser || (Phaser = {}));
///
-///
+///
///
/**
* Phaser - ScrollZone
@@ -11865,9 +12205,9 @@ var Phaser;
Phaser.TweenManager = TweenManager;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
/**
* Phaser - CircleUtils
*
@@ -12967,7 +13307,7 @@ var Phaser;
///
///
///
-///
+///
///
/**
* Phaser - World
@@ -13931,7 +14271,7 @@ var Phaser;
Phaser.RequestAnimationFrame = RequestAnimationFrame;
})(Phaser || (Phaser = {}));
///
-///
+///
/**
* Phaser - PointUtils
*
@@ -14128,7 +14468,7 @@ var Phaser;
})();
})(Phaser || (Phaser = {}));
///
-///
+///
/**
* Phaser - Pointer
*
@@ -16235,8 +16575,8 @@ var Phaser;
*/
function (camera, sprite) {
if(sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
- return false;
- }
+ //return false;
+ }
sprite.renderOrderID = this._count;
this._count++;
// Reset our temp vars
@@ -16245,12 +16585,8 @@ var Phaser;
this._sy = 0;
this._sw = sprite.texture.width;
this._sh = sprite.texture.height;
- this._fx = sprite.transform.scale.x;
- this._fy = sprite.transform.scale.y;
- this._sin = 0;
- this._cos = 1;
- this._dx = (camera.screenView.x * sprite.transform.scrollFactor.x) + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
- this._dy = (camera.screenView.y * sprite.transform.scrollFactor.y) + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
+ this._dx = camera.screenView.x + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
+ this._dy = camera.screenView.y + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
this._dw = sprite.texture.width;
this._dh = sprite.texture.height;
// Global Composite Ops
@@ -16263,14 +16599,6 @@ var Phaser;
this._ga = sprite.texture.context.globalAlpha;
sprite.texture.context.globalAlpha = sprite.texture.alpha;
}
- // Sprite Flip X
- if(sprite.texture.flippedX) {
- this._fx = -sprite.transform.scale.x;
- }
- // Sprite Flip Y
- if(sprite.texture.flippedY) {
- this._fy = -sprite.transform.scale.y;
- }
if(sprite.animations.currentFrame !== null) {
this._sx = sprite.animations.currentFrame.x;
this._sy = sprite.animations.currentFrame.y;
@@ -16283,28 +16611,20 @@ var Phaser;
this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
}
}
- // Rotation and Flipped
if(sprite.modified) {
- if(sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.transform.rotationOffset !== 0)) {
- this._sin = Math.sin(sprite.game.math.degreesToRadians(sprite.transform.rotationOffset + sprite.rotation));
- this._cos = Math.cos(sprite.game.math.degreesToRadians(sprite.transform.rotationOffset + sprite.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
sprite.texture.context.save();
- sprite.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + sprite.transform.skew.x, -(this._sin * this._fy) + sprite.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
- this._dx = -sprite.transform.origin.x;
- this._dy = -sprite.transform.origin.y;
+ sprite.texture.context.setTransform(sprite.transform.local.data[0], // scale x
+ sprite.transform.local.data[3], // skew x
+ sprite.transform.local.data[1], // skew y
+ sprite.transform.local.data[4], // scale y
+ this._dx, // translate x
+ this._dy);
+ // translate y
+ this._dx = sprite.transform.origin.x * -this._dw;
+ this._dy = sprite.transform.origin.y * -this._dh;
} else {
- if(!sprite.transform.origin.equals(0)) {
- this._dx -= sprite.transform.origin.x;
- this._dy -= sprite.transform.origin.y;
- }
+ this._dx -= (this._dw * sprite.transform.origin.x);
+ this._dy -= (this._dh * sprite.transform.origin.y);
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
@@ -16421,9 +16741,9 @@ var Phaser;
Phaser.CanvasRenderer = CanvasRenderer;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
///
///
/**
@@ -16479,12 +16799,12 @@ var Phaser;
})();
Phaser.DebugUtils = DebugUtils;
})(Phaser || (Phaser = {}));
-///
+///
///
///
-///
-///
-///
+///
+///
+///
///
///
///
@@ -17015,69 +17335,6 @@ var Phaser;
})(Phaser || (Phaser = {}));
///
/**
-* Phaser - Polygon
-*
-*
-*/
-var Phaser;
-(function (Phaser) {
- var Polygon = (function () {
- /**
- *
- **/
- function Polygon(game, points) {
- this.game = game;
- this.context = game.stage.context;
- this.points = [];
- for(var i = 0; i < points.length; i++) {
- this.points.push(new Phaser.Point().copyFrom(points[i]));
- }
- }
- Polygon.prototype.render = function () {
- this.context.beginPath();
- this.context.strokeStyle = 'rgb(255,255,0)';
- this.context.moveTo(this.points[0].x, this.points[0].y);
- for(var i = 1; i < this.points.length; i++) {
- this.context.lineTo(this.points[i].x, this.points[i].y);
- }
- this.context.lineTo(this.points[0].x, this.points[0].y);
- this.context.stroke();
- this.context.closePath();
- };
- return Polygon;
- })();
- Phaser.Polygon = Polygon;
-})(Phaser || (Phaser = {}));
-///
-///
-///
-///
-/**
-* Phaser - PixelUtils
-*
-* A collection of methods useful for manipulating pixels.
-*/
-var Phaser;
-(function (Phaser) {
- var PixelUtils = (function () {
- function PixelUtils() { }
- PixelUtils.boot = function boot() {
- PixelUtils.pixelCanvas = document.createElement('canvas');
- PixelUtils.pixelCanvas.width = 1;
- PixelUtils.pixelCanvas.height = 1;
- PixelUtils.pixelContext = PixelUtils.pixelCanvas.getContext('2d');
- };
- PixelUtils.getPixel = function getPixel(key, x, y) {
- // write out a single pixel (won't help with rotated sprites though.. hmm)
- var imageData = PixelUtils.pixelContext.getImageData(0, 0, 1, 1);
- return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
- };
- return PixelUtils;
- })();
- Phaser.PixelUtils = PixelUtils;
-})(Phaser || (Phaser = {}));
-///
-/**
* Phaser - Line
*
* A Line object is an infinte line through space. The two sets of x/y coordinates define the Line Segment.
@@ -17347,6 +17604,189 @@ var Phaser;
Phaser.Line = Line;
})(Phaser || (Phaser = {}));
///
+///
+///
+/**
+* Phaser - Mat3Utils
+*
+* A collection of methods useful for manipulating and performing operations on Mat3 objects.
+*
+*/
+var Phaser;
+(function (Phaser) {
+ var Mat3Utils = (function () {
+ function Mat3Utils() { }
+ Mat3Utils.transpose = /**
+ * Transpose the values of a Mat3
+ **/
+ function transpose(source, dest) {
+ if (typeof dest === "undefined") { dest = null; }
+ if(dest === null) {
+ // Transpose ourselves
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a12 = source.data[5];
+ source.data[1] = source.data[3];
+ source.data[2] = source.data[6];
+ source.data[3] = a01;
+ source.data[5] = source.data[7];
+ source.data[6] = a02;
+ source.data[7] = a12;
+ } else {
+ source.data[0] = dest.data[0];
+ source.data[1] = dest.data[3];
+ source.data[2] = dest.data[6];
+ source.data[3] = dest.data[1];
+ source.data[4] = dest.data[4];
+ source.data[5] = dest.data[7];
+ source.data[6] = dest.data[2];
+ source.data[7] = dest.data[5];
+ source.data[8] = dest.data[8];
+ }
+ return source;
+ };
+ Mat3Utils.invert = /**
+ * Inverts a Mat3
+ **/
+ function invert(source) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ var b01 = a22 * a11 - a12 * a21;
+ var b11 = -a22 * a10 + a12 * a20;
+ var b21 = a21 * a10 - a11 * a20;
+ // Determinant
+ var det = a00 * b01 + a01 * b11 + a02 * b21;
+ if(!det) {
+ return null;
+ }
+ det = 1.0 / det;
+ source.data[0] = b01 * det;
+ source.data[1] = (-a22 * a01 + a02 * a21) * det;
+ source.data[2] = (a12 * a01 - a02 * a11) * det;
+ source.data[3] = b11 * det;
+ source.data[4] = (a22 * a00 - a02 * a20) * det;
+ source.data[5] = (-a12 * a00 + a02 * a10) * det;
+ source.data[6] = b21 * det;
+ source.data[7] = (-a21 * a00 + a01 * a20) * det;
+ source.data[8] = (a11 * a00 - a01 * a10) * det;
+ return source;
+ };
+ Mat3Utils.adjoint = /**
+ * Calculates the adjugate of a Mat3
+ **/
+ function adjoint(source) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ source.data[0] = (a11 * a22 - a12 * a21);
+ source.data[1] = (a02 * a21 - a01 * a22);
+ source.data[2] = (a01 * a12 - a02 * a11);
+ source.data[3] = (a12 * a20 - a10 * a22);
+ source.data[4] = (a00 * a22 - a02 * a20);
+ source.data[5] = (a02 * a10 - a00 * a12);
+ source.data[6] = (a10 * a21 - a11 * a20);
+ source.data[7] = (a01 * a20 - a00 * a21);
+ source.data[8] = (a00 * a11 - a01 * a10);
+ return source;
+ };
+ Mat3Utils.determinant = /**
+ * Calculates the adjugate of a Mat3
+ **/
+ function determinant(source) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
+ };
+ Mat3Utils.multiply = /**
+ * Multiplies two Mat3s
+ **/
+ function multiply(source, b) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ var b00 = b.data[0];
+ var b01 = b.data[1];
+ var b02 = b.data[2];
+ var b10 = b.data[3];
+ var b11 = b.data[4];
+ var b12 = b.data[5];
+ var b20 = b.data[6];
+ var b21 = b.data[7];
+ var b22 = b.data[8];
+ source.data[0] = b00 * a00 + b01 * a10 + b02 * a20;
+ source.data[1] = b00 * a01 + b01 * a11 + b02 * a21;
+ source.data[2] = b00 * a02 + b01 * a12 + b02 * a22;
+ source.data[3] = b10 * a00 + b11 * a10 + b12 * a20;
+ source.data[4] = b10 * a01 + b11 * a11 + b12 * a21;
+ source.data[5] = b10 * a02 + b11 * a12 + b12 * a22;
+ source.data[6] = b20 * a00 + b21 * a10 + b22 * a20;
+ source.data[7] = b20 * a01 + b21 * a11 + b22 * a21;
+ source.data[8] = b20 * a02 + b21 * a12 + b22 * a22;
+ return source;
+ };
+ Mat3Utils.fromQuaternion = function fromQuaternion() {
+ };
+ Mat3Utils.normalFromMat4 = function normalFromMat4() {
+ };
+ return Mat3Utils;
+ })();
+ Phaser.Mat3Utils = Mat3Utils;
+})(Phaser || (Phaser = {}));
+///
+///
+///
+///
+/**
+* Phaser - PixelUtils
+*
+* A collection of methods useful for manipulating pixels.
+*/
+var Phaser;
+(function (Phaser) {
+ var PixelUtils = (function () {
+ function PixelUtils() { }
+ PixelUtils.boot = function boot() {
+ PixelUtils.pixelCanvas = document.createElement('canvas');
+ PixelUtils.pixelCanvas.width = 1;
+ PixelUtils.pixelCanvas.height = 1;
+ PixelUtils.pixelContext = PixelUtils.pixelCanvas.getContext('2d');
+ };
+ PixelUtils.getPixel = function getPixel(key, x, y) {
+ // write out a single pixel (won't help with rotated sprites though.. hmm)
+ var imageData = PixelUtils.pixelContext.getImageData(0, 0, 1, 1);
+ return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ return PixelUtils;
+ })();
+ Phaser.PixelUtils = PixelUtils;
+})(Phaser || (Phaser = {}));
+///
/**
* Phaser - IntersectResult
*
diff --git a/Tests/sprites/origin 5.js b/Tests/sprites/origin 5.js
new file mode 100644
index 00000000..e860d17b
--- /dev/null
+++ b/Tests/sprites/origin 5.js
@@ -0,0 +1,67 @@
+///
+(function () {
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
+ function init() {
+ // Using Phasers asset loader we load up a PNG from the assets folder
+ game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
+ game.load.start();
+ }
+ var fuji;
+ var wn;
+ var hn;
+ function create() {
+ game.stage.backgroundColor = 'rgb(0,0,100)';
+ game.world.setSize(2000, 1200, true);
+ // The sprite is 320 x 200 pixels in size positioned in the middle of the stage
+ fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
+ //fuji.transform.scale.setTo(1.5, 1.5);
+ //fuji.transform.scale.setTo(1.5, 1.5);
+ //fuji.transform.skew.setTo(0.1, 0.1);
+ //fuji.texture.alpha = 0.5;
+ fuji.texture.renderRotation = false;
+ //fuji.texture.flippedX = true;
+ //fuji.texture.flippedY = true;
+ //fuji.transform.scale.setTo(2, 2);
+ //fuji.transform.scale.setTo(2, 2);
+ // This sets the origin to the center
+ //fuji.transform.origin.setTo(0.5, 0.5);
+ game.input.onTap.add(rotateIt, this);
+ }
+ function rotateIt() {
+ fuji.rotation += 20;
+ console.log(fuji.rotation);
+ }
+ function update() {
+ var s = Math.sin(fuji.rotation);
+ var c = Math.cos(fuji.rotation);
+ if(s < 0) {
+ s = -s;
+ }
+ if(c < 0) {
+ c = -c;
+ }
+ wn = fuji.width * s + fuji.width * c;
+ hn = fuji.height * c + fuji.height * s;
+ if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
+ game.camera.x -= 4;
+ } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
+ game.camera.x += 4;
+ }
+ if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
+ game.camera.y -= 4;
+ } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
+ game.camera.y += 4;
+ }
+ }
+ function render() {
+ game.stage.context.fillStyle = 'rgb(255,255,255)';
+ game.stage.context.fillRect(fuji.x, fuji.y, 2, 2);
+ game.stage.context.fillStyle = 'rgb(255,255,0)';
+ game.stage.context.fillRect(fuji.x + fuji.transform.centerX, fuji.y + fuji.transform.centerY, 2, 2);
+ game.stage.context.strokeStyle = 'rgb(255,0,0)';
+ game.stage.context.strokeRect(fuji.worldView.x, fuji.worldView.y, fuji.worldView.width, fuji.worldView.height);
+ game.stage.context.strokeStyle = 'rgb(0,255,0)';
+ game.stage.context.strokeRect(fuji.x, fuji.y, wn, hn);
+ game.camera.renderDebugInfo(32, 32);
+ }
+})();
diff --git a/Tests/sprites/origin 5.ts b/Tests/sprites/origin 5.ts
new file mode 100644
index 00000000..60b2fdc5
--- /dev/null
+++ b/Tests/sprites/origin 5.ts
@@ -0,0 +1,106 @@
+///
+
+(function () {
+
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
+
+ function init() {
+
+ // Using Phasers asset loader we load up a PNG from the assets folder
+ game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
+ game.load.start();
+
+ }
+
+ var fuji: Phaser.Sprite;
+ var wn: number;
+ var hn: number;
+
+
+ function create() {
+
+ game.stage.backgroundColor = 'rgb(0,0,100)';
+ game.world.setSize(2000, 1200, true);
+
+ // The sprite is 320 x 200 pixels in size positioned in the middle of the stage
+ fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji');
+
+ //fuji.transform.scale.setTo(1.5, 1.5);
+ //fuji.transform.scale.setTo(1.5, 1.5);
+ //fuji.transform.skew.setTo(0.1, 0.1);
+ //fuji.texture.alpha = 0.5;
+
+ //fuji.texture.flippedX = true;
+ //fuji.texture.flippedY = true;
+
+ //fuji.transform.scale.setTo(2, 2);
+ //fuji.transform.scale.setTo(2, 2);
+
+ // This sets the origin to the center
+ //fuji.transform.origin.setTo(0.5, 0.5);
+
+ game.input.onTap.add(rotateIt, this);
+
+ }
+
+ function rotateIt() {
+ fuji.rotation += 20;
+ }
+
+ function update() {
+
+ var s = Math.sin(fuji.rotation);
+ var c = Math.cos(fuji.rotation);
+
+ if (s < 0)
+ {
+ s = -s;
+ }
+
+ if (c < 0)
+ {
+ c = -c;
+ }
+
+ wn = fuji.width * s + fuji.width * c;
+ hn = fuji.height * c + fuji.height * s;
+
+ if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
+ {
+ game.camera.x -= 4;
+ }
+ else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
+ {
+ game.camera.x += 4;
+ }
+
+ if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
+ {
+ game.camera.y -= 4;
+ }
+ else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
+ {
+ game.camera.y += 4;
+ }
+
+ }
+
+ function render() {
+
+ game.stage.context.fillStyle = 'rgb(255,255,255)';
+ game.stage.context.fillRect(fuji.x, fuji.y, 2, 2);
+
+ game.stage.context.fillStyle = 'rgb(255,255,0)';
+ game.stage.context.fillRect(fuji.x + fuji.transform.centerX, fuji.y + fuji.transform.centerY, 2, 2);
+
+ game.stage.context.strokeStyle = 'rgb(255,0,0)';
+ game.stage.context.strokeRect(fuji.worldView.x, fuji.worldView.y, fuji.worldView.width, fuji.worldView.height);
+
+ game.stage.context.strokeStyle = 'rgb(0,255,0)';
+ game.stage.context.strokeRect(fuji.x, fuji.y, wn, hn);
+
+ game.camera.renderDebugInfo(32, 32);
+
+ }
+
+})();
diff --git a/build/phaser.d.ts b/build/phaser.d.ts
index 379a1323..ab3fad57 100644
--- a/build/phaser.d.ts
+++ b/build/phaser.d.ts
@@ -492,7 +492,7 @@ module Phaser {
/**
* Phaser - Vec2
*
-* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+* A Vector 2
*/
module Phaser {
class Vec2 {
@@ -1805,6 +1805,88 @@ module Phaser.Components {
}
}
/**
+* Phaser - Mat3
+*
+* A 3x3 Matrix
+*/
+module Phaser {
+ class Mat3 {
+ /**
+ * Creates a new Mat3 object.
+ * @class Mat3
+ * @constructor
+ * @return {Mat3} This object
+ **/
+ constructor();
+ private _a00;
+ private _a01;
+ private _a02;
+ private _a10;
+ private _a11;
+ private _a12;
+ private _a20;
+ private _a21;
+ private _a22;
+ public data: number[];
+ public a00 : number;
+ public a01 : number;
+ public a02 : number;
+ public a10 : number;
+ public a11 : number;
+ public a12 : number;
+ public a20 : number;
+ public a21 : number;
+ public a22 : number;
+ /**
+ * Copies the values from one Mat3 into this Mat3.
+ * @method copyFromMat3
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ public copyFromMat3(source: Mat3): Mat3;
+ /**
+ * Copies the upper-left 3x3 values into this Mat3.
+ * @method copyFromMat4
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ public copyFromMat4(source: any): Mat3;
+ /**
+ * Clones this Mat3 into a new Mat3
+ * @param {Mat3} out The output Mat3, if none is given a new Mat3 object will be created.
+ * @return {Mat3} The new Mat3
+ **/
+ public clone(out?: Mat3): Mat3;
+ /**
+ * Sets this Mat3 to the identity matrix.
+ * @method identity
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ public identity(): Mat3;
+ /**
+ * Translates this Mat3 by the given vector
+ **/
+ public translate(v: Vec2): Mat3;
+ private setTemps();
+ /**
+ * Rotates this Mat3 by the given angle (given in radians)
+ **/
+ public rotate(rad: number): Mat3;
+ /**
+ * Scales this Mat3 by the given vector
+ **/
+ public scale(v: Vec2): Mat3;
+ public setTo(a00: number, a01: number, a02: number, a10: number, a11: number, a12: number, a20: number, a21: number, a22: number): Mat3;
+ /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ public toString(): string;
+ }
+}
+/**
* Phaser - Components - Transform
*/
module Phaser.Components {
@@ -1814,6 +1896,12 @@ module Phaser.Components {
* @param parent The Sprite using this transform
*/
constructor(parent);
+ public local: Mat3;
+ private _sin;
+ private _cos;
+ public update(): void;
+ public calculatedX : number;
+ public calculatedY : number;
/**
* Reference to Phaser.Game
*/
@@ -1835,7 +1923,7 @@ module Phaser.Components {
*/
public scrollFactor: Vec2;
/**
- * The origin is the point around which scale and rotation takes place.
+ * The origin is the point around which scale and rotation takes place and defaults to the center of the sprite.
*/
public origin: Vec2;
/**
@@ -1849,6 +1937,14 @@ module Phaser.Components {
* The rotation of the object in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
*/
public rotation: number;
+ /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ public centerX : number;
+ /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ public centerY : number;
}
}
/**
@@ -3636,6 +3732,8 @@ module Phaser {
class GameMath {
constructor(game: Game);
public game: Game;
+ static sinA: number[];
+ static cosA: number[];
static PI: number;
static PI_2: number;
static PI_4: number;
@@ -8943,44 +9041,6 @@ module Phaser.Components {
}
}
/**
-* Phaser - Polygon
-*
-*
-*/
-module Phaser {
- class Polygon {
- /**
- *
- **/
- constructor(game: Game, points: Point[]);
- public points: Point[];
- public game: Game;
- public context: CanvasRenderingContext2D;
- public render(): void;
- }
-}
-/**
-* Phaser - PixelUtils
-*
-* A collection of methods useful for manipulating pixels.
-*/
-module Phaser {
- class PixelUtils {
- static boot(): void;
- /**
- * Canvas element used in 1x1 pixel checks.
- * @type {HTMLCanvasElement}
- */
- static pixelCanvas: HTMLCanvasElement;
- /**
- * Render context of pixelCanvas
- * @type {CanvasRenderingContext2D}
- */
- static pixelContext: CanvasRenderingContext2D;
- static getPixel(key: string, x: number, y: number): number;
- }
-}
-/**
* Phaser - Line
*
* A Line object is an infinte line through space. The two sets of x/y coordinates define the Line Segment.
@@ -9132,6 +9192,59 @@ module Phaser {
}
}
/**
+* Phaser - Mat3Utils
+*
+* A collection of methods useful for manipulating and performing operations on Mat3 objects.
+*
+*/
+module Phaser {
+ class Mat3Utils {
+ /**
+ * Transpose the values of a Mat3
+ **/
+ static transpose(source: Mat3, dest?: Mat3): Mat3;
+ /**
+ * Inverts a Mat3
+ **/
+ static invert(source: Mat3): Mat3;
+ /**
+ * Calculates the adjugate of a Mat3
+ **/
+ static adjoint(source: Mat3): Mat3;
+ /**
+ * Calculates the adjugate of a Mat3
+ **/
+ static determinant(source: Mat3): number;
+ /**
+ * Multiplies two Mat3s
+ **/
+ static multiply(source: Mat3, b: Mat3): Mat3;
+ static fromQuaternion(): void;
+ static normalFromMat4(): void;
+ }
+}
+/**
+* Phaser - PixelUtils
+*
+* A collection of methods useful for manipulating pixels.
+*/
+module Phaser {
+ class PixelUtils {
+ static boot(): void;
+ /**
+ * Canvas element used in 1x1 pixel checks.
+ * @type {HTMLCanvasElement}
+ */
+ static pixelCanvas: HTMLCanvasElement;
+ /**
+ * Render context of pixelCanvas
+ * @type {CanvasRenderingContext2D}
+ */
+ static pixelContext: CanvasRenderingContext2D;
+ static getPixel(key: string, x: number, y: number): number;
+ }
+}
+/**
* Phaser - IntersectResult
*
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
diff --git a/build/phaser.js b/build/phaser.js
index a07d9581..79107e15 100644
--- a/build/phaser.js
+++ b/build/phaser.js
@@ -384,7 +384,7 @@ var __extends = this.__extends || function (d, b) {
d.prototype = new __();
};
///
-///
+///
///
/**
* Phaser - QuadTree
@@ -734,7 +734,7 @@ var Phaser;
/**
* Phaser - Vec2
*
-* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+* A Vector 2
*/
var Phaser;
(function (Phaser) {
@@ -1264,8 +1264,8 @@ var Phaser;
Phaser.Types = Types;
})(Phaser || (Phaser = {}));
///
-///
-///
+///
+///
/**
* Phaser - RectangleUtils
*
@@ -1455,9 +1455,9 @@ var Phaser;
Phaser.RectangleUtils = RectangleUtils;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
/**
* Phaser - ColorUtils
*
@@ -2797,9 +2797,263 @@ var Phaser;
})(Phaser.Components || (Phaser.Components = {}));
var Components = Phaser.Components;
})(Phaser || (Phaser = {}));
+///
+/**
+* Phaser - Mat3
+*
+* A 3x3 Matrix
+*/
+var Phaser;
+(function (Phaser) {
+ var Mat3 = (function () {
+ /**
+ * Creates a new Mat3 object.
+ * @class Mat3
+ * @constructor
+ * @return {Mat3} This object
+ **/
+ function Mat3() {
+ this.data = [
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1
+ ];
+ }
+ Object.defineProperty(Mat3.prototype, "a00", {
+ get: function () {
+ return this.data[0];
+ },
+ set: function (value) {
+ this.data[0] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a01", {
+ get: function () {
+ return this.data[1];
+ },
+ set: function (value) {
+ this.data[1] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a02", {
+ get: function () {
+ return this.data[2];
+ },
+ set: function (value) {
+ this.data[2] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a10", {
+ get: function () {
+ return this.data[3];
+ },
+ set: function (value) {
+ this.data[3] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a11", {
+ get: function () {
+ return this.data[4];
+ },
+ set: function (value) {
+ this.data[4] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a12", {
+ get: function () {
+ return this.data[5];
+ },
+ set: function (value) {
+ this.data[5] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a20", {
+ get: function () {
+ return this.data[6];
+ },
+ set: function (value) {
+ this.data[6] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a21", {
+ get: function () {
+ return this.data[7];
+ },
+ set: function (value) {
+ this.data[7] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a22", {
+ get: function () {
+ return this.data[8];
+ },
+ set: function (value) {
+ this.data[8] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Mat3.prototype.copyFromMat3 = /**
+ * Copies the values from one Mat3 into this Mat3.
+ * @method copyFromMat3
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function (source) {
+ this.data[0] = source.data[0];
+ this.data[1] = source.data[1];
+ this.data[2] = source.data[2];
+ this.data[3] = source.data[3];
+ this.data[4] = source.data[4];
+ this.data[5] = source.data[5];
+ this.data[6] = source.data[6];
+ this.data[7] = source.data[7];
+ this.data[8] = source.data[8];
+ return this;
+ };
+ Mat3.prototype.copyFromMat4 = /**
+ * Copies the upper-left 3x3 values into this Mat3.
+ * @method copyFromMat4
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function (source) {
+ this.data[0] = source[0];
+ this.data[1] = source[1];
+ this.data[2] = source[2];
+ this.data[3] = source[4];
+ this.data[4] = source[5];
+ this.data[5] = source[6];
+ this.data[6] = source[8];
+ this.data[7] = source[9];
+ this.data[8] = source[10];
+ return this;
+ };
+ Mat3.prototype.clone = /**
+ * Clones this Mat3 into a new Mat3
+ * @param {Mat3} out The output Mat3, if none is given a new Mat3 object will be created.
+ * @return {Mat3} The new Mat3
+ **/
+ function (out) {
+ if (typeof out === "undefined") { out = new Phaser.Mat3(); }
+ out[0] = this.data[0];
+ out[1] = this.data[1];
+ out[2] = this.data[2];
+ out[3] = this.data[3];
+ out[4] = this.data[4];
+ out[5] = this.data[5];
+ out[6] = this.data[6];
+ out[7] = this.data[7];
+ out[8] = this.data[8];
+ return out;
+ };
+ Mat3.prototype.identity = /**
+ * Sets this Mat3 to the identity matrix.
+ * @method identity
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function () {
+ return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ };
+ Mat3.prototype.translate = /**
+ * Translates this Mat3 by the given vector
+ **/
+ function (v) {
+ this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
+ this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
+ this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
+ return this;
+ };
+ Mat3.prototype.setTemps = function () {
+ this._a00 = this.data[0];
+ this._a01 = this.data[1];
+ this._a02 = this.data[2];
+ this._a10 = this.data[3];
+ this._a11 = this.data[4];
+ this._a12 = this.data[5];
+ this._a20 = this.data[6];
+ this._a21 = this.data[7];
+ this._a22 = this.data[8];
+ };
+ Mat3.prototype.rotate = /**
+ * Rotates this Mat3 by the given angle (given in radians)
+ **/
+ function (rad) {
+ this.setTemps();
+ var s = Phaser.GameMath.sinA[rad];
+ var c = Phaser.GameMath.cosA[rad];
+ this.data[0] = c * this._a00 + s * this._a10;
+ this.data[1] = c * this._a01 + s * this._a10;
+ this.data[2] = c * this._a02 + s * this._a12;
+ this.data[3] = c * this._a10 - s * this._a00;
+ this.data[4] = c * this._a11 - s * this._a01;
+ this.data[5] = c * this._a12 - s * this._a02;
+ return this;
+ };
+ Mat3.prototype.scale = /**
+ * Scales this Mat3 by the given vector
+ **/
+ function (v) {
+ this.data[0] = v.x * this.data[0];
+ this.data[1] = v.x * this.data[1];
+ this.data[2] = v.x * this.data[2];
+ this.data[3] = v.y * this.data[3];
+ this.data[4] = v.y * this.data[4];
+ this.data[5] = v.y * this.data[5];
+ return this;
+ };
+ Mat3.prototype.setTo = function (a00, a01, a02, a10, a11, a12, a20, a21, a22) {
+ this.data[0] = a00;
+ this.data[1] = a01;
+ this.data[2] = a02;
+ this.data[3] = a10;
+ this.data[4] = a11;
+ this.data[5] = a12;
+ this.data[6] = a20;
+ this.data[7] = a21;
+ this.data[8] = a22;
+ return this;
+ };
+ Mat3.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ function () {
+ return '';
+ //return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ };
+ return Mat3;
+ })();
+ Phaser.Mat3 = Mat3;
+})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
///
+ ///
/**
* Phaser - Components - Transform
*/
@@ -2823,11 +3077,87 @@ var Phaser;
this.rotation = 0;
this.game = parent.game;
this.parent = parent;
+ this.local = new Phaser.Mat3();
this.scrollFactor = new Phaser.Vec2(1, 1);
this.origin = new Phaser.Vec2();
this.scale = new Phaser.Vec2(1, 1);
this.skew = new Phaser.Vec2();
}
+ Transform.prototype.update = function () {
+ // 0 a = scale x
+ // 3 b = skew x
+ // 1 c = skew y
+ // 4 d = scale y
+ // 2 e = translate x
+ // 5 f = translate y
+ // Scale & Skew
+ // if (sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.transform.rotationOffset !== 0))
+ this._sin = 0;
+ this._cos = 1;
+ if(this.parent.texture.renderRotation) {
+ this._sin = Phaser.GameMath.sinA[this.rotation + this.rotationOffset];
+ this._cos = Phaser.GameMath.cosA[this.rotation + this.rotationOffset];
+ }
+ if(this.parent.texture.flippedX) {
+ //this.local.data[0] = GameMath.cosA[this.rotation + this.rotationOffset] * -this.scale.x;
+ //this.local.data[3] = (GameMath.sinA[this.rotation + this.rotationOffset] * -this.scale.x) + this.skew.x;
+ this.local.data[0] = this._cos * -this.scale.x;
+ this.local.data[3] = (this._sin * -this.scale.x) + this.skew.x;
+ } else {
+ //this.local.data[0] = GameMath.cosA[this.rotation + this.rotationOffset] * this.scale.x;
+ //this.local.data[3] = (GameMath.sinA[this.rotation + this.rotationOffset] * this.scale.x) + this.skew.x;
+ this.local.data[0] = this._cos * this.scale.x;
+ this.local.data[3] = (this._sin * this.scale.x) + this.skew.x;
+ }
+ if(this.parent.texture.flippedY) {
+ //this.local.data[4] = GameMath.cosA[this.rotation + this.rotationOffset] * -this.scale.y;
+ //this.local.data[1] = -(GameMath.sinA[this.rotation + this.rotationOffset] * -this.scale.y) + this.skew.y;
+ this.local.data[4] = this._cos * -this.scale.y;
+ this.local.data[1] = -(this._sin * -this.scale.y) + this.skew.y;
+ } else {
+ //this.local.data[4] = GameMath.cosA[this.rotation + this.rotationOffset] * this.scale.y;
+ //this.local.data[1] = -(GameMath.sinA[this.rotation + this.rotationOffset] * this.scale.y) + this.skew.y;
+ this.local.data[4] = this._cos * this.scale.y;
+ this.local.data[1] = -(this._sin * this.scale.y) + this.skew.y;
+ }
+ // Translate
+ this.local.data[2] = this.parent.x;
+ this.local.data[5] = this.parent.y;
+ };
+ Object.defineProperty(Transform.prototype, "calculatedX", {
+ get: function () {
+ return this.origin.x * this.scale.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "calculatedY", {
+ get: function () {
+ return this.origin.y * this.scale.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "centerX", {
+ get: /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ function () {
+ return this.parent.width / 2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Transform.prototype, "centerY", {
+ get: /**
+ * The center of the Sprite after taking scaling into consideration
+ */
+ function () {
+ return this.parent.height / 2;
+ },
+ enumerable: true,
+ configurable: true
+ });
return Transform;
})();
Components.Transform = Transform;
@@ -3412,7 +3742,7 @@ var Phaser;
var Components = Phaser.Components;
})(Phaser || (Phaser = {}));
///
-///
+///
/**
* Phaser - Vec2Utils
*
@@ -3707,8 +4037,8 @@ var Phaser;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
- ///
- ///
+ ///
+ ///
///
/**
* Phaser - Physics - Body
@@ -3938,8 +4268,8 @@ var Phaser;
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
///
-///
-///
+///
+///
///
///
///
@@ -3997,11 +4327,12 @@ var Phaser;
this.y = y;
this.z = -1;
this.group = null;
- this.transform = new Phaser.Components.Transform(this);
+ // No dependencies
this.animations = new Phaser.Components.AnimationManager(this);
- this.texture = new Phaser.Components.Texture(this);
this.input = new Phaser.Components.Sprite.Input(this);
this.events = new Phaser.Components.Sprite.Events(this);
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
if(key !== null) {
this.texture.loadImage(key, false);
} else {
@@ -4090,10 +4421,13 @@ var Phaser;
* Pre-update is called right before update() on each object in the game loop.
*/
function () {
+ this.transform.update();
//this.worldView.x = this.x * this.transform.scrollFactor.x;
//this.worldView.y = this.y * this.transform.scrollFactor.y;
- this.worldView.x = this.x - this.transform.origin.x;
- this.worldView.y = this.y - this.transform.origin.y;
+ this.worldView.x = this.x;
+ this.worldView.y = this.y;
+ //this.worldView.x = this.x - this.transform.origin.x;
+ //this.worldView.y = this.y - this.transform.origin.y;
this.worldView.width = this.width;
this.worldView.height = this.height;
if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
@@ -4183,9 +4517,9 @@ var Phaser;
Phaser.Sprite = Sprite;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
///
///
/**
@@ -6357,6 +6691,12 @@ var Phaser;
*/
this.globalSeed = Math.random();
this.game = game;
+ GameMath.sinA = [];
+ GameMath.cosA = [];
+ for(var i = 0; i < 360; i++) {
+ GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
+ GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
+ }
}
GameMath.PI = 3.141592653589793;
GameMath.PI_2 = 1.5707963267948965;
@@ -7626,9 +7966,9 @@ var Phaser;
Phaser.CameraFX = CameraFX;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
///
///
///
@@ -9164,8 +9504,8 @@ var Phaser;
Phaser.Emitter = Emitter;
})(Phaser || (Phaser = {}));
///
-///
-///
+///
+///
/**
* Phaser - ScrollRegion
*
@@ -9314,7 +9654,7 @@ var Phaser;
Phaser.ScrollRegion = ScrollRegion;
})(Phaser || (Phaser = {}));
///
-///
+///
///
/**
* Phaser - ScrollZone
@@ -11865,9 +12205,9 @@ var Phaser;
Phaser.TweenManager = TweenManager;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
/**
* Phaser - CircleUtils
*
@@ -12967,7 +13307,7 @@ var Phaser;
///
///
///
-///
+///
///
/**
* Phaser - World
@@ -13931,7 +14271,7 @@ var Phaser;
Phaser.RequestAnimationFrame = RequestAnimationFrame;
})(Phaser || (Phaser = {}));
///
-///
+///
/**
* Phaser - PointUtils
*
@@ -14128,7 +14468,7 @@ var Phaser;
})();
})(Phaser || (Phaser = {}));
///
-///
+///
/**
* Phaser - Pointer
*
@@ -16235,8 +16575,8 @@ var Phaser;
*/
function (camera, sprite) {
if(sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
- return false;
- }
+ //return false;
+ }
sprite.renderOrderID = this._count;
this._count++;
// Reset our temp vars
@@ -16245,12 +16585,8 @@ var Phaser;
this._sy = 0;
this._sw = sprite.texture.width;
this._sh = sprite.texture.height;
- this._fx = sprite.transform.scale.x;
- this._fy = sprite.transform.scale.y;
- this._sin = 0;
- this._cos = 1;
- this._dx = (camera.screenView.x * sprite.transform.scrollFactor.x) + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
- this._dy = (camera.screenView.y * sprite.transform.scrollFactor.y) + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
+ this._dx = camera.screenView.x + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
+ this._dy = camera.screenView.y + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
this._dw = sprite.texture.width;
this._dh = sprite.texture.height;
// Global Composite Ops
@@ -16263,14 +16599,6 @@ var Phaser;
this._ga = sprite.texture.context.globalAlpha;
sprite.texture.context.globalAlpha = sprite.texture.alpha;
}
- // Sprite Flip X
- if(sprite.texture.flippedX) {
- this._fx = -sprite.transform.scale.x;
- }
- // Sprite Flip Y
- if(sprite.texture.flippedY) {
- this._fy = -sprite.transform.scale.y;
- }
if(sprite.animations.currentFrame !== null) {
this._sx = sprite.animations.currentFrame.x;
this._sy = sprite.animations.currentFrame.y;
@@ -16283,28 +16611,20 @@ var Phaser;
this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
}
}
- // Rotation and Flipped
if(sprite.modified) {
- if(sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.transform.rotationOffset !== 0)) {
- this._sin = Math.sin(sprite.game.math.degreesToRadians(sprite.transform.rotationOffset + sprite.rotation));
- this._cos = Math.cos(sprite.game.math.degreesToRadians(sprite.transform.rotationOffset + sprite.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
sprite.texture.context.save();
- sprite.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + sprite.transform.skew.x, -(this._sin * this._fy) + sprite.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
- this._dx = -sprite.transform.origin.x;
- this._dy = -sprite.transform.origin.y;
+ sprite.texture.context.setTransform(sprite.transform.local.data[0], // scale x
+ sprite.transform.local.data[3], // skew x
+ sprite.transform.local.data[1], // skew y
+ sprite.transform.local.data[4], // scale y
+ this._dx, // translate x
+ this._dy);
+ // translate y
+ this._dx = sprite.transform.origin.x * -this._dw;
+ this._dy = sprite.transform.origin.y * -this._dh;
} else {
- if(!sprite.transform.origin.equals(0)) {
- this._dx -= sprite.transform.origin.x;
- this._dy -= sprite.transform.origin.y;
- }
+ this._dx -= (this._dw * sprite.transform.origin.x);
+ this._dy -= (this._dh * sprite.transform.origin.y);
}
this._sx = Math.round(this._sx);
this._sy = Math.round(this._sy);
@@ -16421,9 +16741,9 @@ var Phaser;
Phaser.CanvasRenderer = CanvasRenderer;
})(Phaser || (Phaser = {}));
///
-///
-///
-///
+///
+///
+///
///
///
/**
@@ -16479,12 +16799,12 @@ var Phaser;
})();
Phaser.DebugUtils = DebugUtils;
})(Phaser || (Phaser = {}));
-///
+///
///
///
-///
-///
-///
+///
+///
+///
///
///
///
@@ -17015,69 +17335,6 @@ var Phaser;
})(Phaser || (Phaser = {}));
///
/**
-* Phaser - Polygon
-*
-*
-*/
-var Phaser;
-(function (Phaser) {
- var Polygon = (function () {
- /**
- *
- **/
- function Polygon(game, points) {
- this.game = game;
- this.context = game.stage.context;
- this.points = [];
- for(var i = 0; i < points.length; i++) {
- this.points.push(new Phaser.Point().copyFrom(points[i]));
- }
- }
- Polygon.prototype.render = function () {
- this.context.beginPath();
- this.context.strokeStyle = 'rgb(255,255,0)';
- this.context.moveTo(this.points[0].x, this.points[0].y);
- for(var i = 1; i < this.points.length; i++) {
- this.context.lineTo(this.points[i].x, this.points[i].y);
- }
- this.context.lineTo(this.points[0].x, this.points[0].y);
- this.context.stroke();
- this.context.closePath();
- };
- return Polygon;
- })();
- Phaser.Polygon = Polygon;
-})(Phaser || (Phaser = {}));
-///
-///
-///
-///
-/**
-* Phaser - PixelUtils
-*
-* A collection of methods useful for manipulating pixels.
-*/
-var Phaser;
-(function (Phaser) {
- var PixelUtils = (function () {
- function PixelUtils() { }
- PixelUtils.boot = function boot() {
- PixelUtils.pixelCanvas = document.createElement('canvas');
- PixelUtils.pixelCanvas.width = 1;
- PixelUtils.pixelCanvas.height = 1;
- PixelUtils.pixelContext = PixelUtils.pixelCanvas.getContext('2d');
- };
- PixelUtils.getPixel = function getPixel(key, x, y) {
- // write out a single pixel (won't help with rotated sprites though.. hmm)
- var imageData = PixelUtils.pixelContext.getImageData(0, 0, 1, 1);
- return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
- };
- return PixelUtils;
- })();
- Phaser.PixelUtils = PixelUtils;
-})(Phaser || (Phaser = {}));
-///
-/**
* Phaser - Line
*
* A Line object is an infinte line through space. The two sets of x/y coordinates define the Line Segment.
@@ -17347,6 +17604,189 @@ var Phaser;
Phaser.Line = Line;
})(Phaser || (Phaser = {}));
///
+///
+///
+/**
+* Phaser - Mat3Utils
+*
+* A collection of methods useful for manipulating and performing operations on Mat3 objects.
+*
+*/
+var Phaser;
+(function (Phaser) {
+ var Mat3Utils = (function () {
+ function Mat3Utils() { }
+ Mat3Utils.transpose = /**
+ * Transpose the values of a Mat3
+ **/
+ function transpose(source, dest) {
+ if (typeof dest === "undefined") { dest = null; }
+ if(dest === null) {
+ // Transpose ourselves
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a12 = source.data[5];
+ source.data[1] = source.data[3];
+ source.data[2] = source.data[6];
+ source.data[3] = a01;
+ source.data[5] = source.data[7];
+ source.data[6] = a02;
+ source.data[7] = a12;
+ } else {
+ source.data[0] = dest.data[0];
+ source.data[1] = dest.data[3];
+ source.data[2] = dest.data[6];
+ source.data[3] = dest.data[1];
+ source.data[4] = dest.data[4];
+ source.data[5] = dest.data[7];
+ source.data[6] = dest.data[2];
+ source.data[7] = dest.data[5];
+ source.data[8] = dest.data[8];
+ }
+ return source;
+ };
+ Mat3Utils.invert = /**
+ * Inverts a Mat3
+ **/
+ function invert(source) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ var b01 = a22 * a11 - a12 * a21;
+ var b11 = -a22 * a10 + a12 * a20;
+ var b21 = a21 * a10 - a11 * a20;
+ // Determinant
+ var det = a00 * b01 + a01 * b11 + a02 * b21;
+ if(!det) {
+ return null;
+ }
+ det = 1.0 / det;
+ source.data[0] = b01 * det;
+ source.data[1] = (-a22 * a01 + a02 * a21) * det;
+ source.data[2] = (a12 * a01 - a02 * a11) * det;
+ source.data[3] = b11 * det;
+ source.data[4] = (a22 * a00 - a02 * a20) * det;
+ source.data[5] = (-a12 * a00 + a02 * a10) * det;
+ source.data[6] = b21 * det;
+ source.data[7] = (-a21 * a00 + a01 * a20) * det;
+ source.data[8] = (a11 * a00 - a01 * a10) * det;
+ return source;
+ };
+ Mat3Utils.adjoint = /**
+ * Calculates the adjugate of a Mat3
+ **/
+ function adjoint(source) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ source.data[0] = (a11 * a22 - a12 * a21);
+ source.data[1] = (a02 * a21 - a01 * a22);
+ source.data[2] = (a01 * a12 - a02 * a11);
+ source.data[3] = (a12 * a20 - a10 * a22);
+ source.data[4] = (a00 * a22 - a02 * a20);
+ source.data[5] = (a02 * a10 - a00 * a12);
+ source.data[6] = (a10 * a21 - a11 * a20);
+ source.data[7] = (a01 * a20 - a00 * a21);
+ source.data[8] = (a00 * a11 - a01 * a10);
+ return source;
+ };
+ Mat3Utils.determinant = /**
+ * Calculates the adjugate of a Mat3
+ **/
+ function determinant(source) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
+ };
+ Mat3Utils.multiply = /**
+ * Multiplies two Mat3s
+ **/
+ function multiply(source, b) {
+ var a00 = source.data[0];
+ var a01 = source.data[1];
+ var a02 = source.data[2];
+ var a10 = source.data[3];
+ var a11 = source.data[4];
+ var a12 = source.data[5];
+ var a20 = source.data[6];
+ var a21 = source.data[7];
+ var a22 = source.data[8];
+ var b00 = b.data[0];
+ var b01 = b.data[1];
+ var b02 = b.data[2];
+ var b10 = b.data[3];
+ var b11 = b.data[4];
+ var b12 = b.data[5];
+ var b20 = b.data[6];
+ var b21 = b.data[7];
+ var b22 = b.data[8];
+ source.data[0] = b00 * a00 + b01 * a10 + b02 * a20;
+ source.data[1] = b00 * a01 + b01 * a11 + b02 * a21;
+ source.data[2] = b00 * a02 + b01 * a12 + b02 * a22;
+ source.data[3] = b10 * a00 + b11 * a10 + b12 * a20;
+ source.data[4] = b10 * a01 + b11 * a11 + b12 * a21;
+ source.data[5] = b10 * a02 + b11 * a12 + b12 * a22;
+ source.data[6] = b20 * a00 + b21 * a10 + b22 * a20;
+ source.data[7] = b20 * a01 + b21 * a11 + b22 * a21;
+ source.data[8] = b20 * a02 + b21 * a12 + b22 * a22;
+ return source;
+ };
+ Mat3Utils.fromQuaternion = function fromQuaternion() {
+ };
+ Mat3Utils.normalFromMat4 = function normalFromMat4() {
+ };
+ return Mat3Utils;
+ })();
+ Phaser.Mat3Utils = Mat3Utils;
+})(Phaser || (Phaser = {}));
+///
+///
+///
+///
+/**
+* Phaser - PixelUtils
+*
+* A collection of methods useful for manipulating pixels.
+*/
+var Phaser;
+(function (Phaser) {
+ var PixelUtils = (function () {
+ function PixelUtils() { }
+ PixelUtils.boot = function boot() {
+ PixelUtils.pixelCanvas = document.createElement('canvas');
+ PixelUtils.pixelCanvas.width = 1;
+ PixelUtils.pixelCanvas.height = 1;
+ PixelUtils.pixelContext = PixelUtils.pixelCanvas.getContext('2d');
+ };
+ PixelUtils.getPixel = function getPixel(key, x, y) {
+ // write out a single pixel (won't help with rotated sprites though.. hmm)
+ var imageData = PixelUtils.pixelContext.getImageData(0, 0, 1, 1);
+ return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ return PixelUtils;
+ })();
+ Phaser.PixelUtils = PixelUtils;
+})(Phaser || (Phaser = {}));
+///
/**
* Phaser - IntersectResult
*