diff --git a/Docs/game art/avoid-digits.png b/Docs/game art/avoid-digits.png
new file mode 100644
index 000000000..c3bf0af14
Binary files /dev/null and b/Docs/game art/avoid-digits.png differ
diff --git a/Docs/game art/avoid-panel.png b/Docs/game art/avoid-panel.png
new file mode 100644
index 000000000..741e4fe57
Binary files /dev/null and b/Docs/game art/avoid-panel.png differ
diff --git a/Docs/game art/avoid-sheet.png b/Docs/game art/avoid-sheet.png
new file mode 100644
index 000000000..c88ce1ba6
Binary files /dev/null and b/Docs/game art/avoid-sheet.png differ
diff --git a/Docs/game art/avoidmock4x2.png b/Docs/game art/avoidmock4x2.png
new file mode 100644
index 000000000..4a1a515f3
Binary files /dev/null and b/Docs/game art/avoidmock4x2.png differ
diff --git a/Phaser/components/Texture.ts b/Phaser/components/Texture.ts
index 491147451..593aef867 100644
--- a/Phaser/components/Texture.ts
+++ b/Phaser/components/Texture.ts
@@ -79,7 +79,7 @@ module Phaser.Components {
public cameraBlacklist: number[];
/**
- * Whether the Sprite background is opaque or not. If set to true the Sprite is filled with
+ * Whether the texture background is opaque or not. If set to true the object is filled with
* the value of Texture.backgroundColor every frame. Normally you wouldn't enable this but
* for some effects it can be handy.
* @type {boolean}
@@ -136,6 +136,12 @@ module Phaser.Components {
*/
public renderRotation: bool = true;
+ /**
+ * The direction the animation frame is facing (can be Phaser.Types.RIGHT, LEFT, UP, DOWN).
+ * Very useful when hooking animation to Sprite directions.
+ */
+ public facing: number;
+
/**
* Flip the graphic horizontally (defaults to false)
* @type {boolean}
diff --git a/Phaser/components/TilemapLayer.ts b/Phaser/components/TilemapLayer.ts
index 21360b63f..8fd6c08ea 100644
--- a/Phaser/components/TilemapLayer.ts
+++ b/Phaser/components/TilemapLayer.ts
@@ -26,53 +26,36 @@ module Phaser {
*/
constructor(game: Game, parent:Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number) {
- this._game = game;
- this._parent = parent;
+ this.game = game;
+ this.parent = parent;
this.name = name;
this.mapFormat = mapFormat;
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
this.boundsInTiles = new Rectangle();
- //this.scrollFactor = new MicroPoint(1, 1);
- this.canvas = game.stage.canvas;
- this.context = game.stage.context;
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
+
+ if (key !== null)
+ {
+ this.texture.loadImage(key, false);
+ }
+ else
+ {
+ this.texture.opaque = true;
+ }
+
+ // Handy proxies
+ this.alpha = this.texture.alpha;
this.mapData = [];
this._tempTileBlock = [];
- this._texture = this._game.cache.getImage(key);
}
- /**
- * Local private reference to game.
- */
- private _game: Game;
-
- /**
- * The tilemap that contains this layer.
- * @type {Tilemap}
- */
- private _parent: Tilemap;
-
- /**
- * Tileset of this layer.
- */
- private _texture;
- private _tileOffsets;
- private _startX: number = 0;
- private _startY: number = 0;
- private _maxX: number = 0;
- private _maxY: number = 0;
- private _tx: number = 0;
- private _ty: number = 0;
- private _dx: number = 0;
- private _dy: number = 0;
- private _oldCameraX: number = 0;
- private _oldCameraY: number = 0;
- private _columnData;
-
+ // Private vars to help avoid gc spikes
private _tempTileX: number;
private _tempTileY: number;
private _tempTileW: number;
@@ -80,30 +63,40 @@ module Phaser {
private _tempTileBlock;
private _tempBlockResults;
+ /**
+ * Local private reference to game.
+ */
+ public game: Game;
+
+ /**
+ * The tilemap that contains this layer.
+ * @type {Tilemap}
+ */
+ public parent: Tilemap;
+
+ /**
+ * The texture used to render the Sprite.
+ */
+ public texture: Phaser.Components.Texture;
+
+ /**
+ * The Sprite transform component.
+ */
+ public transform: Phaser.Components.Transform;
+
+ public tileOffsets;
+
+ /**
+ * The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
+ */
+ public alpha: number;
+
/**
* Name of this layer, so you can get this layer by its name.
* @type {string}
*/
public name: string;
- /**
- * A reference to the Canvas this GameObject will render to
- * @type {HTMLCanvasElement}
- */
- public canvas: HTMLCanvasElement;
-
- /**
- * A reference to the Canvas Context2D this GameObject will render to
- * @type {CanvasRenderingContext2D}
- */
- public context: CanvasRenderingContext2D;
-
- /**
- * Opacity of this layer.
- * @type {number}
- */
- public alpha: number = 1;
-
/**
* Controls whether update() and draw() are automatically called.
* @type {boolean}
@@ -116,11 +109,10 @@ module Phaser {
*/
public visible: bool = true;
- //public scrollFactor: MicroPoint;
/**
* @type {string}
*/
- public orientation: string;
+ //public orientation: string;
/**
* Properties of this map layer. (normally set by map editors)
@@ -202,8 +194,8 @@ module Phaser {
*/
public putTile(x: number, y: number, index: number) {
- x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
- y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
+ x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
+ y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if (y >= 0 && y < this.mapData.length)
{
@@ -287,7 +279,7 @@ module Phaser {
for (var r = 0; r < this._tempTileBlock.length; r++)
{
- this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles);
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this.game.math.getRandom(tiles);
}
}
@@ -344,8 +336,8 @@ module Phaser {
*/
public getTileFromWorldXY(x: number, y: number): number {
- x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
- y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
+ x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
+ y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
return this.getTileIndex(x, y);
@@ -365,10 +357,10 @@ module Phaser {
}
// What tiles do we need to check against?
- this._tempTileX = this._game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth;
- this._tempTileY = this._game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight;
- this._tempTileW = (this._game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
- this._tempTileH = (this._game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
+ this._tempTileX = this.game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth;
+ this._tempTileY = this.game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight;
+ this._tempTileW = (this.game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
+ this._tempTileH = (this.game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
@@ -378,7 +370,7 @@ module Phaser {
/*
for (var r = 0; r < this._tempTileBlock.length; r++)
{
- if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
+ if (this.game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
{
this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
}
@@ -428,16 +420,16 @@ module Phaser {
if (collisionOnly)
{
// We only want to consider the tile for checking if you can actually collide with it
- if (this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Types.NONE)
+ if (this.mapData[ty] && this.mapData[ty][tx] && this.parent.tiles[this.mapData[ty][tx]].allowCollisions != Types.NONE)
{
- this._tempTileBlock.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] });
+ this._tempTileBlock.push({ x: tx, y: ty, tile: this.parent.tiles[this.mapData[ty][tx]] });
}
}
else
{
if (this.mapData[ty] && this.mapData[ty][tx])
{
- this._tempTileBlock.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] });
+ this._tempTileBlock.push({ x: tx, y: ty, tile: this.parent.tiles[this.mapData[ty][tx]] });
}
}
}
@@ -502,34 +494,35 @@ module Phaser {
/**
* Parse tile offsets from map data.
- * @return {number} length of _tileOffsets array.
+ * @return {number} length of tileOffsets array.
*/
public parseTileOffsets():number {
- this._tileOffsets = [];
+ this.tileOffsets = [];
var i = 0;
if (this.mapFormat == Tilemap.FORMAT_TILED_JSON)
{
// For some reason Tiled counts from 1 not 0
- this._tileOffsets[0] = null;
+ this.tileOffsets[0] = null;
i = 1;
}
- for (var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing))
+ for (var ty = this.tileMargin; ty < this.texture.height; ty += (this.tileHeight + this.tileSpacing))
{
- for (var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing))
+ for (var tx = this.tileMargin; tx < this.texture.width; tx += (this.tileWidth + this.tileSpacing))
{
- this._tileOffsets[i] = { x: tx, y: ty };
+ this.tileOffsets[i] = { x: tx, y: ty };
i++;
}
}
- return this._tileOffsets.length;
+ return this.tileOffsets.length;
}
+ /*
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this.context.fillStyle = color;
@@ -539,125 +532,7 @@ module Phaser {
this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
}
-
- /**
- * Render this layer to a specific camera with offset to camera.
- * @param camera {Camera} The camera the layer is going to be rendered.
- * @param dx {number} X offset to the camera.
- * @param dy {number} Y offset to the camera.
- * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed.
- */
- public render(camera: Camera, dx, dy): bool {
-
- if (this.visible === false || this.alpha < 0.1)
- {
- return false;
- }
-
- // Work out how many tiles we can fit into our camera and round it up for the edges
- this._maxX = this._game.math.ceil(camera.width / this.tileWidth) + 1;
- this._maxY = this._game.math.ceil(camera.height / this.tileHeight) + 1;
-
- // And now work out where in the tilemap the camera actually is
- this._startX = this._game.math.floor(camera.worldView.x / this.tileWidth);
- this._startY = this._game.math.floor(camera.worldView.y / this.tileHeight);
-
- // Tilemap bounds check
- if (this._startX < 0)
- {
- this._startX = 0;
- }
-
- if (this._startY < 0)
- {
- this._startY = 0;
- }
-
- if (this._maxX > this.widthInTiles)
- {
- this._maxX = this.widthInTiles;
- }
-
- if (this._maxY > this.heightInTiles)
- {
- this._maxY = this.heightInTiles;
- }
-
- if (this._startX + this._maxX > this.widthInTiles)
- {
- this._startX = this.widthInTiles - this._maxX;
- }
-
- if (this._startY + this._maxY > this.heightInTiles)
- {
- this._startY = this.heightInTiles - this._maxY;
- }
-
- // Finally get the offset to avoid the blocky movement
- this._dx = dx;
- this._dy = dy;
-
- this._dx += -(camera.worldView.x - (this._startX * this.tileWidth));
- this._dy += -(camera.worldView.y - (this._startY * this.tileHeight));
-
- this._tx = this._dx;
- this._ty = this._dy;
-
- // Apply camera difference
- /*
- if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
- {
- this._dx -= (camera.worldView.x * this.scrollFactor.x);
- this._dy -= (camera.worldView.y * this.scrollFactor.y);
- }
- */
-
- // Alpha
- if (this.alpha !== 1)
- {
- var globalAlpha = this.context.globalAlpha;
- this.context.globalAlpha = this.alpha;
- }
-
- for (var row = this._startY; row < this._startY + this._maxY; row++)
- {
- this._columnData = this.mapData[row];
-
- for (var tile = this._startX; tile < this._startX + this._maxX; tile++)
- {
- if (this._tileOffsets[this._columnData[tile]])
- {
- this.context.drawImage(
- this._texture, // Source Image
- this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
- this._tileOffsets[this._columnData[tile]].y, // Source Y
- this.tileWidth, // Source Width
- this.tileHeight, // Source Height
- this._tx, // Destination X (where on the canvas it'll be drawn)
- this._ty, // Destination Y
- this.tileWidth, // Destination Width (always same as Source Width unless scaled)
- this.tileHeight // Destination Height (always same as Source Height unless scaled)
- );
-
- }
-
- this._tx += this.tileWidth;
-
- }
-
- this._tx = this._dx;
- this._ty += this.tileHeight;
-
- }
-
- if (globalAlpha > -1)
- {
- this.context.globalAlpha = globalAlpha;
- }
-
- return true;
-
- }
+ */
}
}
\ No newline at end of file
diff --git a/Phaser/components/sprite/Events.ts b/Phaser/components/sprite/Events.ts
index 2dcd55e90..b8e2e3d90 100644
--- a/Phaser/components/sprite/Events.ts
+++ b/Phaser/components/sprite/Events.ts
@@ -24,10 +24,13 @@ module Phaser.Components.Sprite {
this.onKilled = new Phaser.Signal;
this.onRevived = new Phaser.Signal;
+ // Only create these if Sprite input is enabled?
this.onInputOver = new Phaser.Signal;
this.onInputOut = new Phaser.Signal;
this.onInputDown = new Phaser.Signal;
this.onInputUp = new Phaser.Signal;
+ this.onDragStart = new Phaser.Signal;
+ this.onDragStop = new Phaser.Signal;
}
@@ -81,6 +84,15 @@ module Phaser.Components.Sprite {
*/
public onInputUp: Phaser.Signal;
+ /**
+ * Dispatched by the Input component when the Sprite starts being dragged
+ */
+ public onDragStart: Phaser.Signal;
+
+ /**
+ * Dispatched by the Input component when the Sprite stops being dragged
+ */
+ public onDragStop: Phaser.Signal;
diff --git a/Phaser/components/sprite/Input.ts b/Phaser/components/sprite/Input.ts
index c6e0a0b9d..2c36f72aa 100644
--- a/Phaser/components/sprite/Input.ts
+++ b/Phaser/components/sprite/Input.ts
@@ -595,6 +595,8 @@ module Phaser.Components.Sprite {
this.sprite.group.bringToTop(this.sprite);
}
+ this.sprite.events.onDragStart.dispatch(this.sprite, pointer);
+
}
/**
@@ -612,7 +614,7 @@ module Phaser.Components.Sprite {
this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY;
}
- //pointer.draggedObject = null;
+ this.sprite.events.onDragStop.dispatch(this.sprite, pointer);
}
/**
diff --git a/Phaser/core/Group.ts b/Phaser/core/Group.ts
index 8d1633ce7..65a870304 100644
--- a/Phaser/core/Group.ts
+++ b/Phaser/core/Group.ts
@@ -618,17 +618,58 @@ module Phaser {
public bringToTop(child): bool {
+ //console.log('bringToTop', child.name,'current z', child.z);
+ var oldZ = child.z;
+
// If child not in this group, or is already at the top of the group, return false
- if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter)
+ //if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter)
+ if (!child || child.group == null || child.group.ID != this.ID)
+ {
+ //console.log('If child not in this group, or is already at the top of the group, return false');
+ return false;
+ }
+
+ // Find out the largest z index
+ var topZ: number = -1;
+
+ for (var i = 0; i < this.length; i++)
+ {
+ if (this.members[i] && this.members[i].z > topZ)
+ {
+ topZ = this.members[i].z;
+ }
+ }
+
+ // Child is already at the top
+ if (child.z == topZ)
{
return false;
}
+ child.z = topZ + 1;
+
+ // Sort them out based on the current z indexes
this.sort();
+ // Now tidy-up the z indexes, removing gaps, etc
+ for (var i = 0; i < this.length; i++)
+ {
+ if (this.members[i])
+ {
+ this.members[i].z = i;
+ }
+ }
+
+ //console.log('bringToTop', child.name, 'old z', oldZ, 'new z', child.z);
+
+ return true;
+
// What's the z index of the top most child?
+ /*
var childIndex: number = this._zCounter;
+ console.log('childIndex', childIndex);
+
this._i = 0;
while (this._i < this.length)
@@ -649,10 +690,13 @@ module Phaser {
}
}
+ console.log('child inserted at index', child.z);
+
// Maybe redundant?
this.sort();
return true;
+ */
}
diff --git a/Phaser/gameobjects/IGameObject.ts b/Phaser/gameobjects/IGameObject.ts
index 26784eb7c..c5fbce2d1 100644
--- a/Phaser/gameobjects/IGameObject.ts
+++ b/Phaser/gameobjects/IGameObject.ts
@@ -19,6 +19,11 @@ module Phaser {
*/
group: Group;
+ /**
+ * The name of the Game Object. Typically not set by Phaser, but extremely useful for debugging / logic.
+ */
+ name: string;
+
/**
* x value of the object.
*/
diff --git a/Phaser/gameobjects/Sprite.ts b/Phaser/gameobjects/Sprite.ts
index 524c40095..7bc25302d 100644
--- a/Phaser/gameobjects/Sprite.ts
+++ b/Phaser/gameobjects/Sprite.ts
@@ -23,7 +23,7 @@ module Phaser {
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
- * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
+ * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics)
* @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape)
*/
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, frame? = null, bodyType?: number = Phaser.Types.BODY_DISABLED, shapeType?:number = 0) {
@@ -40,6 +40,7 @@ module Phaser {
this.y = y;
this.z = -1;
this.group = null;
+ this.name = '';
this.animations = new Phaser.Components.AnimationManager(this);
this.input = new Phaser.Components.Sprite.Input(this);
@@ -97,6 +98,11 @@ module Phaser {
*/
public type: number;
+ /**
+ * The name of game object.
+ */
+ public name: string;
+
/**
* The Group this Sprite belongs to.
*/
@@ -183,7 +189,7 @@ module Phaser {
/**
* z order value of the object.
*/
- public z: number = 0;
+ public z: number = -1;
/**
* Render iteration counter
@@ -202,7 +208,14 @@ module Phaser {
* The value is automatically wrapped to be between 0 and 360.
*/
public set rotation(value: number) {
+
this.transform.rotation = this.game.math.wrap(value, 360, 0);
+
+ if (this.body)
+ {
+ this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
+ }
+
}
/**
diff --git a/Phaser/gameobjects/Tilemap.ts b/Phaser/gameobjects/Tilemap.ts
index 14408fb66..d128b3963 100644
--- a/Phaser/gameobjects/Tilemap.ts
+++ b/Phaser/gameobjects/Tilemap.ts
@@ -35,9 +35,15 @@ module Phaser {
this.visible = true;
this.alive = true;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
+
this.tiles = [];
this.layers = [];
- this.cameraBlacklist = [];
this.mapFormat = format;
@@ -71,6 +77,16 @@ module Phaser {
*/
public type: number;
+ /**
+ * The name of game object.
+ */
+ public name: string;
+
+ /**
+ * The Group this Sprite belongs to.
+ */
+ public group: Group;
+
/**
* Controls if both update
and render are called by the core game loop.
*/
@@ -87,10 +103,44 @@ module Phaser {
public visible: bool;
/**
- *
+ * A useful state for many game objects. Kill and revive both flip this switch.
*/
public alive: bool;
+ /**
+ * The texture used to render the Sprite.
+ */
+ public texture: Phaser.Components.Texture;
+
+ /**
+ * The Sprite transform component.
+ */
+ public transform: Phaser.Components.Transform;
+
+ /**
+ * The Input component
+ */
+ //public input: Phaser.Components.Sprite.Input;
+
+ /**
+ * The Events component
+ */
+ //public events: Phaser.Components.Sprite.Events;
+
+ /**
+ * z order value of the object.
+ */
+ public z: number = -1;
+
+ /**
+ * Render iteration counter
+ */
+ public renderOrderID: number = 0;
+
+
+
+
+
/**
* Tilemap data format enum: CSV.
* @type {number}
@@ -145,34 +195,15 @@ module Phaser {
public mapFormat: number;
/**
- * An Array of Cameras to which this GameObject won't render
- * @type {Array}
+ * Inherited methods for overriding.
*/
- public cameraBlacklist: number[];
-
- /**
- * Inherited update method.
- */
- public update() {
+ public preUpdate() {
}
- /**
- * Render this tilemap to a specific camera with specific offset.
- * @param camera {Camera} The camera this tilemap will be rendered to.
- * @param cameraOffsetX {number} X offset of the camera.
- * @param cameraOffsetY {number} Y offset of the camera.
- */
- public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
-
- if (this.cameraBlacklist.indexOf(camera.ID) == -1)
- {
- // Loop through the layers
- for (var i = 0; i < this.layers.length; i++)
- {
- this.layers[i].render(camera, cameraOffsetX, cameraOffsetY);
- }
- }
-
+ public update() {
+ }
+
+ public postUpdate() {
}
/**
@@ -202,6 +233,7 @@ module Phaser {
}
layer.updateBounds();
+
var tileQuantity = layer.parseTileOffsets();
this.currentLayer = layer;
diff --git a/Phaser/phaser.js b/Phaser/phaser.js
index ec56656ed..7b20a194e 100644
--- a/Phaser/phaser.js
+++ b/Phaser/phaser.js
@@ -1,3 +1,19 @@
+/**
+* Phaser
+*
+* v1.0.0 - June XX 2013
+*
+* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
+*
+* Richard Davey (@photonstorm)
+*
+* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
+* and my love of game development took a lot of inspiration.
+*
+* "If you want your children to be intelligent, read them fairy tales."
+* "If you want them to be more intelligent, read them more fairy tales."
+* -- Albert Einstein
+*/
var Phaser;
(function (Phaser) {
Phaser.VERSION = 'Phaser version 1.0.0';
diff --git a/Phaser/physics/Body.ts b/Phaser/physics/Body.ts
index 0e65ebabd..c4758a033 100644
--- a/Phaser/physics/Body.ts
+++ b/Phaser/physics/Body.ts
@@ -35,7 +35,7 @@ module Phaser.Physics {
this.sprite = sprite;
this.game = sprite.game;
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Manager.pixelsToMeters(sprite.y));
- this.angle = sprite.rotation;
+ this.angle = this.game.math.degreesToRadians(sprite.rotation);
}
else
{
@@ -61,7 +61,6 @@ module Phaser.Physics {
this.bounds = new Bounds;
this.allowCollisions = Phaser.Types.ANY;
- this.fixedRotation = false;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
@@ -82,11 +81,8 @@ module Phaser.Physics {
}
- public toString(): string {
- return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
- }
-
private _tempVec2: Phaser.Vec2 = new Phaser.Vec2;
+ private _fixedRotation: bool = false;
/**
* Reference to Phaser.Game
@@ -118,8 +114,26 @@ module Phaser.Physics {
*/
public type: number;
+ /**
+ * The angle of the body in radians. Used by all of the internal physics methods.
+ */
public angle: number;
+ /**
+ * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ */
+ public get rotation(): number {
+ return this.game.math.radiansToDegrees(this.angle);
+ }
+
+ /**
+ * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ * The value is automatically wrapped to be between 0 and 360.
+ */
+ public set rotation(value: number) {
+ this.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
+ }
+
// Local to world transform
public transform: Phaser.Transform;
@@ -174,17 +188,16 @@ module Phaser.Physics {
public inertia: number;
public inertiaInverted: number;
- public fixedRotation = false;
- public categoryBits = 0x0001;
- public maskBits = 0xFFFF;
- public stepCount = 0;
+ public categoryBits: number = 0x0001;
+ public maskBits: number = 0xFFFF;
+ public stepCount: number = 0;
public space: Space;
public duplicate() {
console.log('body duplicate called');
- //var body = new Body(this.type, this.transform.t, this.angle);
+ //var body = new Body(this.type, this.transform.t, this.rotation);
//for (var i = 0; i < this.shapes.length; i++)
//{
@@ -313,28 +326,28 @@ module Phaser.Physics {
}
- private setMass(mass) {
+ private setMass(mass:number) {
this.mass = mass;
this.massInverted = mass > 0 ? 1 / mass : 0;
}
- private setInertia(inertia) {
+ private setInertia(inertia:number) {
this.inertia = inertia;
this.inertiaInverted = inertia > 0 ? 1 / inertia : 0;
}
- public setTransform(pos, angle) {
+ public setTransform(pos:Phaser.Vec2, angle:number) {
// inject the transform into this.position
this.transform.setTo(pos, angle);
- Manager.write('setTransform: ' + this.position.toString());
- Manager.write('centroid: ' + this.centroid.toString());
+ //Manager.write('setTransform: ' + this.position.toString());
+ //Manager.write('centroid: ' + this.centroid.toString());
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
- Manager.write('post setTransform: ' + this.position.toString());
+ //Manager.write('post setTransform: ' + this.position.toString());
//this.position.copyFrom(this.transform.transform(this.centroid));
this.angle = angle;
@@ -342,17 +355,17 @@ module Phaser.Physics {
public syncTransform() {
- Manager.write('syncTransform:');
- Manager.write('p: ' + this.position.toString());
- Manager.write('centroid: ' + this.centroid.toString());
- Manager.write('xf: ' + this.transform.toString());
- Manager.write('a: ' + this.angle);
+ //Manager.write('syncTransform:');
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('centroid: ' + this.centroid.toString());
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('a: ' + this.angle);
this.transform.setRotation(this.angle);
// OPTIMISE: Creating new vector
Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t);
- Manager.write('--------------------');
- Manager.write('xf: ' + this.transform.toString());
- Manager.write('--------------------');
+ //Manager.write('--------------------');
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('--------------------');
}
@@ -376,9 +389,16 @@ module Phaser.Physics {
return Phaser.TransformUtils.unrotate(this.transform, v);
}
- public setFixedRotation(flag) {
- this.fixedRotation = flag;
+ public set fixedRotation(value:bool) {
+
+ this._fixedRotation = value;
+
this.resetMassData();
+
+ }
+
+ public get fixedRotation(): bool {
+ return this._fixedRotation;
}
public resetMassData() {
@@ -392,7 +412,6 @@ module Phaser.Physics {
if (this.isDynamic == false)
{
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
- //this.position.copyFrom(this.transform.transform(this.centroid));
return;
}
@@ -407,14 +426,11 @@ module Phaser.Physics {
var mass = shape.area() * shape.density;
var inertia = shape.inertia(mass);
- //console.log('rmd', centroid, shape);
-
totalMassCentroid.multiplyAddByScalar(centroid, mass);
totalMass += mass;
totalInertia += inertia;
}
- //this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass));
Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid);
this.setMass(totalMass);
@@ -455,9 +471,9 @@ module Phaser.Physics {
public cacheData(source:string = '') {
- Manager.write('cacheData -- start');
- Manager.write('p: ' + this.position.toString());
- Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('cacheData -- start');
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('xf: ' + this.transform.toString());
this.bounds.clear();
@@ -468,11 +484,11 @@ module Phaser.Physics {
this.bounds.addBounds(shape.bounds);
}
- Manager.write('bounds: ' + this.bounds.toString());
+ //Manager.write('bounds: ' + this.bounds.toString());
- Manager.write('p: ' + this.position.toString());
- Manager.write('xf: ' + this.transform.toString());
- Manager.write('cacheData -- stop');
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('cacheData -- stop');
}
@@ -538,15 +554,16 @@ module Phaser.Physics {
{
this.sprite.x = this.position.x * 50;
this.sprite.y = this.position.y * 50;
- // Obey fixed rotation?
- this.sprite.rotation = this.game.math.radiansToDegrees(this.angle);
+ this.sprite.transform.rotation = this.game.math.radiansToDegrees(this.angle);
}
}
public resetForce() {
+
this.force.setTo(0, 0);
this.torque = 0;
+
}
public applyForce(force:Phaser.Vec2, p:Phaser.Vec2) {
@@ -638,11 +655,8 @@ module Phaser.Physics {
}
public kineticEnergy() {
-
- var vsq = this.velocity.dot(this.velocity);
- var wsq = this.angularVelocity * this.angularVelocity;
- return 0.5 * (this.mass * vsq + this.inertia * wsq);
+ return 0.5 * (this.mass * this.velocity.dot(this.velocity) + this.inertia * (this.angularVelocity * this.angularVelocity));
}
@@ -670,12 +684,7 @@ module Phaser.Physics {
public isCollidable(other:Body) {
- if (this == other)
- {
- return false;
- }
-
- if (this.isDynamic == false && other.isDynamic == false)
+ if ((this.isDynamic == false && other.isDynamic == false) || this == other)
{
return false;
}
@@ -699,6 +708,10 @@ module Phaser.Physics {
}
+ public toString(): string {
+ return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
+ }
+
}
}
\ No newline at end of file
diff --git a/Phaser/physics/ContactSolver.ts b/Phaser/physics/ContactSolver.ts
index f43db61f7..9db1a609b 100644
--- a/Phaser/physics/ContactSolver.ts
+++ b/Phaser/physics/ContactSolver.ts
@@ -313,12 +313,8 @@ module Phaser.Physics {
var r2 = new Phaser.Vec2;
// Transformed r1, r2
-
Phaser.Vec2Utils.rotate(con.r1_local, body1.angle, r1);
- //var r1 = vec2.rotate(con.r1_local, body1.a);
-
Phaser.Vec2Utils.rotate(con.r2_local, body2.angle, r2);
- //var r2 = vec2.rotate(con.r2_local, body2.a);
Manager.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle);
Manager.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y);
@@ -330,10 +326,7 @@ module Phaser.Physics {
var p2 = new Phaser.Vec2;
Phaser.Vec2Utils.add(body1.position, r1, p1);
- //var p1 = vec2.add(body1.p, r1);
-
Phaser.Vec2Utils.add(body2.position, r2, p2);
- //var p2 = vec2.add(body2.p, r2);
Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
@@ -341,7 +334,6 @@ module Phaser.Physics {
// Corrected delta vector
var dp = new Phaser.Vec2;
Phaser.Vec2Utils.subtract(p2, p1, dp);
- //var dp = vec2.sub(p2, p1);
// Position constraint
var c = Phaser.Vec2Utils.dot(dp, n) + con.depth;
@@ -368,16 +360,11 @@ module Phaser.Physics {
// Apply correction impulses
var impulse_dt = new Phaser.Vec2;
Phaser.Vec2Utils.scale(n, lambda_dt, impulse_dt);
- //var impulse_dt = vec2.scale(n, lambda_dt);
body1.position.multiplyAddByScalar(impulse_dt, -m1_inv);
- //body1.p.mad(impulse_dt, -m1_inv);
-
body1.angle -= sn1 * lambda_dt * i1_inv;
body2.position.multiplyAddByScalar(impulse_dt, m2_inv);
- //body2.p.mad(impulse_dt, m2_inv);
-
body2.angle += sn2 * lambda_dt * i2_inv;
Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
diff --git a/Phaser/renderers/CanvasRenderer.ts b/Phaser/renderers/CanvasRenderer.ts
index c3558af42..7aeb23a2d 100644
--- a/Phaser/renderers/CanvasRenderer.ts
+++ b/Phaser/renderers/CanvasRenderer.ts
@@ -17,7 +17,7 @@ module Phaser {
*/
private _game: Phaser.Game;
- // local rendering related temp vars to help avoid gc spikes with var creation
+ // Local rendering related temp vars to help avoid gc spikes through var creation
private _ga: number = 1;
private _sx: number = 0;
private _sy: number = 0;
@@ -29,9 +29,15 @@ module Phaser {
private _dh: number = 0;
private _fx: number = 1;
private _fy: number = 1;
+ private _tx: number = 0;
+ private _ty: number = 0;
private _sin: number = 0;
private _cos: number = 1;
-
+ private _maxX: number = 0;
+ private _maxY: number = 0;
+ private _startX: number = 0;
+ private _startY: number = 0;
+ private _columnData;
private _cameraList;
private _camera: Camera;
private _groupLength: number;
@@ -74,6 +80,10 @@ module Phaser {
{
this.renderScrollZone(this._camera, object);
}
+ else if (object.type == Types.TILEMAP)
+ {
+ this.renderTilemap(this._camera, object);
+ }
}
@@ -668,6 +678,124 @@ module Phaser {
}
+
+ /**
+ * Render a tilemap to a specific camera.
+ * @param camera {Camera} The camera this tilemap will be rendered to.
+ */
+ public renderTilemap(camera: Camera, tilemap: Tilemap): bool {
+
+ // Loop through the layers
+ for (var i = 0; i < tilemap.layers.length; i++)
+ {
+ var layer: TilemapLayer = tilemap.layers[i];
+
+ if (layer.visible == false || layer.alpha < 0.1)
+ {
+ continue;
+ }
+
+ // Work out how many tiles we can fit into our camera and round it up for the edges
+ this._maxX = this._game.math.ceil(camera.width / layer.tileWidth) + 1;
+ this._maxY = this._game.math.ceil(camera.height / layer.tileHeight) + 1;
+
+ // And now work out where in the tilemap the camera actually is
+ this._startX = this._game.math.floor(camera.worldView.x / layer.tileWidth);
+ this._startY = this._game.math.floor(camera.worldView.y / layer.tileHeight);
+
+ // Tilemap bounds check
+ if (this._startX < 0)
+ {
+ this._startX = 0;
+ }
+
+ if (this._startY < 0)
+ {
+ this._startY = 0;
+ }
+
+ if (this._maxX > layer.widthInTiles)
+ {
+ this._maxX = layer.widthInTiles;
+ }
+
+ if (this._maxY > layer.heightInTiles)
+ {
+ this._maxY = layer.heightInTiles;
+ }
+
+ if (this._startX + this._maxX > layer.widthInTiles)
+ {
+ this._startX = layer.widthInTiles - this._maxX;
+ }
+
+ if (this._startY + this._maxY > layer.heightInTiles)
+ {
+ this._startY = layer.heightInTiles - this._maxY;
+ }
+
+ // Finally get the offset to avoid the blocky movement
+ //this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x);
+ //this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y);
+ //this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x);
+ //this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y);
+ this._dx = 0;
+ this._dy = 0;
+
+ this._dx += -(camera.worldView.x - (this._startX * layer.tileWidth));
+ this._dy += -(camera.worldView.y - (this._startY * layer.tileHeight));
+
+ this._tx = this._dx;
+ this._ty = this._dy;
+
+ // Alpha
+ if (layer.texture.alpha !== 1)
+ {
+ this._ga = layer.texture.context.globalAlpha;
+ layer.texture.context.globalAlpha = layer.texture.alpha;
+ }
+
+ for (var row = this._startY; row < this._startY + this._maxY; row++)
+ {
+ this._columnData = layer.mapData[row];
+
+ for (var tile = this._startX; tile < this._startX + this._maxX; tile++)
+ {
+ if (layer.tileOffsets[this._columnData[tile]])
+ {
+ layer.texture.context.drawImage(
+ layer.texture.texture,
+ layer.tileOffsets[this._columnData[tile]].x,
+ layer.tileOffsets[this._columnData[tile]].y,
+ layer.tileWidth,
+ layer.tileHeight,
+ this._tx,
+ this._ty,
+ layer.tileWidth,
+ layer.tileHeight
+ );
+
+ }
+
+ this._tx += layer.tileWidth;
+
+ }
+
+ this._tx = this._dx;
+ this._ty += layer.tileHeight;
+
+ }
+
+ if (this._ga > -1)
+ {
+ layer.texture.context.globalAlpha = this._ga;
+ }
+ }
+
+ return true;
+
+ }
+
}
}
\ No newline at end of file
diff --git a/Phaser/tweens/Tween.ts b/Phaser/tweens/Tween.ts
index f46d500a9..05b2dd8d4 100644
--- a/Phaser/tweens/Tween.ts
+++ b/Phaser/tweens/Tween.ts
@@ -187,6 +187,8 @@ module Phaser {
}
+ public isRunning: bool = false;
+
/**
* Start to tween.
*/
@@ -205,6 +207,7 @@ module Phaser {
}
this._startTime = this._game.time.now + this._delayTime;
+ this.isRunning = true;
for (var property in this._valuesEnd)
{
@@ -289,6 +292,8 @@ module Phaser {
this._manager.remove(this);
}
+ this.isRunning = false;
+
this.onComplete.dispose();
return this;
@@ -432,6 +437,11 @@ module Phaser {
this._chainedTweens[i].start();
}
+ if (this._chainedTweens.length == 0)
+ {
+ this.isRunning = false;
+ }
+
return false;
}
diff --git a/Phaser/utils/DebugUtils.ts b/Phaser/utils/DebugUtils.ts
index a4ae9613f..7ad622496 100644
--- a/Phaser/utils/DebugUtils.ts
+++ b/Phaser/utils/DebugUtils.ts
@@ -91,6 +91,13 @@ module Phaser {
}
+ static renderRectangle(rect: Phaser.Rectangle, fillStyle: string = 'rgba(0,255,0,0.3)') {
+
+ DebugUtils.context.fillStyle = fillStyle;
+ DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+
+ }
+
static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') {
for (var s = 0; s < body.shapesLength; s++)
diff --git a/Phaser/utils/PointUtils.ts b/Phaser/utils/PointUtils.ts
index 1431f2159..775da3711 100644
--- a/Phaser/utils/PointUtils.ts
+++ b/Phaser/utils/PointUtils.ts
@@ -11,7 +11,7 @@
module Phaser {
- class PointUtils {
+ export class PointUtils {
/**
* Adds the coordinates of two points together to create a new point.
diff --git a/README.md b/README.md
index d92e7722c..d6ce2f628 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,13 @@ TODO:
* See about optimising Advanced Physics a lot more, so it doesn't create lots of Vec2s everywhere.
* QuadTree.physics.checkHullIntersection
* Fix the Motion methods for the new physics system
-* Moved findShapeByPoint etc from Space to Manager (or at least add a proxy to them)
+* Move findShapeByPoint etc from Space to Manager (or at least add a proxy to them)
+* Make onInput events created only if input component is started
+* Add button mode linked to sprite frames
+* Add visible toggle if tween property is alpha <> 01
+* Camera.isHidden uses an array and length check, faster to swap for a single counter, also try to remove indexOf check
+* Tilemap.render - move layers length to var
+* Camera control method (touch/keyboard)
V1.0.0
@@ -126,7 +132,10 @@ V1.0.0
* Fixed issue in Tilemap.parseTiledJSON where it would accidentally think image and object layers were map data.
* Fixed bug in Group.bringToTop if the child didn't have a group property yet.
* Fixed bug in FrameData.checkFrameName where the first index of the _frameNames array would be skipped.
-
+* Added isRunning boolean property to Phaser.Tween
+* Moved 'facing' property from Sprite.body to Sprite.texture (may move to Sprite core)
+* Added Sprite.events.onDragStart and onDragStop
+* A tilemap can now be loaded without a tile sheet, should you just want to get the tile data from it and not render.
V0.9.6
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 3af754cb1..6d56ec2be 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -217,6 +217,22 @@
origin 5.ts
+
+
+ csv tilemap.ts
+
+
+
+
+
+ map draw.ts
+
+
+ tiled layers.ts
+
+
+ tiled tilemap.ts
+
tween loop 1.ts
diff --git a/Tests/phaser.js b/Tests/phaser.js
index 0df38b194..f5d4f68ff 100644
--- a/Tests/phaser.js
+++ b/Tests/phaser.js
@@ -3787,6 +3787,7 @@ var Phaser;
if(this.bringToTop) {
this.sprite.group.bringToTop(this.sprite);
}
+ this.sprite.events.onDragStart.dispatch(this.sprite, pointer);
};
Input.prototype.stopDrag = /**
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
@@ -3799,8 +3800,8 @@ var Phaser;
this.sprite.x = Math.floor(this.sprite.x / this.snapX) * this.snapX;
this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY;
}
- //pointer.draggedObject = null;
- };
+ this.sprite.events.onDragStop.dispatch(this.sprite, pointer);
+ };
Input.prototype.setDragLock = /**
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
*
@@ -3913,10 +3914,13 @@ var Phaser;
this.onRemovedFromGroup = new Phaser.Signal();
this.onKilled = new Phaser.Signal();
this.onRevived = new Phaser.Signal();
+ // Only create these if Sprite input is enabled?
this.onInputOver = new Phaser.Signal();
this.onInputOut = new Phaser.Signal();
this.onInputDown = new Phaser.Signal();
this.onInputUp = new Phaser.Signal();
+ this.onDragStart = new Phaser.Signal();
+ this.onDragStop = new Phaser.Signal();
}
return Events;
})();
@@ -5158,9 +5162,7 @@ var Phaser;
var r2 = new Phaser.Vec2();
// Transformed r1, r2
Phaser.Vec2Utils.rotate(con.r1_local, body1.angle, r1);
- //var r1 = vec2.rotate(con.r1_local, body1.a);
Phaser.Vec2Utils.rotate(con.r2_local, body2.angle, r2);
- //var r2 = vec2.rotate(con.r2_local, body2.a);
Physics.Manager.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle);
Physics.Manager.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y);
Physics.Manager.write('r2_local.x = ' + con.r2_local.x + ' r2_local.y = ' + con.r2_local.y + ' angle: ' + body2.angle);
@@ -5169,15 +5171,12 @@ var Phaser;
var p1 = new Phaser.Vec2();
var p2 = new Phaser.Vec2();
Phaser.Vec2Utils.add(body1.position, r1, p1);
- //var p1 = vec2.add(body1.p, r1);
Phaser.Vec2Utils.add(body2.position, r2, p2);
- //var p2 = vec2.add(body2.p, r2);
Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
// Corrected delta vector
var dp = new Phaser.Vec2();
Phaser.Vec2Utils.subtract(p2, p1, dp);
- //var dp = vec2.sub(p2, p1);
// Position constraint
var c = Phaser.Vec2Utils.dot(dp, n) + con.depth;
var correction = this.clamp(Physics.Manager.CONTACT_SOLVER_BAUMGARTE * (c + Physics.Manager.CONTACT_SOLVER_COLLISION_SLOP), -Physics.Manager.CONTACT_SOLVER_MAX_LINEAR_CORRECTION, 0);
@@ -5195,12 +5194,9 @@ var Phaser;
// Apply correction impulses
var impulse_dt = new Phaser.Vec2();
Phaser.Vec2Utils.scale(n, lambda_dt, impulse_dt);
- //var impulse_dt = vec2.scale(n, lambda_dt);
body1.position.multiplyAddByScalar(impulse_dt, -m1_inv);
- //body1.p.mad(impulse_dt, -m1_inv);
body1.angle -= sn1 * lambda_dt * i1_inv;
body2.position.multiplyAddByScalar(impulse_dt, m2_inv);
- //body2.p.mad(impulse_dt, m2_inv);
body2.angle += sn2 * lambda_dt * i2_inv;
Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
@@ -6664,13 +6660,13 @@ var Phaser;
if (typeof y === "undefined") { y = 0; }
if (typeof shapeType === "undefined") { shapeType = 0; }
this._tempVec2 = new Phaser.Vec2();
+ this._fixedRotation = false;
// Shapes
this.shapes = [];
// Joints
this.joints = [];
this.jointHash = {
};
- this.fixedRotation = false;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
@@ -6681,7 +6677,7 @@ var Phaser;
this.sprite = sprite;
this.game = sprite.game;
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Manager.pixelsToMeters(sprite.y));
- this.angle = sprite.rotation;
+ this.angle = this.game.math.degreesToRadians(sprite.rotation);
} else {
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(x), Phaser.Physics.Manager.pixelsToMeters(y));
this.angle = 0;
@@ -6702,7 +6698,6 @@ var Phaser;
};
this.bounds = new Physics.Bounds();
this.allowCollisions = Phaser.Types.ANY;
- this.fixedRotation = false;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
@@ -6714,12 +6709,26 @@ var Phaser;
}
}
}
- Body.prototype.toString = function () {
- return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
- };
+ Object.defineProperty(Body.prototype, "rotation", {
+ get: /**
+ * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ */
+ function () {
+ return this.game.math.radiansToDegrees(this.angle);
+ },
+ set: /**
+ * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ * The value is automatically wrapped to be between 0 and 360.
+ */
+ function (value) {
+ this.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
+ },
+ enumerable: true,
+ configurable: true
+ });
Body.prototype.duplicate = function () {
console.log('body duplicate called');
- //var body = new Body(this.type, this.transform.t, this.angle);
+ //var body = new Body(this.type, this.transform.t, this.rotation);
//for (var i = 0; i < this.shapes.length; i++)
//{
// body.addShape(this.shapes[i].duplicate());
@@ -6842,26 +6851,26 @@ var Phaser;
Body.prototype.setTransform = function (pos, angle) {
// inject the transform into this.position
this.transform.setTo(pos, angle);
- Physics.Manager.write('setTransform: ' + this.position.toString());
- Physics.Manager.write('centroid: ' + this.centroid.toString());
+ //Manager.write('setTransform: ' + this.position.toString());
+ //Manager.write('centroid: ' + this.centroid.toString());
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
- Physics.Manager.write('post setTransform: ' + this.position.toString());
+ //Manager.write('post setTransform: ' + this.position.toString());
//this.position.copyFrom(this.transform.transform(this.centroid));
this.angle = angle;
};
Body.prototype.syncTransform = function () {
- Physics.Manager.write('syncTransform:');
- Physics.Manager.write('p: ' + this.position.toString());
- Physics.Manager.write('centroid: ' + this.centroid.toString());
- Physics.Manager.write('xf: ' + this.transform.toString());
- Physics.Manager.write('a: ' + this.angle);
+ //Manager.write('syncTransform:');
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('centroid: ' + this.centroid.toString());
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('a: ' + this.angle);
this.transform.setRotation(this.angle);
// OPTIMISE: Creating new vector
Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t);
- Physics.Manager.write('--------------------');
- Physics.Manager.write('xf: ' + this.transform.toString());
- Physics.Manager.write('--------------------');
- };
+ //Manager.write('--------------------');
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('--------------------');
+ };
Body.prototype.getWorldPoint = function (p) {
// OPTIMISE: Creating new vector
return Phaser.TransformUtils.transform(this.transform, p);
@@ -6878,10 +6887,17 @@ var Phaser;
// OPTIMISE: Creating new vector
return Phaser.TransformUtils.unrotate(this.transform, v);
};
- Body.prototype.setFixedRotation = function (flag) {
- this.fixedRotation = flag;
- this.resetMassData();
- };
+ Object.defineProperty(Body.prototype, "fixedRotation", {
+ get: function () {
+ return this._fixedRotation;
+ },
+ set: function (value) {
+ this._fixedRotation = value;
+ this.resetMassData();
+ },
+ enumerable: true,
+ configurable: true
+ });
Body.prototype.resetMassData = function () {
this.centroid.setTo(0, 0);
this.mass = 0;
@@ -6890,7 +6906,6 @@ var Phaser;
this.inertiaInverted = 0;
if(this.isDynamic == false) {
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
- //this.position.copyFrom(this.transform.transform(this.centroid));
return;
}
var totalMassCentroid = new Phaser.Vec2(0, 0);
@@ -6901,12 +6916,10 @@ var Phaser;
var centroid = shape.centroid();
var mass = shape.area() * shape.density;
var inertia = shape.inertia(mass);
- //console.log('rmd', centroid, shape);
totalMassCentroid.multiplyAddByScalar(centroid, mass);
totalMass += mass;
totalInertia += inertia;
}
- //this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass));
Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid);
this.setMass(totalMass);
if(!this.fixedRotation) {
@@ -6933,20 +6946,20 @@ var Phaser;
};
Body.prototype.cacheData = function (source) {
if (typeof source === "undefined") { source = ''; }
- Physics.Manager.write('cacheData -- start');
- Physics.Manager.write('p: ' + this.position.toString());
- Physics.Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('cacheData -- start');
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('xf: ' + this.transform.toString());
this.bounds.clear();
for(var i = 0; i < this.shapesLength; i++) {
var shape = this.shapes[i];
shape.cacheData(this.transform);
this.bounds.addBounds(shape.bounds);
}
- Physics.Manager.write('bounds: ' + this.bounds.toString());
- Physics.Manager.write('p: ' + this.position.toString());
- Physics.Manager.write('xf: ' + this.transform.toString());
- Physics.Manager.write('cacheData -- stop');
- };
+ //Manager.write('bounds: ' + this.bounds.toString());
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('cacheData -- stop');
+ };
Body.prototype.updateVelocity = function (gravity, dt, damping) {
Phaser.Vec2Utils.multiplyAdd(gravity, this.force, this.massInverted, this._tempVec2);
Phaser.Vec2Utils.multiplyAdd(this.velocity, this._tempVec2, dt, this.velocity);
@@ -6987,8 +7000,7 @@ var Phaser;
if(this.sprite) {
this.sprite.x = this.position.x * 50;
this.sprite.y = this.position.y * 50;
- // Obey fixed rotation?
- this.sprite.rotation = this.game.math.radiansToDegrees(this.angle);
+ this.sprite.transform.rotation = this.game.math.radiansToDegrees(this.angle);
}
};
Body.prototype.resetForce = function () {
@@ -7045,9 +7057,7 @@ var Phaser;
this.angularVelocity += impulse * this.inertiaInverted;
};
Body.prototype.kineticEnergy = function () {
- var vsq = this.velocity.dot(this.velocity);
- var wsq = this.angularVelocity * this.angularVelocity;
- return 0.5 * (this.mass * vsq + this.inertia * wsq);
+ return 0.5 * (this.mass * this.velocity.dot(this.velocity) + this.inertia * (this.angularVelocity * this.angularVelocity));
};
Object.defineProperty(Body.prototype, "isAwake", {
get: function () {
@@ -7068,10 +7078,7 @@ var Phaser;
}
};
Body.prototype.isCollidable = function (other) {
- if(this == other) {
- return false;
- }
- if(this.isDynamic == false && other.isDynamic == false) {
+ if((this.isDynamic == false && other.isDynamic == false) || this == other) {
return false;
}
if(!(this.maskBits & other.categoryBits) || !(other.maskBits & this.categoryBits)) {
@@ -7085,6 +7092,9 @@ var Phaser;
}
return true;
};
+ Body.prototype.toString = function () {
+ return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
+ };
return Body;
})();
Physics.Body = Body;
@@ -7113,7 +7123,7 @@ var Phaser;
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
- * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
+ * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics)
* @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape)
*/
function Sprite(game, x, y, key, frame, bodyType, shapeType) {
@@ -7142,7 +7152,7 @@ var Phaser;
/**
* z order value of the object.
*/
- this.z = 0;
+ this.z = -1;
/**
* Render iteration counter
*/
@@ -7157,6 +7167,7 @@ var Phaser;
this.y = y;
this.z = -1;
this.group = null;
+ this.name = '';
this.animations = new Phaser.Components.AnimationManager(this);
this.input = new Phaser.Components.Sprite.Input(this);
this.events = new Phaser.Components.Sprite.Events(this);
@@ -7200,6 +7211,9 @@ var Phaser;
*/
function (value) {
this.transform.rotation = this.game.math.wrap(value, 360, 0);
+ if(this.body) {
+ this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
+ }
},
enumerable: true,
configurable: true
@@ -8185,29 +8199,70 @@ var Phaser;
return true;
};
Group.prototype.bringToTop = function (child) {
+ //console.log('bringToTop', child.name,'current z', child.z);
+ var oldZ = child.z;
// If child not in this group, or is already at the top of the group, return false
- if(!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) {
+ //if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter)
+ if(!child || child.group == null || child.group.ID != this.ID) {
+ //console.log('If child not in this group, or is already at the top of the group, return false');
return false;
}
- this.sort();
- // What's the z index of the top most child?
- var childIndex = this._zCounter;
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member) {
- if(this._i > childIndex) {
- this._member.z--;
- } else if(this._member.z == child.z) {
- childIndex = this._i;
- this._member.z = this._zCounter;
- }
+ // Find out the largest z index
+ var topZ = -1;
+ for(var i = 0; i < this.length; i++) {
+ if(this.members[i] && this.members[i].z > topZ) {
+ topZ = this.members[i].z;
}
}
+ // Child is already at the top
+ if(child.z == topZ) {
+ return false;
+ }
+ child.z = topZ + 1;
+ // Sort them out based on the current z indexes
+ this.sort();
+ // Now tidy-up the z indexes, removing gaps, etc
+ for(var i = 0; i < this.length; i++) {
+ if(this.members[i]) {
+ this.members[i].z = i;
+ }
+ }
+ //console.log('bringToTop', child.name, 'old z', oldZ, 'new z', child.z);
+ return true;
+ // What's the z index of the top most child?
+ /*
+ var childIndex: number = this._zCounter;
+
+ console.log('childIndex', childIndex);
+
+ this._i = 0;
+
+ while (this._i < this.length)
+ {
+ this._member = this.members[this._i++];
+
+ if (this._member)
+ {
+ if (this._i > childIndex)
+ {
+ this._member.z--;
+ }
+ else if (this._member.z == child.z)
+ {
+ childIndex = this._i;
+ this._member.z = this._zCounter;
+ }
+ }
+ }
+
+ console.log('child inserted at index', child.z);
+
// Maybe redundant?
this.sort();
+
return true;
- };
+ */
+ };
Group.prototype.sort = /**
* Call this function to sort the group according to a particular value and order.
* For example, to sort game objects for Zelda-style overlaps you might call
@@ -11782,6 +11837,7 @@ var Phaser;
* @type {Tweens[]}
*/
this._chainedTweens = [];
+ this.isRunning = false;
this._object = object;
this._game = game;
this._manager = this._game.tweens;
@@ -11849,6 +11905,7 @@ var Phaser;
this.onStart.dispatch(this._object);
}
this._startTime = this._game.time.now + this._delayTime;
+ this.isRunning = true;
for(var property in this._valuesEnd) {
// This prevents the interpolation of null values or of non-existing properties
if(this._object[property] === null || !(property in this._object)) {
@@ -11903,6 +11960,7 @@ var Phaser;
if(this._manager !== null) {
this._manager.remove(this);
}
+ this.isRunning = false;
this.onComplete.dispose();
return this;
};
@@ -12013,6 +12071,9 @@ var Phaser;
for(var i = 0; i < this._chainedTweens.length; i++) {
this._chainedTweens[i].start();
}
+ if(this._chainedTweens.length == 0) {
+ this.isRunning = false;
+ }
return false;
}
}
@@ -12633,21 +12694,6 @@ var Phaser;
* @param tileHeight {number} Height of tiles in this map.
*/
function TilemapLayer(game, parent, key, mapFormat, name, tileWidth, tileHeight) {
- this._startX = 0;
- this._startY = 0;
- this._maxX = 0;
- this._maxY = 0;
- this._tx = 0;
- this._ty = 0;
- this._dx = 0;
- this._dy = 0;
- this._oldCameraX = 0;
- this._oldCameraY = 0;
- /**
- * Opacity of this layer.
- * @type {number}
- */
- this.alpha = 1;
/**
* Controls whether update() and draw() are automatically called.
* @type {boolean}
@@ -12690,19 +12736,24 @@ var Phaser;
* @type {number}
*/
this.tileSpacing = 0;
- this._game = game;
- this._parent = parent;
+ this.game = game;
+ this.parent = parent;
this.name = name;
this.mapFormat = mapFormat;
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
this.boundsInTiles = new Phaser.Rectangle();
- //this.scrollFactor = new MicroPoint(1, 1);
- this.canvas = game.stage.canvas;
- this.context = game.stage.context;
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
+ if(key !== null) {
+ this.texture.loadImage(key, false);
+ } else {
+ this.texture.opaque = true;
+ }
+ // Handy proxies
+ this.alpha = this.texture.alpha;
this.mapData = [];
this._tempTileBlock = [];
- this._texture = this._game.cache.getImage(key);
}
TilemapLayer.prototype.putTile = /**
* Set a specific tile with its x and y in tiles.
@@ -12711,8 +12762,8 @@ var Phaser;
* @param index {number} The index of this tile type in the core map data.
*/
function (x, y, index) {
- x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
- y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
+ x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
+ y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if(y >= 0 && y < this.mapData.length) {
if(x >= 0 && x < this.mapData[y].length) {
this.mapData[y][x] = index;
@@ -12784,7 +12835,7 @@ var Phaser;
if (typeof height === "undefined") { height = this.heightInTiles; }
this.getTempBlock(x, y, width, height);
for(var r = 0; r < this._tempTileBlock.length; r++) {
- this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles);
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this.game.math.getRandom(tiles);
}
};
TilemapLayer.prototype.replaceTile = /**
@@ -12833,8 +12884,8 @@ var Phaser;
* @param x {number} Y position of the point in target tile.
*/
function (x, y) {
- x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
- y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
+ x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
+ y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
return this.getTileIndex(x, y);
};
TilemapLayer.prototype.getTileOverlaps = /**
@@ -12848,17 +12899,17 @@ var Phaser;
return;
}
// What tiles do we need to check against?
- this._tempTileX = this._game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth;
- this._tempTileY = this._game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight;
- this._tempTileW = (this._game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
- this._tempTileH = (this._game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
+ this._tempTileX = this.game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth;
+ this._tempTileY = this.game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight;
+ this._tempTileW = (this.game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
+ this._tempTileH = (this.game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
this._tempBlockResults = [];
this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
/*
for (var r = 0; r < this._tempTileBlock.length; r++)
{
- if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
+ if (this.game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
{
this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
}
@@ -12893,11 +12944,11 @@ var Phaser;
for(var tx = x; tx < x + width; tx++) {
if(collisionOnly) {
// We only want to consider the tile for checking if you can actually collide with it
- if(this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) {
+ if(this.mapData[ty] && this.mapData[ty][tx] && this.parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) {
this._tempTileBlock.push({
x: tx,
y: ty,
- tile: this._parent.tiles[this.mapData[ty][tx]]
+ tile: this.parent.tiles[this.mapData[ty][tx]]
});
}
} else {
@@ -12905,7 +12956,7 @@ var Phaser;
this._tempTileBlock.push({
x: tx,
y: ty,
- tile: this._parent.tiles[this.mapData[ty][tx]]
+ tile: this.parent.tiles[this.mapData[ty][tx]]
});
}
}
@@ -12951,120 +13002,42 @@ var Phaser;
};
TilemapLayer.prototype.parseTileOffsets = /**
* Parse tile offsets from map data.
- * @return {number} length of _tileOffsets array.
+ * @return {number} length of tileOffsets array.
*/
function () {
- this._tileOffsets = [];
+ this.tileOffsets = [];
var i = 0;
if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) {
// For some reason Tiled counts from 1 not 0
- this._tileOffsets[0] = null;
+ this.tileOffsets[0] = null;
i = 1;
}
- for(var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing)) {
- for(var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing)) {
- this._tileOffsets[i] = {
+ for(var ty = this.tileMargin; ty < this.texture.height; ty += (this.tileHeight + this.tileSpacing)) {
+ for(var tx = this.tileMargin; tx < this.texture.width; tx += (this.tileWidth + this.tileSpacing)) {
+ this.tileOffsets[i] = {
x: tx,
y: ty
};
i++;
}
}
- return this._tileOffsets.length;
- };
- TilemapLayer.prototype.renderDebugInfo = function (x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- this.context.fillStyle = color;
- this.context.fillText('TilemapLayer: ' + this.name, x, y);
- this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
- this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
- this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
- };
- TilemapLayer.prototype.render = /**
- * Render this layer to a specific camera with offset to camera.
- * @param camera {Camera} The camera the layer is going to be rendered.
- * @param dx {number} X offset to the camera.
- * @param dy {number} Y offset to the camera.
- * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed.
- */
- function (camera, dx, dy) {
- if(this.visible === false || this.alpha < 0.1) {
- return false;
- }
- // Work out how many tiles we can fit into our camera and round it up for the edges
- this._maxX = this._game.math.ceil(camera.width / this.tileWidth) + 1;
- this._maxY = this._game.math.ceil(camera.height / this.tileHeight) + 1;
- // And now work out where in the tilemap the camera actually is
- this._startX = this._game.math.floor(camera.worldView.x / this.tileWidth);
- this._startY = this._game.math.floor(camera.worldView.y / this.tileHeight);
- // Tilemap bounds check
- if(this._startX < 0) {
- this._startX = 0;
- }
- if(this._startY < 0) {
- this._startY = 0;
- }
- if(this._maxX > this.widthInTiles) {
- this._maxX = this.widthInTiles;
- }
- if(this._maxY > this.heightInTiles) {
- this._maxY = this.heightInTiles;
- }
- if(this._startX + this._maxX > this.widthInTiles) {
- this._startX = this.widthInTiles - this._maxX;
- }
- if(this._startY + this._maxY > this.heightInTiles) {
- this._startY = this.heightInTiles - this._maxY;
- }
- // Finally get the offset to avoid the blocky movement
- this._dx = dx;
- this._dy = dy;
- this._dx += -(camera.worldView.x - (this._startX * this.tileWidth));
- this._dy += -(camera.worldView.y - (this._startY * this.tileHeight));
- this._tx = this._dx;
- this._ty = this._dy;
- // Apply camera difference
- /*
- if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
- {
- this._dx -= (camera.worldView.x * this.scrollFactor.x);
- this._dy -= (camera.worldView.y * this.scrollFactor.y);
- }
- */
- // Alpha
- if(this.alpha !== 1) {
- var globalAlpha = this.context.globalAlpha;
- this.context.globalAlpha = this.alpha;
- }
- for(var row = this._startY; row < this._startY + this._maxY; row++) {
- this._columnData = this.mapData[row];
- for(var tile = this._startX; tile < this._startX + this._maxX; tile++) {
- if(this._tileOffsets[this._columnData[tile]]) {
- this.context.drawImage(this._texture, // Source Image
- this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
- this._tileOffsets[this._columnData[tile]].y, // Source Y
- this.tileWidth, // Source Width
- this.tileHeight, // Source Height
- this._tx, // Destination X (where on the canvas it'll be drawn)
- this._ty, // Destination Y
- this.tileWidth, // Destination Width (always same as Source Width unless scaled)
- this.tileHeight);
- // Destination Height (always same as Source Height unless scaled)
- }
- this._tx += this.tileWidth;
- }
- this._tx = this._dx;
- this._ty += this.tileHeight;
- }
- if(globalAlpha > -1) {
- this.context.globalAlpha = globalAlpha;
- }
- return true;
+ return this.tileOffsets.length;
};
return TilemapLayer;
})();
Phaser.TilemapLayer = TilemapLayer;
-})(Phaser || (Phaser = {}));
+ /*
+ public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
+
+ this.context.fillStyle = color;
+ this.context.fillText('TilemapLayer: ' + this.name, x, y);
+ this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
+ this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
+ this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
+
+ }
+ */
+ })(Phaser || (Phaser = {}));
///
/**
* Phaser - Tile
@@ -13217,6 +13190,22 @@ var Phaser;
if (typeof tileWidth === "undefined") { tileWidth = 0; }
if (typeof tileHeight === "undefined") { tileHeight = 0; }
/**
+ * The Input component
+ */
+ //public input: Phaser.Components.Sprite.Input;
+ /**
+ * The Events component
+ */
+ //public events: Phaser.Components.Sprite.Events;
+ /**
+ * z order value of the object.
+ */
+ this.z = -1;
+ /**
+ * Render iteration counter
+ */
+ this.renderOrderID = 0;
+ /**
* Tilemap collision callback.
* @type {function}
*/
@@ -13227,9 +13216,13 @@ var Phaser;
this.active = true;
this.visible = true;
this.alive = true;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
this.tiles = [];
this.layers = [];
- this.cameraBlacklist = [];
this.mapFormat = format;
switch(format) {
case Tilemap.FORMAT_CSV:
@@ -13245,24 +13238,14 @@ var Phaser;
}
Tilemap.FORMAT_CSV = 0;
Tilemap.FORMAT_TILED_JSON = 1;
- Tilemap.prototype.update = /**
- * Inherited update method.
+ Tilemap.prototype.preUpdate = /**
+ * Inherited methods for overriding.
*/
function () {
};
- Tilemap.prototype.render = /**
- * Render this tilemap to a specific camera with specific offset.
- * @param camera {Camera} The camera this tilemap will be rendered to.
- * @param cameraOffsetX {number} X offset of the camera.
- * @param cameraOffsetY {number} Y offset of the camera.
- */
- function (camera, cameraOffsetX, cameraOffsetY) {
- if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
- // Loop through the layers
- for(var i = 0; i < this.layers.length; i++) {
- this.layers[i].render(camera, cameraOffsetX, cameraOffsetY);
- }
- }
+ Tilemap.prototype.update = function () {
+ };
+ Tilemap.prototype.postUpdate = function () {
};
Tilemap.prototype.parseCSV = /**
* Parset csv map data and generate tiles.
@@ -16253,7 +16236,8 @@ var Phaser;
return PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
};
return PointUtils;
- })();
+ })();
+ Phaser.PointUtils = PointUtils;
})(Phaser || (Phaser = {}));
///
///
@@ -18083,7 +18067,7 @@ var Phaser;
(function (Phaser) {
var CanvasRenderer = (function () {
function CanvasRenderer(game) {
- // local rendering related temp vars to help avoid gc spikes with var creation
+ // Local rendering related temp vars to help avoid gc spikes through var creation
this._ga = 1;
this._sx = 0;
this._sy = 0;
@@ -18095,8 +18079,14 @@ var Phaser;
this._dh = 0;
this._fx = 1;
this._fy = 1;
+ this._tx = 0;
+ this._ty = 0;
this._sin = 0;
this._cos = 1;
+ this._maxX = 0;
+ this._maxY = 0;
+ this._startX = 0;
+ this._startY = 0;
this._game = game;
}
CanvasRenderer.prototype.render = function () {
@@ -18117,6 +18107,8 @@ var Phaser;
this.renderSprite(this._camera, object);
} else if(object.type == Phaser.Types.SCROLLZONE) {
this.renderScrollZone(this._camera, object);
+ } else if(object.type == Phaser.Types.TILEMAP) {
+ this.renderTilemap(this._camera, object);
}
};
CanvasRenderer.prototype.preRenderGroup = function (camera, group) {
@@ -18553,6 +18545,75 @@ var Phaser;
}
return true;
};
+ CanvasRenderer.prototype.renderTilemap = /**
+ * Render a tilemap to a specific camera.
+ * @param camera {Camera} The camera this tilemap will be rendered to.
+ */
+ function (camera, tilemap) {
+ // Loop through the layers
+ for(var i = 0; i < tilemap.layers.length; i++) {
+ var layer = tilemap.layers[i];
+ if(layer.visible == false || layer.alpha < 0.1) {
+ continue;
+ }
+ // Work out how many tiles we can fit into our camera and round it up for the edges
+ this._maxX = this._game.math.ceil(camera.width / layer.tileWidth) + 1;
+ this._maxY = this._game.math.ceil(camera.height / layer.tileHeight) + 1;
+ // And now work out where in the tilemap the camera actually is
+ this._startX = this._game.math.floor(camera.worldView.x / layer.tileWidth);
+ this._startY = this._game.math.floor(camera.worldView.y / layer.tileHeight);
+ // Tilemap bounds check
+ if(this._startX < 0) {
+ this._startX = 0;
+ }
+ if(this._startY < 0) {
+ this._startY = 0;
+ }
+ if(this._maxX > layer.widthInTiles) {
+ this._maxX = layer.widthInTiles;
+ }
+ if(this._maxY > layer.heightInTiles) {
+ this._maxY = layer.heightInTiles;
+ }
+ if(this._startX + this._maxX > layer.widthInTiles) {
+ this._startX = layer.widthInTiles - this._maxX;
+ }
+ if(this._startY + this._maxY > layer.heightInTiles) {
+ this._startY = layer.heightInTiles - this._maxY;
+ }
+ // Finally get the offset to avoid the blocky movement
+ //this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x);
+ //this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y);
+ //this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x);
+ //this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y);
+ this._dx = 0;
+ this._dy = 0;
+ this._dx += -(camera.worldView.x - (this._startX * layer.tileWidth));
+ this._dy += -(camera.worldView.y - (this._startY * layer.tileHeight));
+ this._tx = this._dx;
+ this._ty = this._dy;
+ // Alpha
+ if(layer.texture.alpha !== 1) {
+ this._ga = layer.texture.context.globalAlpha;
+ layer.texture.context.globalAlpha = layer.texture.alpha;
+ }
+ for(var row = this._startY; row < this._startY + this._maxY; row++) {
+ this._columnData = layer.mapData[row];
+ for(var tile = this._startX; tile < this._startX + this._maxX; tile++) {
+ if(layer.tileOffsets[this._columnData[tile]]) {
+ layer.texture.context.drawImage(layer.texture.texture, layer.tileOffsets[this._columnData[tile]].x, layer.tileOffsets[this._columnData[tile]].y, layer.tileWidth, layer.tileHeight, this._tx, this._ty, layer.tileWidth, layer.tileHeight);
+ }
+ this._tx += layer.tileWidth;
+ }
+ this._tx = this._dx;
+ this._ty += layer.tileHeight;
+ }
+ if(this._ga > -1) {
+ layer.texture.context.globalAlpha = this._ga;
+ }
+ }
+ return true;
+ };
return CanvasRenderer;
})();
Phaser.CanvasRenderer = CanvasRenderer;
@@ -18626,6 +18687,11 @@ var Phaser;
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
};
+ DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ DebugUtils.context.fillStyle = fillStyle;
+ DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
DebugUtils.renderPhysicsBody = function renderPhysicsBody(body, lineWidth, fillStyle, sleepStyle) {
if (typeof lineWidth === "undefined") { lineWidth = 1; }
if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.2)'; }
@@ -19094,84 +19160,6 @@ var Phaser;
})();
Phaser.Game = Game;
})(Phaser || (Phaser = {}));
-///
-/**
-* Phaser - State
-*
-* This is a base State class which can be extended if you are creating your game using TypeScript.
-*/
-var Phaser;
-(function (Phaser) {
- var State = (function () {
- /**
- * State constructor
- * Create a new State
.
- */
- function State(game) {
- this.game = game;
- this.add = game.add;
- this.camera = game.camera;
- this.cache = game.cache;
- this.input = game.input;
- this.load = game.load;
- this.math = game.math;
- this.motion = game.motion;
- this.sound = game.sound;
- this.stage = game.stage;
- this.time = game.time;
- this.tweens = game.tweens;
- this.world = game.world;
- }
- State.prototype.init = // Override these in your own States
- /**
- * Override this method to add some load operations.
- * If you need to use the loader, you may need to use them here.
- */
- function () {
- };
- State.prototype.create = /**
- * This method is called after the game engine successfully switches states.
- * Feel free to add any setup code here.(Do not load anything here, override init() instead)
- */
- function () {
- };
- State.prototype.update = /**
- * Put update logic here.
- */
- function () {
- };
- State.prototype.render = /**
- * Put render operations here.
- */
- function () {
- };
- State.prototype.paused = /**
- * This method will be called when game paused.
- */
- function () {
- };
- State.prototype.destroy = /**
- * This method will be called when the state is destroyed
- */
- function () {
- };
- return State;
- })();
- Phaser.State = State;
- /**
- * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
- * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
- * @param object1 The first GameObject or Group to check. If null the world.group is used.
- * @param object2 The second GameObject or Group to check.
- * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
- * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
- * @param context The context in which the callbacks will be called
- * @returns {boolean} true if the objects overlap, otherwise false.
- */
- //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
- // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
- //}
- })(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
/**
@@ -19514,206 +19502,6 @@ var Phaser;
Phaser.Line = Line;
})(Phaser || (Phaser = {}));
///
-/**
-* Phaser - IntersectResult
-*
-* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
-*/
-var Phaser;
-(function (Phaser) {
- var IntersectResult = (function () {
- function IntersectResult() {
- /**
- * Did they intersect or not?
- * @property result
- * @type {Boolean}
- */
- this.result = false;
- }
- IntersectResult.prototype.setTo = /**
- *
- * @method setTo
- * @param {Number} x1
- * @param {Number} y1
- * @param {Number} [x2]
- * @param {Number} [y2]
- * @param {Number} [width]
- * @param {Number} [height]
- */
- function (x1, y1, x2, y2, width, height) {
- if (typeof x2 === "undefined") { x2 = 0; }
- if (typeof y2 === "undefined") { y2 = 0; }
- if (typeof width === "undefined") { width = 0; }
- if (typeof height === "undefined") { height = 0; }
- this.x = x1;
- this.y = y1;
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- this.width = width;
- this.height = height;
- };
- return IntersectResult;
- })();
- Phaser.IntersectResult = IntersectResult;
-})(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 = {}));
-///
///
///
///
@@ -19877,6 +19665,161 @@ var Phaser;
Phaser.CircleUtils = CircleUtils;
})(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 = {}));
+///
///
///
///
@@ -19904,3 +19847,126 @@ var Phaser;
})();
Phaser.PixelUtils = PixelUtils;
})(Phaser || (Phaser = {}));
+///
+/**
+* Phaser - IntersectResult
+*
+* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
+*/
+var Phaser;
+(function (Phaser) {
+ var IntersectResult = (function () {
+ function IntersectResult() {
+ /**
+ * Did they intersect or not?
+ * @property result
+ * @type {Boolean}
+ */
+ this.result = false;
+ }
+ IntersectResult.prototype.setTo = /**
+ *
+ * @method setTo
+ * @param {Number} x1
+ * @param {Number} y1
+ * @param {Number} [x2]
+ * @param {Number} [y2]
+ * @param {Number} [width]
+ * @param {Number} [height]
+ */
+ function (x1, y1, x2, y2, width, height) {
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ this.x = x1;
+ this.y = y1;
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ this.width = width;
+ this.height = height;
+ };
+ return IntersectResult;
+ })();
+ Phaser.IntersectResult = IntersectResult;
+})(Phaser || (Phaser = {}));
+///
+/**
+* Phaser - State
+*
+* This is a base State class which can be extended if you are creating your game using TypeScript.
+*/
+var Phaser;
+(function (Phaser) {
+ var State = (function () {
+ /**
+ * State constructor
+ * Create a new State
.
+ */
+ function State(game) {
+ this.game = game;
+ this.add = game.add;
+ this.camera = game.camera;
+ this.cache = game.cache;
+ this.input = game.input;
+ this.load = game.load;
+ this.math = game.math;
+ this.motion = game.motion;
+ this.sound = game.sound;
+ this.stage = game.stage;
+ this.time = game.time;
+ this.tweens = game.tweens;
+ this.world = game.world;
+ }
+ State.prototype.init = // Override these in your own States
+ /**
+ * Override this method to add some load operations.
+ * If you need to use the loader, you may need to use them here.
+ */
+ function () {
+ };
+ State.prototype.create = /**
+ * This method is called after the game engine successfully switches states.
+ * Feel free to add any setup code here.(Do not load anything here, override init() instead)
+ */
+ function () {
+ };
+ State.prototype.update = /**
+ * Put update logic here.
+ */
+ function () {
+ };
+ State.prototype.render = /**
+ * Put render operations here.
+ */
+ function () {
+ };
+ State.prototype.paused = /**
+ * This method will be called when game paused.
+ */
+ function () {
+ };
+ State.prototype.destroy = /**
+ * This method will be called when the state is destroyed
+ */
+ function () {
+ };
+ return State;
+ })();
+ Phaser.State = State;
+ /**
+ * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
+ * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
+ * @param object1 The first GameObject or Group to check. If null the world.group is used.
+ * @param object2 The second GameObject or Group to check.
+ * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
+ * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
+ * @param context The context in which the callbacks will be called
+ * @returns {boolean} true if the objects overlap, otherwise false.
+ */
+ //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
+ // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
+ //}
+ })(Phaser || (Phaser = {}));
diff --git a/Tests/physics/simple test 1.js b/Tests/physics/simple test 1.js
index 44a660aaa..ca4c07360 100644
--- a/Tests/physics/simple test 1.js
+++ b/Tests/physics/simple test 1.js
@@ -1,6 +1,8 @@
+///
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
+ // Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('atari', 'assets/sprites/atari130xe.png');
game.load.image('ball', 'assets/sprites/shinyball.png');
game.load.start();
@@ -8,10 +10,21 @@
var atari;
var ball;
function create() {
+ // Add some gravity to the world, otherwise nothing will actually happen
game.physics.gravity.setTo(0, 5);
+ // We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces
atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC);
+ //atari.rotation = 10;
+ //atari.body.transform.setRotation(1);
+ atari.body.angle = 1;
+ // atari = 220px width (110 = center x)
+ // ball = 32px width (16 = center x)
+ // Ball will be a dynamic body and fall based on gravity
ball = game.add.physicsSprite(300 - 20, 0, 'ball');
- }
+ ball.body.angle = 1;
+ //ball.body.transform.setRotation(1);
+ //ball.body.fixedRotation = true;
+ }
function render() {
Phaser.DebugUtils.renderPhysicsBodyInfo(atari.body, 32, 32);
Phaser.DebugUtils.renderPhysicsBodyInfo(ball.body, 320, 32);
diff --git a/Tests/physics/simple test 1.ts b/Tests/physics/simple test 1.ts
index aef0b3413..a34964d3a 100644
--- a/Tests/physics/simple test 1.ts
+++ b/Tests/physics/simple test 1.ts
@@ -23,12 +23,18 @@
// We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces
atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC);
+ //atari.rotation = 10;
+ //atari.body.transform.setRotation(1);
+ atari.body.angle = 1;
// atari = 220px width (110 = center x)
// ball = 32px width (16 = center x)
// Ball will be a dynamic body and fall based on gravity
ball = game.add.physicsSprite(300-20, 0, 'ball');
+ ball.body.angle = 1;
+ //ball.body.transform.setRotation(1);
+ //ball.body.fixedRotation = true;
}
diff --git a/Tests/tilemaps/csv tilemap.js b/Tests/tilemaps/csv tilemap.js
new file mode 100644
index 000000000..3042fc47c
--- /dev/null
+++ b/Tests/tilemaps/csv tilemap.js
@@ -0,0 +1,32 @@
+///
+///
+(function () {
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+ function init() {
+ // CSV Tilemap Test
+ // First we load our map data (a csv file)
+ game.load.text('csvtest', 'assets/maps/catastrophi_level2.csv');
+ // Then we load the actual tile sheet image
+ game.load.image('csvtiles', 'assets/tiles/catastrophi_tiles_16.png');
+ game.load.start();
+ }
+ function create() {
+ // This creates the tilemap using the csv and tile sheet we loaded.
+ // We tell it use to CSV format parser. The 16x16 are the tile sizes.
+ // The 4th parameter (true) tells the game world to resize itself based on the map dimensions or not.
+ game.add.tilemap('csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, true, 16, 16);
+ }
+ function update() {
+ // Simple camera controls
+ 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;
+ }
+ }
+})();
diff --git a/Tests/tilemaps/csv tilemap.ts b/Tests/tilemaps/csv tilemap.ts
new file mode 100644
index 000000000..a0558dd4c
--- /dev/null
+++ b/Tests/tilemaps/csv tilemap.ts
@@ -0,0 +1,54 @@
+///
+///
+
+(function () {
+
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+
+ function init() {
+
+ // CSV Tilemap Test
+
+ // First we load our map data (a csv file)
+ game.load.text('csvtest', 'assets/maps/catastrophi_level2.csv');
+
+ // Then we load the actual tile sheet image
+ game.load.image('csvtiles', 'assets/tiles/catastrophi_tiles_16.png');
+
+ game.load.start();
+
+ }
+
+ function create() {
+
+ // This creates the tilemap using the csv and tile sheet we loaded.
+ // We tell it use to CSV format parser. The 16x16 are the tile sizes.
+ // The 4th parameter (true) tells the game world to resize itself based on the map dimensions or not.
+ game.add.tilemap('csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, true, 16, 16);
+
+ }
+
+ function update() {
+
+ // Simple camera controls
+ 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;
+ }
+
+ }
+
+})();
diff --git a/Tests/tilemaps/map draw.js b/Tests/tilemaps/map draw.js
new file mode 100644
index 000000000..55107d28d
--- /dev/null
+++ b/Tests/tilemaps/map draw.js
@@ -0,0 +1,41 @@
+///
+///
+(function () {
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+ function init() {
+ game.load.text('platform', 'assets/maps/mapdraw.json');
+ game.load.image('tiles', 'assets/tiles/platformer_tiles.png');
+ game.load.image('carrot', 'assets/sprites/carrot.png');
+ game.load.start();
+ }
+ var map;
+ var emitter;
+ var marker;
+ function create() {
+ map = game.add.tilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON);
+ map.setCollisionRange(21, 53);
+ map.setCollisionRange(105, 109);
+ game.camera.texture.opaque = true;
+ game.camera.texture.backgroundColor = 'rgb(47,154,204)';
+ marker = game.add.sprite(0, 0);
+ marker.texture.width = 16;
+ marker.texture.height = 16;
+ marker.texture.opaque = true;
+ marker.texture.backgroundColor = 'rgba(255,0,0,0.4)';
+ //emitter = game.add.emitter(32, 80);
+ //emitter.width = 700;
+ //emitter.makeParticles('carrot', 100, false, 1);
+ //emitter.gravity = 150;
+ //emitter.bounce = 0.8;
+ //emitter.start(false, 20, 0.05);
+ }
+ function update() {
+ // Collide everything with the map
+ //map.collide();
+ marker.x = game.math.snapToFloor(game.input.getWorldX(), 16);
+ marker.y = game.math.snapToFloor(game.input.getWorldY(), 16);
+ if(game.input.mousePointer.isDown) {
+ map.putTile(marker.x, marker.y, 32);
+ }
+ }
+})();
diff --git a/Tests/tilemaps/map draw.ts b/Tests/tilemaps/map draw.ts
new file mode 100644
index 000000000..5eae897d9
--- /dev/null
+++ b/Tests/tilemaps/map draw.ts
@@ -0,0 +1,60 @@
+///
+///
+
+(function () {
+
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+
+ function init() {
+
+ game.load.text('platform', 'assets/maps/mapdraw.json');
+ game.load.image('tiles', 'assets/tiles/platformer_tiles.png');
+ game.load.image('carrot', 'assets/sprites/carrot.png');
+
+ game.load.start();
+
+ }
+
+ var map: Phaser.Tilemap;
+ var emitter: Phaser.Emitter;
+ var marker: Phaser.Sprite;
+
+ function create() {
+
+ map = game.add.tilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON);
+ map.setCollisionRange(21,53);
+ map.setCollisionRange(105,109);
+
+ game.camera.texture.opaque = true;
+ game.camera.texture.backgroundColor = 'rgb(47,154,204)';
+
+ marker = game.add.sprite(0, 0);
+ marker.texture.width = 16;
+ marker.texture.height = 16;
+ marker.texture.opaque = true;
+ marker.texture.backgroundColor = 'rgba(255,0,0,0.4)';
+
+ //emitter = game.add.emitter(32, 80);
+ //emitter.width = 700;
+ //emitter.makeParticles('carrot', 100, false, 1);
+ //emitter.gravity = 150;
+ //emitter.bounce = 0.8;
+ //emitter.start(false, 20, 0.05);
+ }
+
+ function update() {
+
+ // Collide everything with the map
+ //map.collide();
+
+ marker.x = game.math.snapToFloor(game.input.getWorldX(), 16);
+ marker.y = game.math.snapToFloor(game.input.getWorldY(), 16);
+
+ if (game.input.mousePointer.isDown)
+ {
+ map.putTile(marker.x, marker.y, 32);
+ }
+
+ }
+
+})();
diff --git a/Tests/tilemaps/tiled layers.js b/Tests/tilemaps/tiled layers.js
new file mode 100644
index 000000000..42a8af614
--- /dev/null
+++ b/Tests/tilemaps/tiled layers.js
@@ -0,0 +1,34 @@
+///
+///
+(function () {
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+ function init() {
+ // Tiled Tilemap Test
+ // First we load our map data (a json file exported from the map editor Tiled)
+ // This data file has several layers within it. Phaser will render them all.
+ game.load.text('jsontest', 'assets/maps/multi-layer-test.json');
+ // Then we load the actual tile sheet image
+ game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png');
+ game.load.start();
+ }
+ var map;
+ function create() {
+ // This creates the tilemap using the json data and tile sheet we loaded.
+ // We tell it to use the Tiled JSON format parser.
+ map = game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
+ //map.currentLayer.
+ }
+ function update() {
+ // Simple camera controls
+ 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;
+ }
+ }
+})();
diff --git a/Tests/tilemaps/tiled layers.ts b/Tests/tilemaps/tiled layers.ts
new file mode 100644
index 000000000..4fb89db78
--- /dev/null
+++ b/Tests/tilemaps/tiled layers.ts
@@ -0,0 +1,58 @@
+///
+///
+
+(function () {
+
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+
+ function init() {
+
+ // Tiled Tilemap Test
+
+ // First we load our map data (a json file exported from the map editor Tiled)
+ // This data file has several layers within it. Phaser will render them all.
+ game.load.text('jsontest', 'assets/maps/multi-layer-test.json');
+
+ // Then we load the actual tile sheet image
+ game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png');
+
+ game.load.start();
+
+ }
+
+ var map: Phaser.Tilemap;
+
+ function create() {
+
+ // This creates the tilemap using the json data and tile sheet we loaded.
+ // We tell it to use the Tiled JSON format parser.
+ map = game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
+
+ //map.currentLayer.
+
+ }
+
+ function update() {
+
+ // Simple camera controls
+ 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;
+ }
+
+ }
+
+})();
diff --git a/Tests/tilemaps/tiled tilemap.js b/Tests/tilemaps/tiled tilemap.js
new file mode 100644
index 000000000..55447fbe9
--- /dev/null
+++ b/Tests/tilemaps/tiled tilemap.js
@@ -0,0 +1,32 @@
+///
+///
+(function () {
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+ function init() {
+ // Tiled Tilemap Test
+ // First we load our map data (a json file exported from the map editor Tiled)
+ game.load.text('jsontest', 'assets/maps/test.json');
+ //myGame.loader.addTextFile('jsontest', 'assets/maps/multi-layer-test.json');
+ // Then we load the actual tile sheet image
+ game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png');
+ game.load.start();
+ }
+ function create() {
+ // This creates the tilemap using the json data and tile sheet we loaded.
+ // We tell it to use the Tiled JSON format parser.
+ game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
+ }
+ function update() {
+ // Simple camera controls
+ 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;
+ }
+ }
+})();
diff --git a/Tests/tilemaps/tiled tilemap.ts b/Tests/tilemaps/tiled tilemap.ts
new file mode 100644
index 000000000..749eb47f1
--- /dev/null
+++ b/Tests/tilemaps/tiled tilemap.ts
@@ -0,0 +1,54 @@
+///
+///
+
+(function () {
+
+ var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
+
+ function init() {
+
+ // Tiled Tilemap Test
+
+ // First we load our map data (a json file exported from the map editor Tiled)
+ game.load.text('jsontest', 'assets/maps/test.json');
+ //myGame.loader.addTextFile('jsontest', 'assets/maps/multi-layer-test.json');
+
+ // Then we load the actual tile sheet image
+ game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png');
+
+ game.load.start();
+
+ }
+
+ function create() {
+
+ // This creates the tilemap using the json data and tile sheet we loaded.
+ // We tell it to use the Tiled JSON format parser.
+ game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON);
+
+ }
+
+ function update() {
+
+ // Simple camera controls
+ 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;
+ }
+
+ }
+
+})();
diff --git a/build/phaser.d.ts b/build/phaser.d.ts
index ca8759253..2db10b2e8 100644
--- a/build/phaser.d.ts
+++ b/build/phaser.d.ts
@@ -240,6 +240,10 @@ module Phaser {
*/
group: Group;
/**
+ * The name of the Game Object. Typically not set by Phaser, but extremely useful for debugging / logic.
+ */
+ name: string;
+ /**
* x value of the object.
*/
x: number;
@@ -2335,6 +2339,14 @@ module Phaser.Components.Sprite {
* Dispatched by the Input component when a pointer is released over an Input enabled sprite
*/
public onInputUp: Signal;
+ /**
+ * Dispatched by the Input component when the Sprite starts being dragged
+ */
+ public onDragStart: Signal;
+ /**
+ * Dispatched by the Input component when the Sprite stops being dragged
+ */
+ public onDragStop: Signal;
public onOutOfBounds: Signal;
}
}
@@ -3049,8 +3061,8 @@ module Phaser.Physics.Shapes {
module Phaser.Physics {
class Body {
constructor(sprite: Sprite, type: number, x?: number, y?: number, shapeType?: number);
- public toString(): string;
private _tempVec2;
+ private _fixedRotation;
/**
* Reference to Phaser.Game
*/
@@ -3076,7 +3088,18 @@ module Phaser.Physics {
* @type {number}
*/
public type: number;
+ /**
+ * The angle of the body in radians. Used by all of the internal physics methods.
+ */
public angle: number;
+ /**
+ * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ */
+ /**
+ * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ * The value is automatically wrapped to be between 0 and 360.
+ */
+ public rotation : number;
public transform: Transform;
public centroid: Vec2;
public position: Vec2;
@@ -3098,7 +3121,6 @@ module Phaser.Physics {
public massInverted: number;
public inertia: number;
public inertiaInverted: number;
- public fixedRotation: bool;
public categoryBits: number;
public maskBits: number;
public stepCount: number;
@@ -3117,13 +3139,13 @@ module Phaser.Physics {
public removeShape(shape): void;
private setMass(mass);
private setInertia(inertia);
- public setTransform(pos, angle): void;
+ public setTransform(pos: Vec2, angle: number): void;
public syncTransform(): void;
public getWorldPoint(p: Vec2): Vec2;
public getWorldVector(v: Vec2): Vec2;
public getLocalPoint(p: Vec2): Vec2;
public getLocalVector(v: Vec2): Vec2;
- public setFixedRotation(flag): void;
+ public fixedRotation : bool;
public resetMassData(): void;
public resetJointAnchors(): void;
public cacheData(source?: string): void;
@@ -3141,6 +3163,7 @@ module Phaser.Physics {
public isAwake : bool;
public awake(flag): void;
public isCollidable(other: Body): bool;
+ public toString(): string;
}
}
/**
@@ -3155,7 +3178,7 @@ module Phaser {
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
- * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
+ * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics)
* @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape)
*/
constructor(game: Game, x?: number, y?: number, key?: string, frame?, bodyType?: number, shapeType?: number);
@@ -3168,6 +3191,10 @@ module Phaser {
*/
public type: number;
/**
+ * The name of game object.
+ */
+ public name: string;
+ /**
* The Group this Sprite belongs to.
*/
public group: Group;
@@ -3486,6 +3513,11 @@ module Phaser.Components {
*/
public renderRotation: bool;
/**
+ * The direction the animation frame is facing (can be Phaser.Types.RIGHT, LEFT, UP, DOWN).
+ * Very useful when hooking animation to Sprite directions.
+ */
+ public facing: number;
+ /**
* Flip the graphic horizontally (defaults to false)
* @type {boolean}
*/
@@ -5661,6 +5693,7 @@ module Phaser {
public to(properties, duration?: number, ease?: any, autoStart?: bool, delay?: number, loop?: bool, yoyo?: bool): Tween;
public loop(value: bool): Tween;
public yoyo(value: bool): Tween;
+ public isRunning: bool;
/**
* Start to tween.
*/
@@ -6065,31 +6098,6 @@ module Phaser {
* @param tileHeight {number} Height of tiles in this map.
*/
constructor(game: Game, parent: Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number);
- /**
- * Local private reference to game.
- */
- private _game;
- /**
- * The tilemap that contains this layer.
- * @type {Tilemap}
- */
- private _parent;
- /**
- * Tileset of this layer.
- */
- private _texture;
- private _tileOffsets;
- private _startX;
- private _startY;
- private _maxX;
- private _maxY;
- private _tx;
- private _ty;
- private _dx;
- private _dy;
- private _oldCameraX;
- private _oldCameraY;
- private _columnData;
private _tempTileX;
private _tempTileY;
private _tempTileW;
@@ -6097,26 +6105,33 @@ module Phaser {
private _tempTileBlock;
private _tempBlockResults;
/**
+ * Local private reference to game.
+ */
+ public game: Game;
+ /**
+ * The tilemap that contains this layer.
+ * @type {Tilemap}
+ */
+ public parent: Tilemap;
+ /**
+ * The texture used to render the Sprite.
+ */
+ public texture: Components.Texture;
+ /**
+ * The Sprite transform component.
+ */
+ public transform: Components.Transform;
+ public tileOffsets;
+ /**
+ * The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
+ */
+ public alpha: number;
+ /**
* Name of this layer, so you can get this layer by its name.
* @type {string}
*/
public name: string;
/**
- * A reference to the Canvas this GameObject will render to
- * @type {HTMLCanvasElement}
- */
- public canvas: HTMLCanvasElement;
- /**
- * A reference to the Canvas Context2D this GameObject will render to
- * @type {CanvasRenderingContext2D}
- */
- public context: CanvasRenderingContext2D;
- /**
- * Opacity of this layer.
- * @type {number}
- */
- public alpha: number;
- /**
* Controls whether update() and draw() are automatically called.
* @type {boolean}
*/
@@ -6127,10 +6142,6 @@ module Phaser {
*/
public visible: bool;
/**
- * @type {string}
- */
- public orientation: string;
- /**
* Properties of this map layer. (normally set by map editors)
*/
public properties: {};
@@ -6282,18 +6293,9 @@ module Phaser {
public updateBounds(): void;
/**
* Parse tile offsets from map data.
- * @return {number} length of _tileOffsets array.
+ * @return {number} length of tileOffsets array.
*/
public parseTileOffsets(): number;
- public renderDebugInfo(x: number, y: number, color?: string): void;
- /**
- * Render this layer to a specific camera with offset to camera.
- * @param camera {Camera} The camera the layer is going to be rendered.
- * @param dx {number} X offset to the camera.
- * @param dy {number} Y offset to the camera.
- * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed.
- */
- public render(camera: Camera, dx, dy): bool;
}
}
/**
@@ -6439,6 +6441,14 @@ module Phaser {
*/
public type: number;
/**
+ * The name of game object.
+ */
+ public name: string;
+ /**
+ * The Group this Sprite belongs to.
+ */
+ public group: Group;
+ /**
* Controls if both update
and render are called by the core game loop.
*/
public exists: bool;
@@ -6451,10 +6461,26 @@ module Phaser {
*/
public visible: bool;
/**
- *
+ * A useful state for many game objects. Kill and revive both flip this switch.
*/
public alive: bool;
/**
+ * The texture used to render the Sprite.
+ */
+ public texture: Components.Texture;
+ /**
+ * The Sprite transform component.
+ */
+ public transform: Components.Transform;
+ /**
+ * z order value of the object.
+ */
+ public z: number;
+ /**
+ * Render iteration counter
+ */
+ public renderOrderID: number;
+ /**
* Tilemap data format enum: CSV.
* @type {number}
*/
@@ -6499,21 +6525,11 @@ module Phaser {
*/
public mapFormat: number;
/**
- * An Array of Cameras to which this GameObject won't render
- * @type {Array}
- */
- public cameraBlacklist: number[];
- /**
- * Inherited update method.
+ * Inherited methods for overriding.
*/
+ public preUpdate(): void;
public update(): void;
- /**
- * Render this tilemap to a specific camera with specific offset.
- * @param camera {Camera} The camera this tilemap will be rendered to.
- * @param cameraOffsetX {number} X offset of the camera.
- * @param cameraOffsetY {number} Y offset of the camera.
- */
- public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): void;
+ public postUpdate(): void;
/**
* Parset csv map data and generate tiles.
* @param data {string} CSV map data.
@@ -8122,6 +8138,118 @@ module Phaser {
* TODO: interpolate & polar
*/
module Phaser {
+ class PointUtils {
+ /**
+ * Adds the coordinates of two points together to create a new point.
+ * @method add
+ * @param {Point} a - The first Point object.
+ * @param {Point} b - The second Point object.
+ * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Point} The new Point object.
+ **/
+ static add(a: Point, b: Point, out?: Point): Point;
+ /**
+ * Subtracts the coordinates of two points to create a new point.
+ * @method subtract
+ * @param {Point} a - The first Point object.
+ * @param {Point} b - The second Point object.
+ * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Point} The new Point object.
+ **/
+ static subtract(a: Point, b: Point, out?: Point): Point;
+ /**
+ * Multiplies the coordinates of two points to create a new point.
+ * @method subtract
+ * @param {Point} a - The first Point object.
+ * @param {Point} b - The second Point object.
+ * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Point} The new Point object.
+ **/
+ static multiply(a: Point, b: Point, out?: Point): Point;
+ /**
+ * Divides the coordinates of two points to create a new point.
+ * @method subtract
+ * @param {Point} a - The first Point object.
+ * @param {Point} b - The second Point object.
+ * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Point} The new Point object.
+ **/
+ static divide(a: Point, b: Point, out?: Point): Point;
+ /**
+ * Clamps the Point object values to be between the given min and max
+ * @method clamp
+ * @param {Point} a - The point.
+ * @param {number} The minimum value to clamp this Point to
+ * @param {number} The maximum value to clamp this Point to
+ * @return {Point} This Point object.
+ **/
+ static clamp(a: Point, min: number, max: number): Point;
+ /**
+ * Clamps the x value of the given Point object to be between the min and max values.
+ * @method clampX
+ * @param {Point} a - The point.
+ * @param {number} The minimum value to clamp this Point to
+ * @param {number} The maximum value to clamp this Point to
+ * @return {Point} This Point object.
+ **/
+ static clampX(a: Point, min: number, max: number): Point;
+ /**
+ * Clamps the y value of the given Point object to be between the min and max values.
+ * @method clampY
+ * @param {Point} a - The point.
+ * @param {number} The minimum value to clamp this Point to
+ * @param {number} The maximum value to clamp this Point to
+ * @return {Point} This Point object.
+ **/
+ static clampY(a: Point, min: number, max: number): Point;
+ /**
+ * Creates a copy of the given Point.
+ * @method clone
+ * @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
+ * @return {Point} The new Point object.
+ **/
+ static clone(a: Point, output?: Point): Point;
+ /**
+ * Returns the distance between the two given Point objects.
+ * @method distanceBetween
+ * @param {Point} a - The first Point object.
+ * @param {Point} b - The second Point object.
+ * @param {Boolean} round - Round the distance to the nearest integer (default false)
+ * @return {Number} The distance between the two Point objects.
+ **/
+ static distanceBetween(a: Point, b: Point, round?: bool): number;
+ /**
+ * Determines whether the two given Point objects are equal. They are considered equal if they have the same x and y values.
+ * @method equals
+ * @param {Point} a - The first Point object.
+ * @param {Point} b - The second Point object.
+ * @return {Boolean} A value of true if the Points are equal, otherwise false.
+ **/
+ static equals(a: Point, b: Point): bool;
+ /**
+ * Rotates a Point around the x/y coordinates given to the desired angle.
+ * @param a {Point} The Point object to rotate.
+ * @param x {number} The x coordinate of the anchor point
+ * @param y {number} The y coordinate of the anchor point
+ * @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to.
+ * @param {Boolean} asDegrees Is the given rotation in radians (false) or degrees (true)?
+ * @param {Number} distance An optional distance constraint between the Point and the anchor.
+ * @return The modified point object
+ */
+ static rotate(a: Point, x: number, y: number, angle: number, asDegrees?: bool, distance?: number): Point;
+ /**
+ * Rotates a Point around the given Point to the desired angle.
+ * @param a {Point} The Point object to rotate.
+ * @param b {Point} The Point object to serve as point of rotation.
+ * @param x {number} The x coordinate of the anchor point
+ * @param y {number} The y coordinate of the anchor point
+ * @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to.
+ * @param {Boolean} asDegrees Is the given rotation in radians (false) or degrees (true)?
+ * @param {Number} distance An optional distance constraint between the Point and the anchor.
+ * @return The modified point object
+ */
+ static rotateAroundPoint(a: Point, b: Point, angle: number, asDegrees?: bool, distance?: number): Point;
+ }
}
/**
* Phaser - Pointer
@@ -9246,8 +9374,15 @@ module Phaser {
private _dh;
private _fx;
private _fy;
+ private _tx;
+ private _ty;
private _sin;
private _cos;
+ private _maxX;
+ private _maxY;
+ private _startX;
+ private _startY;
+ private _columnData;
private _cameraList;
private _camera;
private _groupLength;
@@ -9279,6 +9414,11 @@ module Phaser {
*/
public renderSprite(camera: Camera, sprite: Sprite): bool;
public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool;
+ /**
+ * Render a tilemap to a specific camera.
+ * @param camera {Camera} The camera this tilemap will be rendered to.
+ */
+ public renderTilemap(camera: Camera, tilemap: Tilemap): bool;
}
}
/**
@@ -9309,6 +9449,7 @@ module Phaser {
*/
static renderPhysicsBodyInfo(body: Physics.Body, x: number, y: number, color?: string): void;
static renderSpriteBounds(sprite: Sprite, camera?: Camera, color?: string): void;
+ static renderRectangle(rect: Rectangle, fillStyle?: string): void;
static renderPhysicsBody(body: Physics.Body, lineWidth?: number, fillStyle?: string, sleepStyle?: string): void;
}
}
@@ -9551,110 +9692,6 @@ module Phaser {
}
}
/**
-* Phaser - State
-*
-* This is a base State class which can be extended if you are creating your game using TypeScript.
-*/
-module Phaser {
- class State {
- /**
- * State constructor
- * Create a new State
.
- */
- constructor(game: Game);
- /**
- * Reference to Game.
- */
- public game: Game;
- /**
- * Currently used camera.
- * @type {Camera}
- */
- public camera: Camera;
- /**
- * Reference to the assets cache.
- * @type {Cache}
- */
- public cache: Cache;
- /**
- * Reference to the GameObject Factory.
- * @type {GameObjectFactory}
- */
- public add: GameObjectFactory;
- /**
- * Reference to the input manager
- * @type {Input}
- */
- public input: Input;
- /**
- * Reference to the assets loader.
- * @type {Loader}
- */
- public load: Loader;
- /**
- * Reference to the math helper.
- * @type {GameMath}
- */
- public math: GameMath;
- /**
- * Reference to the motion helper.
- * @type {Motion}
- */
- public motion: Motion;
- /**
- * Reference to the sound manager.
- * @type {SoundManager}
- */
- public sound: SoundManager;
- /**
- * Reference to the stage.
- * @type {Stage}
- */
- public stage: Stage;
- /**
- * Reference to game clock.
- * @type {Time}
- */
- public time: Time;
- /**
- * Reference to the tween manager.
- * @type {TweenManager}
- */
- public tweens: TweenManager;
- /**
- * Reference to the world.
- * @type {World}
- */
- public world: World;
- /**
- * Override this method to add some load operations.
- * If you need to use the loader, you may need to use them here.
- */
- public init(): void;
- /**
- * This method is called after the game engine successfully switches states.
- * Feel free to add any setup code here.(Do not load anything here, override init() instead)
- */
- public create(): void;
- /**
- * Put update logic here.
- */
- public update(): void;
- /**
- * Put render operations here.
- */
- public render(): void;
- /**
- * This method will be called when game paused.
- */
- public paused(): void;
- /**
- * This method will be called when the state is destroyed
- */
- public destroy(): void;
- }
-}
-/**
* Phaser - Components - Debug
*
*
@@ -9835,104 +9872,6 @@ module Phaser {
}
}
/**
-* Phaser - IntersectResult
-*
-* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
-*/
-module Phaser {
- class IntersectResult {
- /**
- * Did they intersect or not?
- * @property result
- * @type {Boolean}
- */
- public result: bool;
- /**
- * @property x
- * @type {Number}
- */
- public x: number;
- /**
- * @property y
- * @type {Number}
- */
- public y: number;
- /**
- * @property x1
- * @type {Number}
- */
- public x1: number;
- /**
- * @property y1
- * @type {Number}
- */
- public y1: number;
- /**
- * @property x2
- * @type {Number}
- */
- public x2: number;
- /**
- * @property y2
- * @type {Number}
- */
- public y2: number;
- /**
- * @property width
- * @type {Number}
- */
- public width: number;
- /**
- * @property height
- * @type {Number}
- */
- public height: number;
- /**
- *
- * @method setTo
- * @param {Number} x1
- * @param {Number} y1
- * @param {Number} [x2]
- * @param {Number} [y2]
- * @param {Number} [width]
- * @param {Number} [height]
- */
- public setTo(x1: number, y1: number, x2?: number, y2?: number, width?: number, height?: number): void;
- }
-}
-/**
-* 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 - CircleUtils
*
* A collection of methods useful for manipulating and comparing Circle objects.
@@ -10016,6 +9955,38 @@ 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.
@@ -10036,3 +10007,173 @@ module Phaser {
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.
+*/
+module Phaser {
+ class IntersectResult {
+ /**
+ * Did they intersect or not?
+ * @property result
+ * @type {Boolean}
+ */
+ public result: bool;
+ /**
+ * @property x
+ * @type {Number}
+ */
+ public x: number;
+ /**
+ * @property y
+ * @type {Number}
+ */
+ public y: number;
+ /**
+ * @property x1
+ * @type {Number}
+ */
+ public x1: number;
+ /**
+ * @property y1
+ * @type {Number}
+ */
+ public y1: number;
+ /**
+ * @property x2
+ * @type {Number}
+ */
+ public x2: number;
+ /**
+ * @property y2
+ * @type {Number}
+ */
+ public y2: number;
+ /**
+ * @property width
+ * @type {Number}
+ */
+ public width: number;
+ /**
+ * @property height
+ * @type {Number}
+ */
+ public height: number;
+ /**
+ *
+ * @method setTo
+ * @param {Number} x1
+ * @param {Number} y1
+ * @param {Number} [x2]
+ * @param {Number} [y2]
+ * @param {Number} [width]
+ * @param {Number} [height]
+ */
+ public setTo(x1: number, y1: number, x2?: number, y2?: number, width?: number, height?: number): void;
+ }
+}
+/**
+* Phaser - State
+*
+* This is a base State class which can be extended if you are creating your game using TypeScript.
+*/
+module Phaser {
+ class State {
+ /**
+ * State constructor
+ * Create a new State
.
+ */
+ constructor(game: Game);
+ /**
+ * Reference to Game.
+ */
+ public game: Game;
+ /**
+ * Currently used camera.
+ * @type {Camera}
+ */
+ public camera: Camera;
+ /**
+ * Reference to the assets cache.
+ * @type {Cache}
+ */
+ public cache: Cache;
+ /**
+ * Reference to the GameObject Factory.
+ * @type {GameObjectFactory}
+ */
+ public add: GameObjectFactory;
+ /**
+ * Reference to the input manager
+ * @type {Input}
+ */
+ public input: Input;
+ /**
+ * Reference to the assets loader.
+ * @type {Loader}
+ */
+ public load: Loader;
+ /**
+ * Reference to the math helper.
+ * @type {GameMath}
+ */
+ public math: GameMath;
+ /**
+ * Reference to the motion helper.
+ * @type {Motion}
+ */
+ public motion: Motion;
+ /**
+ * Reference to the sound manager.
+ * @type {SoundManager}
+ */
+ public sound: SoundManager;
+ /**
+ * Reference to the stage.
+ * @type {Stage}
+ */
+ public stage: Stage;
+ /**
+ * Reference to game clock.
+ * @type {Time}
+ */
+ public time: Time;
+ /**
+ * Reference to the tween manager.
+ * @type {TweenManager}
+ */
+ public tweens: TweenManager;
+ /**
+ * Reference to the world.
+ * @type {World}
+ */
+ public world: World;
+ /**
+ * Override this method to add some load operations.
+ * If you need to use the loader, you may need to use them here.
+ */
+ public init(): void;
+ /**
+ * This method is called after the game engine successfully switches states.
+ * Feel free to add any setup code here.(Do not load anything here, override init() instead)
+ */
+ public create(): void;
+ /**
+ * Put update logic here.
+ */
+ public update(): void;
+ /**
+ * Put render operations here.
+ */
+ public render(): void;
+ /**
+ * This method will be called when game paused.
+ */
+ public paused(): void;
+ /**
+ * This method will be called when the state is destroyed
+ */
+ public destroy(): void;
+ }
+}
diff --git a/build/phaser.js b/build/phaser.js
index 0df38b194..f5d4f68ff 100644
--- a/build/phaser.js
+++ b/build/phaser.js
@@ -3787,6 +3787,7 @@ var Phaser;
if(this.bringToTop) {
this.sprite.group.bringToTop(this.sprite);
}
+ this.sprite.events.onDragStart.dispatch(this.sprite, pointer);
};
Input.prototype.stopDrag = /**
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
@@ -3799,8 +3800,8 @@ var Phaser;
this.sprite.x = Math.floor(this.sprite.x / this.snapX) * this.snapX;
this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY;
}
- //pointer.draggedObject = null;
- };
+ this.sprite.events.onDragStop.dispatch(this.sprite, pointer);
+ };
Input.prototype.setDragLock = /**
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
*
@@ -3913,10 +3914,13 @@ var Phaser;
this.onRemovedFromGroup = new Phaser.Signal();
this.onKilled = new Phaser.Signal();
this.onRevived = new Phaser.Signal();
+ // Only create these if Sprite input is enabled?
this.onInputOver = new Phaser.Signal();
this.onInputOut = new Phaser.Signal();
this.onInputDown = new Phaser.Signal();
this.onInputUp = new Phaser.Signal();
+ this.onDragStart = new Phaser.Signal();
+ this.onDragStop = new Phaser.Signal();
}
return Events;
})();
@@ -5158,9 +5162,7 @@ var Phaser;
var r2 = new Phaser.Vec2();
// Transformed r1, r2
Phaser.Vec2Utils.rotate(con.r1_local, body1.angle, r1);
- //var r1 = vec2.rotate(con.r1_local, body1.a);
Phaser.Vec2Utils.rotate(con.r2_local, body2.angle, r2);
- //var r2 = vec2.rotate(con.r2_local, body2.a);
Physics.Manager.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle);
Physics.Manager.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y);
Physics.Manager.write('r2_local.x = ' + con.r2_local.x + ' r2_local.y = ' + con.r2_local.y + ' angle: ' + body2.angle);
@@ -5169,15 +5171,12 @@ var Phaser;
var p1 = new Phaser.Vec2();
var p2 = new Phaser.Vec2();
Phaser.Vec2Utils.add(body1.position, r1, p1);
- //var p1 = vec2.add(body1.p, r1);
Phaser.Vec2Utils.add(body2.position, r2, p2);
- //var p2 = vec2.add(body2.p, r2);
Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
// Corrected delta vector
var dp = new Phaser.Vec2();
Phaser.Vec2Utils.subtract(p2, p1, dp);
- //var dp = vec2.sub(p2, p1);
// Position constraint
var c = Phaser.Vec2Utils.dot(dp, n) + con.depth;
var correction = this.clamp(Physics.Manager.CONTACT_SOLVER_BAUMGARTE * (c + Physics.Manager.CONTACT_SOLVER_COLLISION_SLOP), -Physics.Manager.CONTACT_SOLVER_MAX_LINEAR_CORRECTION, 0);
@@ -5195,12 +5194,9 @@ var Phaser;
// Apply correction impulses
var impulse_dt = new Phaser.Vec2();
Phaser.Vec2Utils.scale(n, lambda_dt, impulse_dt);
- //var impulse_dt = vec2.scale(n, lambda_dt);
body1.position.multiplyAddByScalar(impulse_dt, -m1_inv);
- //body1.p.mad(impulse_dt, -m1_inv);
body1.angle -= sn1 * lambda_dt * i1_inv;
body2.position.multiplyAddByScalar(impulse_dt, m2_inv);
- //body2.p.mad(impulse_dt, m2_inv);
body2.angle += sn2 * lambda_dt * i2_inv;
Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
@@ -6664,13 +6660,13 @@ var Phaser;
if (typeof y === "undefined") { y = 0; }
if (typeof shapeType === "undefined") { shapeType = 0; }
this._tempVec2 = new Phaser.Vec2();
+ this._fixedRotation = false;
// Shapes
this.shapes = [];
// Joints
this.joints = [];
this.jointHash = {
};
- this.fixedRotation = false;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
@@ -6681,7 +6677,7 @@ var Phaser;
this.sprite = sprite;
this.game = sprite.game;
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Manager.pixelsToMeters(sprite.y));
- this.angle = sprite.rotation;
+ this.angle = this.game.math.degreesToRadians(sprite.rotation);
} else {
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(x), Phaser.Physics.Manager.pixelsToMeters(y));
this.angle = 0;
@@ -6702,7 +6698,6 @@ var Phaser;
};
this.bounds = new Physics.Bounds();
this.allowCollisions = Phaser.Types.ANY;
- this.fixedRotation = false;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
@@ -6714,12 +6709,26 @@ var Phaser;
}
}
}
- Body.prototype.toString = function () {
- return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
- };
+ Object.defineProperty(Body.prototype, "rotation", {
+ get: /**
+ * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ */
+ function () {
+ return this.game.math.radiansToDegrees(this.angle);
+ },
+ set: /**
+ * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ * The value is automatically wrapped to be between 0 and 360.
+ */
+ function (value) {
+ this.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
+ },
+ enumerable: true,
+ configurable: true
+ });
Body.prototype.duplicate = function () {
console.log('body duplicate called');
- //var body = new Body(this.type, this.transform.t, this.angle);
+ //var body = new Body(this.type, this.transform.t, this.rotation);
//for (var i = 0; i < this.shapes.length; i++)
//{
// body.addShape(this.shapes[i].duplicate());
@@ -6842,26 +6851,26 @@ var Phaser;
Body.prototype.setTransform = function (pos, angle) {
// inject the transform into this.position
this.transform.setTo(pos, angle);
- Physics.Manager.write('setTransform: ' + this.position.toString());
- Physics.Manager.write('centroid: ' + this.centroid.toString());
+ //Manager.write('setTransform: ' + this.position.toString());
+ //Manager.write('centroid: ' + this.centroid.toString());
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
- Physics.Manager.write('post setTransform: ' + this.position.toString());
+ //Manager.write('post setTransform: ' + this.position.toString());
//this.position.copyFrom(this.transform.transform(this.centroid));
this.angle = angle;
};
Body.prototype.syncTransform = function () {
- Physics.Manager.write('syncTransform:');
- Physics.Manager.write('p: ' + this.position.toString());
- Physics.Manager.write('centroid: ' + this.centroid.toString());
- Physics.Manager.write('xf: ' + this.transform.toString());
- Physics.Manager.write('a: ' + this.angle);
+ //Manager.write('syncTransform:');
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('centroid: ' + this.centroid.toString());
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('a: ' + this.angle);
this.transform.setRotation(this.angle);
// OPTIMISE: Creating new vector
Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t);
- Physics.Manager.write('--------------------');
- Physics.Manager.write('xf: ' + this.transform.toString());
- Physics.Manager.write('--------------------');
- };
+ //Manager.write('--------------------');
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('--------------------');
+ };
Body.prototype.getWorldPoint = function (p) {
// OPTIMISE: Creating new vector
return Phaser.TransformUtils.transform(this.transform, p);
@@ -6878,10 +6887,17 @@ var Phaser;
// OPTIMISE: Creating new vector
return Phaser.TransformUtils.unrotate(this.transform, v);
};
- Body.prototype.setFixedRotation = function (flag) {
- this.fixedRotation = flag;
- this.resetMassData();
- };
+ Object.defineProperty(Body.prototype, "fixedRotation", {
+ get: function () {
+ return this._fixedRotation;
+ },
+ set: function (value) {
+ this._fixedRotation = value;
+ this.resetMassData();
+ },
+ enumerable: true,
+ configurable: true
+ });
Body.prototype.resetMassData = function () {
this.centroid.setTo(0, 0);
this.mass = 0;
@@ -6890,7 +6906,6 @@ var Phaser;
this.inertiaInverted = 0;
if(this.isDynamic == false) {
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
- //this.position.copyFrom(this.transform.transform(this.centroid));
return;
}
var totalMassCentroid = new Phaser.Vec2(0, 0);
@@ -6901,12 +6916,10 @@ var Phaser;
var centroid = shape.centroid();
var mass = shape.area() * shape.density;
var inertia = shape.inertia(mass);
- //console.log('rmd', centroid, shape);
totalMassCentroid.multiplyAddByScalar(centroid, mass);
totalMass += mass;
totalInertia += inertia;
}
- //this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass));
Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid);
this.setMass(totalMass);
if(!this.fixedRotation) {
@@ -6933,20 +6946,20 @@ var Phaser;
};
Body.prototype.cacheData = function (source) {
if (typeof source === "undefined") { source = ''; }
- Physics.Manager.write('cacheData -- start');
- Physics.Manager.write('p: ' + this.position.toString());
- Physics.Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('cacheData -- start');
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('xf: ' + this.transform.toString());
this.bounds.clear();
for(var i = 0; i < this.shapesLength; i++) {
var shape = this.shapes[i];
shape.cacheData(this.transform);
this.bounds.addBounds(shape.bounds);
}
- Physics.Manager.write('bounds: ' + this.bounds.toString());
- Physics.Manager.write('p: ' + this.position.toString());
- Physics.Manager.write('xf: ' + this.transform.toString());
- Physics.Manager.write('cacheData -- stop');
- };
+ //Manager.write('bounds: ' + this.bounds.toString());
+ //Manager.write('p: ' + this.position.toString());
+ //Manager.write('xf: ' + this.transform.toString());
+ //Manager.write('cacheData -- stop');
+ };
Body.prototype.updateVelocity = function (gravity, dt, damping) {
Phaser.Vec2Utils.multiplyAdd(gravity, this.force, this.massInverted, this._tempVec2);
Phaser.Vec2Utils.multiplyAdd(this.velocity, this._tempVec2, dt, this.velocity);
@@ -6987,8 +7000,7 @@ var Phaser;
if(this.sprite) {
this.sprite.x = this.position.x * 50;
this.sprite.y = this.position.y * 50;
- // Obey fixed rotation?
- this.sprite.rotation = this.game.math.radiansToDegrees(this.angle);
+ this.sprite.transform.rotation = this.game.math.radiansToDegrees(this.angle);
}
};
Body.prototype.resetForce = function () {
@@ -7045,9 +7057,7 @@ var Phaser;
this.angularVelocity += impulse * this.inertiaInverted;
};
Body.prototype.kineticEnergy = function () {
- var vsq = this.velocity.dot(this.velocity);
- var wsq = this.angularVelocity * this.angularVelocity;
- return 0.5 * (this.mass * vsq + this.inertia * wsq);
+ return 0.5 * (this.mass * this.velocity.dot(this.velocity) + this.inertia * (this.angularVelocity * this.angularVelocity));
};
Object.defineProperty(Body.prototype, "isAwake", {
get: function () {
@@ -7068,10 +7078,7 @@ var Phaser;
}
};
Body.prototype.isCollidable = function (other) {
- if(this == other) {
- return false;
- }
- if(this.isDynamic == false && other.isDynamic == false) {
+ if((this.isDynamic == false && other.isDynamic == false) || this == other) {
return false;
}
if(!(this.maskBits & other.categoryBits) || !(other.maskBits & this.categoryBits)) {
@@ -7085,6 +7092,9 @@ var Phaser;
}
return true;
};
+ Body.prototype.toString = function () {
+ return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
+ };
return Body;
})();
Physics.Body = Body;
@@ -7113,7 +7123,7 @@ var Phaser;
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
- * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
+ * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics)
* @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape)
*/
function Sprite(game, x, y, key, frame, bodyType, shapeType) {
@@ -7142,7 +7152,7 @@ var Phaser;
/**
* z order value of the object.
*/
- this.z = 0;
+ this.z = -1;
/**
* Render iteration counter
*/
@@ -7157,6 +7167,7 @@ var Phaser;
this.y = y;
this.z = -1;
this.group = null;
+ this.name = '';
this.animations = new Phaser.Components.AnimationManager(this);
this.input = new Phaser.Components.Sprite.Input(this);
this.events = new Phaser.Components.Sprite.Events(this);
@@ -7200,6 +7211,9 @@ var Phaser;
*/
function (value) {
this.transform.rotation = this.game.math.wrap(value, 360, 0);
+ if(this.body) {
+ this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
+ }
},
enumerable: true,
configurable: true
@@ -8185,29 +8199,70 @@ var Phaser;
return true;
};
Group.prototype.bringToTop = function (child) {
+ //console.log('bringToTop', child.name,'current z', child.z);
+ var oldZ = child.z;
// If child not in this group, or is already at the top of the group, return false
- if(!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) {
+ //if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter)
+ if(!child || child.group == null || child.group.ID != this.ID) {
+ //console.log('If child not in this group, or is already at the top of the group, return false');
return false;
}
- this.sort();
- // What's the z index of the top most child?
- var childIndex = this._zCounter;
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member) {
- if(this._i > childIndex) {
- this._member.z--;
- } else if(this._member.z == child.z) {
- childIndex = this._i;
- this._member.z = this._zCounter;
- }
+ // Find out the largest z index
+ var topZ = -1;
+ for(var i = 0; i < this.length; i++) {
+ if(this.members[i] && this.members[i].z > topZ) {
+ topZ = this.members[i].z;
}
}
+ // Child is already at the top
+ if(child.z == topZ) {
+ return false;
+ }
+ child.z = topZ + 1;
+ // Sort them out based on the current z indexes
+ this.sort();
+ // Now tidy-up the z indexes, removing gaps, etc
+ for(var i = 0; i < this.length; i++) {
+ if(this.members[i]) {
+ this.members[i].z = i;
+ }
+ }
+ //console.log('bringToTop', child.name, 'old z', oldZ, 'new z', child.z);
+ return true;
+ // What's the z index of the top most child?
+ /*
+ var childIndex: number = this._zCounter;
+
+ console.log('childIndex', childIndex);
+
+ this._i = 0;
+
+ while (this._i < this.length)
+ {
+ this._member = this.members[this._i++];
+
+ if (this._member)
+ {
+ if (this._i > childIndex)
+ {
+ this._member.z--;
+ }
+ else if (this._member.z == child.z)
+ {
+ childIndex = this._i;
+ this._member.z = this._zCounter;
+ }
+ }
+ }
+
+ console.log('child inserted at index', child.z);
+
// Maybe redundant?
this.sort();
+
return true;
- };
+ */
+ };
Group.prototype.sort = /**
* Call this function to sort the group according to a particular value and order.
* For example, to sort game objects for Zelda-style overlaps you might call
@@ -11782,6 +11837,7 @@ var Phaser;
* @type {Tweens[]}
*/
this._chainedTweens = [];
+ this.isRunning = false;
this._object = object;
this._game = game;
this._manager = this._game.tweens;
@@ -11849,6 +11905,7 @@ var Phaser;
this.onStart.dispatch(this._object);
}
this._startTime = this._game.time.now + this._delayTime;
+ this.isRunning = true;
for(var property in this._valuesEnd) {
// This prevents the interpolation of null values or of non-existing properties
if(this._object[property] === null || !(property in this._object)) {
@@ -11903,6 +11960,7 @@ var Phaser;
if(this._manager !== null) {
this._manager.remove(this);
}
+ this.isRunning = false;
this.onComplete.dispose();
return this;
};
@@ -12013,6 +12071,9 @@ var Phaser;
for(var i = 0; i < this._chainedTweens.length; i++) {
this._chainedTweens[i].start();
}
+ if(this._chainedTweens.length == 0) {
+ this.isRunning = false;
+ }
return false;
}
}
@@ -12633,21 +12694,6 @@ var Phaser;
* @param tileHeight {number} Height of tiles in this map.
*/
function TilemapLayer(game, parent, key, mapFormat, name, tileWidth, tileHeight) {
- this._startX = 0;
- this._startY = 0;
- this._maxX = 0;
- this._maxY = 0;
- this._tx = 0;
- this._ty = 0;
- this._dx = 0;
- this._dy = 0;
- this._oldCameraX = 0;
- this._oldCameraY = 0;
- /**
- * Opacity of this layer.
- * @type {number}
- */
- this.alpha = 1;
/**
* Controls whether update() and draw() are automatically called.
* @type {boolean}
@@ -12690,19 +12736,24 @@ var Phaser;
* @type {number}
*/
this.tileSpacing = 0;
- this._game = game;
- this._parent = parent;
+ this.game = game;
+ this.parent = parent;
this.name = name;
this.mapFormat = mapFormat;
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
this.boundsInTiles = new Phaser.Rectangle();
- //this.scrollFactor = new MicroPoint(1, 1);
- this.canvas = game.stage.canvas;
- this.context = game.stage.context;
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
+ if(key !== null) {
+ this.texture.loadImage(key, false);
+ } else {
+ this.texture.opaque = true;
+ }
+ // Handy proxies
+ this.alpha = this.texture.alpha;
this.mapData = [];
this._tempTileBlock = [];
- this._texture = this._game.cache.getImage(key);
}
TilemapLayer.prototype.putTile = /**
* Set a specific tile with its x and y in tiles.
@@ -12711,8 +12762,8 @@ var Phaser;
* @param index {number} The index of this tile type in the core map data.
*/
function (x, y, index) {
- x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
- y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
+ x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
+ y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if(y >= 0 && y < this.mapData.length) {
if(x >= 0 && x < this.mapData[y].length) {
this.mapData[y][x] = index;
@@ -12784,7 +12835,7 @@ var Phaser;
if (typeof height === "undefined") { height = this.heightInTiles; }
this.getTempBlock(x, y, width, height);
for(var r = 0; r < this._tempTileBlock.length; r++) {
- this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles);
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this.game.math.getRandom(tiles);
}
};
TilemapLayer.prototype.replaceTile = /**
@@ -12833,8 +12884,8 @@ var Phaser;
* @param x {number} Y position of the point in target tile.
*/
function (x, y) {
- x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
- y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
+ x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
+ y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
return this.getTileIndex(x, y);
};
TilemapLayer.prototype.getTileOverlaps = /**
@@ -12848,17 +12899,17 @@ var Phaser;
return;
}
// What tiles do we need to check against?
- this._tempTileX = this._game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth;
- this._tempTileY = this._game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight;
- this._tempTileW = (this._game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
- this._tempTileH = (this._game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
+ this._tempTileX = this.game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth;
+ this._tempTileY = this.game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight;
+ this._tempTileW = (this.game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
+ this._tempTileH = (this.game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
this._tempBlockResults = [];
this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
/*
for (var r = 0; r < this._tempTileBlock.length; r++)
{
- if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
+ if (this.game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
{
this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
}
@@ -12893,11 +12944,11 @@ var Phaser;
for(var tx = x; tx < x + width; tx++) {
if(collisionOnly) {
// We only want to consider the tile for checking if you can actually collide with it
- if(this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) {
+ if(this.mapData[ty] && this.mapData[ty][tx] && this.parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) {
this._tempTileBlock.push({
x: tx,
y: ty,
- tile: this._parent.tiles[this.mapData[ty][tx]]
+ tile: this.parent.tiles[this.mapData[ty][tx]]
});
}
} else {
@@ -12905,7 +12956,7 @@ var Phaser;
this._tempTileBlock.push({
x: tx,
y: ty,
- tile: this._parent.tiles[this.mapData[ty][tx]]
+ tile: this.parent.tiles[this.mapData[ty][tx]]
});
}
}
@@ -12951,120 +13002,42 @@ var Phaser;
};
TilemapLayer.prototype.parseTileOffsets = /**
* Parse tile offsets from map data.
- * @return {number} length of _tileOffsets array.
+ * @return {number} length of tileOffsets array.
*/
function () {
- this._tileOffsets = [];
+ this.tileOffsets = [];
var i = 0;
if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) {
// For some reason Tiled counts from 1 not 0
- this._tileOffsets[0] = null;
+ this.tileOffsets[0] = null;
i = 1;
}
- for(var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing)) {
- for(var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing)) {
- this._tileOffsets[i] = {
+ for(var ty = this.tileMargin; ty < this.texture.height; ty += (this.tileHeight + this.tileSpacing)) {
+ for(var tx = this.tileMargin; tx < this.texture.width; tx += (this.tileWidth + this.tileSpacing)) {
+ this.tileOffsets[i] = {
x: tx,
y: ty
};
i++;
}
}
- return this._tileOffsets.length;
- };
- TilemapLayer.prototype.renderDebugInfo = function (x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- this.context.fillStyle = color;
- this.context.fillText('TilemapLayer: ' + this.name, x, y);
- this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
- this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
- this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
- };
- TilemapLayer.prototype.render = /**
- * Render this layer to a specific camera with offset to camera.
- * @param camera {Camera} The camera the layer is going to be rendered.
- * @param dx {number} X offset to the camera.
- * @param dy {number} Y offset to the camera.
- * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed.
- */
- function (camera, dx, dy) {
- if(this.visible === false || this.alpha < 0.1) {
- return false;
- }
- // Work out how many tiles we can fit into our camera and round it up for the edges
- this._maxX = this._game.math.ceil(camera.width / this.tileWidth) + 1;
- this._maxY = this._game.math.ceil(camera.height / this.tileHeight) + 1;
- // And now work out where in the tilemap the camera actually is
- this._startX = this._game.math.floor(camera.worldView.x / this.tileWidth);
- this._startY = this._game.math.floor(camera.worldView.y / this.tileHeight);
- // Tilemap bounds check
- if(this._startX < 0) {
- this._startX = 0;
- }
- if(this._startY < 0) {
- this._startY = 0;
- }
- if(this._maxX > this.widthInTiles) {
- this._maxX = this.widthInTiles;
- }
- if(this._maxY > this.heightInTiles) {
- this._maxY = this.heightInTiles;
- }
- if(this._startX + this._maxX > this.widthInTiles) {
- this._startX = this.widthInTiles - this._maxX;
- }
- if(this._startY + this._maxY > this.heightInTiles) {
- this._startY = this.heightInTiles - this._maxY;
- }
- // Finally get the offset to avoid the blocky movement
- this._dx = dx;
- this._dy = dy;
- this._dx += -(camera.worldView.x - (this._startX * this.tileWidth));
- this._dy += -(camera.worldView.y - (this._startY * this.tileHeight));
- this._tx = this._dx;
- this._ty = this._dy;
- // Apply camera difference
- /*
- if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
- {
- this._dx -= (camera.worldView.x * this.scrollFactor.x);
- this._dy -= (camera.worldView.y * this.scrollFactor.y);
- }
- */
- // Alpha
- if(this.alpha !== 1) {
- var globalAlpha = this.context.globalAlpha;
- this.context.globalAlpha = this.alpha;
- }
- for(var row = this._startY; row < this._startY + this._maxY; row++) {
- this._columnData = this.mapData[row];
- for(var tile = this._startX; tile < this._startX + this._maxX; tile++) {
- if(this._tileOffsets[this._columnData[tile]]) {
- this.context.drawImage(this._texture, // Source Image
- this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
- this._tileOffsets[this._columnData[tile]].y, // Source Y
- this.tileWidth, // Source Width
- this.tileHeight, // Source Height
- this._tx, // Destination X (where on the canvas it'll be drawn)
- this._ty, // Destination Y
- this.tileWidth, // Destination Width (always same as Source Width unless scaled)
- this.tileHeight);
- // Destination Height (always same as Source Height unless scaled)
- }
- this._tx += this.tileWidth;
- }
- this._tx = this._dx;
- this._ty += this.tileHeight;
- }
- if(globalAlpha > -1) {
- this.context.globalAlpha = globalAlpha;
- }
- return true;
+ return this.tileOffsets.length;
};
return TilemapLayer;
})();
Phaser.TilemapLayer = TilemapLayer;
-})(Phaser || (Phaser = {}));
+ /*
+ public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
+
+ this.context.fillStyle = color;
+ this.context.fillText('TilemapLayer: ' + this.name, x, y);
+ this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
+ this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
+ this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
+
+ }
+ */
+ })(Phaser || (Phaser = {}));
///
/**
* Phaser - Tile
@@ -13217,6 +13190,22 @@ var Phaser;
if (typeof tileWidth === "undefined") { tileWidth = 0; }
if (typeof tileHeight === "undefined") { tileHeight = 0; }
/**
+ * The Input component
+ */
+ //public input: Phaser.Components.Sprite.Input;
+ /**
+ * The Events component
+ */
+ //public events: Phaser.Components.Sprite.Events;
+ /**
+ * z order value of the object.
+ */
+ this.z = -1;
+ /**
+ * Render iteration counter
+ */
+ this.renderOrderID = 0;
+ /**
* Tilemap collision callback.
* @type {function}
*/
@@ -13227,9 +13216,13 @@ var Phaser;
this.active = true;
this.visible = true;
this.alive = true;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.texture = new Phaser.Components.Texture(this);
+ this.transform = new Phaser.Components.Transform(this);
this.tiles = [];
this.layers = [];
- this.cameraBlacklist = [];
this.mapFormat = format;
switch(format) {
case Tilemap.FORMAT_CSV:
@@ -13245,24 +13238,14 @@ var Phaser;
}
Tilemap.FORMAT_CSV = 0;
Tilemap.FORMAT_TILED_JSON = 1;
- Tilemap.prototype.update = /**
- * Inherited update method.
+ Tilemap.prototype.preUpdate = /**
+ * Inherited methods for overriding.
*/
function () {
};
- Tilemap.prototype.render = /**
- * Render this tilemap to a specific camera with specific offset.
- * @param camera {Camera} The camera this tilemap will be rendered to.
- * @param cameraOffsetX {number} X offset of the camera.
- * @param cameraOffsetY {number} Y offset of the camera.
- */
- function (camera, cameraOffsetX, cameraOffsetY) {
- if(this.cameraBlacklist.indexOf(camera.ID) == -1) {
- // Loop through the layers
- for(var i = 0; i < this.layers.length; i++) {
- this.layers[i].render(camera, cameraOffsetX, cameraOffsetY);
- }
- }
+ Tilemap.prototype.update = function () {
+ };
+ Tilemap.prototype.postUpdate = function () {
};
Tilemap.prototype.parseCSV = /**
* Parset csv map data and generate tiles.
@@ -16253,7 +16236,8 @@ var Phaser;
return PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
};
return PointUtils;
- })();
+ })();
+ Phaser.PointUtils = PointUtils;
})(Phaser || (Phaser = {}));
///
///
@@ -18083,7 +18067,7 @@ var Phaser;
(function (Phaser) {
var CanvasRenderer = (function () {
function CanvasRenderer(game) {
- // local rendering related temp vars to help avoid gc spikes with var creation
+ // Local rendering related temp vars to help avoid gc spikes through var creation
this._ga = 1;
this._sx = 0;
this._sy = 0;
@@ -18095,8 +18079,14 @@ var Phaser;
this._dh = 0;
this._fx = 1;
this._fy = 1;
+ this._tx = 0;
+ this._ty = 0;
this._sin = 0;
this._cos = 1;
+ this._maxX = 0;
+ this._maxY = 0;
+ this._startX = 0;
+ this._startY = 0;
this._game = game;
}
CanvasRenderer.prototype.render = function () {
@@ -18117,6 +18107,8 @@ var Phaser;
this.renderSprite(this._camera, object);
} else if(object.type == Phaser.Types.SCROLLZONE) {
this.renderScrollZone(this._camera, object);
+ } else if(object.type == Phaser.Types.TILEMAP) {
+ this.renderTilemap(this._camera, object);
}
};
CanvasRenderer.prototype.preRenderGroup = function (camera, group) {
@@ -18553,6 +18545,75 @@ var Phaser;
}
return true;
};
+ CanvasRenderer.prototype.renderTilemap = /**
+ * Render a tilemap to a specific camera.
+ * @param camera {Camera} The camera this tilemap will be rendered to.
+ */
+ function (camera, tilemap) {
+ // Loop through the layers
+ for(var i = 0; i < tilemap.layers.length; i++) {
+ var layer = tilemap.layers[i];
+ if(layer.visible == false || layer.alpha < 0.1) {
+ continue;
+ }
+ // Work out how many tiles we can fit into our camera and round it up for the edges
+ this._maxX = this._game.math.ceil(camera.width / layer.tileWidth) + 1;
+ this._maxY = this._game.math.ceil(camera.height / layer.tileHeight) + 1;
+ // And now work out where in the tilemap the camera actually is
+ this._startX = this._game.math.floor(camera.worldView.x / layer.tileWidth);
+ this._startY = this._game.math.floor(camera.worldView.y / layer.tileHeight);
+ // Tilemap bounds check
+ if(this._startX < 0) {
+ this._startX = 0;
+ }
+ if(this._startY < 0) {
+ this._startY = 0;
+ }
+ if(this._maxX > layer.widthInTiles) {
+ this._maxX = layer.widthInTiles;
+ }
+ if(this._maxY > layer.heightInTiles) {
+ this._maxY = layer.heightInTiles;
+ }
+ if(this._startX + this._maxX > layer.widthInTiles) {
+ this._startX = layer.widthInTiles - this._maxX;
+ }
+ if(this._startY + this._maxY > layer.heightInTiles) {
+ this._startY = layer.heightInTiles - this._maxY;
+ }
+ // Finally get the offset to avoid the blocky movement
+ //this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x);
+ //this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y);
+ //this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x);
+ //this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y);
+ this._dx = 0;
+ this._dy = 0;
+ this._dx += -(camera.worldView.x - (this._startX * layer.tileWidth));
+ this._dy += -(camera.worldView.y - (this._startY * layer.tileHeight));
+ this._tx = this._dx;
+ this._ty = this._dy;
+ // Alpha
+ if(layer.texture.alpha !== 1) {
+ this._ga = layer.texture.context.globalAlpha;
+ layer.texture.context.globalAlpha = layer.texture.alpha;
+ }
+ for(var row = this._startY; row < this._startY + this._maxY; row++) {
+ this._columnData = layer.mapData[row];
+ for(var tile = this._startX; tile < this._startX + this._maxX; tile++) {
+ if(layer.tileOffsets[this._columnData[tile]]) {
+ layer.texture.context.drawImage(layer.texture.texture, layer.tileOffsets[this._columnData[tile]].x, layer.tileOffsets[this._columnData[tile]].y, layer.tileWidth, layer.tileHeight, this._tx, this._ty, layer.tileWidth, layer.tileHeight);
+ }
+ this._tx += layer.tileWidth;
+ }
+ this._tx = this._dx;
+ this._ty += layer.tileHeight;
+ }
+ if(this._ga > -1) {
+ layer.texture.context.globalAlpha = this._ga;
+ }
+ }
+ return true;
+ };
return CanvasRenderer;
})();
Phaser.CanvasRenderer = CanvasRenderer;
@@ -18626,6 +18687,11 @@ var Phaser;
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
};
+ DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ DebugUtils.context.fillStyle = fillStyle;
+ DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
DebugUtils.renderPhysicsBody = function renderPhysicsBody(body, lineWidth, fillStyle, sleepStyle) {
if (typeof lineWidth === "undefined") { lineWidth = 1; }
if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.2)'; }
@@ -19094,84 +19160,6 @@ var Phaser;
})();
Phaser.Game = Game;
})(Phaser || (Phaser = {}));
-///
-/**
-* Phaser - State
-*
-* This is a base State class which can be extended if you are creating your game using TypeScript.
-*/
-var Phaser;
-(function (Phaser) {
- var State = (function () {
- /**
- * State constructor
- * Create a new State
.
- */
- function State(game) {
- this.game = game;
- this.add = game.add;
- this.camera = game.camera;
- this.cache = game.cache;
- this.input = game.input;
- this.load = game.load;
- this.math = game.math;
- this.motion = game.motion;
- this.sound = game.sound;
- this.stage = game.stage;
- this.time = game.time;
- this.tweens = game.tweens;
- this.world = game.world;
- }
- State.prototype.init = // Override these in your own States
- /**
- * Override this method to add some load operations.
- * If you need to use the loader, you may need to use them here.
- */
- function () {
- };
- State.prototype.create = /**
- * This method is called after the game engine successfully switches states.
- * Feel free to add any setup code here.(Do not load anything here, override init() instead)
- */
- function () {
- };
- State.prototype.update = /**
- * Put update logic here.
- */
- function () {
- };
- State.prototype.render = /**
- * Put render operations here.
- */
- function () {
- };
- State.prototype.paused = /**
- * This method will be called when game paused.
- */
- function () {
- };
- State.prototype.destroy = /**
- * This method will be called when the state is destroyed
- */
- function () {
- };
- return State;
- })();
- Phaser.State = State;
- /**
- * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
- * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
- * @param object1 The first GameObject or Group to check. If null the world.group is used.
- * @param object2 The second GameObject or Group to check.
- * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
- * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
- * @param context The context in which the callbacks will be called
- * @returns {boolean} true if the objects overlap, otherwise false.
- */
- //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
- // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
- //}
- })(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
/**
@@ -19514,206 +19502,6 @@ var Phaser;
Phaser.Line = Line;
})(Phaser || (Phaser = {}));
///
-/**
-* Phaser - IntersectResult
-*
-* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
-*/
-var Phaser;
-(function (Phaser) {
- var IntersectResult = (function () {
- function IntersectResult() {
- /**
- * Did they intersect or not?
- * @property result
- * @type {Boolean}
- */
- this.result = false;
- }
- IntersectResult.prototype.setTo = /**
- *
- * @method setTo
- * @param {Number} x1
- * @param {Number} y1
- * @param {Number} [x2]
- * @param {Number} [y2]
- * @param {Number} [width]
- * @param {Number} [height]
- */
- function (x1, y1, x2, y2, width, height) {
- if (typeof x2 === "undefined") { x2 = 0; }
- if (typeof y2 === "undefined") { y2 = 0; }
- if (typeof width === "undefined") { width = 0; }
- if (typeof height === "undefined") { height = 0; }
- this.x = x1;
- this.y = y1;
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- this.width = width;
- this.height = height;
- };
- return IntersectResult;
- })();
- Phaser.IntersectResult = IntersectResult;
-})(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 = {}));
-///
///
///
///
@@ -19877,6 +19665,161 @@ var Phaser;
Phaser.CircleUtils = CircleUtils;
})(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 = {}));
+///
///
///
///
@@ -19904,3 +19847,126 @@ var Phaser;
})();
Phaser.PixelUtils = PixelUtils;
})(Phaser || (Phaser = {}));
+///
+/**
+* Phaser - IntersectResult
+*
+* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
+*/
+var Phaser;
+(function (Phaser) {
+ var IntersectResult = (function () {
+ function IntersectResult() {
+ /**
+ * Did they intersect or not?
+ * @property result
+ * @type {Boolean}
+ */
+ this.result = false;
+ }
+ IntersectResult.prototype.setTo = /**
+ *
+ * @method setTo
+ * @param {Number} x1
+ * @param {Number} y1
+ * @param {Number} [x2]
+ * @param {Number} [y2]
+ * @param {Number} [width]
+ * @param {Number} [height]
+ */
+ function (x1, y1, x2, y2, width, height) {
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ this.x = x1;
+ this.y = y1;
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ this.width = width;
+ this.height = height;
+ };
+ return IntersectResult;
+ })();
+ Phaser.IntersectResult = IntersectResult;
+})(Phaser || (Phaser = {}));
+///
+/**
+* Phaser - State
+*
+* This is a base State class which can be extended if you are creating your game using TypeScript.
+*/
+var Phaser;
+(function (Phaser) {
+ var State = (function () {
+ /**
+ * State constructor
+ * Create a new State
.
+ */
+ function State(game) {
+ this.game = game;
+ this.add = game.add;
+ this.camera = game.camera;
+ this.cache = game.cache;
+ this.input = game.input;
+ this.load = game.load;
+ this.math = game.math;
+ this.motion = game.motion;
+ this.sound = game.sound;
+ this.stage = game.stage;
+ this.time = game.time;
+ this.tweens = game.tweens;
+ this.world = game.world;
+ }
+ State.prototype.init = // Override these in your own States
+ /**
+ * Override this method to add some load operations.
+ * If you need to use the loader, you may need to use them here.
+ */
+ function () {
+ };
+ State.prototype.create = /**
+ * This method is called after the game engine successfully switches states.
+ * Feel free to add any setup code here.(Do not load anything here, override init() instead)
+ */
+ function () {
+ };
+ State.prototype.update = /**
+ * Put update logic here.
+ */
+ function () {
+ };
+ State.prototype.render = /**
+ * Put render operations here.
+ */
+ function () {
+ };
+ State.prototype.paused = /**
+ * This method will be called when game paused.
+ */
+ function () {
+ };
+ State.prototype.destroy = /**
+ * This method will be called when the state is destroyed
+ */
+ function () {
+ };
+ return State;
+ })();
+ Phaser.State = State;
+ /**
+ * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
+ * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
+ * @param object1 The first GameObject or Group to check. If null the world.group is used.
+ * @param object2 The second GameObject or Group to check.
+ * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
+ * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
+ * @param context The context in which the callbacks will be called
+ * @returns {boolean} true if the objects overlap, otherwise false.
+ */
+ //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
+ // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
+ //}
+ })(Phaser || (Phaser = {}));