+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+*/
+var Phaser;
+(function (Phaser) {
+ var FrameData = (function () {
+ /**
+ * FrameData constructor
+ */
+ function FrameData() {
+ this._frames = [];
+ this._frameNames = [];
+ }
+ Object.defineProperty(FrameData.prototype, "total", {
+ get: function () {
+ return this._frames.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ FrameData.prototype.addFrame = /**
+ * Add a new frame.
+ * @param frame {Frame} The frame you want to add.
+ * @return {Frame} The frame you just added.
+ */
+ function (frame) {
+ frame.index = this._frames.length;
+ this._frames.push(frame);
+ if(frame.name !== '') {
+ this._frameNames[frame.name] = frame.index;
+ }
+ return frame;
+ };
+ FrameData.prototype.getFrame = /**
+ * Get a frame by its index.
+ * @param index {number} Index of the frame you want to get.
+ * @return {Frame} The frame you want.
+ */
+ function (index) {
+ if(this._frames[index]) {
+ return this._frames[index];
+ }
+ return null;
+ };
+ FrameData.prototype.getFrameByName = /**
+ * Get a frame by its name.
+ * @param name {string} Name of the frame you want to get.
+ * @return {Frame} The frame you want.
+ */
+ function (name) {
+ if(this._frameNames[name] !== '') {
+ return this._frames[this._frameNames[name]];
+ }
+ return null;
+ };
+ FrameData.prototype.checkFrameName = /**
+ * Check whether there's a frame with given name.
+ * @param name {string} Name of the frame you want to check.
+ * @return {bool} True if frame with given name found, otherwise return false.
+ */
+ function (name) {
+ if(this._frameNames[name] == null) {
+ return false;
+ }
+ return true;
+ };
+ FrameData.prototype.getFrameRange = /**
+ * Get ranges of frames in an array.
+ * @param start {number} Start index of frames you want.
+ * @param end {number} End index of frames you want.
+ * @param [output] {Frame[]} result will be added into this array.
+ * @return {Frame[]} Ranges of specific frames in an array.
+ */
+ function (start, end, output) {
+ if (typeof output === "undefined") { output = []; }
+ for(var i = start; i <= end; i++) {
+ output.push(this._frames[i]);
+ }
+ return output;
+ };
+ FrameData.prototype.getFrameIndexes = /**
+ * Get all indexes of frames by giving their name.
+ * @param [output] {number[]} result will be added into this array.
+ * @return {number[]} Indexes of specific frames in an array.
+ */
+ function (output) {
+ if (typeof output === "undefined") { output = []; }
+ output.length = 0;
+ for(var i = 0; i < this._frames.length; i++) {
+ output.push(i);
+ }
+ return output;
+ };
+ FrameData.prototype.getFrameIndexesByName = /**
+ * Get the frame indexes by giving the frame names.
+ * @param [output] {number[]} result will be added into this array.
+ * @return {number[]} Names of specific frames in an array.
+ */
+ function (input) {
+ var output = [];
+ for(var i = 0; i < input.length; i++) {
+ if(this.getFrameByName(input[i])) {
+ output.push(this.getFrameByName(input[i]).index);
+ }
+ }
+ return output;
+ };
+ FrameData.prototype.getAllFrames = /**
+ * Get all frames in this frame data.
+ * @return {Frame[]} All the frames in an array.
+ */
+ function () {
+ return this._frames;
+ };
+ FrameData.prototype.getFrames = /**
+ * Get All frames with specific ranges.
+ * @param range {number[]} Ranges in an array.
+ * @return {Frame[]} All frames in an array.
+ */
+ function (range) {
+ var output = [];
+ for(var i = 0; i < range.length; i++) {
+ output.push(this._frames[i]);
+ }
+ return output;
+ };
+ return FrameData;
+ })();
+ Phaser.FrameData = FrameData;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/animation/FrameData.ts b/TS Source/animation/FrameData.ts
similarity index 100%
rename from Phaser/animation/FrameData.ts
rename to TS Source/animation/FrameData.ts
diff --git a/TS Source/cameras/Camera.js b/TS Source/cameras/Camera.js
new file mode 100644
index 00000000..b66006ef
--- /dev/null
+++ b/TS Source/cameras/Camera.js
@@ -0,0 +1,370 @@
+///
+/**
+* Phaser - Camera
+*
+* A Camera is your view into the game world. It has a position, size, scale and rotation and renders only those objects
+* within its field of view. The game automatically creates a single Stage sized camera on boot, but it can be changed and
+* additional cameras created via the CameraManager.
+*/
+var Phaser;
+(function (Phaser) {
+ var Camera = (function () {
+ /**
+ * Instantiates a new camera at the specified location, with the specified size and zoom level.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param id {number} Unique identity.
+ * @param x {number} X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
+ * @param y {number} Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
+ * @param width {number} The width of the camera display in pixels.
+ * @param height {number} The height of the camera display in pixels.
+ */
+ function Camera(game, id, x, y, width, height) {
+ this._target = null;
+ /**
+ * Camera worldBounds.
+ * @type {Rectangle}
+ */
+ this.worldBounds = null;
+ /**
+ * A bool representing if the Camera has been modified in any way via a scale, rotate, flip or skew.
+ */
+ this.modified = false;
+ /**
+ * Sprite moving inside this Rectangle will not cause camera moving.
+ * @type {Rectangle}
+ */
+ this.deadzone = null;
+ /**
+ * Whether this camera is visible or not. (default is true)
+ * @type {bool}
+ */
+ this.visible = true;
+ /**
+ * The z value of this Camera. Cameras are rendered in z-index order by the Renderer.
+ */
+ this.z = -1;
+ this.game = game;
+ this.ID = id;
+ this.z = id;
+ width = this.game.math.clamp(width, this.game.stage.width, 1);
+ height = this.game.math.clamp(height, this.game.stage.height, 1);
+ // The view into the world we wish to render (by default the full game world size)
+ // The size of this Rect is the same as screenView, but the values are all in world coordinates instead of screen coordinates
+ this.worldView = new Phaser.Rectangle(0, 0, width, height);
+ // The rect of the area being rendered in stage/screen coordinates
+ this.screenView = new Phaser.Rectangle(x, y, width, height);
+ this.plugins = new Phaser.PluginManager(this.game, this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.texture = new Phaser.Display.Texture(this);
+ // We create a hidden canvas for our camera the size of the game (we use the screenView to clip the render to the camera size)
+ this._canvas = document.createElement('canvas');
+ this._canvas.width = width;
+ this._canvas.height = height;
+ this._renderLocal = true;
+ this.texture.canvas = this._canvas;
+ this.texture.context = this.texture.canvas.getContext('2d');
+ this.texture.backgroundColor = this.game.stage.backgroundColor;
+ // Handy proxies
+ this.scale = this.transform.scale;
+ this.alpha = this.texture.alpha;
+ this.origin = this.transform.origin;
+ this.crop = this.texture.crop;
+ }
+ Object.defineProperty(Camera.prototype, "alpha", {
+ get: /**
+ * The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
+ */
+ function () {
+ return this.texture.alpha;
+ },
+ set: /**
+ * The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
+ */
+ function (value) {
+ this.texture.alpha = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "directToStage", {
+ set: function (value) {
+ if(value) {
+ this._renderLocal = false;
+ this.texture.canvas = this.game.stage.canvas;
+ Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
+ } else {
+ this._renderLocal = true;
+ this.texture.canvas = this._canvas;
+ Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
+ }
+ this.texture.context = this.texture.canvas.getContext('2d');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Camera.prototype.hide = /**
+ * Hides an object from this Camera. Hidden objects are not rendered.
+ * The object must implement a public cameraBlacklist property.
+ *
+ * @param object {Sprite/Group} The object this camera should ignore.
+ */
+ function (object) {
+ object.texture.hideFromCamera(this);
+ };
+ Camera.prototype.isHidden = /**
+ * Returns true if the object is hidden from this Camera.
+ *
+ * @param object {Sprite/Group} The object to check.
+ */
+ function (object) {
+ return object.texture.isHidden(this);
+ };
+ Camera.prototype.show = /**
+ * Un-hides an object previously hidden to this Camera.
+ * The object must implement a public cameraBlacklist property.
+ *
+ * @param object {Sprite/Group} The object this camera should display.
+ */
+ function (object) {
+ object.texture.showToCamera(this);
+ };
+ Camera.prototype.follow = /**
+ * Tells this camera object what sprite to track.
+ * @param target {Sprite} The object you want the camera to track. Set to null to not follow anything.
+ * @param [style] {number} Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
+ */
+ function (target, style) {
+ if (typeof style === "undefined") { style = Phaser.Types.CAMERA_FOLLOW_LOCKON; }
+ this._target = target;
+ var helper;
+ switch(style) {
+ case Phaser.Types.CAMERA_FOLLOW_PLATFORMER:
+ var w = this.width / 8;
+ var h = this.height / 3;
+ this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_TOPDOWN:
+ helper = Math.max(this.width, this.height) / 4;
+ this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT:
+ helper = Math.max(this.width, this.height) / 8;
+ this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_LOCKON:
+ default:
+ this.deadzone = null;
+ break;
+ }
+ };
+ Camera.prototype.focusOnXY = /**
+ * Move the camera focus to this location instantly.
+ * @param x {number} X position.
+ * @param y {number} Y position.
+ */
+ function (x, y) {
+ x += (x > 0) ? 0.0000001 : -0.0000001;
+ y += (y > 0) ? 0.0000001 : -0.0000001;
+ this.worldView.x = Math.round(x - this.worldView.halfWidth);
+ this.worldView.y = Math.round(y - this.worldView.halfHeight);
+ };
+ Camera.prototype.focusOn = /**
+ * Move the camera focus to this location instantly.
+ * @param point {any} Point you want to focus.
+ */
+ function (point) {
+ point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
+ point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
+ this.worldView.x = Math.round(point.x - this.worldView.halfWidth);
+ this.worldView.y = Math.round(point.y - this.worldView.halfHeight);
+ };
+ Camera.prototype.setBounds = /**
+ * Specify the boundaries of the world or where the camera is allowed to move.
+ *
+ * @param x {number} The smallest X value of your world (usually 0).
+ * @param y {number} The smallest Y value of your world (usually 0).
+ * @param width {number} The largest X value of your world (usually the world width).
+ * @param height {number} The largest Y value of your world (usually the world height).
+ */
+ function (x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ if(this.worldBounds == null) {
+ this.worldBounds = new Phaser.Rectangle();
+ }
+ this.worldBounds.setTo(x, y, width, height);
+ this.worldView.x = x;
+ this.worldView.y = y;
+ this.update();
+ };
+ Camera.prototype.update = /**
+ * Update focusing and scrolling.
+ */
+ function () {
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ this.plugins.preUpdate();
+ if(this._target !== null) {
+ if(this.deadzone == null) {
+ this.focusOnXY(this._target.x, this._target.y);
+ } else {
+ var edge;
+ var targetX = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
+ var targetY = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
+ edge = targetX - this.deadzone.x;
+ if(this.worldView.x > edge) {
+ this.worldView.x = edge;
+ }
+ edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
+ if(this.worldView.x < edge) {
+ this.worldView.x = edge;
+ }
+ edge = targetY - this.deadzone.y;
+ if(this.worldView.y > edge) {
+ this.worldView.y = edge;
+ }
+ edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
+ if(this.worldView.y < edge) {
+ this.worldView.y = edge;
+ }
+ }
+ }
+ // Make sure we didn't go outside the cameras worldBounds
+ if(this.worldBounds !== null) {
+ if(this.worldView.x < this.worldBounds.left) {
+ this.worldView.x = this.worldBounds.left;
+ }
+ if(this.worldView.x > this.worldBounds.right - this.width) {
+ this.worldView.x = (this.worldBounds.right - this.width) + 1;
+ }
+ if(this.worldView.y < this.worldBounds.top) {
+ this.worldView.y = this.worldBounds.top;
+ }
+ if(this.worldView.y > this.worldBounds.bottom - this.height) {
+ this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
+ }
+ }
+ this.worldView.floor();
+ this.plugins.update();
+ };
+ Camera.prototype.postUpdate = /**
+ * Update focusing and scrolling.
+ */
+ function () {
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ // Make sure we didn't go outside the cameras worldBounds
+ if(this.worldBounds !== null) {
+ if(this.worldView.x < this.worldBounds.left) {
+ this.worldView.x = this.worldBounds.left;
+ }
+ if(this.worldView.x > this.worldBounds.right - this.width) {
+ this.worldView.x = this.worldBounds.right - this.width;
+ }
+ if(this.worldView.y < this.worldBounds.top) {
+ this.worldView.y = this.worldBounds.top;
+ }
+ if(this.worldView.y > this.worldBounds.bottom - this.height) {
+ this.worldView.y = this.worldBounds.bottom - this.height;
+ }
+ }
+ this.worldView.floor();
+ this.plugins.postUpdate();
+ };
+ Camera.prototype.destroy = /**
+ * Destroys this camera, associated FX and removes itself from the CameraManager.
+ */
+ function () {
+ this.game.world.cameras.removeCamera(this.ID);
+ this.plugins.destroy();
+ };
+ Object.defineProperty(Camera.prototype, "x", {
+ get: function () {
+ return this.worldView.x;
+ },
+ set: function (value) {
+ this.worldView.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "y", {
+ get: function () {
+ return this.worldView.y;
+ },
+ set: function (value) {
+ this.worldView.y = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "width", {
+ get: function () {
+ return this.screenView.width;
+ },
+ set: function (value) {
+ this.screenView.width = value;
+ this.worldView.width = value;
+ if(value !== this.texture.canvas.width) {
+ this.texture.canvas.width = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "height", {
+ get: function () {
+ return this.screenView.height;
+ },
+ set: function (value) {
+ this.screenView.height = value;
+ this.worldView.height = value;
+ if(value !== this.texture.canvas.height) {
+ this.texture.canvas.height = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Camera.prototype.setPosition = function (x, y) {
+ this.screenView.x = x;
+ this.screenView.y = y;
+ };
+ Camera.prototype.setSize = function (width, height) {
+ this.screenView.width = width * this.transform.scale.x;
+ this.screenView.height = height * this.transform.scale.y;
+ this.worldView.width = width;
+ this.worldView.height = height;
+ if(width !== this.texture.canvas.width) {
+ this.texture.canvas.width = width;
+ }
+ if(height !== this.texture.canvas.height) {
+ this.texture.canvas.height = height;
+ }
+ };
+ Object.defineProperty(Camera.prototype, "rotation", {
+ get: /**
+ * The angle of the Camera in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ */
+ function () {
+ return this.transform.rotation;
+ },
+ set: /**
+ * Set the angle of the Camera 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.transform.rotation = this.game.math.wrap(value, 360, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Camera;
+ })();
+ Phaser.Camera = Camera;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/cameras/Camera.ts b/TS Source/cameras/Camera.ts
similarity index 100%
rename from Phaser/cameras/Camera.ts
rename to TS Source/cameras/Camera.ts
diff --git a/TS Source/cameras/CameraManager.js b/TS Source/cameras/CameraManager.js
new file mode 100644
index 00000000..10dd644d
--- /dev/null
+++ b/TS Source/cameras/CameraManager.js
@@ -0,0 +1,154 @@
+///
+/**
+* Phaser - CameraManager
+*
+* Your game only has one CameraManager instance and it's responsible for looking after, creating and destroying
+* all of the cameras in the world.
+*/
+var Phaser;
+(function (Phaser) {
+ var CameraManager = (function () {
+ /**
+ * CameraManager constructor
+ * This will create a new Camera with position and size.
+ *
+ * @param x {number} X Position of the created camera.
+ * @param y {number} y Position of the created camera.
+ * @param width {number} Width of the created camera.
+ * @param height {number} Height of the created camera.
+ */
+ function CameraManager(game, x, y, width, height) {
+ /**
+ * Helper for sort.
+ */
+ this._sortIndex = '';
+ this.game = game;
+ this._cameras = [];
+ this._cameraLength = 0;
+ this.defaultCamera = this.addCamera(x, y, width, height);
+ this.defaultCamera.directToStage = true;
+ this.current = this.defaultCamera;
+ }
+ CameraManager.prototype.getAll = /**
+ * Get all the cameras.
+ *
+ * @returns {Camera[]} An array contains all the cameras.
+ */
+ function () {
+ return this._cameras;
+ };
+ CameraManager.prototype.update = /**
+ * Update cameras.
+ */
+ function () {
+ for(var i = 0; i < this._cameras.length; i++) {
+ this._cameras[i].update();
+ }
+ };
+ CameraManager.prototype.postUpdate = /**
+ * postUpdate cameras.
+ */
+ function () {
+ for(var i = 0; i < this._cameras.length; i++) {
+ this._cameras[i].postUpdate();
+ }
+ };
+ CameraManager.prototype.addCamera = /**
+ * Create a new camera with specific position and size.
+ *
+ * @param x {number} X position of the new camera.
+ * @param y {number} Y position of the new camera.
+ * @param width {number} Width of the new camera.
+ * @param height {number} Height of the new camera.
+ * @returns {Camera} The newly created camera object.
+ */
+ function (x, y, width, height) {
+ var newCam = new Phaser.Camera(this.game, this._cameraLength, x, y, width, height);
+ this._cameraLength = this._cameras.push(newCam);
+ return newCam;
+ };
+ CameraManager.prototype.removeCamera = /**
+ * Remove a new camera with its id.
+ *
+ * @param id {number} ID of the camera you want to remove.
+ * @returns {bool} True if successfully removed the camera, otherwise return false.
+ */
+ function (id) {
+ for(var c = 0; c < this._cameras.length; c++) {
+ if(this._cameras[c].ID == id) {
+ if(this.current.ID === this._cameras[c].ID) {
+ this.current = null;
+ }
+ this._cameras.splice(c, 1);
+ return true;
+ }
+ }
+ return false;
+ };
+ CameraManager.prototype.swap = function (camera1, camera2, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(camera1.ID == camera2.ID) {
+ return false;
+ }
+ var tempZ = camera1.z;
+ camera1.z = camera2.z;
+ camera2.z = tempZ;
+ if(sort) {
+ this.sort();
+ }
+ return true;
+ };
+ CameraManager.prototype.getCameraUnderPoint = function (x, y) {
+ // Work through the cameras in reverse as they are rendered in array order
+ // Return the first camera we find matching the criteria
+ for(var c = this._cameraLength - 1; c >= 0; c--) {
+ if(this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) {
+ return this._cameras[c];
+ }
+ }
+ return null;
+ };
+ CameraManager.prototype.sort = /**
+ * Call this function to sort the Cameras according to a particular value and order (default is their Z value).
+ * The order in which they are sorted determines the render order. If sorted on z then Cameras with a lower z-index value render first.
+ *
+ * @param {string} index The string name of the Camera variable you want to sort on. Default value is "z".
+ * @param {number} order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
+ */
+ function (index, order) {
+ if (typeof index === "undefined") { index = 'z'; }
+ if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
+ var _this = this;
+ this._sortIndex = index;
+ this._sortOrder = order;
+ this._cameras.sort(function (a, b) {
+ return _this.sortHandler(a, b);
+ });
+ };
+ CameraManager.prototype.sortHandler = /**
+ * Helper function for the sort process.
+ *
+ * @param {Basic} Obj1 The first object being sorted.
+ * @param {Basic} Obj2 The second object being sorted.
+ *
+ * @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
+ */
+ function (obj1, obj2) {
+ if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ CameraManager.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this._cameras.length = 0;
+ this.current = this.addCamera(0, 0, this.game.stage.width, this.game.stage.height);
+ };
+ return CameraManager;
+ })();
+ Phaser.CameraManager = CameraManager;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/cameras/CameraManager.ts b/TS Source/cameras/CameraManager.ts
similarity index 100%
rename from Phaser/cameras/CameraManager.ts
rename to TS Source/cameras/CameraManager.ts
diff --git a/TS Source/core/Group.js b/TS Source/core/Group.js
new file mode 100644
index 00000000..935ff7ad
--- /dev/null
+++ b/TS Source/core/Group.js
@@ -0,0 +1,731 @@
+///
+/**
+* Phaser - Group
+*
+* This class is used for organising, updating and sorting game objects.
+*/
+var Phaser;
+(function (Phaser) {
+ var Group = (function () {
+ function Group(game, maxSize) {
+ if (typeof maxSize === "undefined") { maxSize = 0; }
+ /**
+ * Helper for sort.
+ */
+ this._sortIndex = '';
+ /**
+ * This keeps track of the z value of any game object added to this Group
+ */
+ this._zCounter = 0;
+ /**
+ * The unique Group ID
+ */
+ this.ID = -1;
+ /**
+ * The z value of this Group (within its parent Group, if any)
+ */
+ this.z = -1;
+ /**
+ * The Group this Group is a child of (if any).
+ */
+ this.group = null;
+ /**
+ * A bool representing if the Group has been modified in any way via a scale, rotate, flip or skew.
+ */
+ this.modified = false;
+ this.game = game;
+ this.type = Phaser.Types.GROUP;
+ this.active = true;
+ this.exists = true;
+ this.visible = true;
+ this.members = [];
+ this.length = 0;
+ this._maxSize = maxSize;
+ this._marker = 0;
+ this._sortIndex = null;
+ this.ID = this.game.world.getNextGroupID();
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this.texture.opaque = false;
+ }
+ Group.prototype.getNextZIndex = /**
+ * Gets the next z index value for children of this Group
+ */
+ function () {
+ return this._zCounter++;
+ };
+ Group.prototype.destroy = /**
+ * Override this function to handle any deleting or "shutdown" type operations you might need,
+ * such as removing traditional children like Basic objects.
+ */
+ function () {
+ if(this.members != null) {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ this._member.destroy();
+ }
+ }
+ this.members.length = 0;
+ }
+ this._sortIndex = null;
+ };
+ Group.prototype.update = /**
+ * Calls update on all members of this Group who have a status of active=true and exists=true
+ * You can also call Object.update directly, which will bypass the active/exists check.
+ */
+ function () {
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.active) {
+ if(this._member.type != Phaser.Types.GROUP) {
+ this._member.preUpdate();
+ }
+ this._member.update();
+ }
+ }
+ };
+ Group.prototype.postUpdate = /**
+ * Calls update on all members of this Group who have a status of active=true and exists=true
+ * You can also call Object.postUpdate directly, which will bypass the active/exists check.
+ */
+ function () {
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.active) {
+ this._member.postUpdate();
+ }
+ }
+ };
+ Group.prototype.render = /**
+ * Calls render on all members of this Group who have a status of visible=true and exists=true
+ * You can also call Object.render directly, which will bypass the visible/exists check.
+ */
+ function (camera) {
+ if(camera.isHidden(this) == true) {
+ return;
+ }
+ this.game.renderer.groupRenderer.preRender(camera, this);
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) {
+ if(this._member.type == Phaser.Types.GROUP) {
+ this._member.render(camera);
+ } else {
+ this.game.renderer.renderGameObject(camera, this._member);
+ }
+ }
+ }
+ this.game.renderer.groupRenderer.postRender(camera, this);
+ };
+ Group.prototype.directRender = /**
+ * Calls render on all members of this Group regardless of their visible status and also ignores the camera blacklist.
+ * Use this when the Group objects render to hidden canvases for example.
+ */
+ function (camera) {
+ this.game.renderer.groupRenderer.preRender(camera, this);
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists) {
+ if(this._member.type == Phaser.Types.GROUP) {
+ this._member.directRender(camera);
+ } else {
+ this.game.renderer.renderGameObject(this._member);
+ }
+ }
+ }
+ this.game.renderer.groupRenderer.postRender(camera, this);
+ };
+ Object.defineProperty(Group.prototype, "maxSize", {
+ get: /**
+ * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
+ */
+ function () {
+ return this._maxSize;
+ },
+ set: /**
+ * @private
+ */
+ function (size) {
+ this._maxSize = size;
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ if(this._maxSize == 0 || this.members == null || (this._maxSize >= this.members.length)) {
+ return;
+ }
+ //If the max size has shrunk, we need to get rid of some objects
+ this._i = this._maxSize;
+ this._length = this.members.length;
+ while(this._i < this._length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ this._member.destroy();
+ }
+ }
+ this.length = this.members.length = this._maxSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Group.prototype.add = /**
+ * Adds a new Game Object to the group.
+ * Group will try to replace a null member of the array first.
+ * Failing that, Group will add it to the end of the member array,
+ * assuming there is room for it, and doubling the size of the array if necessary.
+ *
+ * WARNING: If the group has a maxSize that has already been met,
+ * the object will NOT be added to the group!
+ *
+ * @param {Basic} Object The object you want to add to the group.
+ * @return {Basic} The same object that was passed in.
+ */
+ function (object) {
+ // Is this object already in another Group?
+ // You can't add a Group to itself or an object to the same Group twice
+ if(object.group && (object.group.ID == this.ID || (object.type == Phaser.Types.GROUP && object.ID == this.ID))) {
+ return object;
+ }
+ // First, look for a null entry where we can add the object.
+ this._i = 0;
+ this._length = this.members.length;
+ while(this._i < this._length) {
+ if(this.members[this._i] == null) {
+ this.members[this._i] = object;
+ this.setObjectIDs(object);
+ if(this._i >= this.length) {
+ this.length = this._i + 1;
+ }
+ return object;
+ }
+ this._i++;
+ }
+ // Failing that, expand the array (if we can) and add the object.
+ if(this._maxSize > 0) {
+ if(this.members.length >= this._maxSize) {
+ return object;
+ } else if(this.members.length * 2 <= this._maxSize) {
+ this.members.length *= 2;
+ } else {
+ this.members.length = this._maxSize;
+ }
+ } else {
+ this.members.length *= 2;
+ }
+ // If we made it this far, then we successfully grew the group,
+ // and we can go ahead and add the object at the first open slot.
+ this.members[this._i] = object;
+ this.length = this._i + 1;
+ this.setObjectIDs(object);
+ return object;
+ };
+ Group.prototype.addNewSprite = /**
+ * Create a new Sprite within this Group at the specified position.
+ *
+ * @param x {number} X position of the new sprite.
+ * @param y {number} Y position of the new sprite.
+ * @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
+ * @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
+ * @returns {Sprite} The newly created sprite object.
+ */
+ function (x, y, key, frame) {
+ if (typeof key === "undefined") { key = ''; }
+ if (typeof frame === "undefined") { frame = null; }
+ return this.add(new Phaser.Sprite(this.game, x, y, key, frame));
+ };
+ Group.prototype.setObjectIDs = /**
+ * Sets all of the game object properties needed to exist within this Group.
+ */
+ function (object, zIndex) {
+ if (typeof zIndex === "undefined") { zIndex = -1; }
+ // If the object is already in another Group, inform that Group it has left
+ if(object.group !== null) {
+ object.group.remove(object);
+ }
+ object.group = this;
+ if(zIndex == -1) {
+ zIndex = this.getNextZIndex();
+ }
+ object.z = zIndex;
+ if(object['events']) {
+ object['events'].onAddedToGroup.dispatch(object, this, object.z);
+ }
+ };
+ Group.prototype.recycle = /**
+ * Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
+ *
+ * If you specified a maximum size for this group (like in Emitter),
+ * then recycle will employ what we're calling "rotating" recycling.
+ * Recycle() will first check to see if the group is at capacity yet.
+ * If group is not yet at capacity, recycle() returns a new object.
+ * If the group IS at capacity, then recycle() just returns the next object in line.
+ *
+ * If you did NOT specify a maximum size for this group,
+ * then recycle() will employ what we're calling "grow-style" recycling.
+ * Recycle() will return either the first object with exists == false,
+ * or, finding none, add a new object to the array,
+ * doubling the size of the array if necessary.
+ *
+ * WARNING: If this function needs to create a new object,
+ * and no object class was provided, it will return null
+ * instead of a valid object!
+ *
+ * @param {class} ObjectClass The class type you want to recycle (e.g. Basic, EvilRobot, etc). Do NOT "new" the class in the parameter!
+ *
+ * @return {any} A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;).
+ */
+ function (objectClass) {
+ if (typeof objectClass === "undefined") { objectClass = null; }
+ if(this._maxSize > 0) {
+ if(this.length < this._maxSize) {
+ if(objectClass == null) {
+ return null;
+ }
+ return this.add(new objectClass(this.game));
+ } else {
+ this._member = this.members[this._marker++];
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ return this._member;
+ }
+ } else {
+ this._member = this.getFirstAvailable(objectClass);
+ if(this._member != null) {
+ return this._member;
+ }
+ if(objectClass == null) {
+ return null;
+ }
+ return this.add(new objectClass(this.game));
+ }
+ };
+ Group.prototype.remove = /**
+ * Removes an object from the group.
+ *
+ * @param {Basic} object The Game Object you want to remove.
+ * @param {bool} splice Whether the object should be cut from the array entirely or not.
+ *
+ * @return {Basic} The removed object.
+ */
+ function (object, splice) {
+ if (typeof splice === "undefined") { splice = false; }
+ //console.log('removing from group: ', object.name);
+ this._i = this.members.indexOf(object);
+ if(this._i < 0 || (this._i >= this.members.length)) {
+ return null;
+ }
+ if(splice) {
+ this.members.splice(this._i, 1);
+ this.length--;
+ } else {
+ this.members[this._i] = null;
+ }
+ //console.log('nulled');
+ if(object['events']) {
+ object['events'].onRemovedFromGroup.dispatch(object, this);
+ }
+ object.group = null;
+ object.z = -1;
+ return object;
+ };
+ Group.prototype.replace = /**
+ * Replaces an existing game object in this Group with a new one.
+ *
+ * @param {Basic} oldObject The object you want to replace.
+ * @param {Basic} newObject The new object you want to use instead.
+ *
+ * @return {Basic} The new object.
+ */
+ function (oldObject, newObject) {
+ this._i = this.members.indexOf(oldObject);
+ if(this._i < 0 || (this._i >= this.members.length)) {
+ return null;
+ }
+ this.setObjectIDs(newObject, this.members[this._i].z);
+ // Null the old object
+ this.remove(this.members[this._i]);
+ this.members[this._i] = newObject;
+ return newObject;
+ };
+ Group.prototype.swap = /**
+ * Swaps two existing game object in this Group with each other.
+ *
+ * @param {Basic} child1 The first object to swap.
+ * @param {Basic} child2 The second object to swap.
+ *
+ * @return {Basic} True if the two objects successfully swapped position.
+ */
+ function (child1, child2, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(child1.group.ID != this.ID || child2.group.ID != this.ID || child1 === child2) {
+ return false;
+ }
+ var tempZ = child1.z;
+ child1.z = child2.z;
+ child2.z = tempZ;
+ if(sort) {
+ this.sort();
+ }
+ 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) {
+ //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 = -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
+ * myGroup.sort("y",Group.ASCENDING) at the bottom of your
+ * State.update() override. To sort all existing objects after
+ * a big explosion or bomb attack, you might call myGroup.sort("exists",Group.DESCENDING).
+ *
+ * @param {string} index The string name of the member variable you want to sort on. Default value is "z".
+ * @param {number} order A Group constant that defines the sort order. Possible values are Group.ASCENDING and Group.DESCENDING. Default value is Group.ASCENDING.
+ */
+ function (index, order) {
+ if (typeof index === "undefined") { index = 'z'; }
+ if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
+ var _this = this;
+ this._sortIndex = index;
+ this._sortOrder = order;
+ this.members.sort(function (a, b) {
+ return _this.sortHandler(a, b);
+ });
+ };
+ Group.prototype.sortHandler = /**
+ * Helper function for the sort process.
+ *
+ * @param {Basic} Obj1 The first object being sorted.
+ * @param {Basic} Obj2 The second object being sorted.
+ *
+ * @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
+ */
+ function (obj1, obj2) {
+ if(!obj1 || !obj2) {
+ //console.log('null objects in sort', obj1, obj2);
+ return 0;
+ }
+ if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ Group.prototype.setAll = /**
+ * Go through and set the specified variable to the specified value on all members of the group.
+ *
+ * @param {string} VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
+ * @param {Object} Value The value you want to assign to that variable.
+ * @param {bool} Recurse Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.
+ */
+ function (variableName, value, recurse) {
+ if (typeof recurse === "undefined") { recurse = true; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recurse && this._member.type == Phaser.Types.GROUP) {
+ this._member.setAll(variableName, value, recurse);
+ } else {
+ this._member[variableName] = value;
+ }
+ }
+ }
+ };
+ Group.prototype.callAll = /**
+ * Go through and call the specified function on all members of the group.
+ * Currently only works on functions that have no required parameters.
+ *
+ * @param {string} FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
+ * @param {bool} Recurse Default value is true, meaning if callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.
+ */
+ function (functionName, recurse) {
+ if (typeof recurse === "undefined") { recurse = true; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recurse && this._member.type == Phaser.Types.GROUP) {
+ this._member.callAll(functionName, recurse);
+ } else {
+ this._member[functionName]();
+ }
+ }
+ }
+ };
+ Group.prototype.forEach = /**
+ * @param {function} callback
+ * @param {bool} recursive
+ */
+ function (callback, recursive) {
+ if (typeof recursive === "undefined") { recursive = false; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recursive && this._member.type == Phaser.Types.GROUP) {
+ this._member.forEach(callback, true);
+ } else {
+ callback.call(this, this._member);
+ }
+ }
+ }
+ };
+ Group.prototype.forEachAlive = /**
+ * @param {any} context
+ * @param {function} callback
+ * @param {bool} recursive
+ */
+ function (context, callback, recursive) {
+ if (typeof recursive === "undefined") { recursive = false; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.alive) {
+ if(recursive && this._member.type == Phaser.Types.GROUP) {
+ this._member.forEachAlive(context, callback, true);
+ } else {
+ callback.call(context, this._member);
+ }
+ }
+ }
+ };
+ Group.prototype.getFirstAvailable = /**
+ * Call this function to retrieve the first object with exists == false in the group.
+ * This is handy for recycling in general, e.g. respawning enemies.
+ *
+ * @param {any} [ObjectClass] An optional parameter that lets you narrow the results to instances of this particular class.
+ *
+ * @return {any} A Basic currently flagged as not existing.
+ */
+ function (objectClass) {
+ if (typeof objectClass === "undefined") { objectClass = null; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && !this._member.exists && ((objectClass == null) || (typeof this._member === objectClass))) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstNull = /**
+ * Call this function to retrieve the first index set to 'null'.
+ * Returns -1 if no index stores a null object.
+ *
+ * @return {number} An int indicating the first null slot in the group.
+ */
+ function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ if(this.members[this._i] == null) {
+ return this._i;
+ } else {
+ this._i++;
+ }
+ }
+ return -1;
+ };
+ Group.prototype.getFirstExtant = /**
+ * Call this function to retrieve the first object with exists == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return {Basic} A Basic currently flagged as existing.
+ */
+ function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstAlive = /**
+ * Call this function to retrieve the first object with dead == false in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return {Basic} A Basic currently flagged as not dead.
+ */
+ function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && this._member.exists && this._member.alive) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstDead = /**
+ * Call this function to retrieve the first object with dead == true in the group.
+ * This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
+ *
+ * @return {Basic} A Basic currently flagged as dead.
+ */
+ function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && !this._member.alive) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.countLiving = /**
+ * Call this function to find out how many members of the group are not dead.
+ *
+ * @return {number} The number of Basics flagged as not dead. Returns -1 if group is empty.
+ */
+ function () {
+ this._count = -1;
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(this._count < 0) {
+ this._count = 0;
+ }
+ if(this._member.exists && this._member.alive) {
+ this._count++;
+ }
+ }
+ }
+ return this._count;
+ };
+ Group.prototype.countDead = /**
+ * Call this function to find out how many members of the group are dead.
+ *
+ * @return {number} The number of Basics flagged as dead. Returns -1 if group is empty.
+ */
+ function () {
+ this._count = -1;
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(this._count < 0) {
+ this._count = 0;
+ }
+ if(!this._member.alive) {
+ this._count++;
+ }
+ }
+ }
+ return this._count;
+ };
+ Group.prototype.getRandom = /**
+ * Returns a member at random from the group.
+ *
+ * @param {number} StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param {number} Length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return {Basic} A Basic from the members list.
+ */
+ function (startIndex, length) {
+ if (typeof startIndex === "undefined") { startIndex = 0; }
+ if (typeof length === "undefined") { length = 0; }
+ if(length == 0) {
+ length = this.length;
+ }
+ return this.game.math.getRandom(this.members, startIndex, length);
+ };
+ Group.prototype.clear = /**
+ * Remove all instances of Basic subclass (Basic, Block, etc) from the list.
+ * WARNING: does not destroy() or kill() any of these objects!
+ */
+ function () {
+ this.length = this.members.length = 0;
+ };
+ Group.prototype.kill = /**
+ * Calls kill on the group's members and then on the group itself.
+ */
+ function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && this._member.exists) {
+ this._member.kill();
+ }
+ }
+ };
+ return Group;
+ })();
+ Phaser.Group = Group;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/core/Group.ts b/TS Source/core/Group.ts
similarity index 100%
rename from Phaser/core/Group.ts
rename to TS Source/core/Group.ts
diff --git a/TS Source/core/Plugin.js b/TS Source/core/Plugin.js
new file mode 100644
index 00000000..fc67eaf0
--- /dev/null
+++ b/TS Source/core/Plugin.js
@@ -0,0 +1,68 @@
+///
+/**
+* Phaser - Plugin
+*/
+var Phaser;
+(function (Phaser) {
+ var Plugin = (function () {
+ function Plugin(game, parent) {
+ this.game = game;
+ this.parent = parent;
+ this.active = false;
+ this.visible = false;
+ this.hasPreUpdate = false;
+ this.hasUpdate = false;
+ this.hasPostUpdate = false;
+ this.hasPreRender = false;
+ this.hasRender = false;
+ this.hasPostRender = false;
+ }
+ Plugin.prototype.preUpdate = /**
+ * Pre-update is called at the start of the update cycle, before any other updates have taken place.
+ * It is only called if active is set to true.
+ */
+ function () {
+ };
+ Plugin.prototype.update = /**
+ * Pre-update is called at the start of the update cycle, before any other updates have taken place.
+ * It is only called if active is set to true.
+ */
+ function () {
+ };
+ Plugin.prototype.postUpdate = /**
+ * Post-update is called at the end of the objects update cycle, after other update logic has taken place.
+ * It is only called if active is set to true.
+ */
+ function () {
+ };
+ Plugin.prototype.preRender = /**
+ * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
+ * It is only called if visible is set to true.
+ */
+ function () {
+ };
+ Plugin.prototype.render = /**
+ * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
+ * It is only called if visible is set to true.
+ */
+ function () {
+ };
+ Plugin.prototype.postRender = /**
+ * Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run.
+ * It is only called if visible is set to true.
+ */
+ function () {
+ };
+ Plugin.prototype.destroy = /**
+ * Clear down this Plugin and null out references
+ */
+ function () {
+ this.game = null;
+ this.parent = null;
+ this.active = false;
+ this.visible = false;
+ };
+ return Plugin;
+ })();
+ Phaser.Plugin = Plugin;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/core/Plugin.ts b/TS Source/core/Plugin.ts
similarity index 100%
rename from Phaser/core/Plugin.ts
rename to TS Source/core/Plugin.ts
diff --git a/TS Source/core/PluginManager.js b/TS Source/core/PluginManager.js
new file mode 100644
index 00000000..f23ea805
--- /dev/null
+++ b/TS Source/core/PluginManager.js
@@ -0,0 +1,121 @@
+///
+/**
+* Phaser - PluginManager
+*/
+var Phaser;
+(function (Phaser) {
+ var PluginManager = (function () {
+ function PluginManager(game, parent) {
+ this.game = game;
+ this._parent = parent;
+ this.plugins = [];
+ }
+ PluginManager.prototype.add = /**
+ * Add a new Plugin to the PluginManager.
+ * The plugins game and parent reference are set to this game and pluginmanager parent.
+ * @type {Phaser.Plugin}
+ */
+ function (plugin) {
+ var result = false;
+ // Prototype?
+ if(typeof plugin === 'function') {
+ plugin = new plugin(this.game, this._parent);
+ } else {
+ plugin.game = this.game;
+ plugin.parent = this._parent;
+ }
+ // Check for methods now to avoid having to do this every loop
+ if(typeof plugin['preUpdate'] === 'function') {
+ plugin.hasPreUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['update'] === 'function') {
+ plugin.hasUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['postUpdate'] === 'function') {
+ plugin.hasPostUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['preRender'] === 'function') {
+ plugin.hasPreRender = true;
+ result = true;
+ }
+ if(typeof plugin['render'] === 'function') {
+ plugin.hasRender = true;
+ result = true;
+ }
+ if(typeof plugin['postRender'] === 'function') {
+ plugin.hasPostRender = true;
+ result = true;
+ }
+ // The plugin must have at least one of the above functions to be added to the PluginManager.
+ if(result == true) {
+ if(plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) {
+ plugin.active = true;
+ }
+ if(plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender) {
+ plugin.visible = true;
+ }
+ this._pluginsLength = this.plugins.push(plugin);
+ return plugin;
+ } else {
+ return null;
+ }
+ };
+ PluginManager.prototype.remove = function (plugin) {
+ // TODO :)
+ this._pluginsLength--;
+ };
+ PluginManager.prototype.preUpdate = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) {
+ this.plugins[this._p].preUpdate();
+ }
+ }
+ };
+ PluginManager.prototype.update = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasUpdate) {
+ this.plugins[this._p].update();
+ }
+ }
+ };
+ PluginManager.prototype.postUpdate = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) {
+ this.plugins[this._p].postUpdate();
+ }
+ }
+ };
+ PluginManager.prototype.preRender = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) {
+ this.plugins[this._p].preRender();
+ }
+ }
+ };
+ PluginManager.prototype.render = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasRender) {
+ this.plugins[this._p].render();
+ }
+ }
+ };
+ PluginManager.prototype.postRender = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) {
+ this.plugins[this._p].postRender();
+ }
+ }
+ };
+ PluginManager.prototype.destroy = function () {
+ this.plugins.length = 0;
+ this._pluginsLength = 0;
+ this.game = null;
+ this._parent = null;
+ };
+ return PluginManager;
+ })();
+ Phaser.PluginManager = PluginManager;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/core/PluginManager.ts b/TS Source/core/PluginManager.ts
similarity index 100%
rename from Phaser/core/PluginManager.ts
rename to TS Source/core/PluginManager.ts
diff --git a/TS Source/core/Signal.js b/TS Source/core/Signal.js
new file mode 100644
index 00000000..6640c57b
--- /dev/null
+++ b/TS Source/core/Signal.js
@@ -0,0 +1,250 @@
+///
+/**
+* Phaser - Signal
+*
+* A Signal is used for object communication via a custom broadcaster instead of Events.
+* Based on JS Signals by Miller Medeiros. Converted by TypeScript by Richard Davey.
+* Released under the MIT license
+* http://millermedeiros.github.com/js-signals/
+*/
+var Phaser;
+(function (Phaser) {
+ var Signal = (function () {
+ function Signal() {
+ /**
+ *
+ * @property _bindings
+ * @type Array
+ * @private
+ */
+ this._bindings = [];
+ /**
+ *
+ * @property _prevParams
+ * @type Any
+ * @private
+ */
+ this._prevParams = null;
+ /**
+ * If Signal should keep record of previously dispatched parameters and
+ * automatically execute listener during `add()`/`addOnce()` if Signal was
+ * already dispatched before.
+ * @type bool
+ */
+ this.memorize = false;
+ /**
+ * @type bool
+ * @private
+ */
+ this._shouldPropagate = true;
+ /**
+ * If Signal is active and should broadcast events.
+ * IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
+ * @type bool
+ */
+ this.active = true;
+ }
+ Signal.VERSION = '1.0.0';
+ Signal.prototype.validateListener = /**
+ *
+ * @method validateListener
+ * @param {Any} listener
+ * @param {Any} fnName
+ */
+ function (listener, fnName) {
+ if(typeof listener !== 'function') {
+ throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName));
+ }
+ };
+ Signal.prototype._registerListener = /**
+ * @param {Function} listener
+ * @param {bool} isOnce
+ * @param {Object} [listenerContext]
+ * @param {Number} [priority]
+ * @return {SignalBinding}
+ * @private
+ */
+ function (listener, isOnce, listenerContext, priority) {
+ var prevIndex = this._indexOfListener(listener, listenerContext);
+ var binding;
+ if(prevIndex !== -1) {
+ binding = this._bindings[prevIndex];
+ if(binding.isOnce() !== isOnce) {
+ throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.');
+ }
+ } else {
+ binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
+ this._addBinding(binding);
+ }
+ if(this.memorize && this._prevParams) {
+ binding.execute(this._prevParams);
+ }
+ return binding;
+ };
+ Signal.prototype._addBinding = /**
+ *
+ * @method _addBinding
+ * @param {SignalBinding} binding
+ * @private
+ */
+ function (binding) {
+ //simplified insertion sort
+ var n = this._bindings.length;
+ do {
+ --n;
+ }while(this._bindings[n] && binding.priority <= this._bindings[n].priority);
+ this._bindings.splice(n + 1, 0, binding);
+ };
+ Signal.prototype._indexOfListener = /**
+ *
+ * @method _indexOfListener
+ * @param {Function} listener
+ * @return {number}
+ * @private
+ */
+ function (listener, context) {
+ var n = this._bindings.length;
+ var cur;
+ while(n--) {
+ cur = this._bindings[n];
+ if(cur.getListener() === listener && cur.context === context) {
+ return n;
+ }
+ }
+ return -1;
+ };
+ Signal.prototype.has = /**
+ * Check if listener was attached to Signal.
+ * @param {Function} listener
+ * @param {Object} [context]
+ * @return {bool} if Signal has the specified listener.
+ */
+ function (listener, context) {
+ if (typeof context === "undefined") { context = null; }
+ return this._indexOfListener(listener, context) !== -1;
+ };
+ Signal.prototype.add = /**
+ * Add a listener to the signal.
+ * @param {Function} listener Signal handler function.
+ * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
+ * @return {SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ function (listener, listenerContext, priority) {
+ if (typeof listenerContext === "undefined") { listenerContext = null; }
+ if (typeof priority === "undefined") { priority = 0; }
+ this.validateListener(listener, 'add');
+ return this._registerListener(listener, false, listenerContext, priority);
+ };
+ Signal.prototype.addOnce = /**
+ * Add listener to the signal that should be removed after first execution (will be executed only once).
+ * @param {Function} listener Signal handler function.
+ * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
+ * @return {SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ function (listener, listenerContext, priority) {
+ if (typeof listenerContext === "undefined") { listenerContext = null; }
+ if (typeof priority === "undefined") { priority = 0; }
+ this.validateListener(listener, 'addOnce');
+ return this._registerListener(listener, true, listenerContext, priority);
+ };
+ Signal.prototype.remove = /**
+ * Remove a single listener from the dispatch queue.
+ * @param {Function} listener Handler function that should be removed.
+ * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
+ * @return {Function} Listener handler function.
+ */
+ function (listener, context) {
+ if (typeof context === "undefined") { context = null; }
+ this.validateListener(listener, 'remove');
+ var i = this._indexOfListener(listener, context);
+ if(i !== -1) {
+ this._bindings[i]._destroy();
+ this._bindings.splice(i, 1);
+ }
+ return listener;
+ };
+ Signal.prototype.removeAll = /**
+ * Remove all listeners from the Signal.
+ */
+ function () {
+ if(this._bindings) {
+ var n = this._bindings.length;
+ while(n--) {
+ this._bindings[n]._destroy();
+ }
+ this._bindings.length = 0;
+ }
+ };
+ Signal.prototype.getNumListeners = /**
+ * @return {number} Number of listeners attached to the Signal.
+ */
+ function () {
+ return this._bindings.length;
+ };
+ Signal.prototype.halt = /**
+ * Stop propagation of the event, blocking the dispatch to next listeners on the queue.
+ * IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
+ * @see Signal.prototype.disable
+ */
+ function () {
+ this._shouldPropagate = false;
+ };
+ Signal.prototype.dispatch = /**
+ * Dispatch/Broadcast Signal to all listeners added to the queue.
+ * @param {...*} [params] Parameters that should be passed to each handler.
+ */
+ function () {
+ var paramsArr = [];
+ for (var _i = 0; _i < (arguments.length - 0); _i++) {
+ paramsArr[_i] = arguments[_i + 0];
+ }
+ if(!this.active) {
+ return;
+ }
+ var n = this._bindings.length;
+ var bindings;
+ if(this.memorize) {
+ this._prevParams = paramsArr;
+ }
+ if(!n) {
+ //should come after memorize
+ return;
+ }
+ bindings = this._bindings.slice(0)//clone array in case add/remove items during dispatch
+ ;
+ this._shouldPropagate = true//in case `halt` was called before dispatch or during the previous dispatch.
+ ;
+ //execute all callbacks until end of the list or until a callback returns `false` or stops propagation
+ //reverse loop since listeners with higher priority will be added at the end of the list
+ do {
+ n--;
+ }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
+ };
+ Signal.prototype.forget = /**
+ * Forget memorized arguments.
+ * @see Signal.memorize
+ */
+ function () {
+ this._prevParams = null;
+ };
+ Signal.prototype.dispose = /**
+ * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
+ * IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
+ */
+ function () {
+ this.removeAll();
+ delete this._bindings;
+ delete this._prevParams;
+ };
+ Signal.prototype.toString = /**
+ * @return {string} String representation of the object.
+ */
+ function () {
+ return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']';
+ };
+ return Signal;
+ })();
+ Phaser.Signal = Signal;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/core/Signal.ts b/TS Source/core/Signal.ts
similarity index 100%
rename from Phaser/core/Signal.ts
rename to TS Source/core/Signal.ts
diff --git a/TS Source/core/SignalBinding.js b/TS Source/core/SignalBinding.js
new file mode 100644
index 00000000..7f8dd528
--- /dev/null
+++ b/TS Source/core/SignalBinding.js
@@ -0,0 +1,113 @@
+///
+/**
+* Phaser - SignalBinding
+*
+* An object that represents a binding between a Signal and a listener function.
+* Based on JS Signals by Miller Medeiros. Converted by TypeScript by Richard Davey.
+* Released under the MIT license
+* http://millermedeiros.github.com/js-signals/
+*/
+var Phaser;
+(function (Phaser) {
+ var SignalBinding = (function () {
+ /**
+ * Object that represents a binding between a Signal and a listener function.
+ *
- This is an internal constructor and shouldn't be called by regular users.
+ *
- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
+ * @author Miller Medeiros
+ * @constructor
+ * @internal
+ * @name SignalBinding
+ * @param {Signal} signal Reference to Signal object that listener is currently bound to.
+ * @param {Function} listener Handler function bound to the signal.
+ * @param {bool} isOnce If binding should be executed just once.
+ * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. (default = 0).
+ */
+ function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
+ if (typeof priority === "undefined") { priority = 0; }
+ /**
+ * If binding is active and should be executed.
+ * @type bool
+ */
+ this.active = true;
+ /**
+ * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters)
+ * @type Array|null
+ */
+ this.params = null;
+ this._listener = listener;
+ this._isOnce = isOnce;
+ this.context = listenerContext;
+ this._signal = signal;
+ this.priority = priority || 0;
+ }
+ SignalBinding.prototype.execute = /**
+ * Call listener passing arbitrary parameters.
+ * If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
+ * @param {Array} [paramsArr] Array of parameters that should be passed to the listener
+ * @return {*} Value returned by the listener.
+ */
+ function (paramsArr) {
+ var handlerReturn;
+ var params;
+ if(this.active && !!this._listener) {
+ params = this.params ? this.params.concat(paramsArr) : paramsArr;
+ handlerReturn = this._listener.apply(this.context, params);
+ if(this._isOnce) {
+ this.detach();
+ }
+ }
+ return handlerReturn;
+ };
+ SignalBinding.prototype.detach = /**
+ * Detach binding from signal.
+ * - alias to: mySignal.remove(myBinding.getListener());
+ * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
+ */
+ function () {
+ return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
+ };
+ SignalBinding.prototype.isBound = /**
+ * @return {bool} `true` if binding is still bound to the signal and have a listener.
+ */
+ function () {
+ return (!!this._signal && !!this._listener);
+ };
+ SignalBinding.prototype.isOnce = /**
+ * @return {bool} If SignalBinding will only be executed once.
+ */
+ function () {
+ return this._isOnce;
+ };
+ SignalBinding.prototype.getListener = /**
+ * @return {Function} Handler function bound to the signal.
+ */
+ function () {
+ return this._listener;
+ };
+ SignalBinding.prototype.getSignal = /**
+ * @return {Signal} Signal that listener is currently bound to.
+ */
+ function () {
+ return this._signal;
+ };
+ SignalBinding.prototype._destroy = /**
+ * Delete instance properties
+ * @private
+ */
+ function () {
+ delete this._signal;
+ delete this._listener;
+ delete this.context;
+ };
+ SignalBinding.prototype.toString = /**
+ * @return {string} String representation of the object.
+ */
+ function () {
+ return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']';
+ };
+ return SignalBinding;
+ })();
+ Phaser.SignalBinding = SignalBinding;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/core/SignalBinding.ts b/TS Source/core/SignalBinding.ts
similarity index 100%
rename from Phaser/core/SignalBinding.ts
rename to TS Source/core/SignalBinding.ts
diff --git a/TS Source/display/CSS3Filters.js b/TS Source/display/CSS3Filters.js
new file mode 100644
index 00000000..e2213e54
--- /dev/null
+++ b/TS Source/display/CSS3Filters.js
@@ -0,0 +1,177 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Display - CSS3Filters
+ *
+ * Allows for easy addition and modification of CSS3 Filters on DOM objects (typically the Game.Stage.canvas).
+ */
+ (function (Display) {
+ var CSS3Filters = (function () {
+ /**
+ * Creates a new CSS3 Filter component
+ * @param parent The DOM object to apply the filters to.
+ */
+ function CSS3Filters(parent) {
+ this._blur = 0;
+ this._grayscale = 0;
+ this._sepia = 0;
+ this._brightness = 0;
+ this._contrast = 0;
+ this._hueRotate = 0;
+ this._invert = 0;
+ this._opacity = 0;
+ this._saturate = 0;
+ this.parent = parent;
+ }
+ CSS3Filters.prototype.setFilter = function (local, prefix, value, unit) {
+ this[local] = value;
+ if(this.parent) {
+ this.parent.style['-webkit-filter'] = prefix + '(' + value + unit + ')';
+ }
+ };
+ Object.defineProperty(CSS3Filters.prototype, "blur", {
+ get: function () {
+ return this._blur;
+ },
+ set: /**
+ * Applies a Gaussian blur to the DOM element. The value of 'radius' defines the value of the standard deviation to the Gaussian function,
+ * or how many pixels on the screen blend into each other, so a larger value will create more blur.
+ * If no parameter is provided, then a value 0 is used. The parameter is specified as a CSS length, but does not accept percentage values.
+ */
+ function (radius) {
+ this.setFilter('_blur', 'blur', radius, 'px');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "grayscale", {
+ get: function () {
+ return this._grayscale;
+ },
+ set: /**
+ * Converts the input image to grayscale. The value of 'amount' defines the proportion of the conversion.
+ * A value of 100% is completely grayscale. A value of 0% leaves the input unchanged.
+ * Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
+ */
+ function (amount) {
+ this.setFilter('_grayscale', 'grayscale', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "sepia", {
+ get: function () {
+ return this._sepia;
+ },
+ set: /**
+ * Converts the input image to sepia. The value of 'amount' defines the proportion of the conversion.
+ * A value of 100% is completely sepia. A value of 0 leaves the input unchanged.
+ * Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
+ */
+ function (amount) {
+ this.setFilter('_sepia', 'sepia', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "brightness", {
+ get: function () {
+ return this._brightness;
+ },
+ set: /**
+ * Applies a linear multiplier to input image, making it appear more or less bright.
+ * A value of 0% will create an image that is completely black. A value of 100% leaves the input unchanged.
+ * Other values are linear multipliers on the effect. Values of an amount over 100% are allowed, providing brighter results.
+ * If the 'amount' parameter is missing, a value of 100% is used.
+ */
+ function (amount) {
+ this.setFilter('_brightness', 'brightness', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "contrast", {
+ get: function () {
+ return this._contrast;
+ },
+ set: /**
+ * Adjusts the contrast of the input. A value of 0% will create an image that is completely black.
+ * A value of 100% leaves the input unchanged. Values of amount over 100% are allowed, providing results with less contrast.
+ * If the 'amount' parameter is missing, a value of 100% is used.
+ */
+ function (amount) {
+ this.setFilter('_contrast', 'contrast', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "hueRotate", {
+ get: function () {
+ return this._hueRotate;
+ },
+ set: /**
+ * Applies a hue rotation on the input image. The value of 'angle' defines the number of degrees around the color circle
+ * the input samples will be adjusted. A value of 0deg leaves the input unchanged. If the 'angle' parameter is missing,
+ * a value of 0deg is used. Maximum value is 360deg.
+ */
+ function (angle) {
+ this.setFilter('_hueRotate', 'hue-rotate', angle, 'deg');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "invert", {
+ get: function () {
+ return this._invert;
+ },
+ set: /**
+ * Inverts the samples in the input image. The value of 'amount' defines the proportion of the conversion.
+ * A value of 100% is completely inverted. A value of 0% leaves the input unchanged.
+ * Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
+ */
+ function (value) {
+ this.setFilter('_invert', 'invert', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "opacity", {
+ get: function () {
+ return this._opacity;
+ },
+ set: /**
+ * Applies transparency to the samples in the input image. The value of 'amount' defines the proportion of the conversion.
+ * A value of 0% is completely transparent. A value of 100% leaves the input unchanged.
+ * Values between 0% and 100% are linear multipliers on the effect. This is equivalent to multiplying the input image samples by amount.
+ * If the 'amount' parameter is missing, a value of 100% is used.
+ * This function is similar to the more established opacity property; the difference is that with filters, some browsers provide hardware acceleration for better performance.
+ */
+ function (value) {
+ this.setFilter('_opacity', 'opacity', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "saturate", {
+ get: function () {
+ return this._saturate;
+ },
+ set: /**
+ * Saturates the input image. The value of 'amount' defines the proportion of the conversion.
+ * A value of 0% is completely un-saturated. A value of 100% leaves the input unchanged.
+ * Other values are linear multipliers on the effect. Values of amount over 100% are allowed, providing super-saturated results.
+ * If the 'amount' parameter is missing, a value of 100% is used.
+ */
+ function (value) {
+ this.setFilter('_saturate', 'saturate', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return CSS3Filters;
+ })();
+ Display.CSS3Filters = CSS3Filters;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/display/CSS3Filters.ts b/TS Source/display/CSS3Filters.ts
similarity index 100%
rename from Phaser/display/CSS3Filters.ts
rename to TS Source/display/CSS3Filters.ts
diff --git a/TS Source/display/DynamicTexture.js b/TS Source/display/DynamicTexture.js
new file mode 100644
index 00000000..2ac6fbee
--- /dev/null
+++ b/TS Source/display/DynamicTexture.js
@@ -0,0 +1,238 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Display - DynamicTexture
+ *
+ * A DynamicTexture can be thought of as a mini canvas into which you can draw anything.
+ * Game Objects can be assigned a DynamicTexture, so when they render in the world they do so
+ * based on the contents of the texture at the time. This allows you to create powerful effects
+ * once and have them replicated across as many game objects as you like.
+ */
+ (function (Display) {
+ var DynamicTexture = (function () {
+ /**
+ * DynamicTexture constructor
+ * Create a new DynamicTexture.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param width {number} Init width of this texture.
+ * @param height {number} Init height of this texture.
+ */
+ function DynamicTexture(game, width, height) {
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ /**
+ * You can set a globalCompositeOperation that will be applied before the render method is called on this Sprite.
+ * This is useful if you wish to apply an effect like 'lighten'.
+ * If this value is set it will call a canvas context save and restore before and after the render pass, so use it sparingly.
+ * Set to null to disable.
+ */
+ this.globalCompositeOperation = null;
+ this.game = game;
+ this.type = Phaser.Types.DYNAMICTEXTURE;
+ this.canvas = document.createElement('canvas');
+ this.canvas.width = width;
+ this.canvas.height = height;
+ this.context = this.canvas.getContext('2d');
+ this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
+ this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ }
+ DynamicTexture.prototype.getPixel = /**
+ * Get a color of a specific pixel.
+ * @param x {number} X position of the pixel in this texture.
+ * @param y {number} Y position of the pixel in this texture.
+ * @return {number} A native color value integer (format: 0xRRGGBB)
+ */
+ function (x, y) {
+ //r = imageData.data[0];
+ //g = imageData.data[1];
+ //b = imageData.data[2];
+ //a = imageData.data[3];
+ var imageData = this.context.getImageData(x, y, 1, 1);
+ return Phaser.ColorUtils.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ DynamicTexture.prototype.getPixel32 = /**
+ * Get a color of a specific pixel (including alpha value).
+ * @param x {number} X position of the pixel in this texture.
+ * @param y {number} Y position of the pixel in this texture.
+ * @return A native color value integer (format: 0xAARRGGBB)
+ */
+ function (x, y) {
+ var imageData = this.context.getImageData(x, y, 1, 1);
+ return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ DynamicTexture.prototype.getPixels = /**
+ * Get pixels in array in a specific Rectangle.
+ * @param rect {Rectangle} The specific Rectangle.
+ * @returns {array} CanvasPixelArray.
+ */
+ function (rect) {
+ return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
+ };
+ DynamicTexture.prototype.setPixel = /**
+ * Set color of a specific pixel.
+ * @param x {number} X position of the target pixel.
+ * @param y {number} Y position of the target pixel.
+ * @param color {number} Native integer with color value. (format: 0xRRGGBB)
+ */
+ function (x, y, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(x, y, 1, 1);
+ };
+ DynamicTexture.prototype.setPixel32 = /**
+ * Set color (with alpha) of a specific pixel.
+ * @param x {number} X position of the target pixel.
+ * @param y {number} Y position of the target pixel.
+ * @param color {number} Native integer with color value. (format: 0xAARRGGBB)
+ */
+ function (x, y, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(x, y, 1, 1);
+ };
+ DynamicTexture.prototype.setPixels = /**
+ * Set image data to a specific Rectangle.
+ * @param rect {Rectangle} Target Rectangle.
+ * @param input {object} Source image data.
+ */
+ function (rect, input) {
+ this.context.putImageData(input, rect.x, rect.y);
+ };
+ DynamicTexture.prototype.fillRect = /**
+ * Fill a given Rectangle with specific color.
+ * @param rect {Rectangle} Target Rectangle you want to fill.
+ * @param color {number} A native number with color value. (format: 0xRRGGBB)
+ */
+ function (rect, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
+ DynamicTexture.prototype.pasteImage = /**
+ *
+ */
+ function (key, frame, destX, destY, destWidth, destHeight) {
+ if (typeof frame === "undefined") { frame = -1; }
+ if (typeof destX === "undefined") { destX = 0; }
+ if (typeof destY === "undefined") { destY = 0; }
+ if (typeof destWidth === "undefined") { destWidth = null; }
+ if (typeof destHeight === "undefined") { destHeight = null; }
+ var texture = null;
+ var frameData;
+ this._sx = 0;
+ this._sy = 0;
+ this._dx = destX;
+ this._dy = destY;
+ // TODO - Load a frame from a sprite sheet, otherwise we'll draw the whole lot
+ if(frame > -1) {
+ //if (this.game.cache.isSpriteSheet(key))
+ //{
+ // texture = this.game.cache.getImage(key);
+ //this.animations.loadFrameData(this.game.cache.getFrameData(key));
+ //}
+ } else {
+ texture = this.game.cache.getImage(key);
+ this._sw = texture.width;
+ this._sh = texture.height;
+ this._dw = texture.width;
+ this._dh = texture.height;
+ }
+ if(destWidth !== null) {
+ this._dw = destWidth;
+ }
+ if(destHeight !== null) {
+ this._dh = destHeight;
+ }
+ if(texture != null) {
+ this.context.drawImage(texture, // Source Image
+ this._sx, // Source X (location within the source image)
+ this._sy, // Source Y
+ this._sw, // Source Width
+ this._sh, // Source Height
+ this._dx, // Destination X (where on the canvas it'll be drawn)
+ this._dy, // Destination Y
+ this._dw, // Destination Width (always same as Source Width unless scaled)
+ this._dh);
+ // Destination Height (always same as Source Height unless scaled)
+ }
+ };
+ DynamicTexture.prototype.copyPixels = // TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
+ /**
+ * Copy pixel from another DynamicTexture to this texture.
+ * @param sourceTexture {DynamicTexture} Source texture object.
+ * @param sourceRect {Rectangle} The specific region Rectangle to be copied to this in the source.
+ * @param destPoint {Point} Top-left point the target image data will be paste at.
+ */
+ function (sourceTexture, sourceRect, destPoint) {
+ // Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
+ if(Phaser.RectangleUtils.equals(sourceRect, this.bounds) == true) {
+ this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
+ } else {
+ this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
+ }
+ };
+ DynamicTexture.prototype.add = function (sprite) {
+ sprite.texture.canvas = this.canvas;
+ sprite.texture.context = this.context;
+ };
+ DynamicTexture.prototype.assignCanvasToGameObjects = /**
+ * Given an array of Sprites it will update each of them so that their canvas/contexts reference this DynamicTexture
+ * @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
+ */
+ function (objects) {
+ for(var i = 0; i < objects.length; i++) {
+ if(objects[i].texture) {
+ objects[i].texture.canvas = this.canvas;
+ objects[i].texture.context = this.context;
+ }
+ }
+ };
+ DynamicTexture.prototype.clear = /**
+ * Clear the whole canvas.
+ */
+ function () {
+ this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
+ };
+ DynamicTexture.prototype.render = /**
+ * Renders this DynamicTexture to the Stage at the given x/y coordinates
+ *
+ * @param x {number} The X coordinate to render on the stage to (given in screen coordinates, not world)
+ * @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
+ */
+ function (x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if(this.globalCompositeOperation) {
+ this.game.stage.context.save();
+ this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
+ }
+ this.game.stage.context.drawImage(this.canvas, x, y);
+ if(this.globalCompositeOperation) {
+ this.game.stage.context.restore();
+ }
+ };
+ Object.defineProperty(DynamicTexture.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(DynamicTexture.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return DynamicTexture;
+ })();
+ Display.DynamicTexture = DynamicTexture;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/display/DynamicTexture.ts b/TS Source/display/DynamicTexture.ts
similarity index 100%
rename from Phaser/display/DynamicTexture.ts
rename to TS Source/display/DynamicTexture.ts
diff --git a/TS Source/display/Texture.js b/TS Source/display/Texture.js
new file mode 100644
index 00000000..68e29473
--- /dev/null
+++ b/TS Source/display/Texture.js
@@ -0,0 +1,218 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Display - Texture
+ *
+ * The Texture being used to render the object (Sprite, Group background, etc). Either Image based on a DynamicTexture.
+ */
+ (function (Display) {
+ var Texture = (function () {
+ /**
+ * Creates a new Texture component
+ * @param parent The object using this Texture to render.
+ * @param key An optional Game.Cache key to load an image from
+ */
+ function Texture(parent) {
+ /**
+ * Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite.
+ */
+ this.imageTexture = null;
+ /**
+ * Reference to the DynamicTexture that is used as the texture for the Sprite.
+ * @type {DynamicTexture}
+ */
+ this.dynamicTexture = null;
+ /**
+ * The load status of the texture image.
+ * @type {bool}
+ */
+ this.loaded = false;
+ /**
+ * 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 {bool}
+ */
+ this.opaque = false;
+ /**
+ * The Background Color of the Sprite if Texture.opaque is set to true.
+ * Given in css color string format, i.e. 'rgb(0,0,0)' or '#ff0000'.
+ * @type {string}
+ */
+ this.backgroundColor = 'rgb(255,255,255)';
+ /**
+ * You can set a globalCompositeOperation that will be applied before the render method is called on this Sprite.
+ * This is useful if you wish to apply an effect like 'lighten'.
+ * If this value is set it will call a canvas context save and restore before and after the render pass, so use it sparingly.
+ * Set to null to disable.
+ */
+ this.globalCompositeOperation = null;
+ /**
+ * Controls if the Sprite is rendered rotated or not.
+ * If renderRotation is false then the object can still rotate but it will never be rendered rotated.
+ * @type {bool}
+ */
+ this.renderRotation = true;
+ /**
+ * Flip the graphic horizontally (defaults to false)
+ * @type {bool}
+ */
+ this.flippedX = false;
+ /**
+ * Flip the graphic vertically (defaults to false)
+ * @type {bool}
+ */
+ this.flippedY = false;
+ /**
+ * Is the texture a DynamicTexture?
+ * @type {bool}
+ */
+ this.isDynamic = false;
+ this.game = parent.game;
+ this.parent = parent;
+ this.canvas = parent.game.stage.canvas;
+ this.context = parent.game.stage.context;
+ this.alpha = 1;
+ this.flippedX = false;
+ this.flippedY = false;
+ this._width = 16;
+ this._height = 16;
+ this.cameraBlacklist = [];
+ this._blacklist = 0;
+ }
+ Texture.prototype.hideFromCamera = /**
+ * Hides an object from this Camera. Hidden objects are not rendered.
+ *
+ * @param object {Camera} The camera this object should ignore.
+ */
+ function (camera) {
+ if(this.isHidden(camera) == false) {
+ this.cameraBlacklist.push(camera.ID);
+ this._blacklist++;
+ }
+ };
+ Texture.prototype.isHidden = /**
+ * Returns true if this texture is hidden from rendering to the given camera, otherwise false.
+ */
+ function (camera) {
+ if(this._blacklist && this.cameraBlacklist.indexOf(camera.ID) !== -1) {
+ return true;
+ }
+ return false;
+ };
+ Texture.prototype.showToCamera = /**
+ * Un-hides an object previously hidden to this Camera.
+ * The object must implement a public cameraBlacklist property.
+ *
+ * @param object {Sprite/Group} The object this camera should display.
+ */
+ function (camera) {
+ if(this.isHidden(camera)) {
+ this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
+ this._blacklist--;
+ }
+ };
+ Texture.prototype.setTo = /**
+ * Updates the texture being used to render the Sprite.
+ * Called automatically by SpriteUtils.loadTexture and SpriteUtils.loadDynamicTexture.
+ */
+ function (image, dynamic) {
+ if (typeof image === "undefined") { image = null; }
+ if (typeof dynamic === "undefined") { dynamic = null; }
+ if(dynamic) {
+ this.isDynamic = true;
+ this.dynamicTexture = dynamic;
+ this.texture = this.dynamicTexture.canvas;
+ } else {
+ this.isDynamic = false;
+ this.imageTexture = image;
+ this.texture = this.imageTexture;
+ this._width = image.width;
+ this._height = image.height;
+ }
+ this.loaded = true;
+ return this.parent;
+ };
+ Texture.prototype.loadImage = /**
+ * Sets a new graphic from the game cache to use as the texture for this Sprite.
+ * The graphic can be SpriteSheet or Texture Atlas. If you need to use a DynamicTexture see loadDynamicTexture.
+ * @param key {string} Key of the graphic you want to load for this sprite.
+ * @param clearAnimations {bool} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this bool
+ * @param updateBody {bool} Update the physics body dimensions to match the newly loaded texture/frame?
+ */
+ function (key, clearAnimations, updateBody) {
+ if (typeof clearAnimations === "undefined") { clearAnimations = true; }
+ if (typeof updateBody === "undefined") { updateBody = true; }
+ if(clearAnimations && this.parent['animations'] && this.parent['animations'].frameData !== null) {
+ this.parent.animations.destroy();
+ }
+ if(this.game.cache.getImage(key) !== null) {
+ this.setTo(this.game.cache.getImage(key), null);
+ this.cacheKey = key;
+ if(this.game.cache.isSpriteSheet(key) && this.parent['animations']) {
+ this.parent.animations.loadFrameData(this.parent.game.cache.getFrameData(key));
+ } else {
+ if(updateBody && this.parent['body']) {
+ this.parent.body.bounds.width = this.width;
+ this.parent.body.bounds.height = this.height;
+ }
+ }
+ }
+ };
+ Texture.prototype.loadDynamicTexture = /**
+ * Load a DynamicTexture as its texture.
+ * @param texture {DynamicTexture} The texture object to be used by this sprite.
+ */
+ function (texture) {
+ if(this.parent.animations.frameData !== null) {
+ this.parent.animations.destroy();
+ }
+ this.setTo(null, texture);
+ this.parent.texture.width = this.width;
+ this.parent.texture.height = this.height;
+ };
+ Object.defineProperty(Texture.prototype, "width", {
+ get: /**
+ * The width of the texture. If an animation it will be the frame width, not the width of the sprite sheet.
+ * If using a DynamicTexture it will be the width of the dynamic texture itself.
+ * @type {number}
+ */
+ function () {
+ if(this.isDynamic) {
+ return this.dynamicTexture.width;
+ } else {
+ return this._width;
+ }
+ },
+ set: function (value) {
+ this._width = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Texture.prototype, "height", {
+ get: /**
+ * The height of the texture. If an animation it will be the frame height, not the height of the sprite sheet.
+ * If using a DynamicTexture it will be the height of the dynamic texture itself.
+ * @type {number}
+ */
+ function () {
+ if(this.isDynamic) {
+ return this.dynamicTexture.height;
+ } else {
+ return this._height;
+ }
+ },
+ set: function (value) {
+ this._height = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Texture;
+ })();
+ Display.Texture = Texture;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/display/Texture.ts b/TS Source/display/Texture.ts
similarity index 100%
rename from Phaser/display/Texture.ts
rename to TS Source/display/Texture.ts
diff --git a/TS Source/gameobjects/Events.js b/TS Source/gameobjects/Events.js
new file mode 100644
index 00000000..7393e4b8
--- /dev/null
+++ b/TS Source/gameobjects/Events.js
@@ -0,0 +1,29 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Components - Events
+ *
+ * Signals that are dispatched by the Sprite and its various components
+ */
+ (function (Components) {
+ var Events = (function () {
+ /**
+ * The Events component is a collection of events fired by the parent game object and its components.
+ * @param parent The game object using this Input component
+ */
+ function Events(parent) {
+ this.game = parent.game;
+ this._parent = parent;
+ this.onAddedToGroup = new Phaser.Signal();
+ this.onRemovedFromGroup = new Phaser.Signal();
+ this.onKilled = new Phaser.Signal();
+ this.onRevived = new Phaser.Signal();
+ this.onOutOfBounds = new Phaser.Signal();
+ }
+ return Events;
+ })();
+ Components.Events = Events;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/gameobjects/Events.ts b/TS Source/gameobjects/Events.ts
similarity index 100%
rename from Phaser/gameobjects/Events.ts
rename to TS Source/gameobjects/Events.ts
diff --git a/TS Source/gameobjects/GameObjectFactory.js b/TS Source/gameobjects/GameObjectFactory.js
new file mode 100644
index 00000000..b71e94a8
--- /dev/null
+++ b/TS Source/gameobjects/GameObjectFactory.js
@@ -0,0 +1,260 @@
+///
+/**
+* Phaser - GameObjectFactory
+*
+* A quick way to create new world objects and add existing objects to the current world.
+*/
+var Phaser;
+(function (Phaser) {
+ var GameObjectFactory = (function () {
+ /**
+ * GameObjectFactory constructor
+ * @param game {Game} A reference to the current Game.
+ */
+ function GameObjectFactory(game) {
+ this.game = game;
+ this._world = this.game.world;
+ }
+ GameObjectFactory.prototype.camera = /**
+ * Create a new camera with specific position and size.
+ *
+ * @param x {number} X position of the new camera.
+ * @param y {number} Y position of the new camera.
+ * @param width {number} Width of the new camera.
+ * @param height {number} Height of the new camera.
+ * @returns {Camera} The newly created camera object.
+ */
+ function (x, y, width, height) {
+ return this._world.cameras.addCamera(x, y, width, height);
+ };
+ GameObjectFactory.prototype.button = /**
+ * Create a new GeomSprite with specific position.
+ *
+ * @param x {number} X position of the new geom sprite.
+ * @param y {number} Y position of the new geom sprite.
+ * @returns {GeomSprite} The newly created geom sprite object.
+ */
+ //public geomSprite(x: number, y: number): GeomSprite {
+ // return this._world.group.add(new GeomSprite(this.game, x, y));
+ //}
+ /**
+ * Create a new Button game object.
+ *
+ * @param [x] {number} X position of the button.
+ * @param [y] {number} Y position of the button.
+ * @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button.
+ * @param [callback] {function} The function to call when this button is pressed
+ * @param [callbackContext] {object} The context in which the callback will be called (usually 'this')
+ * @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+ * @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+ * @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
+ * @returns {Button} The newly created button object.
+ */
+ function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof callbackContext === "undefined") { callbackContext = null; }
+ if (typeof overFrame === "undefined") { overFrame = null; }
+ if (typeof outFrame === "undefined") { outFrame = null; }
+ if (typeof downFrame === "undefined") { downFrame = null; }
+ return this._world.group.add(new Phaser.UI.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
+ };
+ GameObjectFactory.prototype.sprite = /**
+ * Create a new Sprite with specific position and sprite sheet key.
+ *
+ * @param x {number} X position of the new sprite.
+ * @param y {number} Y position of the new sprite.
+ * @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
+ * @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
+ * @returns {Sprite} The newly created sprite object.
+ */
+ function (x, y, key, frame) {
+ if (typeof key === "undefined") { key = ''; }
+ if (typeof frame === "undefined") { frame = null; }
+ return this._world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
+ };
+ GameObjectFactory.prototype.audio = function (key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ return this.game.sound.add(key, volume, loop);
+ };
+ GameObjectFactory.prototype.circle = function (x, y, radius) {
+ return new Phaser.Physics.Circle(this.game, x, y, radius);
+ };
+ GameObjectFactory.prototype.aabb = function (x, y, width, height) {
+ return new Phaser.Physics.AABB(this.game, x, y, Math.floor(width / 2), Math.floor(height / 2));
+ };
+ GameObjectFactory.prototype.cell = function (x, y, width, height, state) {
+ if (typeof state === "undefined") { state = Phaser.Physics.TileMapCell.TID_FULL; }
+ return new Phaser.Physics.TileMapCell(this.game, x, y, width, height).SetState(state);
+ };
+ GameObjectFactory.prototype.dynamicTexture = /**
+ * Create a new DynamicTexture with specific size.
+ *
+ * @param width {number} Width of the texture.
+ * @param height {number} Height of the texture.
+ * @returns {DynamicTexture} The newly created dynamic texture object.
+ */
+ function (width, height) {
+ return new Phaser.Display.DynamicTexture(this.game, width, height);
+ };
+ GameObjectFactory.prototype.group = /**
+ * Create a new object container.
+ *
+ * @param maxSize {number} Optional, capacity of this group.
+ * @returns {Group} The newly created group.
+ */
+ function (maxSize) {
+ if (typeof maxSize === "undefined") { maxSize = 0; }
+ return this._world.group.add(new Phaser.Group(this.game, maxSize));
+ };
+ GameObjectFactory.prototype.scrollZone = /**
+ * Create a new Particle.
+ *
+ * @return {Particle} The newly created particle object.
+ */
+ //public particle(): Phaser.ArcadeParticle {
+ // return new Phaser.ArcadeParticle(this.game);
+ //}
+ /**
+ * Create a new Emitter.
+ *
+ * @param x {number} Optional, x position of the emitter.
+ * @param y {number} Optional, y position of the emitter.
+ * @param size {number} Optional, size of this emitter.
+ * @return {Emitter} The newly created emitter object.
+ */
+ //public emitter(x: number = 0, y: number = 0, size: number = 0): Phaser.ArcadeEmitter {
+ // return this._world.group.add(new Phaser.ArcadeEmitter(this.game, x, y, size));
+ //}
+ /**
+ * Create a new ScrollZone object with image key, position and size.
+ *
+ * @param key {string} Key to a image you wish this object to use.
+ * @param x {number} X position of this object.
+ * @param y {number} Y position of this object.
+ * @param width number} Width of this object.
+ * @param height {number} Height of this object.
+ * @returns {ScrollZone} The newly created scroll zone object.
+ */
+ function (key, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ return this._world.group.add(new Phaser.ScrollZone(this.game, key, x, y, width, height));
+ };
+ GameObjectFactory.prototype.tilemap = /**
+ * Create a new Tilemap.
+ *
+ * @param key {string} Key for tileset image.
+ * @param mapData {string} Data of this tilemap.
+ * @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
+ * @param [resizeWorld] {bool} resize the world to make same as tilemap?
+ * @param [tileWidth] {number} width of each tile.
+ * @param [tileHeight] {number} height of each tile.
+ * @return {Tilemap} The newly created tilemap object.
+ */
+ function (key, mapData, format, resizeWorld, tileWidth, tileHeight) {
+ if (typeof resizeWorld === "undefined") { resizeWorld = true; }
+ if (typeof tileWidth === "undefined") { tileWidth = 0; }
+ if (typeof tileHeight === "undefined") { tileHeight = 0; }
+ return this._world.group.add(new Phaser.Tilemap(this.game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
+ };
+ GameObjectFactory.prototype.tween = /**
+ * Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
+ *
+ * @param obj {object} Object the tween will be run on.
+ * @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
+ * @return {Phaser.Tween} The newly created tween object.
+ */
+ function (obj, localReference) {
+ if (typeof localReference === "undefined") { localReference = false; }
+ return this.game.tweens.create(obj, localReference);
+ };
+ GameObjectFactory.prototype.existingSprite = /**
+ * Add an existing Sprite to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param sprite The Sprite to add to the Game World
+ * @return {Phaser.Sprite} The Sprite object
+ */
+ function (sprite) {
+ return this._world.group.add(sprite);
+ };
+ GameObjectFactory.prototype.existingGroup = /**
+ * Add an existing Group to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param group The Group to add to the Game World
+ * @return {Phaser.Group} The Group object
+ */
+ function (group) {
+ return this._world.group.add(group);
+ };
+ GameObjectFactory.prototype.existingButton = /**
+ * Add an existing Button to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param button The Button to add to the Game World
+ * @return {Phaser.Button} The Button object
+ */
+ function (button) {
+ return this._world.group.add(button);
+ };
+ GameObjectFactory.prototype.existingScrollZone = /**
+ * Add an existing GeomSprite to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param sprite The GeomSprite to add to the Game World
+ * @return {Phaser.GeomSprite} The GeomSprite object
+ */
+ //public existingGeomSprite(sprite: GeomSprite): GeomSprite {
+ // return this._world.group.add(sprite);
+ //}
+ /**
+ * Add an existing Emitter to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param emitter The Emitter to add to the Game World
+ * @return {Phaser.Emitter} The Emitter object
+ */
+ //public existingEmitter(emitter: Phaser.ArcadeEmitter): Phaser.ArcadeEmitter {
+ // return this._world.group.add(emitter);
+ //}
+ /**
+ * Add an existing ScrollZone to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param scrollZone The ScrollZone to add to the Game World
+ * @return {Phaser.ScrollZone} The ScrollZone object
+ */
+ function (scrollZone) {
+ return this._world.group.add(scrollZone);
+ };
+ GameObjectFactory.prototype.existingTilemap = /**
+ * Add an existing Tilemap to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param tilemap The Tilemap to add to the Game World
+ * @return {Phaser.Tilemap} The Tilemap object
+ */
+ function (tilemap) {
+ return this._world.group.add(tilemap);
+ };
+ GameObjectFactory.prototype.existingTween = /**
+ * Add an existing Tween to the current world.
+ * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
+ *
+ * @param tween The Tween to add to the Game World
+ * @return {Phaser.Tween} The Tween object
+ */
+ function (tween) {
+ return this.game.tweens.add(tween);
+ };
+ return GameObjectFactory;
+ })();
+ Phaser.GameObjectFactory = GameObjectFactory;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/gameobjects/GameObjectFactory.ts b/TS Source/gameobjects/GameObjectFactory.ts
similarity index 100%
rename from Phaser/gameobjects/GameObjectFactory.ts
rename to TS Source/gameobjects/GameObjectFactory.ts
diff --git a/Phaser/gameobjects/IGameObject.ts b/TS Source/gameobjects/IGameObject.ts
similarity index 100%
rename from Phaser/gameobjects/IGameObject.ts
rename to TS Source/gameobjects/IGameObject.ts
diff --git a/TS Source/gameobjects/ScrollRegion.js b/TS Source/gameobjects/ScrollRegion.js
new file mode 100644
index 00000000..a07b1912
--- /dev/null
+++ b/TS Source/gameobjects/ScrollRegion.js
@@ -0,0 +1,148 @@
+///
+/**
+* Phaser - ScrollRegion
+*
+* Creates a scrolling region within a ScrollZone.
+* It is scrolled via the scrollSpeed.x/y properties.
+*/
+var Phaser;
+(function (Phaser) {
+ var ScrollRegion = (function () {
+ /**
+ * ScrollRegion constructor
+ * Create a new ScrollRegion.
+ *
+ * @param x {number} X position in world coordinate.
+ * @param y {number} Y position in world coordinate.
+ * @param width {number} Width of this object.
+ * @param height {number} Height of this object.
+ * @param speedX {number} X-axis scrolling speed.
+ * @param speedY {number} Y-axis scrolling speed.
+ */
+ function ScrollRegion(x, y, width, height, speedX, speedY) {
+ this._anchorWidth = 0;
+ this._anchorHeight = 0;
+ this._inverseWidth = 0;
+ this._inverseHeight = 0;
+ /**
+ * Will this region be rendered? (default to true)
+ * @type {bool}
+ */
+ this.visible = true;
+ // Our seamless scrolling quads
+ this._A = new Phaser.Rectangle(x, y, width, height);
+ this._B = new Phaser.Rectangle(x, y, width, height);
+ this._C = new Phaser.Rectangle(x, y, width, height);
+ this._D = new Phaser.Rectangle(x, y, width, height);
+ this._scroll = new Phaser.Vec2();
+ this._bounds = new Phaser.Rectangle(x, y, width, height);
+ this.scrollSpeed = new Phaser.Vec2(speedX, speedY);
+ }
+ ScrollRegion.prototype.update = /**
+ * Update region scrolling with tick time.
+ * @param delta {number} Elapsed time since last update.
+ */
+ function (delta) {
+ this._scroll.x += this.scrollSpeed.x;
+ this._scroll.y += this.scrollSpeed.y;
+ if(this._scroll.x > this._bounds.right) {
+ this._scroll.x = this._bounds.x;
+ }
+ if(this._scroll.x < this._bounds.x) {
+ this._scroll.x = this._bounds.right;
+ }
+ if(this._scroll.y > this._bounds.bottom) {
+ this._scroll.y = this._bounds.y;
+ }
+ if(this._scroll.y < this._bounds.y) {
+ this._scroll.y = this._bounds.bottom;
+ }
+ // Anchor Dimensions
+ this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
+ this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
+ if(this._anchorWidth > this._bounds.width) {
+ this._anchorWidth = this._bounds.width;
+ }
+ if(this._anchorHeight > this._bounds.height) {
+ this._anchorHeight = this._bounds.height;
+ }
+ this._inverseWidth = this._bounds.width - this._anchorWidth;
+ this._inverseHeight = this._bounds.height - this._anchorHeight;
+ // Rectangle A
+ this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
+ // Rectangle B
+ this._B.y = this._scroll.y;
+ this._B.width = this._inverseWidth;
+ this._B.height = this._anchorHeight;
+ // Rectangle C
+ this._C.x = this._scroll.x;
+ this._C.width = this._anchorWidth;
+ this._C.height = this._inverseHeight;
+ // Rectangle D
+ this._D.width = this._inverseWidth;
+ this._D.height = this._inverseHeight;
+ };
+ ScrollRegion.prototype.render = /**
+ * Render this region to specific context.
+ * @param context {CanvasRenderingContext2D} Canvas context this region will be rendered to.
+ * @param texture {object} The texture to be rendered.
+ * @param dx {number} X position in world coordinate.
+ * @param dy {number} Y position in world coordinate.
+ * @param width {number} Width of this region to be rendered.
+ * @param height {number} Height of this region to be rendered.
+ */
+ function (context, texture, dx, dy, dw, dh) {
+ if(this.visible == false) {
+ return;
+ }
+ // dx/dy are the world coordinates to render the FULL ScrollZone into.
+ // This ScrollRegion may be smaller than that and offset from the dx/dy coordinates.
+ this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
+ this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
+ this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
+ this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
+ //context.fillStyle = 'rgb(255,255,255)';
+ //context.font = '18px Arial';
+ //context.fillText('RectangleA: ' + this._A.toString(), 32, 450);
+ //context.fillText('RectangleB: ' + this._B.toString(), 32, 480);
+ //context.fillText('RectangleC: ' + this._C.toString(), 32, 510);
+ //context.fillText('RectangleD: ' + this._D.toString(), 32, 540);
+ };
+ ScrollRegion.prototype.crop = /**
+ * Crop part of the texture and render it to the given context.
+ * @param context {CanvasRenderingContext2D} Canvas context the texture will be rendered to.
+ * @param texture {object} Texture to be rendered.
+ * @param srcX {number} Target region top-left x coordinate in the texture.
+ * @param srcX {number} Target region top-left y coordinate in the texture.
+ * @param srcW {number} Target region width in the texture.
+ * @param srcH {number} Target region height in the texture.
+ * @param destX {number} Render region top-left x coordinate in the context.
+ * @param destX {number} Render region top-left y coordinate in the context.
+ * @param destW {number} Target region width in the context.
+ * @param destH {number} Target region height in the context.
+ * @param offsetX {number} X offset to the context.
+ * @param offsetY {number} Y offset to the context.
+ */
+ function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
+ offsetX += destX;
+ offsetY += destY;
+ if(srcW > (destX + destW) - offsetX) {
+ srcW = (destX + destW) - offsetX;
+ }
+ if(srcH > (destY + destH) - offsetY) {
+ srcH = (destY + destH) - offsetY;
+ }
+ srcX = Math.floor(srcX);
+ srcY = Math.floor(srcY);
+ srcW = Math.floor(srcW);
+ srcH = Math.floor(srcH);
+ offsetX = Math.floor(offsetX + this._bounds.x);
+ offsetY = Math.floor(offsetY + this._bounds.y);
+ if(srcW > 0 && srcH > 0) {
+ context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
+ }
+ };
+ return ScrollRegion;
+ })();
+ Phaser.ScrollRegion = ScrollRegion;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/gameobjects/ScrollRegion.ts b/TS Source/gameobjects/ScrollRegion.ts
similarity index 100%
rename from Phaser/gameobjects/ScrollRegion.ts
rename to TS Source/gameobjects/ScrollRegion.ts
diff --git a/TS Source/gameobjects/ScrollZone.js b/TS Source/gameobjects/ScrollZone.js
new file mode 100644
index 00000000..b293617d
--- /dev/null
+++ b/TS Source/gameobjects/ScrollZone.js
@@ -0,0 +1,111 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+///
+/**
+* Phaser - ScrollZone
+*
+* Creates a scrolling region of the given width and height from an image in the cache.
+* The ScrollZone can be positioned anywhere in-world like a normal game object, re-act to physics, collision, etc.
+* The image within it is scrolled via ScrollRegions and their scrollSpeed.x/y properties.
+* If you create a scroll zone larger than the given source image it will create a DynamicTexture and fill it with a pattern of the source image.
+*/
+var Phaser;
+(function (Phaser) {
+ var ScrollZone = (function (_super) {
+ __extends(ScrollZone, _super);
+ /**
+ * ScrollZone constructor
+ * Create a new ScrollZone.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param key {string} Asset key for image texture of this object.
+ * @param x {number} X position in world coordinate.
+ * @param y {number} Y position in world coordinate.
+ * @param [width] {number} width of this object.
+ * @param [height] {number} height of this object.
+ */
+ function ScrollZone(game, key, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ _super.call(this, game, x, y, key);
+ this.type = Phaser.Types.SCROLLZONE;
+ this.regions = [];
+ if(this.texture.loaded) {
+ if(width > this.width || height > this.height) {
+ // Create our repeating texture (as the source image wasn't large enough for the requested size)
+ this.createRepeatingTexture(width, height);
+ this.width = width;
+ this.height = height;
+ }
+ // Create a default ScrollRegion at the requested size
+ this.addRegion(0, 0, this.width, this.height);
+ // If the zone is smaller than the image itself then shrink the bounds
+ if((width < this.width || height < this.height) && width !== 0 && height !== 0) {
+ this.width = width;
+ this.height = height;
+ }
+ }
+ }
+ ScrollZone.prototype.addRegion = /**
+ * Add a new region to this zone.
+ * @param x {number} X position of the new region.
+ * @param y {number} Y position of the new region.
+ * @param width {number} Width of the new region.
+ * @param height {number} Height of the new region.
+ * @param [speedX] {number} x-axis scrolling speed.
+ * @param [speedY] {number} y-axis scrolling speed.
+ * @return {ScrollRegion} The newly added region.
+ */
+ function (x, y, width, height, speedX, speedY) {
+ if (typeof speedX === "undefined") { speedX = 0; }
+ if (typeof speedY === "undefined") { speedY = 0; }
+ if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
+ throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
+ return null;
+ }
+ this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
+ this.regions.push(this.currentRegion);
+ return this.currentRegion;
+ };
+ ScrollZone.prototype.setSpeed = /**
+ * Set scrolling speed of current region.
+ * @param x {number} X speed of current region.
+ * @param y {number} Y speed of current region.
+ */
+ function (x, y) {
+ if(this.currentRegion) {
+ this.currentRegion.scrollSpeed.setTo(x, y);
+ }
+ return this;
+ };
+ ScrollZone.prototype.update = /**
+ * Update regions.
+ */
+ function () {
+ for(var i = 0; i < this.regions.length; i++) {
+ this.regions[i].update(this.game.time.delta);
+ }
+ };
+ ScrollZone.prototype.createRepeatingTexture = /**
+ * Create repeating texture with _texture, and store it into the _dynamicTexture.
+ * Used to create texture when texture image is small than size of the zone.
+ */
+ function (regionWidth, regionHeight) {
+ // Work out how many we'll need of the source image to make it tile properly
+ var tileWidth = Math.ceil(this.width / regionWidth) * regionWidth;
+ var tileHeight = Math.ceil(this.height / regionHeight) * regionHeight;
+ var dt = new Phaser.Display.DynamicTexture(this.game, tileWidth, tileHeight);
+ dt.context.rect(0, 0, tileWidth, tileHeight);
+ dt.context.fillStyle = dt.context.createPattern(this.texture.imageTexture, "repeat");
+ dt.context.fill();
+ this.texture.loadDynamicTexture(dt);
+ };
+ return ScrollZone;
+ })(Phaser.Sprite);
+ Phaser.ScrollZone = ScrollZone;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/gameobjects/ScrollZone.ts b/TS Source/gameobjects/ScrollZone.ts
similarity index 100%
rename from Phaser/gameobjects/ScrollZone.ts
rename to TS Source/gameobjects/ScrollZone.ts
diff --git a/TS Source/gameobjects/Sprite.js b/TS Source/gameobjects/Sprite.js
new file mode 100644
index 00000000..c9d95482
--- /dev/null
+++ b/TS Source/gameobjects/Sprite.js
@@ -0,0 +1,263 @@
+///
+/**
+* Phaser - Sprite
+*/
+var Phaser;
+(function (Phaser) {
+ var Sprite = (function () {
+ /**
+ * Create a new Sprite.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @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.
+ */
+ function Sprite(game, x, y, key, frame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof frame === "undefined") { frame = null; }
+ /**
+ * A bool representing if the Sprite has been modified in any way via a scale, rotate, flip or skew.
+ */
+ this.modified = false;
+ /**
+ * x value of the object.
+ */
+ this.x = 0;
+ /**
+ * y value of the object.
+ */
+ this.y = 0;
+ /**
+ * z order value of the object.
+ */
+ this.z = -1;
+ /**
+ * Render iteration counter
+ */
+ this.renderOrderID = 0;
+ this.game = game;
+ this.type = Phaser.Types.SPRITE;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.x = x;
+ this.y = y;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.events = new Phaser.Components.Events(this);
+ this.animations = new Phaser.Components.AnimationManager(this);
+ this.input = new Phaser.Components.InputHandler(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ if(key !== null) {
+ this.texture.loadImage(key, false);
+ } else {
+ this.texture.opaque = true;
+ }
+ if(frame !== null) {
+ if(typeof frame == 'string') {
+ this.frameName = frame;
+ } else {
+ this.frame = frame;
+ }
+ }
+ this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
+ this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
+ this.transform.setCache();
+ this.body = new Phaser.Physics.Body(this, 0);
+ this.outOfBounds = false;
+ this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
+ // Handy proxies
+ this.scale = this.transform.scale;
+ this.alpha = this.texture.alpha;
+ this.origin = this.transform.origin;
+ this.crop = this.texture.crop;
+ }
+ Object.defineProperty(Sprite.prototype, "rotation", {
+ get: /**
+ * The rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ */
+ function () {
+ return this.transform.rotation;
+ },
+ set: /**
+ * Set the rotation of the sprite 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.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
+ });
+ Sprite.prototype.bringToTop = /**
+ * Brings this Sprite to the top of its current Group, if set.
+ */
+ function () {
+ if(this.group) {
+ this.group.bringToTop(this);
+ }
+ };
+ Object.defineProperty(Sprite.prototype, "alpha", {
+ get: /**
+ * The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
+ */
+ function () {
+ return this.texture.alpha;
+ },
+ set: /**
+ * The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
+ */
+ function (value) {
+ this.texture.alpha = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "frame", {
+ get: /**
+ * Get the animation frame number.
+ */
+ function () {
+ return this.animations.frame;
+ },
+ set: /**
+ * Set the animation frame by frame number.
+ */
+ function (value) {
+ this.animations.frame = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "frameName", {
+ get: /**
+ * Get the animation frame name.
+ */
+ function () {
+ return this.animations.frameName;
+ },
+ set: /**
+ * Set the animation frame by frame name.
+ */
+ function (value) {
+ this.animations.frameName = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "width", {
+ get: function () {
+ return this.texture.width * this.transform.scale.x;
+ },
+ set: function (value) {
+ this.transform.scale.x = value / this.texture.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "height", {
+ get: function () {
+ return this.texture.height * this.transform.scale.y;
+ },
+ set: function (value) {
+ this.transform.scale.y = value / this.texture.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sprite.prototype.preUpdate = /**
+ * Pre-update is called right before update() on each object in the game loop.
+ */
+ function () {
+ this.transform.update();
+ if(this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0) {
+ this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
+ } else {
+ this.worldView.x = this.x - (this.width * this.transform.origin.x);
+ }
+ if(this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0) {
+ this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
+ } else {
+ this.worldView.y = this.y - (this.height * this.transform.origin.y);
+ }
+ this.worldView.width = this.width;
+ this.worldView.height = this.height;
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ };
+ Sprite.prototype.update = /**
+ * Override this function to update your sprites position and appearance.
+ */
+ function () {
+ };
+ Sprite.prototype.postUpdate = /**
+ * Automatically called after update() by the game loop for all 'alive' objects.
+ */
+ function () {
+ this.animations.update();
+ this.checkBounds();
+ //this.transform.centerOn(this.body.aabb.pos.x, this.body.aabb.pos.y);
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ };
+ Sprite.prototype.checkBounds = function () {
+ if(Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds)) {
+ this.outOfBounds = false;
+ } else {
+ if(this.outOfBounds == false) {
+ this.events.onOutOfBounds.dispatch(this);
+ }
+ this.outOfBounds = true;
+ if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL) {
+ this.kill();
+ } else if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY) {
+ this.destroy();
+ }
+ }
+ };
+ Sprite.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this.input.destroy();
+ };
+ Sprite.prototype.kill = /**
+ * Handy for "killing" game objects.
+ * Default behavior is to flag them as nonexistent AND dead.
+ * However, if you want the "corpse" to remain in the game,
+ * like to animate an effect or whatever, you should override this,
+ * setting only alive to false, and leaving exists true.
+ */
+ function (removeFromGroup) {
+ if (typeof removeFromGroup === "undefined") { removeFromGroup = false; }
+ this.alive = false;
+ this.exists = false;
+ if(removeFromGroup && this.group) {
+ //this.group.remove(this);
+ }
+ this.events.onKilled.dispatch(this);
+ };
+ Sprite.prototype.revive = /**
+ * Handy for bringing game objects "back to life". Just sets alive and exists back to true.
+ * In practice, this is most often called by Object.reset().
+ */
+ function () {
+ this.alive = true;
+ this.exists = true;
+ this.events.onRevived.dispatch(this);
+ };
+ return Sprite;
+ })();
+ Phaser.Sprite = Sprite;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/gameobjects/Sprite.ts b/TS Source/gameobjects/Sprite.ts
similarity index 100%
rename from Phaser/gameobjects/Sprite.ts
rename to TS Source/gameobjects/Sprite.ts
diff --git a/TS Source/gameobjects/TransformManager.js b/TS Source/gameobjects/TransformManager.js
new file mode 100644
index 00000000..6b51c8ec
--- /dev/null
+++ b/TS Source/gameobjects/TransformManager.js
@@ -0,0 +1,251 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Components - TransformManager
+ */
+ (function (Components) {
+ var TransformManager = (function () {
+ /**
+ * Creates a new TransformManager component
+ * @param parent The game object using this transform
+ */
+ function TransformManager(parent) {
+ this._dirty = false;
+ /**
+ * This value is added to the rotation of the object.
+ * For example if you had a texture drawn facing straight up then you could set
+ * rotationOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
+ * @type {number}
+ */
+ this.rotationOffset = 0;
+ /**
+ * The rotation of the object in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
+ */
+ this.rotation = 0;
+ this.game = parent.game;
+ this.parent = parent;
+ this.local = new Phaser.Mat3();
+ this.scrollFactor = new Phaser.Vec2(1, 1);
+ this.origin = new Phaser.Vec2();
+ this.scale = new Phaser.Vec2(1, 1);
+ this.skew = new Phaser.Vec2();
+ this.center = new Phaser.Point();
+ this.upperLeft = new Phaser.Point();
+ this.upperRight = new Phaser.Point();
+ this.bottomLeft = new Phaser.Point();
+ this.bottomRight = new Phaser.Point();
+ this._pos = new Phaser.Point();
+ this._scale = new Phaser.Point();
+ this._size = new Phaser.Point();
+ this._halfSize = new Phaser.Point();
+ this._offset = new Phaser.Point();
+ this._origin = new Phaser.Point();
+ this._sc = new Phaser.Point();
+ this._scA = new Phaser.Point();
+ }
+ Object.defineProperty(TransformManager.prototype, "distance", {
+ get: /**
+ * The distance from the center of the transform to the rotation origin.
+ */
+ function () {
+ return this._distance;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "angleToCenter", {
+ get: /**
+ * The angle between the center of the transform to the rotation origin.
+ */
+ function () {
+ return this._angle;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "offsetX", {
+ get: /**
+ * The offset on the X axis of the origin That is the difference between the top left of the Sprite and the origin.x.
+ * So if the origin.x is 0 the offsetX will be 0. If the origin.x is 0.5 then offsetX will be sprite width / 2, and so on.
+ */
+ function () {
+ return this._offset.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "offsetY", {
+ get: /**
+ * The offset on the Y axis of the origin
+ */
+ function () {
+ return this._offset.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "halfWidth", {
+ get: /**
+ * Half the width of the parent sprite, taking into consideration scaling
+ */
+ function () {
+ return this._halfSize.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "halfHeight", {
+ get: /**
+ * Half the height of the parent sprite, taking into consideration scaling
+ */
+ function () {
+ return this._halfSize.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "sin", {
+ get: /**
+ * The equivalent of Math.sin(rotation + rotationOffset)
+ */
+ function () {
+ return this._sc.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "cos", {
+ get: /**
+ * The equivalent of Math.cos(rotation + rotationOffset)
+ */
+ function () {
+ return this._sc.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TransformManager.prototype.centerOn = /**
+ * Moves the sprite so its center is located on the given x and y coordinates.
+ * Doesn't change the origin of the sprite.
+ */
+ function (x, y) {
+ this.parent.x = x + (this.parent.x - this.center.x);
+ this.parent.y = y + (this.parent.y - this.center.y);
+ //this.setCache();
+ };
+ TransformManager.prototype.setCache = /**
+ * Populates the transform cache. Called by the parent object on creation.
+ */
+ function () {
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this._halfSize.x = this.parent.width / 2;
+ this._halfSize.y = this.parent.height / 2;
+ this._offset.x = this.origin.x * this.parent.width;
+ this._offset.y = this.origin.y * this.parent.height;
+ this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
+ this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
+ this._size.x = this.parent.width;
+ this._size.y = this.parent.height;
+ this._origin.x = this.origin.x;
+ this._origin.y = this.origin.y;
+ this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._prevRotation = this.rotation;
+ if(this.parent.texture && this.parent.texture.renderRotation) {
+ this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ } else {
+ this._sc.x = 0;
+ this._sc.y = 1;
+ }
+ this.center.x = this.parent.x + this._distance * this._scA.y;
+ this.center.y = this.parent.y + this._distance * this._scA.x;
+ this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this._flippedX = this.parent.texture.flippedX;
+ this._flippedY = this.parent.texture.flippedY;
+ };
+ TransformManager.prototype.update = /**
+ * Updates the local transform matrix and the cache values if anything has changed in the parent.
+ */
+ function () {
+ // Check cache
+ this._dirty = false;
+ // 1) Height or Width change (also triggered by a change in scale) or an Origin change
+ if(this.parent.width !== this._size.x || this.parent.height !== this._size.y || this.origin.x !== this._origin.x || this.origin.y !== this._origin.y) {
+ this._halfSize.x = this.parent.width / 2;
+ this._halfSize.y = this.parent.height / 2;
+ this._offset.x = this.origin.x * this.parent.width;
+ this._offset.y = this.origin.y * this.parent.height;
+ this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
+ this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
+ // Store
+ this._size.x = this.parent.width;
+ this._size.y = this.parent.height;
+ this._origin.x = this.origin.x;
+ this._origin.y = this.origin.y;
+ this._dirty = true;
+ }
+ // 2) Rotation change
+ if(this.rotation != this._prevRotation || this._dirty) {
+ this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ if(this.parent.texture.renderRotation) {
+ this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ } else {
+ this._sc.x = 0;
+ this._sc.y = 1;
+ }
+ // Store
+ this._prevRotation = this.rotation;
+ this._dirty = true;
+ }
+ // 3) If it has moved (or any of the above) then update the edges and center
+ if(this._dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y) {
+ this.center.x = this.parent.x + this._distance * this._scA.y;
+ this.center.y = this.parent.y + this._distance * this._scA.x;
+ this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ // Translate
+ this.local.data[2] = this.parent.x;
+ this.local.data[5] = this.parent.y;
+ }
+ // Scale and Skew
+ if(this._dirty || this._flippedX != this.parent.texture.flippedX) {
+ this._flippedX = this.parent.texture.flippedX;
+ if(this._flippedX) {
+ this.local.data[0] = this._sc.y * -this.scale.x;
+ this.local.data[3] = (this._sc.x * -this.scale.x) + this.skew.x;
+ } else {
+ this.local.data[0] = this._sc.y * this.scale.x;
+ this.local.data[3] = (this._sc.x * this.scale.x) + this.skew.x;
+ }
+ }
+ if(this._dirty || this._flippedY != this.parent.texture.flippedY) {
+ this._flippedY = this.parent.texture.flippedY;
+ if(this._flippedY) {
+ this.local.data[4] = this._sc.y * -this.scale.y;
+ this.local.data[1] = -(this._sc.x * -this.scale.y) + this.skew.y;
+ } else {
+ this.local.data[4] = this._sc.y * this.scale.y;
+ this.local.data[1] = -(this._sc.x * this.scale.y) + this.skew.y;
+ }
+ }
+ };
+ return TransformManager;
+ })();
+ Components.TransformManager = TransformManager;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/gameobjects/TransformManager.ts b/TS Source/gameobjects/TransformManager.ts
similarity index 100%
rename from Phaser/gameobjects/TransformManager.ts
rename to TS Source/gameobjects/TransformManager.ts
diff --git a/TS Source/geom/Circle.js b/TS Source/geom/Circle.js
new file mode 100644
index 00000000..ce23a5ea
--- /dev/null
+++ b/TS Source/geom/Circle.js
@@ -0,0 +1,285 @@
+///
+/**
+* Phaser - Circle
+*
+* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
+*/
+var Phaser;
+(function (Phaser) {
+ var Circle = (function () {
+ /**
+ * Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
+ * @class Circle
+ * @constructor
+ * @param {Number} [x] The x coordinate of the center of the circle.
+ * @param {Number} [y] The y coordinate of the center of the circle.
+ * @param {Number} [diameter] The diameter of the circle.
+ * @return {Circle} This circle object
+ **/
+ function Circle(x, y, diameter) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof diameter === "undefined") { diameter = 0; }
+ this._diameter = 0;
+ this._radius = 0;
+ /**
+ * The x coordinate of the center of the circle
+ * @property x
+ * @type Number
+ **/
+ this.x = 0;
+ /**
+ * The y coordinate of the center of the circle
+ * @property y
+ * @type Number
+ **/
+ this.y = 0;
+ this.setTo(x, y, diameter);
+ }
+ Object.defineProperty(Circle.prototype, "diameter", {
+ get: /**
+ * The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
+ * @method diameter
+ * @return {Number}
+ **/
+ function () {
+ return this._diameter;
+ },
+ set: /**
+ * The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
+ * @method diameter
+ * @param {Number} The diameter of the circle.
+ **/
+ function (value) {
+ if(value > 0) {
+ this._diameter = value;
+ this._radius = value * 0.5;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "radius", {
+ get: /**
+ * The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter.
+ * @method radius
+ * @return {Number}
+ **/
+ function () {
+ return this._radius;
+ },
+ set: /**
+ * The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter.
+ * @method radius
+ * @param {Number} The radius of the circle.
+ **/
+ function (value) {
+ if(value > 0) {
+ this._radius = value;
+ this._diameter = value * 2;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.circumference = /**
+ * The circumference of the circle.
+ * @method circumference
+ * @return {Number}
+ **/
+ function () {
+ return 2 * (Math.PI * this._radius);
+ };
+ Object.defineProperty(Circle.prototype, "bottom", {
+ get: /**
+ * The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
+ * @method bottom
+ * @return {Number}
+ **/
+ function () {
+ return this.y + this._radius;
+ },
+ set: /**
+ * The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
+ * @method bottom
+ * @param {Number} The value to adjust the height of the circle by.
+ **/
+ function (value) {
+ if(value < this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.y;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "left", {
+ get: /**
+ * The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
+ * @method left
+ * @return {Number} The x coordinate of the leftmost point of the circle.
+ **/
+ function () {
+ return this.x - this._radius;
+ },
+ set: /**
+ * The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
+ * @method left
+ * @param {Number} The value to adjust the position of the leftmost point of the circle by.
+ **/
+ function (value) {
+ if(value > this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.x - value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "right", {
+ get: /**
+ * The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
+ * @method right
+ * @return {Number}
+ **/
+ function () {
+ return this.x + this._radius;
+ },
+ set: /**
+ * The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
+ * @method right
+ * @param {Number} The amount to adjust the diameter of the circle by.
+ **/
+ function (value) {
+ if(value < this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.x;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "top", {
+ get: /**
+ * The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
+ * @method bottom
+ * @return {Number}
+ **/
+ function () {
+ return this.y - this._radius;
+ },
+ set: /**
+ * The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
+ * @method bottom
+ * @param {Number} The amount to adjust the height of the circle by.
+ **/
+ function (value) {
+ if(value > this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.y - value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "area", {
+ get: /**
+ * Gets the area of this Circle.
+ * @method area
+ * @return {Number} This area of this circle.
+ **/
+ function () {
+ if(this._radius > 0) {
+ return Math.PI * this._radius * this._radius;
+ } else {
+ return 0;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.setTo = /**
+ * Sets the members of Circle to the specified values.
+ * @method setTo
+ * @param {Number} x The x coordinate of the center of the circle.
+ * @param {Number} y The y coordinate of the center of the circle.
+ * @param {Number} diameter The diameter of the circle in pixels.
+ * @return {Circle} This circle object
+ **/
+ function (x, y, diameter) {
+ this.x = x;
+ this.y = y;
+ this._diameter = diameter;
+ this._radius = diameter * 0.5;
+ return this;
+ };
+ Circle.prototype.copyFrom = /**
+ * Copies the x, y and diameter properties from any given object to this Circle.
+ * @method copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Circle} This Circle object.
+ **/
+ function (source) {
+ return this.setTo(source.x, source.y, source.diameter);
+ };
+ Object.defineProperty(Circle.prototype, "empty", {
+ get: /**
+ * Determines whether or not this Circle object is empty.
+ * @method empty
+ * @return {bool} A value of true if the Circle objects diameter is less than or equal to 0; otherwise false.
+ **/
+ function () {
+ return (this._diameter == 0);
+ },
+ set: /**
+ * Sets all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0.
+ * @method setEmpty
+ * @return {Circle} This Circle object
+ **/
+ function (value) {
+ this.setTo(0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.offset = /**
+ * Adjusts the location of the Circle object, as determined by its center coordinate, by the specified amounts.
+ * @method offset
+ * @param {Number} dx Moves the x value of the Circle object by this amount.
+ * @param {Number} dy Moves the y value of the Circle object by this amount.
+ * @return {Circle} This Circle object.
+ **/
+ function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Circle.prototype.offsetPoint = /**
+ * Adjusts the location of the Circle object using a Point object as a parameter. This method is similar to the Circle.offset() method, except that it takes a Point object as a parameter.
+ * @method offsetPoint
+ * @param {Point} point A Point object to use to offset this Circle object.
+ * @return {Circle} This Circle object.
+ **/
+ function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Circle.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the instance.
+ **/
+ function () {
+ return "[{Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
+ };
+ return Circle;
+ })();
+ Phaser.Circle = Circle;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/geom/Circle.ts b/TS Source/geom/Circle.ts
similarity index 100%
rename from Phaser/geom/Circle.ts
rename to TS Source/geom/Circle.ts
diff --git a/TS Source/geom/Line.js b/TS Source/geom/Line.js
new file mode 100644
index 00000000..01f2ce2f
--- /dev/null
+++ b/TS Source/geom/Line.js
@@ -0,0 +1,279 @@
+///
+/**
+* Phaser - Line
+*
+* A Line object is an infinte line through space. The two sets of x/y coordinates define the Line Segment.
+*/
+var Phaser;
+(function (Phaser) {
+ var Line = (function () {
+ /**
+ *
+ * @constructor
+ * @param {Number} x1
+ * @param {Number} y1
+ * @param {Number} x2
+ * @param {Number} y2
+ * @return {Phaser.Line} This Object
+ */
+ function Line(x1, y1, x2, y2) {
+ if (typeof x1 === "undefined") { x1 = 0; }
+ if (typeof y1 === "undefined") { y1 = 0; }
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ /**
+ *
+ * @property x1
+ * @type {Number}
+ */
+ this.x1 = 0;
+ /**
+ *
+ * @property y1
+ * @type {Number}
+ */
+ this.y1 = 0;
+ /**
+ *
+ * @property x2
+ * @type {Number}
+ */
+ this.x2 = 0;
+ /**
+ *
+ * @property y2
+ * @type {Number}
+ */
+ this.y2 = 0;
+ this.setTo(x1, y1, x2, y2);
+ }
+ Line.prototype.clone = /**
+ *
+ * @method clone
+ * @param {Phaser.Line} [output]
+ * @return {Phaser.Line}
+ */
+ function (output) {
+ if (typeof output === "undefined") { output = new Line(); }
+ return output.setTo(this.x1, this.y1, this.x2, this.y2);
+ };
+ Line.prototype.copyFrom = /**
+ *
+ * @method copyFrom
+ * @param {Phaser.Line} source
+ * @return {Phaser.Line}
+ */
+ function (source) {
+ return this.setTo(source.x1, source.y1, source.x2, source.y2);
+ };
+ Line.prototype.copyTo = /**
+ *
+ * @method copyTo
+ * @param {Phaser.Line} target
+ * @return {Phaser.Line}
+ */
+ function (target) {
+ return target.copyFrom(this);
+ };
+ Line.prototype.setTo = /**
+ *
+ * @method setTo
+ * @param {Number} x1
+ * @param {Number} y1
+ * @param {Number} x2
+ * @param {Number} y2
+ * @return {Phaser.Line}
+ */
+ function (x1, y1, x2, y2) {
+ if (typeof x1 === "undefined") { x1 = 0; }
+ if (typeof y1 === "undefined") { y1 = 0; }
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ return this;
+ };
+ Object.defineProperty(Line.prototype, "width", {
+ get: function () {
+ return Math.max(this.x1, this.x2) - Math.min(this.x1, this.x2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "height", {
+ get: function () {
+ return Math.max(this.y1, this.y2) - Math.min(this.y1, this.y2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "length", {
+ get: /**
+ *
+ * @method length
+ * @return {Number}
+ */
+ function () {
+ return Math.sqrt((this.x2 - this.x1) * (this.x2 - this.x1) + (this.y2 - this.y1) * (this.y2 - this.y1));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Line.prototype.getY = /**
+ *
+ * @method getY
+ * @param {Number} x
+ * @return {Number}
+ */
+ function (x) {
+ return this.slope * x + this.yIntercept;
+ };
+ Object.defineProperty(Line.prototype, "angle", {
+ get: /**
+ *
+ * @method angle
+ * @return {Number}
+ */
+ function () {
+ return Math.atan2(this.x2 - this.x1, this.y2 - this.y1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "slope", {
+ get: /**
+ *
+ * @method slope
+ * @return {Number}
+ */
+ function () {
+ return (this.y2 - this.y1) / (this.x2 - this.x1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "perpSlope", {
+ get: /**
+ *
+ * @method perpSlope
+ * @return {Number}
+ */
+ function () {
+ return -((this.x2 - this.x1) / (this.y2 - this.y1));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "yIntercept", {
+ get: /**
+ *
+ * @method yIntercept
+ * @return {Number}
+ */
+ function () {
+ return (this.y1 - this.slope * this.x1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Line.prototype.isPointOnLine = /**
+ *
+ * @method isPointOnLine
+ * @param {Number} x
+ * @param {Number} y
+ * @return {bool}
+ */
+ function (x, y) {
+ if((x - this.x1) * (this.y2 - this.y1) === (this.x2 - this.x1) * (y - this.y1)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Line.prototype.isPointOnLineSegment = /**
+ *
+ * @method isPointOnLineSegment
+ * @param {Number} x
+ * @param {Number} y
+ * @return {bool}
+ */
+ function (x, y) {
+ var xMin = Math.min(this.x1, this.x2);
+ var xMax = Math.max(this.x1, this.x2);
+ var yMin = Math.min(this.y1, this.y2);
+ var yMax = Math.max(this.y1, this.y2);
+ if(this.isPointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Line.prototype.intersectLineLine = /**
+ *
+ * @method intersectLineLine
+ * @param {Any} line
+ * @return {Any}
+ */
+ function (line) {
+ //return Phaser.intersectLineLine(this,line);
+ };
+ Line.prototype.toString = /**
+ *
+ * @method perp
+ * @param {Number} x
+ * @param {Number} y
+ * @param {Phaser.Line} [output]
+ * @return {Phaser.Line}
+ */
+ /*
+ public perp(x: number, y: number, output: Line): Line {
+
+ if (this.y1 === this.y2)
+ {
+ if (output)
+ {
+ output.setTo(x, y, x, this.y1);
+ }
+ else
+ {
+ return new Line(x, y, x, this.y1);
+ }
+ }
+
+ var yInt: number = (y - this.perpSlope * x);
+
+ var pt = this.intersectLineLine({ x1: x, y1: y, x2: 0, y2: yInt });
+
+ if (output)
+ {
+ output.setTo(x, y, pt.x, pt.y);
+ }
+ else
+ {
+ return new Line(x, y, pt.x, pt.y);
+ }
+
+ }
+ */
+ /*
+ intersectLineCircle (circle:Circle)
+ {
+ var perp = this.perp()
+ return Phaser.intersectLineCircle(this,circle);
+
+ }
+ */
+ /**
+ *
+ * @method toString
+ * @return {String}
+ */
+ function () {
+ return "[{Line (x1=" + this.x1 + " y1=" + this.y1 + " x2=" + this.x2 + " y2=" + this.y2 + ")}]";
+ };
+ return Line;
+ })();
+ Phaser.Line = Line;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/geom/Line.ts b/TS Source/geom/Line.ts
similarity index 100%
rename from Phaser/geom/Line.ts
rename to TS Source/geom/Line.ts
diff --git a/TS Source/geom/Point.js b/TS Source/geom/Point.js
new file mode 100644
index 00000000..43353db4
--- /dev/null
+++ b/TS Source/geom/Point.js
@@ -0,0 +1,63 @@
+///
+/**
+* Phaser - Point
+*
+* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
+*/
+var Phaser;
+(function (Phaser) {
+ var Point = (function () {
+ /**
+ * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
+ * @class Point
+ * @constructor
+ * @param {Number} x The horizontal position of this Point (default 0)
+ * @param {Number} y The vertical position of this Point (default 0)
+ **/
+ function Point(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ this.x = x;
+ this.y = y;
+ }
+ Point.prototype.copyFrom = /**
+ * Copies the x and y properties from any given object to this Point.
+ * @method copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Point} This Point object.
+ **/
+ function (source) {
+ return this.setTo(source.x, source.y);
+ };
+ Point.prototype.invert = /**
+ * Inverts the x and y values of this Point
+ * @method invert
+ * @return {Point} This Point object.
+ **/
+ function () {
+ return this.setTo(this.y, this.x);
+ };
+ Point.prototype.setTo = /**
+ * Sets the x and y values of this MicroPoint object to the given coordinates.
+ * @method setTo
+ * @param {Number} x - The horizontal position of this point.
+ * @param {Number} y - The vertical position of this point.
+ * @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
+ **/
+ function (x, y) {
+ this.x = x;
+ this.y = y;
+ return this;
+ };
+ Point.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the instance.
+ **/
+ function () {
+ return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
+ };
+ return Point;
+ })();
+ Phaser.Point = Point;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/geom/Point.ts b/TS Source/geom/Point.ts
similarity index 100%
rename from Phaser/geom/Point.ts
rename to TS Source/geom/Point.ts
diff --git a/TS Source/geom/Rectangle.js b/TS Source/geom/Rectangle.js
new file mode 100644
index 00000000..cab2a0de
--- /dev/null
+++ b/TS Source/geom/Rectangle.js
@@ -0,0 +1,295 @@
+///
+/**
+* Rectangle
+*
+* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
+*
+* @version 1.6 - 24th May 2013
+* @author Richard Davey
+*/
+var Phaser;
+(function (Phaser) {
+ var Rectangle = (function () {
+ /**
+ * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
+ * @class Rectangle
+ * @constructor
+ * @param {Number} x The x coordinate of the top-left corner of the Rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the Rectangle.
+ * @param {Number} width The width of the Rectangle in pixels.
+ * @param {Number} height The height of the Rectangle in pixels.
+ * @return {Rectangle} This Rectangle object
+ **/
+ function Rectangle(x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+ Object.defineProperty(Rectangle.prototype, "halfWidth", {
+ get: /**
+ * Half of the width of the Rectangle
+ * @property halfWidth
+ * @type Number
+ **/
+ function () {
+ return Math.round(this.width / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "halfHeight", {
+ get: /**
+ * Half of the height of the Rectangle
+ * @property halfHeight
+ * @type Number
+ **/
+ function () {
+ return Math.round(this.height / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottom", {
+ get: /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @return {Number}
+ **/
+ function () {
+ return this.y + this.height;
+ },
+ set: /**
+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
+ * @method bottom
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value <= this.y) {
+ this.height = 0;
+ } else {
+ this.height = (this.y - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottomRight", {
+ set: /**
+ * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
+ * @method bottomRight
+ * @param {Point} value
+ **/
+ function (value) {
+ this.right = value.x;
+ this.bottom = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "left", {
+ get: /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
+ * @method left
+ * @ return {number}
+ **/
+ function () {
+ return this.x;
+ },
+ set: /**
+ * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
+ * However it does affect the width, whereas changing the x value does not affect the width property.
+ * @method left
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value >= this.right) {
+ this.width = 0;
+ } else {
+ this.width = this.right - value;
+ }
+ this.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "right", {
+ get: /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @return {Number}
+ **/
+ function () {
+ return this.x + this.width;
+ },
+ set: /**
+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
+ * However it does affect the width property.
+ * @method right
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value <= this.x) {
+ this.width = 0;
+ } else {
+ this.width = this.x + value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "volume", {
+ get: /**
+ * The volume of the Rectangle derived from width * height
+ * @method volume
+ * @return {Number}
+ **/
+ function () {
+ return this.width * this.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "perimeter", {
+ get: /**
+ * The perimeter size of the Rectangle. This is the sum of all 4 sides.
+ * @method perimeter
+ * @return {Number}
+ **/
+ function () {
+ return (this.width * 2) + (this.height * 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "top", {
+ get: /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @return {Number}
+ **/
+ function () {
+ return this.y;
+ },
+ set: /**
+ * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
+ * However it does affect the height property, whereas changing the y value does not affect the height property.
+ * @method top
+ * @param {Number} value
+ **/
+ function (value) {
+ if(value >= this.bottom) {
+ this.height = 0;
+ this.y = value;
+ } else {
+ this.height = (this.bottom - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "topLeft", {
+ set: /**
+ * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
+ * @method topLeft
+ * @param {Point} value
+ **/
+ function (value) {
+ this.x = value.x;
+ this.y = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "empty", {
+ get: /**
+ * Determines whether or not this Rectangle object is empty.
+ * @method isEmpty
+ * @return {bool} A value of true if the Rectangle objects width or height is less than or equal to 0; otherwise false.
+ **/
+ function () {
+ return (!this.width || !this.height);
+ },
+ set: /**
+ * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
+ * @method setEmpty
+ * @return {Rectangle} This Rectangle object
+ **/
+ function (value) {
+ this.setTo(0, 0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Rectangle.prototype.offset = /**
+ * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
+ * @method offset
+ * @param {Number} dx Moves the x value of the Rectangle object by this amount.
+ * @param {Number} dy Moves the y value of the Rectangle object by this amount.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Rectangle.prototype.offsetPoint = /**
+ * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
+ * @method offsetPoint
+ * @param {Point} point A Point object to use to offset this Rectangle object.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Rectangle.prototype.setTo = /**
+ * Sets the members of Rectangle to the specified values.
+ * @method setTo
+ * @param {Number} x The x coordinate of the top-left corner of the Rectangle.
+ * @param {Number} y The y coordinate of the top-left corner of the Rectangle.
+ * @param {Number} width The width of the Rectangle in pixels.
+ * @param {Number} height The height of the Rectangle in pixels.
+ * @return {Rectangle} This Rectangle object
+ **/
+ function (x, y, width, height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ return this;
+ };
+ Rectangle.prototype.floor = /**
+ * Runs Math.floor() on both the x and y values of this Rectangle.
+ * @method floor
+ **/
+ function () {
+ this.x = Math.floor(this.x);
+ this.y = Math.floor(this.y);
+ };
+ Rectangle.prototype.copyFrom = /**
+ * Copies the x, y, width and height properties from any given object to this Rectangle.
+ * @method copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Rectangle} This Rectangle object.
+ **/
+ function (source) {
+ return this.setTo(source.x, source.y, source.width, source.height);
+ };
+ Rectangle.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the instance.
+ **/
+ function () {
+ return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
+ };
+ return Rectangle;
+ })();
+ Phaser.Rectangle = Rectangle;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/geom/Rectangle.ts b/TS Source/geom/Rectangle.ts
similarity index 100%
rename from Phaser/geom/Rectangle.ts
rename to TS Source/geom/Rectangle.ts
diff --git a/TS Source/input/InputHandler.js b/TS Source/input/InputHandler.js
new file mode 100644
index 00000000..91153c23
--- /dev/null
+++ b/TS Source/input/InputHandler.js
@@ -0,0 +1,574 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Components - InputHandler
+ *
+ * Input detection component
+ */
+ (function (Components) {
+ var InputHandler = (function () {
+ /**
+ * Sprite Input component constructor
+ * @param parent The Sprite using this Input component
+ */
+ function InputHandler(parent) {
+ /**
+ * The PriorityID controls which Sprite receives an Input event first if they should overlap.
+ */
+ this.priorityID = 0;
+ /**
+ * The index of this Input component entry in the Game.Input manager.
+ */
+ this.indexID = 0;
+ this.isDragged = false;
+ this.dragPixelPerfect = false;
+ this.allowHorizontalDrag = true;
+ this.allowVerticalDrag = true;
+ this.bringToTop = false;
+ this.snapOnDrag = false;
+ this.snapOnRelease = false;
+ this.snapX = 0;
+ this.snapY = 0;
+ /**
+ * Is this sprite allowed to be dragged by the mouse? true = yes, false = no
+ * @default false
+ */
+ this.draggable = false;
+ /**
+ * A region of the game world within which the sprite is restricted during drag
+ * @default null
+ */
+ this.boundsRect = null;
+ /**
+ * An Sprite the bounds of which this sprite is restricted during drag
+ * @default null
+ */
+ this.boundsSprite = null;
+ /**
+ * If this object is set to consume the pointer event then it will stop all propogation from this object on.
+ * For example if you had a stack of 6 sprites with the same priority IDs and one consumed the event, none of the others would receive it.
+ * @type {bool}
+ */
+ this.consumePointerEvent = false;
+ this.game = parent.game;
+ this._parent = parent;
+ this.enabled = false;
+ }
+ InputHandler.prototype.pointerX = /**
+ * The x coordinate of the Input pointer, relative to the top-left of the parent Sprite.
+ * This value is only set when the pointer is over this Sprite.
+ * @type {number}
+ */
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].x;
+ };
+ InputHandler.prototype.pointerY = /**
+ * The y coordinate of the Input pointer, relative to the top-left of the parent Sprite
+ * This value is only set when the pointer is over this Sprite.
+ * @type {number}
+ */
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].y;
+ };
+ InputHandler.prototype.pointerDown = /**
+ * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
+ * @property isDown
+ * @type {bool}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isDown;
+ };
+ InputHandler.prototype.pointerUp = /**
+ * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
+ * @property isUp
+ * @type {bool}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isUp;
+ };
+ InputHandler.prototype.pointerTimeDown = /**
+ * A timestamp representing when the Pointer first touched the touchscreen.
+ * @property timeDown
+ * @type {Number}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeDown;
+ };
+ InputHandler.prototype.pointerTimeUp = /**
+ * A timestamp representing when the Pointer left the touchscreen.
+ * @property timeUp
+ * @type {Number}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeUp;
+ };
+ InputHandler.prototype.pointerOver = /**
+ * Is the Pointer over this Sprite
+ * @property isOver
+ * @type {bool}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isOver;
+ };
+ InputHandler.prototype.pointerOut = /**
+ * Is the Pointer outside of this Sprite
+ * @property isOut
+ * @type {bool}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isOut;
+ };
+ InputHandler.prototype.pointerTimeOver = /**
+ * A timestamp representing when the Pointer first touched the touchscreen.
+ * @property timeDown
+ * @type {Number}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeOver;
+ };
+ InputHandler.prototype.pointerTimeOut = /**
+ * A timestamp representing when the Pointer left the touchscreen.
+ * @property timeUp
+ * @type {Number}
+ **/
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeOut;
+ };
+ InputHandler.prototype.pointerDragged = /**
+ * Is this sprite being dragged by the mouse or not?
+ * @default false
+ */
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isDragged;
+ };
+ InputHandler.prototype.start = function (priority, checkBody, useHandCursor) {
+ if (typeof priority === "undefined") { priority = 0; }
+ if (typeof checkBody === "undefined") { checkBody = false; }
+ if (typeof useHandCursor === "undefined") { useHandCursor = false; }
+ // Turning on
+ if(this.enabled == false) {
+ // Register, etc
+ this.checkBody = checkBody;
+ this.useHandCursor = useHandCursor;
+ this.priorityID = priority;
+ this._pointerData = [];
+ for(var i = 0; i < 10; i++) {
+ this._pointerData.push({
+ id: i,
+ x: 0,
+ y: 0,
+ isDown: false,
+ isUp: false,
+ isOver: false,
+ isOut: false,
+ timeOver: 0,
+ timeOut: 0,
+ timeDown: 0,
+ timeUp: 0,
+ downDuration: 0,
+ isDragged: false
+ });
+ }
+ this.snapOffset = new Phaser.Point();
+ this.enabled = true;
+ this.game.input.addGameObject(this._parent);
+ // Create the signals the Input component will emit
+ if(this._parent.events.onInputOver == null) {
+ this._parent.events.onInputOver = new Phaser.Signal();
+ this._parent.events.onInputOut = new Phaser.Signal();
+ this._parent.events.onInputDown = new Phaser.Signal();
+ this._parent.events.onInputUp = new Phaser.Signal();
+ this._parent.events.onDragStart = new Phaser.Signal();
+ this._parent.events.onDragStop = new Phaser.Signal();
+ }
+ }
+ return this._parent;
+ };
+ InputHandler.prototype.reset = function () {
+ this.enabled = false;
+ for(var i = 0; i < 10; i++) {
+ this._pointerData[i] = {
+ id: i,
+ x: 0,
+ y: 0,
+ isDown: false,
+ isUp: false,
+ isOver: false,
+ isOut: false,
+ timeOver: 0,
+ timeOut: 0,
+ timeDown: 0,
+ timeUp: 0,
+ downDuration: 0,
+ isDragged: false
+ };
+ }
+ };
+ InputHandler.prototype.stop = function () {
+ // Turning off
+ if(this.enabled == false) {
+ return;
+ } else {
+ // De-register, etc
+ this.enabled = false;
+ this.game.input.removeGameObject(this.indexID);
+ }
+ };
+ InputHandler.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ if(this.enabled) {
+ this.enabled = false;
+ this.game.input.removeGameObject(this.indexID);
+ }
+ };
+ InputHandler.prototype.checkPointerOver = /**
+ * Checks if the given pointer is over this Sprite. All checks are done in world coordinates.
+ */
+ function (pointer) {
+ if(this.enabled == false || this._parent.visible == false) {
+ return false;
+ } else {
+ //return SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
+ //return SpriteUtils.overlapsXY(this._parent, pointer.screenX, pointer.screenY);
+ return Phaser.SpriteUtils.overlapsPointer(this._parent, pointer);
+ }
+ };
+ InputHandler.prototype.update = /**
+ * Update
+ */
+ function (pointer) {
+ if(this.enabled == false || this._parent.visible == false) {
+ this._pointerOutHandler(pointer);
+ return false;
+ }
+ if(this.draggable && this._draggedPointerID == pointer.id) {
+ return this.updateDrag(pointer);
+ } else if(this._pointerData[pointer.id].isOver == true) {
+ //if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
+ if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
+ this._pointerData[pointer.id].x = pointer.x - this._parent.x;
+ this._pointerData[pointer.id].y = pointer.y - this._parent.y;
+ return true;
+ } else {
+ this._pointerOutHandler(pointer);
+ return false;
+ }
+ }
+ };
+ InputHandler.prototype._pointerOverHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isOver == false) {
+ this._pointerData[pointer.id].isOver = true;
+ this._pointerData[pointer.id].isOut = false;
+ this._pointerData[pointer.id].timeOver = this.game.time.now;
+ this._pointerData[pointer.id].x = pointer.x - this._parent.x;
+ this._pointerData[pointer.id].y = pointer.y - this._parent.y;
+ if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
+ this.game.stage.canvas.style.cursor = "pointer";
+ }
+ this._parent.events.onInputOver.dispatch(this._parent, pointer);
+ }
+ };
+ InputHandler.prototype._pointerOutHandler = function (pointer) {
+ this._pointerData[pointer.id].isOver = false;
+ this._pointerData[pointer.id].isOut = true;
+ this._pointerData[pointer.id].timeOut = this.game.time.now;
+ if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
+ this.game.stage.canvas.style.cursor = "default";
+ }
+ this._parent.events.onInputOut.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype._touchedHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) {
+ this._pointerData[pointer.id].isDown = true;
+ this._pointerData[pointer.id].isUp = false;
+ this._pointerData[pointer.id].timeDown = this.game.time.now;
+ //console.log('touchedHandler: ' + Date.now());
+ this._parent.events.onInputDown.dispatch(this._parent, pointer);
+ // Start drag
+ //if (this.draggable && this.isDragged == false && pointer.targetObject == null)
+ if(this.draggable && this.isDragged == false) {
+ this.startDrag(pointer);
+ }
+ if(this.bringToTop) {
+ this._parent.bringToTop();
+ //this._parent.game.world.group.bringToTop(this._parent);
+ }
+ }
+ // Consume the event?
+ return this.consumePointerEvent;
+ };
+ InputHandler.prototype._releasedHandler = function (pointer) {
+ // If was previously touched by this Pointer, check if still is AND still over this item
+ if(this._pointerData[pointer.id].isDown && pointer.isUp) {
+ this._pointerData[pointer.id].isDown = false;
+ this._pointerData[pointer.id].isUp = true;
+ this._pointerData[pointer.id].timeUp = this.game.time.now;
+ this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
+ // Only release the InputUp signal if the pointer is still over this sprite
+ //if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
+ if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
+ //console.log('releasedHandler: ' + Date.now());
+ this._parent.events.onInputUp.dispatch(this._parent, pointer);
+ } else {
+ // Pointer outside the sprite? Reset the cursor
+ if(this.useHandCursor) {
+ this.game.stage.canvas.style.cursor = "default";
+ }
+ }
+ // Stop drag
+ if(this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
+ this.stopDrag(pointer);
+ }
+ }
+ };
+ InputHandler.prototype.updateDrag = /**
+ * Updates the Pointer drag on this Sprite.
+ */
+ function (pointer) {
+ if(pointer.isUp) {
+ this.stopDrag(pointer);
+ return false;
+ }
+ if(this.allowHorizontalDrag) {
+ this._parent.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
+ }
+ if(this.allowVerticalDrag) {
+ this._parent.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
+ }
+ if(this.boundsRect) {
+ this.checkBoundsRect();
+ }
+ if(this.boundsSprite) {
+ this.checkBoundsSprite();
+ }
+ if(this.snapOnDrag) {
+ this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
+ this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
+ }
+ return true;
+ };
+ InputHandler.prototype.justOver = /**
+ * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
+ * @param delay The time below which the pointer is considered as just over.
+ * @returns {bool}
+ */
+ function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay);
+ };
+ InputHandler.prototype.justOut = /**
+ * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
+ * @param delay The time below which the pointer is considered as just out.
+ * @returns {bool}
+ */
+ function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay));
+ };
+ InputHandler.prototype.justPressed = /**
+ * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
+ * @param delay The time below which the pointer is considered as just over.
+ * @returns {bool}
+ */
+ function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay);
+ };
+ InputHandler.prototype.justReleased = /**
+ * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
+ * @param delay The time below which the pointer is considered as just out.
+ * @returns {bool}
+ */
+ function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay));
+ };
+ InputHandler.prototype.overDuration = /**
+ * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
+ * @returns {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
+ */
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if(this._pointerData[pointer].isOver) {
+ return this.game.time.now - this._pointerData[pointer].timeOver;
+ }
+ return -1;
+ };
+ InputHandler.prototype.downDuration = /**
+ * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
+ * @returns {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
+ */
+ function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if(this._pointerData[pointer].isDown) {
+ return this.game.time.now - this._pointerData[pointer].timeDown;
+ }
+ return -1;
+ };
+ InputHandler.prototype.enableDrag = /**
+ * Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
+ *
+ * @param lockCenter If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer.
+ * @param bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group.
+ * @param pixelPerfect If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
+ * @param alphaThreshold If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255)
+ * @param boundsRect If you want to restrict the drag of this sprite to a specific FlxRect, pass the FlxRect here, otherwise it's free to drag anywhere
+ * @param boundsSprite If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here
+ */
+ function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
+ if (typeof lockCenter === "undefined") { lockCenter = false; }
+ if (typeof bringToTop === "undefined") { bringToTop = false; }
+ if (typeof pixelPerfect === "undefined") { pixelPerfect = false; }
+ if (typeof alphaThreshold === "undefined") { alphaThreshold = 255; }
+ if (typeof boundsRect === "undefined") { boundsRect = null; }
+ if (typeof boundsSprite === "undefined") { boundsSprite = null; }
+ this._dragPoint = new Phaser.Point();
+ this.draggable = true;
+ this.bringToTop = bringToTop;
+ this.dragOffset = new Phaser.Point();
+ this.dragFromCenter = lockCenter;
+ this.dragPixelPerfect = pixelPerfect;
+ this.dragPixelPerfectAlpha = alphaThreshold;
+ if(boundsRect) {
+ this.boundsRect = boundsRect;
+ }
+ if(boundsSprite) {
+ this.boundsSprite = boundsSprite;
+ }
+ };
+ InputHandler.prototype.disableDrag = /**
+ * Stops this sprite from being able to be dragged. If it is currently the target of an active drag it will be stopped immediately. Also disables any set callbacks.
+ */
+ function () {
+ if(this._pointerData) {
+ for(var i = 0; i < 10; i++) {
+ this._pointerData[i].isDragged = false;
+ }
+ }
+ this.draggable = false;
+ this.isDragged = false;
+ this._draggedPointerID = -1;
+ };
+ InputHandler.prototype.startDrag = /**
+ * Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
+ */
+ function (pointer) {
+ this.isDragged = true;
+ this._draggedPointerID = pointer.id;
+ this._pointerData[pointer.id].isDragged = true;
+ if(this.dragFromCenter) {
+ this._parent.transform.centerOn(pointer.worldX, pointer.worldY);
+ this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
+ } else {
+ this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
+ }
+ this.updateDrag(pointer);
+ if(this.bringToTop) {
+ this._parent.bringToTop();
+ }
+ this._parent.events.onDragStart.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype.stopDrag = /**
+ * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
+ */
+ function (pointer) {
+ this.isDragged = false;
+ this._draggedPointerID = -1;
+ this._pointerData[pointer.id].isDragged = false;
+ if(this.snapOnRelease) {
+ this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
+ this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
+ }
+ this._parent.events.onDragStop.dispatch(this._parent, pointer);
+ this._parent.events.onInputUp.dispatch(this._parent, pointer);
+ };
+ InputHandler.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!
+ *
+ * @param allowHorizontal To enable the sprite to be dragged horizontally set to true, otherwise false
+ * @param allowVertical To enable the sprite to be dragged vertically set to true, otherwise false
+ */
+ function (allowHorizontal, allowVertical) {
+ if (typeof allowHorizontal === "undefined") { allowHorizontal = true; }
+ if (typeof allowVertical === "undefined") { allowVertical = true; }
+ this.allowHorizontalDrag = allowHorizontal;
+ this.allowVerticalDrag = allowVertical;
+ };
+ InputHandler.prototype.enableSnap = /**
+ * Make this Sprite snap to the given grid either during drag or when it's released.
+ * For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels.
+ *
+ * @param snapX The width of the grid cell in pixels
+ * @param snapY The height of the grid cell in pixels
+ * @param onDrag If true the sprite will snap to the grid while being dragged
+ * @param onRelease If true the sprite will snap to the grid when released
+ */
+ function (snapX, snapY, onDrag, onRelease) {
+ if (typeof onDrag === "undefined") { onDrag = true; }
+ if (typeof onRelease === "undefined") { onRelease = false; }
+ this.snapOnDrag = onDrag;
+ this.snapOnRelease = onRelease;
+ this.snapX = snapX;
+ this.snapY = snapY;
+ };
+ InputHandler.prototype.disableSnap = /**
+ * Stops the sprite from snapping to a grid during drag or release.
+ */
+ function () {
+ this.snapOnDrag = false;
+ this.snapOnRelease = false;
+ };
+ InputHandler.prototype.checkBoundsRect = /**
+ * Bounds Rect check for the sprite drag
+ */
+ function () {
+ if(this._parent.x < this.boundsRect.left) {
+ this._parent.x = this.boundsRect.x;
+ } else if((this._parent.x + this._parent.width) > this.boundsRect.right) {
+ this._parent.x = this.boundsRect.right - this._parent.width;
+ }
+ if(this._parent.y < this.boundsRect.top) {
+ this._parent.y = this.boundsRect.top;
+ } else if((this._parent.y + this._parent.height) > this.boundsRect.bottom) {
+ this._parent.y = this.boundsRect.bottom - this._parent.height;
+ }
+ };
+ InputHandler.prototype.checkBoundsSprite = /**
+ * Parent Sprite Bounds check for the sprite drag
+ */
+ function () {
+ if(this._parent.x < this.boundsSprite.x) {
+ this._parent.x = this.boundsSprite.x;
+ } else if((this._parent.x + this._parent.width) > (this.boundsSprite.x + this.boundsSprite.width)) {
+ this._parent.x = (this.boundsSprite.x + this.boundsSprite.width) - this._parent.width;
+ }
+ if(this._parent.y < this.boundsSprite.y) {
+ this._parent.y = this.boundsSprite.y;
+ } else if((this._parent.y + this._parent.height) > (this.boundsSprite.y + this.boundsSprite.height)) {
+ this._parent.y = (this.boundsSprite.y + this.boundsSprite.height) - this._parent.height;
+ }
+ };
+ return InputHandler;
+ })();
+ Components.InputHandler = InputHandler;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/input/InputHandler.ts b/TS Source/input/InputHandler.ts
similarity index 100%
rename from Phaser/input/InputHandler.ts
rename to TS Source/input/InputHandler.ts
diff --git a/TS Source/input/InputManager.js b/TS Source/input/InputManager.js
new file mode 100644
index 00000000..19547435
--- /dev/null
+++ b/TS Source/input/InputManager.js
@@ -0,0 +1,604 @@
+///
+/**
+* Phaser - InputManager
+*
+* A game specific Input manager that looks after the mouse, keyboard and touch objects.
+* This is updated by the core game loop.
+*/
+var Phaser;
+(function (Phaser) {
+ var InputManager = (function () {
+ function InputManager(game) {
+ /**
+ * How often should the input pointers be checked for updates?
+ * A value of 0 means every single frame (60fps), a value of 1 means every other frame (30fps) and so on.
+ * @type {number}
+ */
+ this.pollRate = 0;
+ this._pollCounter = 0;
+ /**
+ * A vector object representing the previous position of the Pointer.
+ * @property vector
+ * @type {Vec2}
+ **/
+ this._oldPosition = null;
+ /**
+ * X coordinate of the most recent Pointer event
+ * @type {Number}
+ * @private
+ */
+ this._x = 0;
+ /**
+ * X coordinate of the most recent Pointer event
+ * @type {Number}
+ * @private
+ */
+ this._y = 0;
+ /**
+ * You can disable all Input by setting Input.disabled = true. While set all new input related events will be ignored.
+ * If you need to disable just one type of input, for example mouse, use Input.mouse.disabled = true instead
+ * @type {bool}
+ */
+ this.disabled = false;
+ /**
+ * Controls the expected behaviour when using a mouse and touch together on a multi-input device
+ */
+ this.multiInputOverride = InputManager.MOUSE_TOUCH_COMBINE;
+ /**
+ * Phaser.Gestures handler
+ * @type {Gestures}
+ */
+ //public gestures: Gestures;
+ /**
+ * A vector object representing the current position of the Pointer.
+ * @property vector
+ * @type {Vec2}
+ **/
+ this.position = null;
+ /**
+ * A vector object representing the speed of the Pointer. Only really useful in single Pointer games,
+ * otherwise see the Pointer objects directly.
+ * @property vector
+ * @type {Vec2}
+ **/
+ this.speed = null;
+ /**
+ * A Circle object centered on the x/y screen coordinates of the Input.
+ * Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything
+ * @property circle
+ * @type {Circle}
+ **/
+ this.circle = null;
+ /**
+ * The scale by which all input coordinates are multiplied, calculated by the StageScaleMode.
+ * In an un-scaled game the values will be x: 1 and y: 1.
+ * @type {Vec2}
+ */
+ this.scale = null;
+ /**
+ * The maximum number of Pointers allowed to be active at any one time.
+ * For lots of games it's useful to set this to 1
+ * @type {Number}
+ */
+ this.maxPointers = 10;
+ /**
+ * The current number of active Pointers.
+ * @type {Number}
+ */
+ this.currentPointers = 0;
+ /**
+ * The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click
+ * @property tapRate
+ * @type {Number}
+ **/
+ this.tapRate = 200;
+ /**
+ * The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click
+ * @property doubleTapRate
+ * @type {Number}
+ **/
+ this.doubleTapRate = 300;
+ /**
+ * The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
+ * @property holdRate
+ * @type {Number}
+ **/
+ this.holdRate = 2000;
+ /**
+ * The number of milliseconds below which the Pointer is considered justPressed
+ * @property justPressedRate
+ * @type {Number}
+ **/
+ this.justPressedRate = 200;
+ /**
+ * The number of milliseconds below which the Pointer is considered justReleased
+ * @property justReleasedRate
+ * @type {Number}
+ **/
+ this.justReleasedRate = 200;
+ /**
+ * Sets if the Pointer objects should record a history of x/y coordinates they have passed through.
+ * The history is cleared each time the Pointer is pressed down.
+ * The history is updated at the rate specified in Input.pollRate
+ * @property recordPointerHistory
+ * @type {bool}
+ **/
+ this.recordPointerHistory = false;
+ /**
+ * The rate in milliseconds at which the Pointer objects should update their tracking history
+ * @property recordRate
+ * @type {Number}
+ */
+ this.recordRate = 100;
+ /**
+ * The total number of entries that can be recorded into the Pointer objects tracking history.
+ * If the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
+ * @property recordLimit
+ * @type {Number}
+ */
+ this.recordLimit = 100;
+ /**
+ * A Pointer object
+ * @property pointer3
+ * @type {Pointer}
+ **/
+ this.pointer3 = null;
+ /**
+ * A Pointer object
+ * @property pointer4
+ * @type {Pointer}
+ **/
+ this.pointer4 = null;
+ /**
+ * A Pointer object
+ * @property pointer5
+ * @type {Pointer}
+ **/
+ this.pointer5 = null;
+ /**
+ * A Pointer object
+ * @property pointer6
+ * @type {Pointer}
+ **/
+ this.pointer6 = null;
+ /**
+ * A Pointer object
+ * @property pointer7
+ * @type {Pointer}
+ **/
+ this.pointer7 = null;
+ /**
+ * A Pointer object
+ * @property pointer8
+ * @type {Pointer}
+ **/
+ this.pointer8 = null;
+ /**
+ * A Pointer object
+ * @property pointer9
+ * @type {Pointer}
+ **/
+ this.pointer9 = null;
+ /**
+ * A Pointer object
+ * @property pointer10
+ * @type {Pointer}
+ **/
+ this.pointer10 = null;
+ /**
+ * The most recently active Pointer object.
+ * When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse.
+ * @property activePointer
+ * @type {Pointer}
+ **/
+ this.activePointer = null;
+ this.inputObjects = [];
+ this.totalTrackedObjects = 0;
+ this.game = game;
+ this.mousePointer = new Phaser.Pointer(this.game, 0);
+ this.pointer1 = new Phaser.Pointer(this.game, 1);
+ this.pointer2 = new Phaser.Pointer(this.game, 2);
+ this.mouse = new Phaser.Mouse(this.game);
+ this.keyboard = new Phaser.Keyboard(this.game);
+ this.touch = new Phaser.Touch(this.game);
+ this.mspointer = new Phaser.MSPointer(this.game);
+ //this.gestures = new Gestures(this.game);
+ this.onDown = new Phaser.Signal();
+ this.onUp = new Phaser.Signal();
+ this.onTap = new Phaser.Signal();
+ this.onHold = new Phaser.Signal();
+ this.scale = new Phaser.Vec2(1, 1);
+ this.speed = new Phaser.Vec2();
+ this.position = new Phaser.Vec2();
+ this._oldPosition = new Phaser.Vec2();
+ this.circle = new Phaser.Circle(0, 0, 44);
+ this.activePointer = this.mousePointer;
+ this.currentPointers = 0;
+ this.hitCanvas = document.createElement('canvas');
+ this.hitCanvas.width = 1;
+ this.hitCanvas.height = 1;
+ this.hitContext = this.hitCanvas.getContext('2d');
+ }
+ InputManager.MOUSE_OVERRIDES_TOUCH = 0;
+ InputManager.TOUCH_OVERRIDES_MOUSE = 1;
+ InputManager.MOUSE_TOUCH_COMBINE = 2;
+ Object.defineProperty(InputManager.prototype, "camera", {
+ get: /**
+ * The camera being used for mouse and touch based pointers to calculate their world coordinates.
+ * This is only ever the camera set by the most recently active Pointer.
+ * If you need to know exactly which camera a specific Pointer is over then see Pointer.camera instead.
+ * @property camera
+ * @type {Camera}
+ **/
+ function () {
+ return this.activePointer.camera;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "x", {
+ get: /**
+ * The X coordinate of the most recently active pointer.
+ * This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
+ * @property x
+ * @type {Number}
+ **/
+ function () {
+ return this._x;
+ },
+ set: function (value) {
+ this._x = Math.floor(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "y", {
+ get: /**
+ * The Y coordinate of the most recently active pointer.
+ * This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
+ * @property y
+ * @type {Number}
+ **/
+ function () {
+ return this._y;
+ },
+ set: function (value) {
+ this._y = Math.floor(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.addPointer = /**
+ * Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more
+ * use this to create a new one, up to a maximum of 10.
+ * @method addPointer
+ * @return {Pointer} A reference to the new Pointer object
+ **/
+ function () {
+ var next = 0;
+ for(var i = 10; i > 0; i--) {
+ if(this['pointer' + i] === null) {
+ next = i;
+ }
+ }
+ if(next == 0) {
+ throw new Error("You can only have 10 Pointer objects");
+ return null;
+ } else {
+ this['pointer' + next] = new Phaser.Pointer(this.game, next);
+ return this['pointer' + next];
+ }
+ };
+ InputManager.prototype.boot = /**
+ * Starts the Input Manager running
+ * @method start
+ **/
+ function () {
+ this.mouse.start();
+ this.keyboard.start();
+ this.touch.start();
+ this.mspointer.start();
+ //this.gestures.start();
+ this.mousePointer.active = true;
+ };
+ InputManager.prototype.addGameObject = /**
+ * Adds a new game object to be tracked by the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
+ * @method addGameObject
+ **/
+ function (object) {
+ // Find a spare slot
+ for(var i = 0; i < this.inputObjects.length; i++) {
+ if(this.inputObjects[i] == null) {
+ this.inputObjects[i] = object;
+ object.input.indexID = i;
+ this.totalTrackedObjects++;
+ return;
+ }
+ }
+ // If we got this far we need to push a new entry into the array
+ object.input.indexID = this.inputObjects.length;
+ this.inputObjects.push(object);
+ this.totalTrackedObjects++;
+ };
+ InputManager.prototype.removeGameObject = /**
+ * Removes a game object from the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
+ * @method removeGameObject
+ **/
+ function (index) {
+ if(this.inputObjects[index]) {
+ this.inputObjects[index] = null;
+ }
+ };
+ Object.defineProperty(InputManager.prototype, "pollLocked", {
+ get: function () {
+ return (this.pollRate > 0 && this._pollCounter < this.pollRate);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.update = /**
+ * Updates the Input Manager. Called by the core Game loop.
+ * @method update
+ **/
+ function () {
+ if(this.pollRate > 0 && this._pollCounter < this.pollRate) {
+ this._pollCounter++;
+ return;
+ }
+ this.speed.x = this.position.x - this._oldPosition.x;
+ this.speed.y = this.position.y - this._oldPosition.y;
+ this._oldPosition.copyFrom(this.position);
+ this.mousePointer.update();
+ this.pointer1.update();
+ this.pointer2.update();
+ if(this.pointer3) {
+ this.pointer3.update();
+ }
+ if(this.pointer4) {
+ this.pointer4.update();
+ }
+ if(this.pointer5) {
+ this.pointer5.update();
+ }
+ if(this.pointer6) {
+ this.pointer6.update();
+ }
+ if(this.pointer7) {
+ this.pointer7.update();
+ }
+ if(this.pointer8) {
+ this.pointer8.update();
+ }
+ if(this.pointer9) {
+ this.pointer9.update();
+ }
+ if(this.pointer10) {
+ this.pointer10.update();
+ }
+ this._pollCounter = 0;
+ };
+ InputManager.prototype.reset = /**
+ * Reset all of the Pointers and Input states
+ * @method reset
+ * @param hard {bool} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
+ **/
+ function (hard) {
+ if (typeof hard === "undefined") { hard = false; }
+ this.keyboard.reset();
+ this.mousePointer.reset();
+ for(var i = 1; i <= 10; i++) {
+ if(this['pointer' + i]) {
+ this['pointer' + i].reset();
+ }
+ }
+ this.currentPointers = 0;
+ this.game.stage.canvas.style.cursor = "default";
+ if(hard == true) {
+ this.onDown.dispose();
+ this.onUp.dispose();
+ this.onTap.dispose();
+ this.onHold.dispose();
+ this.onDown = new Phaser.Signal();
+ this.onUp = new Phaser.Signal();
+ this.onTap = new Phaser.Signal();
+ this.onHold = new Phaser.Signal();
+ for(var i = 0; i < this.totalTrackedObjects; i++) {
+ if(this.inputObjects[i] && this.inputObjects[i].input) {
+ this.inputObjects[i].input.reset();
+ }
+ }
+ this.inputObjects.length = 0;
+ this.totalTrackedObjects = 0;
+ }
+ this._pollCounter = 0;
+ };
+ InputManager.prototype.resetSpeed = function (x, y) {
+ this._oldPosition.setTo(x, y);
+ this.speed.setTo(0, 0);
+ };
+ Object.defineProperty(InputManager.prototype, "totalInactivePointers", {
+ get: /**
+ * Get the total number of inactive Pointers
+ * @method totalInactivePointers
+ * @return {Number} The number of Pointers currently inactive
+ **/
+ function () {
+ return 10 - this.currentPointers;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "totalActivePointers", {
+ get: /**
+ * Recalculates the total number of active Pointers
+ * @method totalActivePointers
+ * @return {Number} The number of Pointers currently active
+ **/
+ function () {
+ this.currentPointers = 0;
+ for(var i = 1; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active) {
+ this.currentPointers++;
+ }
+ }
+ return this.currentPointers;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.startPointer = /**
+ * Find the first free Pointer object and start it, passing in the event data.
+ * @method startPointer
+ * @param {Any} event The event data from the Touch event
+ * @return {Pointer} The Pointer object that was started or null if no Pointer object is available
+ **/
+ function (event) {
+ if(this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) {
+ return null;
+ }
+ // Unrolled for speed
+ if(this.pointer1.active == false) {
+ return this.pointer1.start(event);
+ } else if(this.pointer2.active == false) {
+ return this.pointer2.start(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active == false) {
+ return this['pointer' + i].start(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.updatePointer = /**
+ * Updates the matching Pointer object, passing in the event data.
+ * @method updatePointer
+ * @param {Any} event The event data from the Touch event
+ * @return {Pointer} The Pointer object that was updated or null if no Pointer object is available
+ **/
+ function (event) {
+ // Unrolled for speed
+ if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
+ return this.pointer1.move(event);
+ } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
+ return this.pointer2.move(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
+ return this['pointer' + i].move(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.stopPointer = /**
+ * Stops the matching Pointer object, passing in the event data.
+ * @method stopPointer
+ * @param {Any} event The event data from the Touch event
+ * @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available
+ **/
+ function (event) {
+ // Unrolled for speed
+ if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
+ return this.pointer1.stop(event);
+ } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
+ return this.pointer2.stop(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
+ return this['pointer' + i].stop(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.getPointer = /**
+ * Get the next Pointer object whos active property matches the given state
+ * @method getPointer
+ * @param {bool} state The state the Pointer should be in (false for inactive, true for active)
+ * @return {Pointer} A Pointer object or null if no Pointer object matches the requested state.
+ **/
+ function (state) {
+ if (typeof state === "undefined") { state = false; }
+ // Unrolled for speed
+ if(this.pointer1.active == state) {
+ return this.pointer1;
+ } else if(this.pointer2.active == state) {
+ return this.pointer2;
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active == state) {
+ return this['pointer' + i];
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.getPointerFromIdentifier = /**
+ * Get the Pointer object whos identified property matches the given identifier value
+ * @method getPointerFromIdentifier
+ * @param {Number} identifier The Pointer.identifier value to search for
+ * @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier.
+ **/
+ function (identifier) {
+ // Unrolled for speed
+ if(this.pointer1.identifier == identifier) {
+ return this.pointer1;
+ } else if(this.pointer2.identifier == identifier) {
+ return this.pointer2;
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].identifier == identifier) {
+ return this['pointer' + i];
+ }
+ }
+ }
+ return null;
+ };
+ Object.defineProperty(InputManager.prototype, "worldX", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "worldY", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.getDistance = /**
+ * Get the distance between two Pointer objects
+ * @method getDistance
+ * @param {Pointer} pointer1
+ * @param {Pointer} pointer2
+ **/
+ function (pointer1, pointer2) {
+ return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position);
+ };
+ InputManager.prototype.getAngle = /**
+ * Get the angle between two Pointer objects
+ * @method getAngle
+ * @param {Pointer} pointer1
+ * @param {Pointer} pointer2
+ **/
+ function (pointer1, pointer2) {
+ return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
+ };
+ InputManager.prototype.pixelPerfectCheck = function (sprite, pointer, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ this.hitContext.clearRect(0, 0, 1, 1);
+ return true;
+ };
+ return InputManager;
+ })();
+ Phaser.InputManager = InputManager;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/input/InputManager.ts b/TS Source/input/InputManager.ts
similarity index 100%
rename from Phaser/input/InputManager.ts
rename to TS Source/input/InputManager.ts
diff --git a/TS Source/input/Keyboard.js b/TS Source/input/Keyboard.js
new file mode 100644
index 00000000..dfe1338a
--- /dev/null
+++ b/TS Source/input/Keyboard.js
@@ -0,0 +1,250 @@
+///
+/**
+* Phaser - Keyboard
+*
+* The Keyboard class handles keyboard interactions with the game and the resulting events.
+* The avoid stealing all browser input we don't use event.preventDefault. If you would like to trap a specific key however
+* then use the addKeyCapture() method.
+*/
+var Phaser;
+(function (Phaser) {
+ var Keyboard = (function () {
+ function Keyboard(game) {
+ this._keys = {
+ };
+ this._capture = {
+ };
+ /**
+ * You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
+ * @type {bool}
+ */
+ this.disabled = false;
+ this.game = game;
+ }
+ Keyboard.prototype.start = function () {
+ var _this = this;
+ this._onKeyDown = function (event) {
+ return _this.onKeyDown(event);
+ };
+ this._onKeyUp = function (event) {
+ return _this.onKeyUp(event);
+ };
+ document.body.addEventListener('keydown', this._onKeyDown, false);
+ document.body.addEventListener('keyup', this._onKeyUp, false);
+ };
+ Keyboard.prototype.stop = function () {
+ document.body.removeEventListener('keydown', this._onKeyDown);
+ document.body.removeEventListener('keyup', this._onKeyUp);
+ };
+ Keyboard.prototype.addKeyCapture = /**
+ * By default when a key is pressed Phaser will not stop the event from propagating up to the browser.
+ * There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll.
+ * You can use addKeyCapture to consume the keyboard event for specific keys so it doesn't bubble up to the the browser.
+ * Pass in either a single keycode or an array of keycodes.
+ * @param {Any} keycode
+ */
+ function (keycode) {
+ if(typeof keycode === 'object') {
+ for(var i = 0; i < keycode.length; i++) {
+ this._capture[keycode[i]] = true;
+ }
+ } else {
+ this._capture[keycode] = true;
+ }
+ };
+ Keyboard.prototype.removeKeyCapture = /**
+ * @param {Number} keycode
+ */
+ function (keycode) {
+ delete this._capture[keycode];
+ };
+ Keyboard.prototype.clearCaptures = function () {
+ this._capture = {
+ };
+ };
+ Keyboard.prototype.onKeyDown = /**
+ * @param {KeyboardEvent} event
+ */
+ function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ if(this._capture[event.keyCode]) {
+ event.preventDefault();
+ }
+ if(!this._keys[event.keyCode]) {
+ this._keys[event.keyCode] = {
+ isDown: true,
+ timeDown: this.game.time.now,
+ timeUp: 0
+ };
+ } else {
+ this._keys[event.keyCode].isDown = true;
+ this._keys[event.keyCode].timeDown = this.game.time.now;
+ }
+ };
+ Keyboard.prototype.onKeyUp = /**
+ * @param {KeyboardEvent} event
+ */
+ function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ if(this._capture[event.keyCode]) {
+ event.preventDefault();
+ }
+ if(!this._keys[event.keyCode]) {
+ this._keys[event.keyCode] = {
+ isDown: false,
+ timeDown: 0,
+ timeUp: this.game.time.now
+ };
+ } else {
+ this._keys[event.keyCode].isDown = false;
+ this._keys[event.keyCode].timeUp = this.game.time.now;
+ }
+ };
+ Keyboard.prototype.reset = function () {
+ for(var key in this._keys) {
+ this._keys[key].isDown = false;
+ }
+ };
+ Keyboard.prototype.justPressed = /**
+ * @param {Number} keycode
+ * @param {Number} [duration]
+ * @return {bool}
+ */
+ function (keycode, duration) {
+ if (typeof duration === "undefined") { duration = 250; }
+ if(this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.prototype.justReleased = /**
+ * @param {Number} keycode
+ * @param {Number} [duration]
+ * @return {bool}
+ */
+ function (keycode, duration) {
+ if (typeof duration === "undefined") { duration = 250; }
+ if(this._keys[keycode] && this._keys[keycode].isDown === false && (this.game.time.now - this._keys[keycode].timeUp < duration)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.prototype.isDown = /**
+ * @param {Number} keycode
+ * @return {bool}
+ */
+ function (keycode) {
+ if(this._keys[keycode]) {
+ return this._keys[keycode].isDown;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.A = "A".charCodeAt(0);
+ Keyboard.B = "B".charCodeAt(0);
+ Keyboard.C = "C".charCodeAt(0);
+ Keyboard.D = "D".charCodeAt(0);
+ Keyboard.E = "E".charCodeAt(0);
+ Keyboard.F = "F".charCodeAt(0);
+ Keyboard.G = "G".charCodeAt(0);
+ Keyboard.H = "H".charCodeAt(0);
+ Keyboard.I = "I".charCodeAt(0);
+ Keyboard.J = "J".charCodeAt(0);
+ Keyboard.K = "K".charCodeAt(0);
+ Keyboard.L = "L".charCodeAt(0);
+ Keyboard.M = "M".charCodeAt(0);
+ Keyboard.N = "N".charCodeAt(0);
+ Keyboard.O = "O".charCodeAt(0);
+ Keyboard.P = "P".charCodeAt(0);
+ Keyboard.Q = "Q".charCodeAt(0);
+ Keyboard.R = "R".charCodeAt(0);
+ Keyboard.S = "S".charCodeAt(0);
+ Keyboard.T = "T".charCodeAt(0);
+ Keyboard.U = "U".charCodeAt(0);
+ Keyboard.V = "V".charCodeAt(0);
+ Keyboard.W = "W".charCodeAt(0);
+ Keyboard.X = "X".charCodeAt(0);
+ Keyboard.Y = "Y".charCodeAt(0);
+ Keyboard.Z = "Z".charCodeAt(0);
+ Keyboard.ZERO = "0".charCodeAt(0);
+ Keyboard.ONE = "1".charCodeAt(0);
+ Keyboard.TWO = "2".charCodeAt(0);
+ Keyboard.THREE = "3".charCodeAt(0);
+ Keyboard.FOUR = "4".charCodeAt(0);
+ Keyboard.FIVE = "5".charCodeAt(0);
+ Keyboard.SIX = "6".charCodeAt(0);
+ Keyboard.SEVEN = "7".charCodeAt(0);
+ Keyboard.EIGHT = "8".charCodeAt(0);
+ Keyboard.NINE = "9".charCodeAt(0);
+ Keyboard.NUMPAD_0 = 96;
+ Keyboard.NUMPAD_1 = 97;
+ Keyboard.NUMPAD_2 = 98;
+ Keyboard.NUMPAD_3 = 99;
+ Keyboard.NUMPAD_4 = 100;
+ Keyboard.NUMPAD_5 = 101;
+ Keyboard.NUMPAD_6 = 102;
+ Keyboard.NUMPAD_7 = 103;
+ Keyboard.NUMPAD_8 = 104;
+ Keyboard.NUMPAD_9 = 105;
+ Keyboard.NUMPAD_MULTIPLY = 106;
+ Keyboard.NUMPAD_ADD = 107;
+ Keyboard.NUMPAD_ENTER = 108;
+ Keyboard.NUMPAD_SUBTRACT = 109;
+ Keyboard.NUMPAD_DECIMAL = 110;
+ Keyboard.NUMPAD_DIVIDE = 111;
+ Keyboard.F1 = 112;
+ Keyboard.F2 = 113;
+ Keyboard.F3 = 114;
+ Keyboard.F4 = 115;
+ Keyboard.F5 = 116;
+ Keyboard.F6 = 117;
+ Keyboard.F7 = 118;
+ Keyboard.F8 = 119;
+ Keyboard.F9 = 120;
+ Keyboard.F10 = 121;
+ Keyboard.F11 = 122;
+ Keyboard.F12 = 123;
+ Keyboard.F13 = 124;
+ Keyboard.F14 = 125;
+ Keyboard.F15 = 126;
+ Keyboard.COLON = 186;
+ Keyboard.EQUALS = 187;
+ Keyboard.UNDERSCORE = 189;
+ Keyboard.QUESTION_MARK = 191;
+ Keyboard.TILDE = 192;
+ Keyboard.OPEN_BRACKET = 219;
+ Keyboard.BACKWARD_SLASH = 220;
+ Keyboard.CLOSED_BRACKET = 221;
+ Keyboard.QUOTES = 222;
+ Keyboard.BACKSPACE = 8;
+ Keyboard.TAB = 9;
+ Keyboard.CLEAR = 12;
+ Keyboard.ENTER = 13;
+ Keyboard.SHIFT = 16;
+ Keyboard.CONTROL = 17;
+ Keyboard.ALT = 18;
+ Keyboard.CAPS_LOCK = 20;
+ Keyboard.ESC = 27;
+ Keyboard.SPACEBAR = 32;
+ Keyboard.PAGE_UP = 33;
+ Keyboard.PAGE_DOWN = 34;
+ Keyboard.END = 35;
+ Keyboard.HOME = 36;
+ Keyboard.LEFT = 37;
+ Keyboard.UP = 38;
+ Keyboard.RIGHT = 39;
+ Keyboard.DOWN = 40;
+ Keyboard.INSERT = 45;
+ Keyboard.DELETE = 46;
+ Keyboard.HELP = 47;
+ Keyboard.NUM_LOCK = 144;
+ return Keyboard;
+ })();
+ Phaser.Keyboard = Keyboard;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/input/Keyboard.ts b/TS Source/input/Keyboard.ts
similarity index 100%
rename from Phaser/input/Keyboard.ts
rename to TS Source/input/Keyboard.ts
diff --git a/TS Source/input/MSPointer.js b/TS Source/input/MSPointer.js
new file mode 100644
index 00000000..ad67f8c6
--- /dev/null
+++ b/TS Source/input/MSPointer.js
@@ -0,0 +1,99 @@
+///
+/**
+* Phaser - MSPointer
+*
+* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
+* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
+* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
+*/
+var Phaser;
+(function (Phaser) {
+ var MSPointer = (function () {
+ /**
+ * Constructor
+ * @param {Game} game.
+ * @return {MSPointer} This object.
+ */
+ function MSPointer(game) {
+ /**
+ * You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
+ * @type {bool}
+ */
+ this.disabled = false;
+ this.game = game;
+ }
+ MSPointer.prototype.start = /**
+ * Starts the event listeners running
+ * @method start
+ */
+ function () {
+ var _this = this;
+ if(this.game.device.mspointer == true) {
+ this._onMSPointerDown = function (event) {
+ return _this.onPointerDown(event);
+ };
+ this._onMSPointerMove = function (event) {
+ return _this.onPointerMove(event);
+ };
+ this._onMSPointerUp = function (event) {
+ return _this.onPointerUp(event);
+ };
+ this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
+ this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
+ this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
+ }
+ };
+ MSPointer.prototype.onPointerDown = /**
+ *
+ * @method onPointerDown
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.startPointer(event);
+ };
+ MSPointer.prototype.onPointerMove = /**
+ *
+ * @method onPointerMove
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.updatePointer(event);
+ };
+ MSPointer.prototype.onPointerUp = /**
+ *
+ * @method onPointerUp
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.stopPointer(event);
+ };
+ MSPointer.prototype.stop = /**
+ * Stop the event listeners
+ * @method stop
+ */
+ function () {
+ if(this.game.device.mspointer == true) {
+ this.game.stage.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
+ this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
+ this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
+ }
+ };
+ return MSPointer;
+ })();
+ Phaser.MSPointer = MSPointer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/input/MSPointer.ts b/TS Source/input/MSPointer.ts
similarity index 100%
rename from Phaser/input/MSPointer.ts
rename to TS Source/input/MSPointer.ts
diff --git a/TS Source/input/Mouse.js b/TS Source/input/Mouse.js
new file mode 100644
index 00000000..4f9ed6a8
--- /dev/null
+++ b/TS Source/input/Mouse.js
@@ -0,0 +1,99 @@
+///
+/**
+* Phaser - Mouse
+*
+* The Mouse class handles mouse interactions with the game and the resulting events.
+*/
+var Phaser;
+(function (Phaser) {
+ var Mouse = (function () {
+ function Mouse(game) {
+ /**
+ * You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
+ * @type {bool}
+ */
+ this.disabled = false;
+ this.mouseDownCallback = null;
+ this.mouseMoveCallback = null;
+ this.mouseUpCallback = null;
+ this.game = game;
+ this.callbackContext = this.game;
+ }
+ Mouse.LEFT_BUTTON = 0;
+ Mouse.MIDDLE_BUTTON = 1;
+ Mouse.RIGHT_BUTTON = 2;
+ Mouse.prototype.start = /**
+ * Starts the event listeners running
+ * @method start
+ */
+ function () {
+ var _this = this;
+ if(this.game.device.android && this.game.device.chrome == false) {
+ // Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
+ return;
+ }
+ this._onMouseDown = function (event) {
+ return _this.onMouseDown(event);
+ };
+ this._onMouseMove = function (event) {
+ return _this.onMouseMove(event);
+ };
+ this._onMouseUp = function (event) {
+ return _this.onMouseUp(event);
+ };
+ this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
+ this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
+ this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
+ };
+ Mouse.prototype.onMouseDown = /**
+ * @param {MouseEvent} event
+ */
+ function (event) {
+ if(this.mouseDownCallback) {
+ this.mouseDownCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.start(event);
+ };
+ Mouse.prototype.onMouseMove = /**
+ * @param {MouseEvent} event
+ */
+ function (event) {
+ if(this.mouseMoveCallback) {
+ this.mouseMoveCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.move(event);
+ };
+ Mouse.prototype.onMouseUp = /**
+ * @param {MouseEvent} event
+ */
+ function (event) {
+ if(this.mouseUpCallback) {
+ this.mouseUpCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.stop(event);
+ };
+ Mouse.prototype.stop = /**
+ * Stop the event listeners
+ * @method stop
+ */
+ function () {
+ this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown);
+ this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove);
+ this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp);
+ };
+ return Mouse;
+ })();
+ Phaser.Mouse = Mouse;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/input/Mouse.ts b/TS Source/input/Mouse.ts
similarity index 100%
rename from Phaser/input/Mouse.ts
rename to TS Source/input/Mouse.ts
diff --git a/TS Source/input/Pointer.js b/TS Source/input/Pointer.js
new file mode 100644
index 00000000..4de3ab4b
--- /dev/null
+++ b/TS Source/input/Pointer.js
@@ -0,0 +1,497 @@
+///
+/**
+* Phaser - Pointer
+*
+* A Pointer object is used by the Touch and MSPoint managers and represents a single finger on the touch screen.
+*/
+var Phaser;
+(function (Phaser) {
+ var Pointer = (function () {
+ /**
+ * Constructor
+ * @param {Phaser.Game} game.
+ * @return {Phaser.Pointer} This object.
+ */
+ function Pointer(game, id) {
+ /**
+ * Local private variable to store the status of dispatching a hold event
+ * @property _holdSent
+ * @type {bool}
+ * @private
+ */
+ this._holdSent = false;
+ /**
+ * Local private variable storing the short-term history of pointer movements
+ * @property _history
+ * @type {Array}
+ * @private
+ */
+ this._history = [];
+ /**
+ * Local private variable storing the time at which the next history drop should occur
+ * @property _lastDrop
+ * @type {Number}
+ * @private
+ */
+ this._nextDrop = 0;
+ // Monitor events outside of a state reset loop
+ this._stateReset = false;
+ /**
+ * A Vector object containing the initial position when the Pointer was engaged with the screen.
+ * @property positionDown
+ * @type {Vec2}
+ **/
+ this.positionDown = null;
+ /**
+ * A Vector object containing the current position of the Pointer on the screen.
+ * @property position
+ * @type {Vec2}
+ **/
+ this.position = null;
+ /**
+ * A Circle object centered on the x/y screen coordinates of the Pointer.
+ * Default size of 44px (Apple's recommended "finger tip" size)
+ * @property circle
+ * @type {Circle}
+ **/
+ this.circle = null;
+ /**
+ *
+ * @property withinGame
+ * @type {bool}
+ */
+ this.withinGame = false;
+ /**
+ * The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
+ * @property clientX
+ * @type {Number}
+ */
+ this.clientX = -1;
+ /**
+ * The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
+ * @property clientY
+ * @type {Number}
+ */
+ this.clientY = -1;
+ /**
+ * The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
+ * @property pageX
+ * @type {Number}
+ */
+ this.pageX = -1;
+ /**
+ * The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
+ * @property pageY
+ * @type {Number}
+ */
+ this.pageY = -1;
+ /**
+ * The horizontal coordinate of point relative to the screen in pixels
+ * @property screenX
+ * @type {Number}
+ */
+ this.screenX = -1;
+ /**
+ * The vertical coordinate of point relative to the screen in pixels
+ * @property screenY
+ * @type {Number}
+ */
+ this.screenY = -1;
+ /**
+ * The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
+ * @property x
+ * @type {Number}
+ */
+ this.x = -1;
+ /**
+ * The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
+ * @property y
+ * @type {Number}
+ */
+ this.y = -1;
+ /**
+ * If the Pointer is a mouse this is true, otherwise false
+ * @property isMouse
+ * @type {bool}
+ **/
+ this.isMouse = false;
+ /**
+ * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
+ * @property isDown
+ * @type {bool}
+ **/
+ this.isDown = false;
+ /**
+ * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
+ * @property isUp
+ * @type {bool}
+ **/
+ this.isUp = true;
+ /**
+ * A timestamp representing when the Pointer first touched the touchscreen.
+ * @property timeDown
+ * @type {Number}
+ **/
+ this.timeDown = 0;
+ /**
+ * A timestamp representing when the Pointer left the touchscreen.
+ * @property timeUp
+ * @type {Number}
+ **/
+ this.timeUp = 0;
+ /**
+ * A timestamp representing when the Pointer was last tapped or clicked
+ * @property previousTapTime
+ * @type {Number}
+ **/
+ this.previousTapTime = 0;
+ /**
+ * The total number of times this Pointer has been touched to the touchscreen
+ * @property totalTouches
+ * @type {Number}
+ **/
+ this.totalTouches = 0;
+ /**
+ * The number of miliseconds since the last click
+ * @property msSinceLastClick
+ * @type {Number}
+ **/
+ this.msSinceLastClick = Number.MAX_VALUE;
+ /**
+ * The Game Object this Pointer is currently over / touching / dragging.
+ * @property targetObject
+ * @type {Any}
+ **/
+ this.targetObject = null;
+ /**
+ * The top-most Camera that this Pointer is over (if any, null if none).
+ * If the Pointer is over several cameras that are stacked on-top of each other this is only ever set to the top-most rendered camera.
+ * @property camera
+ * @type {Phaser.Camera}
+ **/
+ this.camera = null;
+ this.game = game;
+ this.id = id;
+ this.active = false;
+ this.position = new Phaser.Vec2();
+ this.positionDown = new Phaser.Vec2();
+ this.circle = new Phaser.Circle(0, 0, 44);
+ if(id == 0) {
+ this.isMouse = true;
+ }
+ }
+ Object.defineProperty(Pointer.prototype, "duration", {
+ get: /**
+ * How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
+ * @property duration
+ * @type {Number}
+ **/
+ function () {
+ if(this.isUp) {
+ return -1;
+ }
+ return this.game.time.now - this.timeDown;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Pointer.prototype, "worldX", {
+ get: /**
+ * Gets the X value of this Pointer in world coordinates based on the given camera.
+ * @param {Camera} [camera]
+ */
+ function () {
+ if(this.camera) {
+ return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Pointer.prototype, "worldY", {
+ get: /**
+ * Gets the Y value of this Pointer in world coordinates based on the given camera.
+ * @param {Camera} [camera]
+ */
+ function () {
+ if(this.camera) {
+ return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Pointer.prototype.start = /**
+ * Called when the Pointer is pressed onto the touchscreen
+ * @method start
+ * @param {Any} event
+ */
+ function (event) {
+ this.identifier = event.identifier;
+ this.target = event.target;
+ if(event.button) {
+ this.button = event.button;
+ }
+ // Fix to stop rogue browser plugins from blocking the visibility state event
+ if(this.game.paused == true && this.game.stage.scale.incorrectOrientation == false) {
+ this.game.stage.resumeGame();
+ return this;
+ }
+ this._history.length = 0;
+ this.active = true;
+ this.withinGame = true;
+ this.isDown = true;
+ this.isUp = false;
+ // Work out how long it has been since the last click
+ this.msSinceLastClick = this.game.time.now - this.timeDown;
+ this.timeDown = this.game.time.now;
+ this._holdSent = false;
+ // This sets the x/y and other local values
+ this.move(event);
+ // x and y are the old values here?
+ this.positionDown.setTo(this.x, this.y);
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ //this.game.input.x = this.x * this.game.input.scale.x;
+ //this.game.input.y = this.y * this.game.input.scale.y;
+ this.game.input.x = this.x;
+ this.game.input.y = this.y;
+ this.game.input.position.setTo(this.x, this.y);
+ this.game.input.onDown.dispatch(this);
+ this.game.input.resetSpeed(this.x, this.y);
+ }
+ this._stateReset = false;
+ this.totalTouches++;
+ if(this.isMouse == false) {
+ this.game.input.currentPointers++;
+ }
+ if(this.targetObject !== null) {
+ this.targetObject.input._touchedHandler(this);
+ }
+ return this;
+ };
+ Pointer.prototype.update = function () {
+ if(this.active) {
+ if(this._holdSent == false && this.duration >= this.game.input.holdRate) {
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.onHold.dispatch(this);
+ }
+ this._holdSent = true;
+ }
+ // Update the droppings history
+ if(this.game.input.recordPointerHistory && this.game.time.now >= this._nextDrop) {
+ this._nextDrop = this.game.time.now + this.game.input.recordRate;
+ this._history.push({
+ x: this.position.x,
+ y: this.position.y
+ });
+ if(this._history.length > this.game.input.recordLimit) {
+ this._history.shift();
+ }
+ }
+ // Check which camera they are over
+ this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y);
+ }
+ };
+ Pointer.prototype.move = /**
+ * Called when the Pointer is moved on the touchscreen
+ * @method move
+ * @param {Any} event
+ */
+ function (event) {
+ if(this.game.input.pollLocked) {
+ return;
+ }
+ if(event.button) {
+ this.button = event.button;
+ }
+ this.clientX = event.clientX;
+ this.clientY = event.clientY;
+ this.pageX = event.pageX;
+ this.pageY = event.pageY;
+ this.screenX = event.screenX;
+ this.screenY = event.screenY;
+ this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
+ this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
+ this.position.setTo(this.x, this.y);
+ this.circle.x = this.x;
+ this.circle.y = this.y;
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.activePointer = this;
+ this.game.input.x = this.x;
+ this.game.input.y = this.y;
+ this.game.input.position.setTo(this.game.input.x, this.game.input.y);
+ this.game.input.circle.x = this.game.input.x;
+ this.game.input.circle.y = this.game.input.y;
+ }
+ // If the game is paused we don't process any target objects
+ if(this.game.paused) {
+ return this;
+ }
+ // Easy out if we're dragging something and it still exists
+ if(this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true) {
+ if(this.targetObject.input.update(this) == false) {
+ this.targetObject = null;
+ }
+ return this;
+ }
+ // Work out which object is on the top
+ this._highestRenderOrderID = -1;
+ this._highestRenderObject = -1;
+ this._highestInputPriorityID = -1;
+ for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
+ if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) {
+ // If the object has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top
+ if(this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID)) {
+ this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID;
+ this._highestRenderObject = i;
+ this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID;
+ }
+ }
+ }
+ if(this._highestRenderObject == -1) {
+ // The pointer isn't over anything, check if we've got a lingering previous target
+ if(this.targetObject !== null) {
+ this.targetObject.input._pointerOutHandler(this);
+ this.targetObject = null;
+ }
+ } else {
+ if(this.targetObject == null) {
+ // And now set the new one
+ this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
+ this.targetObject.input._pointerOverHandler(this);
+ } else {
+ // We've got a target from the last update
+ if(this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) {
+ // Same target as before, so update it
+ if(this.targetObject.input.update(this) == false) {
+ this.targetObject = null;
+ }
+ } else {
+ // The target has changed, so tell the old one we've left it
+ this.targetObject.input._pointerOutHandler(this);
+ // And now set the new one
+ this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
+ this.targetObject.input._pointerOverHandler(this);
+ }
+ }
+ }
+ return this;
+ };
+ Pointer.prototype.leave = /**
+ * Called when the Pointer leaves the target area
+ * @method leave
+ * @param {Any} event
+ */
+ function (event) {
+ this.withinGame = false;
+ this.move(event);
+ };
+ Pointer.prototype.stop = /**
+ * Called when the Pointer leaves the touchscreen
+ * @method stop
+ * @param {Any} event
+ */
+ function (event) {
+ if(this._stateReset) {
+ event.preventDefault();
+ return;
+ }
+ this.timeUp = this.game.time.now;
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.onUp.dispatch(this);
+ // Was it a tap?
+ if(this.duration >= 0 && this.duration <= this.game.input.tapRate) {
+ // Was it a double-tap?
+ if(this.timeUp - this.previousTapTime < this.game.input.doubleTapRate) {
+ // Yes, let's dispatch the signal then with the 2nd parameter set to true
+ this.game.input.onTap.dispatch(this, true);
+ } else {
+ // Wasn't a double-tap, so dispatch a single tap signal
+ this.game.input.onTap.dispatch(this, false);
+ }
+ this.previousTapTime = this.timeUp;
+ }
+ }
+ // Mouse is always active
+ if(this.id > 0) {
+ this.active = false;
+ }
+ this.withinGame = false;
+ this.isDown = false;
+ this.isUp = true;
+ if(this.isMouse == false) {
+ this.game.input.currentPointers--;
+ }
+ for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
+ if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) {
+ this.game.input.inputObjects[i].input._releasedHandler(this);
+ }
+ }
+ if(this.targetObject) {
+ this.targetObject.input._releasedHandler(this);
+ }
+ this.targetObject = null;
+ return this;
+ };
+ Pointer.prototype.justPressed = /**
+ * The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate
+ * @method justPressed
+ * @param {Number} [duration].
+ * @return {bool}
+ */
+ function (duration) {
+ if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; }
+ if(this.isDown === true && (this.timeDown + duration) > this.game.time.now) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Pointer.prototype.justReleased = /**
+ * The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate
+ * @method justReleased
+ * @param {Number} [duration].
+ * @return {bool}
+ */
+ function (duration) {
+ if (typeof duration === "undefined") { duration = this.game.input.justReleasedRate; }
+ if(this.isUp === true && (this.timeUp + duration) > this.game.time.now) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Pointer.prototype.reset = /**
+ * Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
+ * @method reset
+ */
+ function () {
+ if(this.isMouse == false) {
+ this.active = false;
+ }
+ this.identifier = null;
+ this.isDown = false;
+ this.isUp = true;
+ this.totalTouches = 0;
+ this._holdSent = false;
+ this._history.length = 0;
+ this._stateReset = true;
+ if(this.targetObject && this.targetObject.input) {
+ this.targetObject.input._releasedHandler(this);
+ }
+ this.targetObject = null;
+ };
+ Pointer.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {String} a string representation of the instance.
+ **/
+ function () {
+ return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
+ };
+ return Pointer;
+ })();
+ Phaser.Pointer = Pointer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/input/Pointer.ts b/TS Source/input/Pointer.ts
similarity index 100%
rename from Phaser/input/Pointer.ts
rename to TS Source/input/Pointer.ts
diff --git a/TS Source/input/Touch.js b/TS Source/input/Touch.js
new file mode 100644
index 00000000..e87040ed
--- /dev/null
+++ b/TS Source/input/Touch.js
@@ -0,0 +1,201 @@
+///
+/**
+* Phaser - Touch
+*
+* The Touch class handles touch interactions with the game and the resulting Pointer objects.
+* http://www.w3.org/TR/touch-events/
+* https://developer.mozilla.org/en-US/docs/DOM/TouchList
+* http://www.html5rocks.com/en/mobile/touchandmouse/
+* Note: Android 2.x only supports 1 touch event at once, no multi-touch
+*/
+var Phaser;
+(function (Phaser) {
+ var Touch = (function () {
+ /**
+ * Constructor
+ * @param {Game} game.
+ * @return {Touch} This object.
+ */
+ function Touch(game) {
+ /**
+ * You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
+ * @type {bool}
+ */
+ this.disabled = false;
+ this.touchStartCallback = null;
+ this.touchMoveCallback = null;
+ this.touchEndCallback = null;
+ this.touchEnterCallback = null;
+ this.touchLeaveCallback = null;
+ this.touchCancelCallback = null;
+ this.game = game;
+ this.callbackContext = this.game;
+ }
+ Touch.prototype.start = /**
+ * Starts the event listeners running
+ * @method start
+ */
+ function () {
+ var _this = this;
+ if(this.game.device.touch) {
+ this._onTouchStart = function (event) {
+ return _this.onTouchStart(event);
+ };
+ this._onTouchMove = function (event) {
+ return _this.onTouchMove(event);
+ };
+ this._onTouchEnd = function (event) {
+ return _this.onTouchEnd(event);
+ };
+ this._onTouchEnter = function (event) {
+ return _this.onTouchEnter(event);
+ };
+ this._onTouchLeave = function (event) {
+ return _this.onTouchLeave(event);
+ };
+ this._onTouchCancel = function (event) {
+ return _this.onTouchCancel(event);
+ };
+ this._documentTouchMove = function (event) {
+ return _this.consumeTouchMove(event);
+ };
+ this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false);
+ this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false);
+ this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false);
+ this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false);
+ this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false);
+ this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
+ document.addEventListener('touchmove', this._documentTouchMove, false);
+ }
+ };
+ Touch.prototype.consumeTouchMove = /**
+ * Prevent iOS bounce-back (doesn't work?)
+ * @method consumeTouchMove
+ * @param {Any} event
+ **/
+ function (event) {
+ event.preventDefault();
+ };
+ Touch.prototype.onTouchStart = /**
+ *
+ * @method onTouchStart
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.touchStartCallback) {
+ this.touchStartCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ // event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
+ // event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
+ // event.changedTouches = the touches that CHANGED in this event, not the total number of them
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.startPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchCancel = /**
+ * Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
+ * Occurs for example on iOS when you put down 4 fingers and the app selector UI appears
+ * @method onTouchCancel
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.touchCancelCallback) {
+ this.touchCancelCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ // Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
+ // http://www.w3.org/TR/touch-events/#dfn-touchcancel
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.stopPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchEnter = /**
+ * For touch enter and leave its a list of the touch points that have entered or left the target
+ * Doesn't appear to be supported by most browsers yet
+ * @method onTouchEnter
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.touchEnterCallback) {
+ this.touchEnterCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ //console.log('touch enter');
+ }
+ };
+ Touch.prototype.onTouchLeave = /**
+ * For touch enter and leave its a list of the touch points that have entered or left the target
+ * Doesn't appear to be supported by most browsers yet
+ * @method onTouchLeave
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.touchLeaveCallback) {
+ this.touchLeaveCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ //console.log('touch leave');
+ }
+ };
+ Touch.prototype.onTouchMove = /**
+ *
+ * @method onTouchMove
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.touchMoveCallback) {
+ this.touchMoveCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.updatePointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchEnd = /**
+ *
+ * @method onTouchEnd
+ * @param {Any} event
+ **/
+ function (event) {
+ if(this.touchEndCallback) {
+ this.touchEndCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ // For touch end its a list of the touch points that have been removed from the surface
+ // https://developer.mozilla.org/en-US/docs/DOM/TouchList
+ // event.changedTouches = the touches that CHANGED in this event, not the total number of them
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.stopPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.stop = /**
+ * Stop the event listeners
+ * @method stop
+ */
+ function () {
+ if(this.game.device.touch) {
+ this.game.stage.canvas.removeEventListener('touchstart', this._onTouchStart);
+ this.game.stage.canvas.removeEventListener('touchmove', this._onTouchMove);
+ this.game.stage.canvas.removeEventListener('touchend', this._onTouchEnd);
+ this.game.stage.canvas.removeEventListener('touchenter', this._onTouchEnter);
+ this.game.stage.canvas.removeEventListener('touchleave', this._onTouchLeave);
+ this.game.stage.canvas.removeEventListener('touchcancel', this._onTouchCancel);
+ document.removeEventListener('touchmove', this._documentTouchMove);
+ }
+ };
+ return Touch;
+ })();
+ Phaser.Touch = Touch;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/input/Touch.ts b/TS Source/input/Touch.ts
similarity index 100%
rename from Phaser/input/Touch.ts
rename to TS Source/input/Touch.ts
diff --git a/TS Source/loader/AnimationLoader.js b/TS Source/loader/AnimationLoader.js
new file mode 100644
index 00000000..32dae6a8
--- /dev/null
+++ b/TS Source/loader/AnimationLoader.js
@@ -0,0 +1,96 @@
+///
+/**
+* Phaser - AnimationLoader
+*
+* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
+*/
+var Phaser;
+(function (Phaser) {
+ var AnimationLoader = (function () {
+ function AnimationLoader() { }
+ AnimationLoader.parseSpriteSheet = /**
+ * Parse a sprite sheet from asset data.
+ * @param key {string} Asset key for the sprite sheet data.
+ * @param frameWidth {number} Width of animation frame.
+ * @param frameHeight {number} Height of animation frame.
+ * @param frameMax {number} Number of animation frames.
+ * @return {FrameData} Generated FrameData object.
+ */
+ function parseSpriteSheet(game, key, frameWidth, frameHeight, frameMax) {
+ // How big is our image?
+ var img = game.cache.getImage(key);
+ if(img == null) {
+ return null;
+ }
+ var width = img.width;
+ var height = img.height;
+ var row = Math.round(width / frameWidth);
+ var column = Math.round(height / frameHeight);
+ var total = row * column;
+ if(frameMax !== -1) {
+ total = frameMax;
+ }
+ // Zero or smaller than frame sizes?
+ if(width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
+ throw new Error("AnimationLoader.parseSpriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
+ return null;
+ }
+ // Let's create some frames then
+ var data = new Phaser.FrameData();
+ var x = 0;
+ var y = 0;
+ for(var i = 0; i < total; i++) {
+ data.addFrame(new Phaser.Frame(x, y, frameWidth, frameHeight, ''));
+ x += frameWidth;
+ if(x === width) {
+ x = 0;
+ y += frameHeight;
+ }
+ }
+ return data;
+ };
+ AnimationLoader.parseJSONData = /**
+ * Parse frame datas from json.
+ * @param json {object} Json data you want to parse.
+ * @return {FrameData} Generated FrameData object.
+ */
+ function parseJSONData(game, json) {
+ // Malformed?
+ if(!json['frames']) {
+ console.log(json);
+ throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
+ }
+ // Let's create some frames then
+ var data = new Phaser.FrameData();
+ // By this stage frames is a fully parsed array
+ var frames = json['frames'];
+ var newFrame;
+ for(var i = 0; i < frames.length; i++) {
+ newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
+ newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
+ }
+ return data;
+ };
+ AnimationLoader.parseXMLData = function parseXMLData(game, xml, format) {
+ // Malformed?
+ if(!xml.getElementsByTagName('TextureAtlas')) {
+ throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing tag");
+ }
+ // Let's create some frames then
+ var data = new Phaser.FrameData();
+ var frames = xml.getElementsByTagName('SubTexture');
+ var newFrame;
+ for(var i = 0; i < frames.length; i++) {
+ var frame = frames[i].attributes;
+ newFrame = data.addFrame(new Phaser.Frame(frame.x.nodeValue, frame.y.nodeValue, frame.width.nodeValue, frame.height.nodeValue, frame.name.nodeValue));
+ // Trimmed?
+ if(frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0') {
+ newFrame.setTrim(true, frame.width.nodeValue, frame.height.nodeValue, Math.abs(frame.frameX.nodeValue), Math.abs(frame.frameY.nodeValue), frame.frameWidth.nodeValue, frame.frameHeight.nodeValue);
+ }
+ }
+ return data;
+ };
+ return AnimationLoader;
+ })();
+ Phaser.AnimationLoader = AnimationLoader;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/loader/AnimationLoader.ts b/TS Source/loader/AnimationLoader.ts
similarity index 100%
rename from Phaser/loader/AnimationLoader.ts
rename to TS Source/loader/AnimationLoader.ts
diff --git a/TS Source/loader/Cache.js b/TS Source/loader/Cache.js
new file mode 100644
index 00000000..ba313d32
--- /dev/null
+++ b/TS Source/loader/Cache.js
@@ -0,0 +1,318 @@
+///
+/**
+* Phaser - Cache
+*
+* A game only has one instance of a Cache and it is used to store all externally loaded assets such
+* as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up.
+*/
+var Phaser;
+(function (Phaser) {
+ var Cache = (function () {
+ /**
+ * Cache constructor
+ */
+ function Cache(game) {
+ this.onSoundUnlock = new Phaser.Signal();
+ this.game = game;
+ this._canvases = {
+ };
+ this._images = {
+ };
+ this._sounds = {
+ };
+ this._text = {
+ };
+ }
+ Cache.prototype.addCanvas = /**
+ * Add a new canvas.
+ * @param key {string} Asset key for this canvas.
+ * @param canvas {HTMLCanvasElement} Canvas DOM element.
+ * @param context {CanvasRenderingContext2D} Render context of this canvas.
+ */
+ function (key, canvas, context) {
+ this._canvases[key] = {
+ canvas: canvas,
+ context: context
+ };
+ };
+ Cache.prototype.addSpriteSheet = /**
+ * Add a new sprite sheet.
+ * @param key {string} Asset key for the sprite sheet.
+ * @param url {string} URL of this sprite sheet file.
+ * @param data {object} Extra sprite sheet data.
+ * @param frameWidth {number} Width of the sprite sheet.
+ * @param frameHeight {number} Height of the sprite sheet.
+ * @param frameMax {number} How many frames stored in the sprite sheet.
+ */
+ function (key, url, data, frameWidth, frameHeight, frameMax) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: true,
+ frameWidth: frameWidth,
+ frameHeight: frameHeight
+ };
+ this._images[key].frameData = Phaser.AnimationLoader.parseSpriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
+ };
+ Cache.prototype.addTextureAtlas = /**
+ * Add a new texture atlas.
+ * @param key {string} Asset key for the texture atlas.
+ * @param url {string} URL of this texture atlas file.
+ * @param data {object} Extra texture atlas data.
+ * @param atlasData {object} Texture atlas frames data.
+ */
+ function (key, url, data, atlasData, format) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: true
+ };
+ if(format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ this._images[key].frameData = Phaser.AnimationLoader.parseJSONData(this.game, atlasData);
+ } else if(format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING) {
+ this._images[key].frameData = Phaser.AnimationLoader.parseXMLData(this.game, atlasData, format);
+ }
+ };
+ Cache.prototype.addImage = /**
+ * Add a new image.
+ * @param key {string} Asset key for the image.
+ * @param url {string} URL of this image file.
+ * @param data {object} Extra image data.
+ */
+ function (key, url, data) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: false
+ };
+ };
+ Cache.prototype.addSound = /**
+ * Add a new sound.
+ * @param key {string} Asset key for the sound.
+ * @param url {string} URL of this sound file.
+ * @param data {object} Extra sound data.
+ */
+ function (key, url, data, webAudio, audioTag) {
+ if (typeof webAudio === "undefined") { webAudio = true; }
+ if (typeof audioTag === "undefined") { audioTag = false; }
+ var locked = this.game.sound.touchLocked;
+ var decoded = false;
+ if(audioTag) {
+ decoded = true;
+ }
+ this._sounds[key] = {
+ url: url,
+ data: data,
+ locked: locked,
+ isDecoding: false,
+ decoded: decoded,
+ webAudio: webAudio,
+ audioTag: audioTag
+ };
+ };
+ Cache.prototype.reloadSound = function (key) {
+ var _this = this;
+ if(this._sounds[key]) {
+ this._sounds[key].data.src = this._sounds[key].url;
+ this._sounds[key].data.addEventListener('canplaythrough', function () {
+ return _this.reloadSoundComplete(key);
+ }, false);
+ this._sounds[key].data.load();
+ }
+ };
+ Cache.prototype.reloadSoundComplete = function (key) {
+ if(this._sounds[key]) {
+ this._sounds[key].locked = false;
+ this.onSoundUnlock.dispatch(key);
+ }
+ };
+ Cache.prototype.updateSound = function (key, property, value) {
+ if(this._sounds[key]) {
+ this._sounds[key][property] = value;
+ }
+ };
+ Cache.prototype.decodedSound = /**
+ * Add a new decoded sound.
+ * @param key {string} Asset key for the sound.
+ * @param data {object} Extra sound data.
+ */
+ function (key, data) {
+ this._sounds[key].data = data;
+ this._sounds[key].decoded = true;
+ this._sounds[key].isDecoding = false;
+ };
+ Cache.prototype.addText = /**
+ * Add a new text data.
+ * @param key {string} Asset key for the text data.
+ * @param url {string} URL of this text data file.
+ * @param data {object} Extra text data.
+ */
+ function (key, url, data) {
+ this._text[key] = {
+ url: url,
+ data: data
+ };
+ };
+ Cache.prototype.getCanvas = /**
+ * Get canvas by key.
+ * @param key Asset key of the canvas you want.
+ * @return {object} The canvas you want.
+ */
+ function (key) {
+ if(this._canvases[key]) {
+ return this._canvases[key].canvas;
+ }
+ return null;
+ };
+ Cache.prototype.getImage = /**
+ * Get image data by key.
+ * @param key Asset key of the image you want.
+ * @return {object} The image data you want.
+ */
+ function (key) {
+ if(this._images[key]) {
+ return this._images[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.getFrameData = /**
+ * Get frame data by key.
+ * @param key Asset key of the frame data you want.
+ * @return {object} The frame data you want.
+ */
+ function (key) {
+ if(this._images[key] && this._images[key].spriteSheet == true) {
+ return this._images[key].frameData;
+ }
+ return null;
+ };
+ Cache.prototype.getSound = /**
+ * Get sound by key.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound you want.
+ */
+ function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key];
+ }
+ return null;
+ };
+ Cache.prototype.getSoundData = /**
+ * Get sound data by key.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound data you want.
+ */
+ function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.isSoundDecoded = /**
+ * Check whether an asset is decoded sound.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound data you want.
+ */
+ function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key].decoded;
+ }
+ };
+ Cache.prototype.isSoundReady = /**
+ * Check whether an asset is decoded sound.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound data you want.
+ */
+ function (key) {
+ if(this._sounds[key] && this._sounds[key].decoded == true && this._sounds[key].locked == false) {
+ return true;
+ }
+ return false;
+ };
+ Cache.prototype.isSpriteSheet = /**
+ * Check whether an asset is sprite sheet.
+ * @param key Asset key of the sprite sheet you want.
+ * @return {object} The sprite sheet data you want.
+ */
+ function (key) {
+ if(this._images[key]) {
+ return this._images[key].spriteSheet;
+ }
+ };
+ Cache.prototype.getText = /**
+ * Get text data by key.
+ * @param key Asset key of the text data you want.
+ * @return {object} The text data you want.
+ */
+ function (key) {
+ if(this._text[key]) {
+ return this._text[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.getImageKeys = /**
+ * Returns an array containing all of the keys of Images in the Cache.
+ * @return {Array} The string based keys in the Cache.
+ */
+ function () {
+ var output = [];
+ for(var item in this._images) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.getSoundKeys = /**
+ * Returns an array containing all of the keys of Sounds in the Cache.
+ * @return {Array} The string based keys in the Cache.
+ */
+ function () {
+ var output = [];
+ for(var item in this._sounds) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.getTextKeys = /**
+ * Returns an array containing all of the keys of Text Files in the Cache.
+ * @return {Array} The string based keys in the Cache.
+ */
+ function () {
+ var output = [];
+ for(var item in this._text) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.removeCanvas = function (key) {
+ delete this._canvases[key];
+ };
+ Cache.prototype.removeImage = function (key) {
+ delete this._images[key];
+ };
+ Cache.prototype.removeSound = function (key) {
+ delete this._sounds[key];
+ };
+ Cache.prototype.removeText = function (key) {
+ delete this._text[key];
+ };
+ Cache.prototype.destroy = /**
+ * Clean up cache memory.
+ */
+ function () {
+ for(var item in this._canvases) {
+ delete this._canvases[item['key']];
+ }
+ for(var item in this._images) {
+ delete this._images[item['key']];
+ }
+ for(var item in this._sounds) {
+ delete this._sounds[item['key']];
+ }
+ for(var item in this._text) {
+ delete this._text[item['key']];
+ }
+ };
+ return Cache;
+ })();
+ Phaser.Cache = Cache;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/loader/Cache.ts b/TS Source/loader/Cache.ts
similarity index 100%
rename from Phaser/loader/Cache.ts
rename to TS Source/loader/Cache.ts
diff --git a/TS Source/loader/Loader.js b/TS Source/loader/Loader.js
new file mode 100644
index 00000000..1620e81b
--- /dev/null
+++ b/TS Source/loader/Loader.js
@@ -0,0 +1,503 @@
+///
+/**
+* Phaser - Loader
+*
+* The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.
+* It uses a combination of Image() loading and xhr and provides for progress and completion callbacks.
+*/
+var Phaser;
+(function (Phaser) {
+ var Loader = (function () {
+ /**
+ * Loader constructor
+ *
+ * @param game {Phaser.Game} Current game instance.
+ */
+ function Loader(game) {
+ /**
+ * The crossOrigin value applied to loaded images
+ * @type {string}
+ */
+ this.crossOrigin = '';
+ // If you want to append a URL before the path of any asset you can set this here.
+ // Useful if you need to allow an asset url to be configured outside of the game code.
+ // MUST have / on the end of it!
+ this.baseURL = '';
+ this.game = game;
+ this._keys = [];
+ this._fileList = {
+ };
+ this._xhr = new XMLHttpRequest();
+ this._queueSize = 0;
+ this.isLoading = false;
+ this.onFileComplete = new Phaser.Signal();
+ this.onFileError = new Phaser.Signal();
+ this.onLoadStart = new Phaser.Signal();
+ this.onLoadComplete = new Phaser.Signal();
+ }
+ Loader.TEXTURE_ATLAS_JSON_ARRAY = 0;
+ Loader.TEXTURE_ATLAS_JSON_HASH = 1;
+ Loader.TEXTURE_ATLAS_XML_STARLING = 2;
+ Loader.prototype.reset = /**
+ * Reset loader, this will remove all loaded assets.
+ */
+ function () {
+ this._queueSize = 0;
+ this.isLoading = false;
+ };
+ Object.defineProperty(Loader.prototype, "queueSize", {
+ get: function () {
+ return this._queueSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Loader.prototype.image = /**
+ * Add a new image asset loading request with key and url.
+ * @param key {string} Unique asset key of this image file.
+ * @param url {string} URL of image file.
+ */
+ function (key, url, overwrite) {
+ if (typeof overwrite === "undefined") { overwrite = false; }
+ if(overwrite == true || this.checkKeyExists(key) == false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'image',
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.spritesheet = /**
+ * Add a new sprite sheet loading request.
+ * @param key {string} Unique asset key of the sheet file.
+ * @param url {string} URL of sheet file.
+ * @param frameWidth {number} Width of each single frame.
+ * @param frameHeight {number} Height of each single frame.
+ * @param frameMax {number} How many frames in this sprite sheet.
+ */
+ function (key, url, frameWidth, frameHeight, frameMax) {
+ if (typeof frameMax === "undefined") { frameMax = -1; }
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'spritesheet',
+ key: key,
+ url: url,
+ data: null,
+ frameWidth: frameWidth,
+ frameHeight: frameHeight,
+ frameMax: frameMax,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.atlas = /**
+ * Add a new texture atlas loading request.
+ * @param key {string} Unique asset key of the texture atlas file.
+ * @param textureURL {string} The url of the texture atlas image file.
+ * @param [atlasURL] {string} The url of the texture atlas data file (json/xml)
+ * @param [atlasData] {object} A JSON or XML data object.
+ * @param [format] {number} A value describing the format of the data.
+ */
+ function (key, textureURL, atlasURL, atlasData, format) {
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ if (typeof format === "undefined") { format = Loader.TEXTURE_ATLAS_JSON_ARRAY; }
+ if(this.checkKeyExists(key) === false) {
+ if(atlasURL !== null) {
+ // A URL to a json/xml file has been given
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ atlasURL: atlasURL,
+ data: null,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ } else {
+ if(format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ // A json string or object has been given
+ if(typeof atlasData === 'string') {
+ atlasData = JSON.parse(atlasData);
+ }
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ data: null,
+ atlasURL: null,
+ atlasData: atlasData,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ } else if(format == Loader.TEXTURE_ATLAS_XML_STARLING) {
+ // An xml string or object has been given
+ if(typeof atlasData === 'string') {
+ var xml;
+ try {
+ if(window['DOMParser']) {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ } else {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ } catch (e) {
+ xml = undefined;
+ }
+ if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
+ throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
+ } else {
+ atlasData = xml;
+ }
+ }
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ data: null,
+ atlasURL: null,
+ atlasData: atlasData,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ }
+ }
+ };
+ Loader.prototype.audio = /**
+ * Add a new audio file loading request.
+ * @param key {string} Unique asset key of the audio file.
+ * @param urls {Array} An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ]
+ * @param autoDecode {bool} When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process.
+ */
+ function (key, urls, autoDecode) {
+ if (typeof autoDecode === "undefined") { autoDecode = true; }
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'audio',
+ key: key,
+ url: urls,
+ data: null,
+ buffer: null,
+ error: false,
+ loaded: false,
+ autoDecode: autoDecode
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.text = /**
+ * Add a new text file loading request.
+ * @param key {string} Unique asset key of the text file.
+ * @param url {string} URL of text file.
+ */
+ function (key, url) {
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'text',
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.removeFile = /**
+ * Remove loading request of a file.
+ * @param key {string} Key of the file you want to remove.
+ */
+ function (key) {
+ delete this._fileList[key];
+ };
+ Loader.prototype.removeAll = /**
+ * Remove all file loading requests.
+ */
+ function () {
+ this._fileList = {
+ };
+ };
+ Loader.prototype.start = /**
+ * Load assets.
+ */
+ function () {
+ if(this.isLoading) {
+ return;
+ }
+ this.progress = 0;
+ this.hasLoaded = false;
+ this.isLoading = true;
+ this.onLoadStart.dispatch(this.queueSize);
+ if(this._keys.length > 0) {
+ this._progressChunk = 100 / this._keys.length;
+ this.loadFile();
+ } else {
+ this.progress = 100;
+ this.hasLoaded = true;
+ this.onLoadComplete.dispatch();
+ }
+ };
+ Loader.prototype.loadFile = /**
+ * Load files. Private method ONLY used by loader.
+ */
+ function () {
+ var _this = this;
+ var file = this._fileList[this._keys.pop()];
+ // Image or Data?
+ switch(file.type) {
+ case 'image':
+ case 'spritesheet':
+ case 'textureatlas':
+ file.data = new Image();
+ file.data.name = file.key;
+ file.data.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.crossOrigin = this.crossOrigin;
+ file.data.src = this.baseURL + file.url;
+ break;
+ case 'audio':
+ file.url = this.getAudioURL(file.url);
+ if(file.url !== null) {
+ // WebAudio or Audio Tag?
+ if(this.game.sound.usingWebAudio) {
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "arraybuffer";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ } else if(this.game.sound.usingAudioTag) {
+ if(this.game.sound.touchLocked) {
+ // If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ this.fileComplete(file.key);
+ } else {
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
+ file.data.load();
+ }
+ }
+ }
+ break;
+ case 'text':
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "text";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ break;
+ }
+ };
+ Loader.prototype.getAudioURL = function (urls) {
+ var extension;
+ for(var i = 0; i < urls.length; i++) {
+ extension = urls[i].toLowerCase();
+ extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
+ if(this.game.device.canPlayAudio(extension)) {
+ return urls[i];
+ }
+ }
+ return null;
+ };
+ Loader.prototype.fileError = /**
+ * Error occured when load a file.
+ * @param key {string} Key of the error loading file.
+ */
+ function (key) {
+ this._fileList[key].loaded = true;
+ this._fileList[key].error = true;
+ this.onFileError.dispatch(key);
+ throw new Error("Phaser.Loader error loading file: " + key);
+ this.nextFile(key, false);
+ };
+ Loader.prototype.fileComplete = /**
+ * Called when a file is successfully loaded.
+ * @param key {string} Key of the successfully loaded file.
+ */
+ function (key) {
+ var _this = this;
+ if(!this._fileList[key]) {
+ throw new Error('Phaser.Loader fileComplete invalid key ' + key);
+ return;
+ }
+ this._fileList[key].loaded = true;
+ var file = this._fileList[key];
+ var loadNext = true;
+ switch(file.type) {
+ case 'image':
+ this.game.cache.addImage(file.key, file.url, file.data);
+ break;
+ case 'spritesheet':
+ this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax);
+ break;
+ case 'textureatlas':
+ if(file.atlasURL == null) {
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
+ } else {
+ // Load the JSON or XML before carrying on with the next file
+ loadNext = false;
+ this._xhr.open("GET", this.baseURL + file.atlasURL, true);
+ this._xhr.responseType = "text";
+ if(file.format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ this._xhr.onload = function () {
+ return _this.jsonLoadComplete(file.key);
+ };
+ } else if(file.format == Loader.TEXTURE_ATLAS_XML_STARLING) {
+ this._xhr.onload = function () {
+ return _this.xmlLoadComplete(file.key);
+ };
+ }
+ this._xhr.onerror = function () {
+ return _this.dataLoadError(file.key);
+ };
+ this._xhr.send();
+ }
+ break;
+ case 'audio':
+ if(this.game.sound.usingWebAudio) {
+ file.data = this._xhr.response;
+ this.game.cache.addSound(file.key, file.url, file.data, true, false);
+ if(file.autoDecode) {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+ var that = this;
+ var key = file.key;
+ this.game.sound.context.decodeAudioData(file.data, function (buffer) {
+ if(buffer) {
+ that.game.cache.decodedSound(key, buffer);
+ }
+ });
+ }
+ } else {
+ file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete);
+ this.game.cache.addSound(file.key, file.url, file.data, false, true);
+ }
+ break;
+ case 'text':
+ file.data = this._xhr.response;
+ this.game.cache.addText(file.key, file.url, file.data);
+ break;
+ }
+ if(loadNext) {
+ this.nextFile(key, true);
+ }
+ };
+ Loader.prototype.jsonLoadComplete = /**
+ * Successfully loaded a JSON file.
+ * @param key {string} Key of the loaded JSON file.
+ */
+ function (key) {
+ var data = JSON.parse(this._xhr.response);
+ var file = this._fileList[key];
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.dataLoadError = /**
+ * Error occured when load a JSON.
+ * @param key {string} Key of the error loading JSON file.
+ */
+ function (key) {
+ var file = this._fileList[key];
+ file.error = true;
+ throw new Error("Phaser.Loader dataLoadError: " + key);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.xmlLoadComplete = function (key) {
+ var atlasData = this._xhr.response;
+ var xml;
+ try {
+ if(window['DOMParser']) {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ } else {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ } catch (e) {
+ xml = undefined;
+ }
+ if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
+ throw new Error("Phaser.Loader. Invalid XML given");
+ }
+ var file = this._fileList[key];
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.nextFile = /**
+ * Handle loading next file.
+ * @param previousKey {string} Key of previous loaded asset.
+ * @param success {bool} Whether the previous asset loaded successfully or not.
+ */
+ function (previousKey, success) {
+ this.progress = Math.round(this.progress + this._progressChunk);
+ if(this.progress > 100) {
+ this.progress = 100;
+ }
+ this.onFileComplete.dispatch(this.progress, previousKey, success, this._queueSize - this._keys.length, this._queueSize);
+ if(this._keys.length > 0) {
+ this.loadFile();
+ } else {
+ this.hasLoaded = true;
+ this.isLoading = false;
+ this.removeAll();
+ this.onLoadComplete.dispatch();
+ }
+ };
+ Loader.prototype.checkKeyExists = /**
+ * Check whether asset exists with a specific key.
+ * @param key {string} Key of the asset you want to check.
+ * @return {bool} Return true if exists, otherwise return false.
+ */
+ function (key) {
+ if(this._fileList[key]) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ return Loader;
+ })();
+ Phaser.Loader = Loader;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/loader/Loader.ts b/TS Source/loader/Loader.ts
similarity index 100%
rename from Phaser/loader/Loader.ts
rename to TS Source/loader/Loader.ts
diff --git a/TS Source/math/GameMath.js b/TS Source/math/GameMath.js
new file mode 100644
index 00000000..85b082e9
--- /dev/null
+++ b/TS Source/math/GameMath.js
@@ -0,0 +1,868 @@
+///
+/**
+* Phaser - GameMath
+*
+* Adds a set of extra Math functions used through-out Phaser.
+* Includes methods written by Dylan Engelman and Adam Saltsman.
+*/
+var Phaser;
+(function (Phaser) {
+ var GameMath = (function () {
+ function GameMath(game) {
+ //arbitrary 8 digit epsilon
+ this.cosTable = [];
+ this.sinTable = [];
+ this.game = game;
+ GameMath.sinA = [];
+ GameMath.cosA = [];
+ for(var i = 0; i < 360; i++) {
+ GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
+ GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
+ }
+ }
+ GameMath.PI = 3.141592653589793;
+ GameMath.PI_2 = 1.5707963267948965;
+ GameMath.PI_4 = 0.7853981633974483;
+ GameMath.PI_8 = 0.39269908169872413;
+ GameMath.PI_16 = 0.19634954084936206;
+ GameMath.TWO_PI = 6.283185307179586;
+ GameMath.THREE_PI_2 = 4.7123889803846895;
+ GameMath.E = 2.71828182845905;
+ GameMath.LN10 = 2.302585092994046;
+ GameMath.LN2 = 0.6931471805599453;
+ GameMath.LOG10E = 0.4342944819032518;
+ GameMath.LOG2E = 1.442695040888963387;
+ GameMath.SQRT1_2 = 0.7071067811865476;
+ GameMath.SQRT2 = 1.4142135623730951;
+ GameMath.DEG_TO_RAD = 0.017453292519943294444444444444444;
+ GameMath.RAD_TO_DEG = 57.295779513082325225835265587527;
+ GameMath.B_16 = 65536;
+ GameMath.B_31 = 2147483648;
+ GameMath.B_32 = 4294967296;
+ GameMath.B_48 = 281474976710656;
+ GameMath.B_53 = 9007199254740992;
+ GameMath.B_64 = 18446744073709551616;
+ GameMath.ONE_THIRD = 0.333333333333333333333333333333333;
+ GameMath.TWO_THIRDS = 0.666666666666666666666666666666666;
+ GameMath.ONE_SIXTH = 0.166666666666666666666666666666666;
+ GameMath.COS_PI_3 = 0.86602540378443864676372317075294;
+ GameMath.SIN_2PI_3 = 0.03654595;
+ GameMath.CIRCLE_ALPHA = 0.5522847498307933984022516322796;
+ GameMath.ON = true;
+ GameMath.OFF = false;
+ GameMath.SHORT_EPSILON = 0.1;
+ GameMath.PERC_EPSILON = 0.001;
+ GameMath.EPSILON = 0.0001;
+ GameMath.LONG_EPSILON = 0.00000001;
+ GameMath.prototype.fuzzyEqual = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.abs(a - b) < epsilon;
+ };
+ GameMath.prototype.fuzzyLessThan = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return a < b + epsilon;
+ };
+ GameMath.prototype.fuzzyGreaterThan = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return a > b - epsilon;
+ };
+ GameMath.prototype.fuzzyCeil = function (val, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.ceil(val - epsilon);
+ };
+ GameMath.prototype.fuzzyFloor = function (val, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.floor(val + epsilon);
+ };
+ GameMath.prototype.average = function () {
+ var args = [];
+ for (var _i = 0; _i < (arguments.length - 0); _i++) {
+ args[_i] = arguments[_i + 0];
+ }
+ var avg = 0;
+ for(var i = 0; i < args.length; i++) {
+ avg += args[i];
+ }
+ return avg / args.length;
+ };
+ GameMath.prototype.slam = function (value, target, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return (Math.abs(value - target) < epsilon) ? target : value;
+ };
+ GameMath.prototype.percentageMinMax = /**
+ * ratio of value to a range
+ */
+ function (val, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ val -= min;
+ max -= min;
+ if(!max) {
+ return 0;
+ } else {
+ return val / max;
+ }
+ };
+ GameMath.prototype.sign = /**
+ * a value representing the sign of the value.
+ * -1 for negative, +1 for positive, 0 if value is 0
+ */
+ function (n) {
+ if(n) {
+ return n / Math.abs(n);
+ } else {
+ return 0;
+ }
+ };
+ GameMath.prototype.truncate = function (n) {
+ return (n > 0) ? Math.floor(n) : Math.ceil(n);
+ };
+ GameMath.prototype.shear = function (n) {
+ return n % 1;
+ };
+ GameMath.prototype.wrap = /**
+ * wrap a value around a range, similar to modulus with a floating minimum
+ */
+ function (val, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ val -= min;
+ max -= min;
+ if(max == 0) {
+ return min;
+ }
+ val %= max;
+ val += min;
+ while(val < min) {
+ val += max;
+ }
+ return val;
+ };
+ GameMath.prototype.arithWrap = /**
+ * arithmetic version of wrap... need to decide which is more efficient
+ */
+ function (value, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ max -= min;
+ if(max == 0) {
+ return min;
+ }
+ return value - max * Math.floor((value - min) / max);
+ };
+ GameMath.prototype.clamp = /**
+ * force a value within the boundaries of two values
+ *
+ * if max < min, min is returned
+ */
+ function (input, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ return Math.max(min, Math.min(max, input));
+ };
+ GameMath.prototype.snapTo = /**
+ * Snap a value to nearest grid slice, using rounding.
+ *
+ * example if you have an interval gap of 5 and a position of 12... you will snap to 10. Where as 14 will snap to 15
+ *
+ * @param input - the value to snap
+ * @param gap - the interval gap of the grid
+ * @param [start] - optional starting offset for gap
+ */
+ function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.round(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToFloor = /**
+ * Snap a value to nearest grid slice, using floor.
+ *
+ * example if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15
+ *
+ * @param input - the value to snap
+ * @param gap - the interval gap of the grid
+ * @param [start] - optional starting offset for gap
+ */
+ function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.floor(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToCeil = /**
+ * Snap a value to nearest grid slice, using ceil.
+ *
+ * example if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20
+ *
+ * @param input - the value to snap
+ * @param gap - the interval gap of the grid
+ * @param [start] - optional starting offset for gap
+ */
+ function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.ceil(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToInArray = /**
+ * Snaps a value to the nearest value in an array.
+ */
+ function (input, arr, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(sort) {
+ arr.sort();
+ }
+ if(input < arr[0]) {
+ return arr[0];
+ }
+ var i = 1;
+ while(arr[i] < input) {
+ i++;
+ }
+ var low = arr[i - 1];
+ var high = (i < arr.length) ? arr[i] : Number.POSITIVE_INFINITY;
+ return ((high - input) <= (input - low)) ? high : low;
+ };
+ GameMath.prototype.roundTo = /**
+ * roundTo some place comparative to a 'base', default is 10 for decimal place
+ *
+ * 'place' is represented by the power applied to 'base' to get that place
+ *
+ * @param value - the value to round
+ * @param place - the place to round to
+ * @param base - the base to round in... default is 10 for decimal
+ *
+ * e.g.
+ *
+ * 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011
+ *
+ * roundTo(2000/7,3) == 0
+ * roundTo(2000/7,2) == 300
+ * roundTo(2000/7,1) == 290
+ * roundTo(2000/7,0) == 286
+ * roundTo(2000/7,-1) == 285.7
+ * roundTo(2000/7,-2) == 285.71
+ * roundTo(2000/7,-3) == 285.714
+ * roundTo(2000/7,-4) == 285.7143
+ * roundTo(2000/7,-5) == 285.71429
+ *
+ * roundTo(2000/7,3,2) == 288 -- 100100000
+ * roundTo(2000/7,2,2) == 284 -- 100011100
+ * roundTo(2000/7,1,2) == 286 -- 100011110
+ * roundTo(2000/7,0,2) == 286 -- 100011110
+ * roundTo(2000/7,-1,2) == 285.5 -- 100011101.1
+ * roundTo(2000/7,-2,2) == 285.75 -- 100011101.11
+ * roundTo(2000/7,-3,2) == 285.75 -- 100011101.11
+ * roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011
+ * roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111
+ *
+ * note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed
+ * because we are rounding 100011.1011011011011011 which rounds up.
+ */
+ function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.round(value * p) / p;
+ };
+ GameMath.prototype.floorTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.floor(value * p) / p;
+ };
+ GameMath.prototype.ceilTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.ceil(value * p) / p;
+ };
+ GameMath.prototype.interpolateFloat = /**
+ * a one dimensional linear interpolation of a value.
+ */
+ function (a, b, weight) {
+ return (b - a) * weight + a;
+ };
+ GameMath.prototype.radiansToDegrees = /**
+ * convert radians to degrees
+ */
+ function (angle) {
+ return angle * GameMath.RAD_TO_DEG;
+ };
+ GameMath.prototype.degreesToRadians = /**
+ * convert degrees to radians
+ */
+ function (angle) {
+ return angle * GameMath.DEG_TO_RAD;
+ };
+ GameMath.prototype.angleBetween = /**
+ * Find the angle of a segment from (x1, y1) -> (x2, y2 )
+ */
+ function (x1, y1, x2, y2) {
+ return Math.atan2(y2 - y1, x2 - x1);
+ };
+ GameMath.prototype.normalizeAngle = /**
+ * set an angle within the bounds of -PI to PI
+ */
+ function (angle, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ var rd = (radians) ? GameMath.PI : 180;
+ return this.wrap(angle, rd, -rd);
+ };
+ GameMath.prototype.nearestAngleBetween = /**
+ * closest angle between two angles from a1 to a2
+ * absolute value the return for exact angle
+ */
+ function (a1, a2, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ var rd = (radians) ? GameMath.PI : 180;
+ a1 = this.normalizeAngle(a1, radians);
+ a2 = this.normalizeAngle(a2, radians);
+ if(a1 < -rd / 2 && a2 > rd / 2) {
+ a1 += rd * 2;
+ }
+ if(a2 < -rd / 2 && a1 > rd / 2) {
+ a2 += rd * 2;
+ }
+ return a2 - a1;
+ };
+ GameMath.prototype.normalizeAngleToAnother = /**
+ * normalizes independent and then sets dep to the nearest value respective to independent
+ *
+ * for instance if dep=-170 and ind=170 then 190 will be returned as an alternative to -170
+ */
+ function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ return ind + this.nearestAngleBetween(ind, dep, radians);
+ };
+ GameMath.prototype.normalizeAngleAfterAnother = /**
+ * normalize independent and dependent and then set dependent to an angle relative to 'after/clockwise' independent
+ *
+ * for instance dep=-170 and ind=170, then 190 will be reutrned as alternative to -170
+ */
+ function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ dep = this.normalizeAngle(dep - ind, radians);
+ return ind + dep;
+ };
+ GameMath.prototype.normalizeAngleBeforeAnother = /**
+ * normalizes indendent and dependent and then sets dependent to an angle relative to 'before/counterclockwise' independent
+ *
+ * for instance dep = 190 and ind = 170, then -170 will be returned as an alternative to 190
+ */
+ function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ dep = this.normalizeAngle(ind - dep, radians);
+ return ind - dep;
+ };
+ GameMath.prototype.interpolateAngles = /**
+ * interpolate across the shortest arc between two angles
+ */
+ function (a1, a2, weight, radians, ease) {
+ if (typeof radians === "undefined") { radians = true; }
+ if (typeof ease === "undefined") { ease = null; }
+ a1 = this.normalizeAngle(a1, radians);
+ a2 = this.normalizeAngleToAnother(a2, a1, radians);
+ return (typeof ease === 'function') ? ease(weight, a1, a2 - a1, 1) : this.interpolateFloat(a1, a2, weight);
+ };
+ GameMath.prototype.logBaseOf = /**
+ * Compute the logarithm of any value of any base
+ *
+ * a logarithm is the exponent that some constant (base) would have to be raised to
+ * to be equal to value.
+ *
+ * i.e.
+ * 4 ^ x = 16
+ * can be rewritten as to solve for x
+ * logB4(16) = x
+ * which with this function would be
+ * LoDMath.logBaseOf(16,4)
+ *
+ * which would return 2, because 4^2 = 16
+ */
+ function (value, base) {
+ return Math.log(value) / Math.log(base);
+ };
+ GameMath.prototype.GCD = /**
+ * Greatest Common Denominator using Euclid's algorithm
+ */
+ function (m, n) {
+ var r;
+ //make sure positive, GCD is always positive
+ m = Math.abs(m);
+ n = Math.abs(n);
+ //m must be >= n
+ if(m < n) {
+ r = m;
+ m = n;
+ n = r;
+ }
+ //now start loop
+ while(true) {
+ r = m % n;
+ if(!r) {
+ return n;
+ }
+ m = n;
+ n = r;
+ }
+ return 1;
+ };
+ GameMath.prototype.LCM = /**
+ * Lowest Common Multiple
+ */
+ function (m, n) {
+ return (m * n) / this.GCD(m, n);
+ };
+ GameMath.prototype.factorial = /**
+ * Factorial - N!
+ *
+ * simple product series
+ *
+ * by definition:
+ * 0! == 1
+ */
+ function (value) {
+ if(value == 0) {
+ return 1;
+ }
+ var res = value;
+ while(--value) {
+ res *= value;
+ }
+ return res;
+ };
+ GameMath.prototype.gammaFunction = /**
+ * gamma function
+ *
+ * defined: gamma(N) == (N - 1)!
+ */
+ function (value) {
+ return this.factorial(value - 1);
+ };
+ GameMath.prototype.fallingFactorial = /**
+ * falling factorial
+ *
+ * defined: (N)! / (N - x)!
+ *
+ * written subscript: (N)x OR (base)exp
+ */
+ function (base, exp) {
+ return this.factorial(base) / this.factorial(base - exp);
+ };
+ GameMath.prototype.risingFactorial = /**
+ * rising factorial
+ *
+ * defined: (N + x - 1)! / (N - 1)!
+ *
+ * written superscript N^(x) OR base^(exp)
+ */
+ function (base, exp) {
+ //expanded from gammaFunction for speed
+ return this.factorial(base + exp - 1) / this.factorial(base - 1);
+ };
+ GameMath.prototype.binCoef = /**
+ * binomial coefficient
+ *
+ * defined: N! / (k!(N-k)!)
+ * reduced: N! / (N-k)! == (N)k (fallingfactorial)
+ * reduced: (N)k / k!
+ */
+ function (n, k) {
+ return this.fallingFactorial(n, k) / this.factorial(k);
+ };
+ GameMath.prototype.risingBinCoef = /**
+ * rising binomial coefficient
+ *
+ * as one can notice in the analysis of binCoef(...) that
+ * binCoef is the (N)k divided by k!. Similarly rising binCoef
+ * is merely N^(k) / k!
+ */
+ function (n, k) {
+ return this.risingFactorial(n, k) / this.factorial(k);
+ };
+ GameMath.prototype.chanceRoll = /**
+ * Generate a random bool result based on the chance value
+ *
+ * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance
+ * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed.
+ *
+ * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%)
+ * @return true if the roll passed, or false
+ */
+ function (chance) {
+ if (typeof chance === "undefined") { chance = 50; }
+ if(chance <= 0) {
+ return false;
+ } else if(chance >= 100) {
+ return true;
+ } else {
+ if(Math.random() * 100 >= chance) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ };
+ GameMath.prototype.maxAdd = /**
+ * Adds the given amount to the value, but never lets the value go over the specified maximum
+ *
+ * @param value The value to add the amount to
+ * @param amount The amount to add to the value
+ * @param max The maximum the value is allowed to be
+ * @return The new value
+ */
+ function (value, amount, max) {
+ value += amount;
+ if(value > max) {
+ value = max;
+ }
+ return value;
+ };
+ GameMath.prototype.minSub = /**
+ * Subtracts the given amount from the value, but never lets the value go below the specified minimum
+ *
+ * @param value The base value
+ * @param amount The amount to subtract from the base value
+ * @param min The minimum the value is allowed to be
+ * @return The new value
+ */
+ function (value, amount, min) {
+ value -= amount;
+ if(value < min) {
+ value = min;
+ }
+ return value;
+ };
+ GameMath.prototype.wrapValue = /**
+ * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.
+ * Values must be positive integers, and are passed through Math.abs
+ *
+ * @param value The value to add the amount to
+ * @param amount The amount to add to the value
+ * @param max The maximum the value is allowed to be
+ * @return The wrapped value
+ */
+ function (value, amount, max) {
+ var diff;
+ value = Math.abs(value);
+ amount = Math.abs(amount);
+ max = Math.abs(max);
+ diff = (value + amount) % max;
+ return diff;
+ };
+ GameMath.prototype.randomSign = /**
+ * Randomly returns either a 1 or -1
+ *
+ * @return 1 or -1
+ */
+ function () {
+ return (Math.random() > 0.5) ? 1 : -1;
+ };
+ GameMath.prototype.isOdd = /**
+ * Returns true if the number given is odd.
+ *
+ * @param n The number to check
+ *
+ * @return True if the given number is odd. False if the given number is even.
+ */
+ function (n) {
+ if(n & 1) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ GameMath.prototype.isEven = /**
+ * Returns true if the number given is even.
+ *
+ * @param n The number to check
+ *
+ * @return True if the given number is even. False if the given number is odd.
+ */
+ function (n) {
+ if(n & 1) {
+ return false;
+ } else {
+ return true;
+ }
+ };
+ GameMath.prototype.wrapAngle = /**
+ * Keeps an angle value between -180 and +180
+ * Should be called whenever the angle is updated on the Sprite to stop it from going insane.
+ *
+ * @param angle The angle value to check
+ *
+ * @return The new angle value, returns the same as the input angle if it was within bounds
+ */
+ function (angle) {
+ var result = angle;
+ // Nothing needs to change
+ if(angle >= -180 && angle <= 180) {
+ return angle;
+ }
+ // Else normalise it to -180, 180
+ result = (angle + 180) % 360;
+ if(result < 0) {
+ result += 360;
+ }
+ return result - 180;
+ };
+ GameMath.prototype.angleLimit = /**
+ * Keeps an angle value between the given min and max values
+ *
+ * @param angle The angle value to check. Must be between -180 and +180
+ * @param min The minimum angle that is allowed (must be -180 or greater)
+ * @param max The maximum angle that is allowed (must be 180 or less)
+ *
+ * @return The new angle value, returns the same as the input angle if it was within bounds
+ */
+ function (angle, min, max) {
+ var result = angle;
+ if(angle > max) {
+ result = max;
+ } else if(angle < min) {
+ result = min;
+ }
+ return result;
+ };
+ GameMath.prototype.linearInterpolation = /**
+ * @method linear
+ * @param {Any} v
+ * @param {Any} k
+ * @public
+ */
+ function (v, k) {
+ var m = v.length - 1;
+ var f = m * k;
+ var i = Math.floor(f);
+ if(k < 0) {
+ return this.linear(v[0], v[1], f);
+ }
+ if(k > 1) {
+ return this.linear(v[m], v[m - 1], m - f);
+ }
+ return this.linear(v[i], v[i + 1 > m ? m : i + 1], f - i);
+ };
+ GameMath.prototype.bezierInterpolation = /**
+ * @method Bezier
+ * @param {Any} v
+ * @param {Any} k
+ * @public
+ */
+ function (v, k) {
+ var b = 0;
+ var n = v.length - 1;
+ for(var i = 0; i <= n; i++) {
+ b += Math.pow(1 - k, n - i) * Math.pow(k, i) * v[i] * this.bernstein(n, i);
+ }
+ return b;
+ };
+ GameMath.prototype.catmullRomInterpolation = /**
+ * @method CatmullRom
+ * @param {Any} v
+ * @param {Any} k
+ * @public
+ */
+ function (v, k) {
+ var m = v.length - 1;
+ var f = m * k;
+ var i = Math.floor(f);
+ if(v[0] === v[m]) {
+ if(k < 0) {
+ i = Math.floor(f = m * (1 + k));
+ }
+ return this.catmullRom(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
+ } else {
+ if(k < 0) {
+ return v[0] - (this.catmullRom(v[0], v[0], v[1], v[1], -f) - v[0]);
+ }
+ if(k > 1) {
+ return v[m] - (this.catmullRom(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
+ }
+ return this.catmullRom(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
+ }
+ };
+ GameMath.prototype.linear = /**
+ * @method Linear
+ * @param {Any} p0
+ * @param {Any} p1
+ * @param {Any} t
+ * @public
+ */
+ function (p0, p1, t) {
+ return (p1 - p0) * t + p0;
+ };
+ GameMath.prototype.bernstein = /**
+ * @method Bernstein
+ * @param {Any} n
+ * @param {Any} i
+ * @public
+ */
+ function (n, i) {
+ return this.factorial(n) / this.factorial(i) / this.factorial(n - i);
+ };
+ GameMath.prototype.catmullRom = /**
+ * @method CatmullRom
+ * @param {Any} p0
+ * @param {Any} p1
+ * @param {Any} p2
+ * @param {Any} p3
+ * @param {Any} t
+ * @public
+ */
+ function (p0, p1, p2, p3, t) {
+ var v0 = (p2 - p0) * 0.5, v1 = (p3 - p1) * 0.5, t2 = t * t, t3 = t * t2;
+ return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
+ };
+ GameMath.prototype.difference = function (a, b) {
+ return Math.abs(a - b);
+ };
+ GameMath.prototype.getRandom = /**
+ * Fetch a random entry from the given array.
+ * Will return null if random selection is missing, or array has no entries.
+ *
+ * @param objects An array of objects.
+ * @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
+ * @param length Optional restriction on the number of values you want to randomly select from.
+ *
+ * @return The random object that was selected.
+ */
+ function (objects, startIndex, length) {
+ if (typeof startIndex === "undefined") { startIndex = 0; }
+ if (typeof length === "undefined") { length = 0; }
+ if(objects != null) {
+ var l = length;
+ if((l == 0) || (l > objects.length - startIndex)) {
+ l = objects.length - startIndex;
+ }
+ if(l > 0) {
+ return objects[startIndex + Math.floor(Math.random() * l)];
+ }
+ }
+ return null;
+ };
+ GameMath.prototype.floor = /**
+ * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ function (value) {
+ var n = value | 0;
+ return (value > 0) ? (n) : ((n != value) ? (n - 1) : (n));
+ };
+ GameMath.prototype.ceil = /**
+ * Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
+ *
+ * @param Value Any number.
+ *
+ * @return The rounded value of that number.
+ */
+ function (value) {
+ var n = value | 0;
+ return (value > 0) ? ((n != value) ? (n + 1) : (n)) : (n);
+ };
+ GameMath.prototype.sinCosGenerator = /**
+ * Generate a sine and cosine table simultaneously and extremely quickly. Based on research by Franky of scene.at
+ *
+ * The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function
+ * you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time.
+ *
+ * @param length The length of the wave
+ * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value
+ * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value
+ * @param frequency The frequency of the sine and cosine table data
+ * @return Returns the sine table
+ * @see getSinTable
+ * @see getCosTable
+ */
+ function (length, sinAmplitude, cosAmplitude, frequency) {
+ if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; }
+ if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; }
+ if (typeof frequency === "undefined") { frequency = 1.0; }
+ var sin = sinAmplitude;
+ var cos = cosAmplitude;
+ var frq = frequency * Math.PI / length;
+ this.cosTable = [];
+ this.sinTable = [];
+ for(var c = 0; c < length; c++) {
+ cos -= sin * frq;
+ sin += cos * frq;
+ this.cosTable[c] = cos;
+ this.sinTable[c] = sin;
+ }
+ return this.sinTable;
+ };
+ GameMath.prototype.shiftSinTable = /**
+ * Shifts through the sin table data by one value and returns it.
+ * This effectively moves the position of the data from the start to the end of the table.
+ * @return The sin value.
+ */
+ function () {
+ if(this.sinTable) {
+ var s = this.sinTable.shift();
+ this.sinTable.push(s);
+ return s;
+ }
+ };
+ GameMath.prototype.shiftCosTable = /**
+ * Shifts through the cos table data by one value and returns it.
+ * This effectively moves the position of the data from the start to the end of the table.
+ * @return The cos value.
+ */
+ function () {
+ if(this.cosTable) {
+ var s = this.cosTable.shift();
+ this.cosTable.push(s);
+ return s;
+ }
+ };
+ GameMath.prototype.shuffleArray = /**
+ * Shuffles the data in the given array into a new order
+ * @param array The array to shuffle
+ * @return The array
+ */
+ function (array) {
+ for(var i = array.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ }
+ return array;
+ };
+ GameMath.prototype.distanceBetween = /**
+ * Returns the distance from this Point object to the given Point object.
+ * @method distanceFrom
+ * @param {Point} target - The destination Point object.
+ * @param {bool} round - Round the distance to the nearest integer (default false)
+ * @return {Number} The distance between this Point object and the destination Point object.
+ **/
+ function (x1, y1, x2, y2) {
+ var dx = x1 - x2;
+ var dy = y1 - y2;
+ return Math.sqrt(dx * dx + dy * dy);
+ };
+ GameMath.prototype.vectorLength = /**
+ * Finds the length of the given vector
+ *
+ * @param dx
+ * @param dy
+ *
+ * @return
+ */
+ function (dx, dy) {
+ return Math.sqrt(dx * dx + dy * dy);
+ };
+ return GameMath;
+ })();
+ Phaser.GameMath = GameMath;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/math/GameMath.ts b/TS Source/math/GameMath.ts
similarity index 100%
rename from Phaser/math/GameMath.ts
rename to TS Source/math/GameMath.ts
diff --git a/TS Source/math/LinkedList.js b/TS Source/math/LinkedList.js
new file mode 100644
index 00000000..0efc4242
--- /dev/null
+++ b/TS Source/math/LinkedList.js
@@ -0,0 +1,30 @@
+///
+/**
+* Phaser - LinkedList
+*
+* A miniature linked list class. Useful for optimizing time-critical or highly repetitive tasks!
+*/
+var Phaser;
+(function (Phaser) {
+ var LinkedList = (function () {
+ /**
+ * Creates a new link, and sets object and next to null.
+ */
+ function LinkedList() {
+ this.object = null;
+ this.next = null;
+ }
+ LinkedList.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this.object = null;
+ if(this.next != null) {
+ this.next.destroy();
+ }
+ this.next = null;
+ };
+ return LinkedList;
+ })();
+ Phaser.LinkedList = LinkedList;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/math/LinkedList.ts b/TS Source/math/LinkedList.ts
similarity index 100%
rename from Phaser/math/LinkedList.ts
rename to TS Source/math/LinkedList.ts
diff --git a/TS Source/math/Mat3.js b/TS Source/math/Mat3.js
new file mode 100644
index 00000000..98bd3390
--- /dev/null
+++ b/TS Source/math/Mat3.js
@@ -0,0 +1,253 @@
+///
+/**
+* Phaser - Mat3
+*
+* A 3x3 Matrix
+*/
+var Phaser;
+(function (Phaser) {
+ var Mat3 = (function () {
+ /**
+ * Creates a new Mat3 object.
+ * @class Mat3
+ * @constructor
+ * @return {Mat3} This object
+ **/
+ function Mat3() {
+ this.data = [
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1
+ ];
+ }
+ Object.defineProperty(Mat3.prototype, "a00", {
+ get: function () {
+ return this.data[0];
+ },
+ set: function (value) {
+ this.data[0] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a01", {
+ get: function () {
+ return this.data[1];
+ },
+ set: function (value) {
+ this.data[1] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a02", {
+ get: function () {
+ return this.data[2];
+ },
+ set: function (value) {
+ this.data[2] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a10", {
+ get: function () {
+ return this.data[3];
+ },
+ set: function (value) {
+ this.data[3] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a11", {
+ get: function () {
+ return this.data[4];
+ },
+ set: function (value) {
+ this.data[4] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a12", {
+ get: function () {
+ return this.data[5];
+ },
+ set: function (value) {
+ this.data[5] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a20", {
+ get: function () {
+ return this.data[6];
+ },
+ set: function (value) {
+ this.data[6] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a21", {
+ get: function () {
+ return this.data[7];
+ },
+ set: function (value) {
+ this.data[7] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a22", {
+ get: function () {
+ return this.data[8];
+ },
+ set: function (value) {
+ this.data[8] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Mat3.prototype.copyFromMat3 = /**
+ * Copies the values from one Mat3 into this Mat3.
+ * @method copyFromMat3
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function (source) {
+ this.data[0] = source.data[0];
+ this.data[1] = source.data[1];
+ this.data[2] = source.data[2];
+ this.data[3] = source.data[3];
+ this.data[4] = source.data[4];
+ this.data[5] = source.data[5];
+ this.data[6] = source.data[6];
+ this.data[7] = source.data[7];
+ this.data[8] = source.data[8];
+ return this;
+ };
+ Mat3.prototype.copyFromMat4 = /**
+ * Copies the upper-left 3x3 values into this Mat3.
+ * @method copyFromMat4
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function (source) {
+ this.data[0] = source[0];
+ this.data[1] = source[1];
+ this.data[2] = source[2];
+ this.data[3] = source[4];
+ this.data[4] = source[5];
+ this.data[5] = source[6];
+ this.data[6] = source[8];
+ this.data[7] = source[9];
+ this.data[8] = source[10];
+ return this;
+ };
+ Mat3.prototype.clone = /**
+ * Clones this Mat3 into a new Mat3
+ * @param {Mat3} out The output Mat3, if none is given a new Mat3 object will be created.
+ * @return {Mat3} The new Mat3
+ **/
+ function (out) {
+ if (typeof out === "undefined") { out = new Phaser.Mat3(); }
+ out[0] = this.data[0];
+ out[1] = this.data[1];
+ out[2] = this.data[2];
+ out[3] = this.data[3];
+ out[4] = this.data[4];
+ out[5] = this.data[5];
+ out[6] = this.data[6];
+ out[7] = this.data[7];
+ out[8] = this.data[8];
+ return out;
+ };
+ Mat3.prototype.identity = /**
+ * Sets this Mat3 to the identity matrix.
+ * @method identity
+ * @param {any} source - The object to copy from.
+ * @return {Mat3} This Mat3 object.
+ **/
+ function () {
+ return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ };
+ Mat3.prototype.translate = /**
+ * Translates this Mat3 by the given vector
+ **/
+ function (v) {
+ this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
+ this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
+ this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
+ return this;
+ };
+ Mat3.prototype.setTemps = function () {
+ this._a00 = this.data[0];
+ this._a01 = this.data[1];
+ this._a02 = this.data[2];
+ this._a10 = this.data[3];
+ this._a11 = this.data[4];
+ this._a12 = this.data[5];
+ this._a20 = this.data[6];
+ this._a21 = this.data[7];
+ this._a22 = this.data[8];
+ };
+ Mat3.prototype.rotate = /**
+ * Rotates this Mat3 by the given angle (given in radians)
+ **/
+ function (rad) {
+ this.setTemps();
+ var s = Phaser.GameMath.sinA[rad];
+ var c = Phaser.GameMath.cosA[rad];
+ this.data[0] = c * this._a00 + s * this._a10;
+ this.data[1] = c * this._a01 + s * this._a10;
+ this.data[2] = c * this._a02 + s * this._a12;
+ this.data[3] = c * this._a10 - s * this._a00;
+ this.data[4] = c * this._a11 - s * this._a01;
+ this.data[5] = c * this._a12 - s * this._a02;
+ return this;
+ };
+ Mat3.prototype.scale = /**
+ * Scales this Mat3 by the given vector
+ **/
+ function (v) {
+ this.data[0] = v.x * this.data[0];
+ this.data[1] = v.x * this.data[1];
+ this.data[2] = v.x * this.data[2];
+ this.data[3] = v.y * this.data[3];
+ this.data[4] = v.y * this.data[4];
+ this.data[5] = v.y * this.data[5];
+ return this;
+ };
+ Mat3.prototype.setTo = function (a00, a01, a02, a10, a11, a12, a20, a21, a22) {
+ this.data[0] = a00;
+ this.data[1] = a01;
+ this.data[2] = a02;
+ this.data[3] = a10;
+ this.data[4] = a11;
+ this.data[5] = a12;
+ this.data[6] = a20;
+ this.data[7] = a21;
+ this.data[8] = a22;
+ return this;
+ };
+ Mat3.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ function () {
+ return '';
+ //return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ };
+ return Mat3;
+ })();
+ Phaser.Mat3 = Mat3;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/math/Mat3.ts b/TS Source/math/Mat3.ts
similarity index 100%
rename from Phaser/math/Mat3.ts
rename to TS Source/math/Mat3.ts
diff --git a/TS Source/math/Mat3Utils.js b/TS Source/math/Mat3Utils.js
new file mode 100644
index 00000000..ed0577a8
--- /dev/null
+++ b/TS Source/math/Mat3Utils.js
@@ -0,0 +1,153 @@
+///
+/**
+* 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 = {}));
diff --git a/Phaser/math/Mat3Utils.ts b/TS Source/math/Mat3Utils.ts
similarity index 100%
rename from Phaser/math/Mat3Utils.ts
rename to TS Source/math/Mat3Utils.ts
diff --git a/TS Source/math/QuadTree.js b/TS Source/math/QuadTree.js
new file mode 100644
index 00000000..6f05e343
--- /dev/null
+++ b/TS Source/math/QuadTree.js
@@ -0,0 +1,359 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+///
+/**
+* Phaser - QuadTree
+*
+* A fairly generic quad tree structure for rapid overlap checks. QuadTree is also configured for single or dual list operation.
+* You can add items either to its A list or its B list. When you do an overlap check, you can compare the A list to itself,
+* or the A list against the B list. Handy for different things!
+*/
+var Phaser;
+(function (Phaser) {
+ var QuadTree = (function (_super) {
+ __extends(QuadTree, _super);
+ /**
+ * Instantiate a new Quad Tree node.
+ *
+ * @param {Number} x The X-coordinate of the point in space.
+ * @param {Number} y The Y-coordinate of the point in space.
+ * @param {Number} width Desired width of this node.
+ * @param {Number} height Desired height of this node.
+ * @param {Number} parent The parent branch or node. Pass null to create a root.
+ */
+ //constructor(manager: Phaser.Physics.Manager, x: number, y: number, width: number, height: number, parent: QuadTree = null) {
+ function QuadTree(manager, x, y, width, height, parent) {
+ if (typeof parent === "undefined") { parent = null; }
+ _super.call(this, x, y, width, height);
+ QuadTree.physics = manager;
+ this._headA = this._tailA = new Phaser.LinkedList();
+ this._headB = this._tailB = new Phaser.LinkedList();
+ //Copy the parent's children (if there are any)
+ if(parent != null) {
+ if(parent._headA.object != null) {
+ this._iterator = parent._headA;
+ while(this._iterator != null) {
+ if(this._tailA.object != null) {
+ this._ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ this._ot.next = this._tailA;
+ }
+ this._tailA.object = this._iterator.object;
+ this._iterator = this._iterator.next;
+ }
+ }
+ if(parent._headB.object != null) {
+ this._iterator = parent._headB;
+ while(this._iterator != null) {
+ if(this._tailB.object != null) {
+ this._ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ this._ot.next = this._tailB;
+ }
+ this._tailB.object = this._iterator.object;
+ this._iterator = this._iterator.next;
+ }
+ }
+ } else {
+ QuadTree._min = (this.width + this.height) / (2 * QuadTree.divisions);
+ }
+ this._canSubdivide = (this.width > QuadTree._min) || (this.height > QuadTree._min);
+ //Set up comparison/sort helpers
+ this._northWestTree = null;
+ this._northEastTree = null;
+ this._southEastTree = null;
+ this._southWestTree = null;
+ this._leftEdge = this.x;
+ this._rightEdge = this.x + this.width;
+ this._halfWidth = this.width / 2;
+ this._midpointX = this._leftEdge + this._halfWidth;
+ this._topEdge = this.y;
+ this._bottomEdge = this.y + this.height;
+ this._halfHeight = this.height / 2;
+ this._midpointY = this._topEdge + this._halfHeight;
+ }
+ QuadTree.A_LIST = 0;
+ QuadTree.B_LIST = 1;
+ QuadTree.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this._tailA.destroy();
+ this._tailB.destroy();
+ this._headA.destroy();
+ this._headB.destroy();
+ this._tailA = null;
+ this._tailB = null;
+ this._headA = null;
+ this._headB = null;
+ if(this._northWestTree != null) {
+ this._northWestTree.destroy();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.destroy();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.destroy();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.destroy();
+ }
+ this._northWestTree = null;
+ this._northEastTree = null;
+ this._southEastTree = null;
+ this._southWestTree = null;
+ QuadTree._object = null;
+ QuadTree._processingCallback = null;
+ QuadTree._notifyCallback = null;
+ };
+ QuadTree.prototype.load = /**
+ * Load objects and/or groups into the quad tree, and register notify and processing callbacks.
+ *
+ * @param {} objectOrGroup1 Any object that is or extends IGameObject or Group.
+ * @param {} objectOrGroup2 Any object that is or extends IGameObject or Group. If null, the first parameter will be checked against itself.
+ * @param {Function} notifyCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject) that is called whenever two objects are found to overlap in world space, and either no processCallback is specified, or the processCallback returns true.
+ * @param {Function} processCallback A function with the form myFunction(Object1:GameObject,Object2:GameObject):bool that is called whenever two objects are found to overlap in world space. The notifyCallback is only called if this function returns true. See GameObject.separate().
+ * @param context The context in which the callbacks will be called
+ */
+ function (objectOrGroup1, objectOrGroup2, notifyCallback, processCallback, context) {
+ if (typeof objectOrGroup2 === "undefined") { objectOrGroup2 = null; }
+ if (typeof notifyCallback === "undefined") { notifyCallback = null; }
+ if (typeof processCallback === "undefined") { processCallback = null; }
+ if (typeof context === "undefined") { context = null; }
+ this.add(objectOrGroup1, QuadTree.A_LIST);
+ if(objectOrGroup2 != null) {
+ this.add(objectOrGroup2, QuadTree.B_LIST);
+ QuadTree._useBothLists = true;
+ } else {
+ QuadTree._useBothLists = false;
+ }
+ QuadTree._notifyCallback = notifyCallback;
+ QuadTree._processingCallback = processCallback;
+ QuadTree._callbackContext = context;
+ };
+ QuadTree.prototype.add = /**
+ * Call this function to add an object to the root of the tree.
+ * This function will recursively add all group members, but
+ * not the groups themselves.
+ *
+ * @param {} objectOrGroup GameObjects are just added, Groups are recursed and their applicable members added accordingly.
+ * @param {Number} list A uint flag indicating the list to which you want to add the objects. Options are QuadTree.A_LIST and QuadTree.B_LIST.
+ */
+ function (objectOrGroup, list) {
+ QuadTree._list = list;
+ if(objectOrGroup.type == Phaser.Types.GROUP) {
+ this._i = 0;
+ this._members = objectOrGroup['members'];
+ this._l = objectOrGroup['length'];
+ while(this._i < this._l) {
+ this._basic = this._members[this._i++];
+ if(this._basic != null && this._basic.exists) {
+ if(this._basic.type == Phaser.Types.GROUP) {
+ this.add(this._basic, list);
+ } else {
+ QuadTree._object = this._basic;
+ if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
+ this.addObject();
+ }
+ }
+ }
+ }
+ } else {
+ QuadTree._object = objectOrGroup;
+ if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
+ this.addObject();
+ }
+ }
+ };
+ QuadTree.prototype.addObject = /**
+ * Internal function for recursively navigating and creating the tree
+ * while adding objects to the appropriate nodes.
+ */
+ function () {
+ //If this quad (not its children) lies entirely inside this object, add it here
+ if(!this._canSubdivide || ((this._leftEdge >= QuadTree._object.body.bounds.x) && (this._rightEdge <= QuadTree._object.body.bounds.right) && (this._topEdge >= QuadTree._object.body.bounds.y) && (this._bottomEdge <= QuadTree._object.body.bounds.bottom))) {
+ this.addToList();
+ return;
+ }
+ //See if the selected object fits completely inside any of the quadrants
+ if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) {
+ if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ return;
+ }
+ if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ return;
+ }
+ }
+ if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) {
+ if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ return;
+ }
+ if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ return;
+ }
+ }
+ //If it wasn't completely contained we have to check out the partial overlaps
+ if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ }
+ };
+ QuadTree.prototype.addToList = /**
+ * Internal function for recursively adding objects to leaf lists.
+ */
+ function () {
+ if(QuadTree._list == QuadTree.A_LIST) {
+ if(this._tailA.object != null) {
+ this._ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ this._ot.next = this._tailA;
+ }
+ this._tailA.object = QuadTree._object;
+ } else {
+ if(this._tailB.object != null) {
+ this._ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ this._ot.next = this._tailB;
+ }
+ this._tailB.object = QuadTree._object;
+ }
+ if(!this._canSubdivide) {
+ return;
+ }
+ if(this._northWestTree != null) {
+ this._northWestTree.addToList();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.addToList();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.addToList();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.addToList();
+ }
+ };
+ QuadTree.prototype.execute = /**
+ * QuadTree's other main function. Call this after adding objects
+ * using QuadTree.load() to compare the objects that you loaded.
+ *
+ * @return {bool} Whether or not any overlaps were found.
+ */
+ function () {
+ this._overlapProcessed = false;
+ if(this._headA.object != null) {
+ this._iterator = this._headA;
+ while(this._iterator != null) {
+ QuadTree._object = this._iterator.object;
+ if(QuadTree._useBothLists) {
+ QuadTree._iterator = this._headB;
+ } else {
+ QuadTree._iterator = this._iterator.next;
+ }
+ if(QuadTree._object.exists && (QuadTree._object.body.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
+ this._overlapProcessed = true;
+ }
+ this._iterator = this._iterator.next;
+ }
+ }
+ //Advance through the tree by calling overlap on each child
+ if((this._northWestTree != null) && this._northWestTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._northEastTree != null) && this._northEastTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._southEastTree != null) && this._southEastTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._southWestTree != null) && this._southWestTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ return this._overlapProcessed;
+ };
+ QuadTree.prototype.overlapNode = /**
+ * A private for comparing an object against the contents of a node.
+ *
+ * @return {bool} Whether or not any overlaps were found.
+ */
+ function () {
+ //Walk the list and check for overlaps
+ this._overlapProcessed = false;
+ while(QuadTree._iterator != null) {
+ if(!QuadTree._object.exists || (QuadTree._object.body.allowCollisions <= 0)) {
+ break;
+ }
+ this._checkObject = QuadTree._iterator.object;
+ if((QuadTree._object === this._checkObject) || !this._checkObject.exists || (this._checkObject.body.allowCollisions <= 0)) {
+ QuadTree._iterator = QuadTree._iterator.next;
+ continue;
+ }
+ /*
+ if (QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body))
+ {
+ //Execute callback functions if they exist
+ if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject))
+ {
+ this._overlapProcessed = true;
+ }
+
+ if (this._overlapProcessed && (QuadTree._notifyCallback != null))
+ {
+ if (QuadTree._callbackContext !== null)
+ {
+ QuadTree._notifyCallback.call(QuadTree._callbackContext, QuadTree._object, this._checkObject);
+ }
+ else
+ {
+ QuadTree._notifyCallback(QuadTree._object, this._checkObject);
+ }
+ }
+ }
+ */
+ QuadTree._iterator = QuadTree._iterator.next;
+ }
+ return this._overlapProcessed;
+ };
+ return QuadTree;
+ })(Phaser.Rectangle);
+ Phaser.QuadTree = QuadTree;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/math/QuadTree.ts b/TS Source/math/QuadTree.ts
similarity index 100%
rename from Phaser/math/QuadTree.ts
rename to TS Source/math/QuadTree.ts
diff --git a/TS Source/math/RandomDataGenerator.js b/TS Source/math/RandomDataGenerator.js
new file mode 100644
index 00000000..9177d144
--- /dev/null
+++ b/TS Source/math/RandomDataGenerator.js
@@ -0,0 +1,227 @@
+///
+/**
+* Phaser - RandomDataGenerator
+*
+* An extremely useful repeatable random data generator. Access it via Game.rnd
+* Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense
+* Random number generator from http://baagoe.org/en/wiki/Better_random_numbers_for_javascript
+*/
+var Phaser;
+(function (Phaser) {
+ var RandomDataGenerator = (function () {
+ /**
+ * @constructor
+ * @param {Array} seeds
+ * @return {Phaser.RandomDataGenerator}
+ */
+ function RandomDataGenerator(seeds) {
+ if (typeof seeds === "undefined") { seeds = []; }
+ /**
+ * @property c
+ * @type Number
+ * @private
+ */
+ this.c = 1;
+ this.sow(seeds);
+ }
+ RandomDataGenerator.prototype.uint32 = /**
+ * @method uint32
+ * @private
+ */
+ function () {
+ return this.rnd.apply(this) * 0x100000000;// 2^32
+
+ };
+ RandomDataGenerator.prototype.fract32 = /**
+ * @method fract32
+ * @private
+ */
+ function () {
+ return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
+
+ };
+ RandomDataGenerator.prototype.rnd = // private random helper
+ /**
+ * @method rnd
+ * @private
+ */
+ function () {
+ var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10;// 2^-32
+
+ this.c = t | 0;
+ this.s0 = this.s1;
+ this.s1 = this.s2;
+ this.s2 = t - this.c;
+ return this.s2;
+ };
+ RandomDataGenerator.prototype.hash = /**
+ * @method hash
+ * @param {Any} data
+ * @private
+ */
+ function (data) {
+ var h, i, n;
+ n = 0xefc8249d;
+ data = data.toString();
+ for(i = 0; i < data.length; i++) {
+ n += data.charCodeAt(i);
+ h = 0.02519603282416938 * n;
+ n = h >>> 0;
+ h -= n;
+ h *= n;
+ n = h >>> 0;
+ h -= n;
+ n += h * 0x100000000// 2^32
+ ;
+ }
+ return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
+
+ };
+ RandomDataGenerator.prototype.sow = /**
+ * Reset the seed of the random data generator
+ * @method sow
+ * @param {Array} seeds
+ */
+ function (seeds) {
+ if (typeof seeds === "undefined") { seeds = []; }
+ this.s0 = this.hash(' ');
+ this.s1 = this.hash(this.s0);
+ this.s2 = this.hash(this.s1);
+ var seed;
+ for(var i = 0; seed = seeds[i++]; ) {
+ this.s0 -= this.hash(seed);
+ this.s0 += ~~(this.s0 < 0);
+ this.s1 -= this.hash(seed);
+ this.s1 += ~~(this.s1 < 0);
+ this.s2 -= this.hash(seed);
+ this.s2 += ~~(this.s2 < 0);
+ }
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "integer", {
+ get: /**
+ * Returns a random integer between 0 and 2^32
+ * @method integer
+ * @return {Number}
+ */
+ function () {
+ return this.uint32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "frac", {
+ get: /**
+ * Returns a random real number between 0 and 1
+ * @method frac
+ * @return {Number}
+ */
+ function () {
+ return this.fract32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "real", {
+ get: /**
+ * Returns a random real number between 0 and 2^32
+ * @method real
+ * @return {Number}
+ */
+ function () {
+ return this.uint32() + this.fract32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RandomDataGenerator.prototype.integerInRange = /**
+ * Returns a random integer between min and max
+ * @method integerInRange
+ * @param {Number} min
+ * @param {Number} max
+ * @return {Number}
+ */
+ function (min, max) {
+ return Math.floor(this.realInRange(min, max));
+ };
+ RandomDataGenerator.prototype.realInRange = /**
+ * Returns a random real number between min and max
+ * @method realInRange
+ * @param {Number} min
+ * @param {Number} max
+ * @return {Number}
+ */
+ function (min, max) {
+ min = min || 0;
+ max = max || 0;
+ return this.frac * (max - min) + min;
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "normal", {
+ get: /**
+ * Returns a random real number between -1 and 1
+ * @method normal
+ * @return {Number}
+ */
+ function () {
+ return 1 - 2 * this.frac;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "uuid", {
+ get: /**
+ * Returns a valid v4 UUID hex string (from https://gist.github.com/1308368)
+ * @method uuid
+ * @return {String}
+ */
+ function () {
+ var a, b;
+ for(b = a = ''; a++ < 36; b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-') {
+ ;
+ }
+ return b;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RandomDataGenerator.prototype.pick = /**
+ * Returns a random member of `array`
+ * @method pick
+ * @param {Any} array
+ */
+ function (array) {
+ return array[this.integerInRange(0, array.length)];
+ };
+ RandomDataGenerator.prototype.weightedPick = /**
+ * Returns a random member of `array`, favoring the earlier entries
+ * @method weightedPick
+ * @param {Any} array
+ */
+ function (array) {
+ return array[~~(Math.pow(this.frac, 2) * array.length)];
+ };
+ RandomDataGenerator.prototype.timestamp = /**
+ * Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified
+ * @method timestamp
+ * @param {Number} min
+ * @param {Number} max
+ */
+ function (min, max) {
+ if (typeof min === "undefined") { min = 946684800000; }
+ if (typeof max === "undefined") { max = 1577862000000; }
+ return this.realInRange(min, max);
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "angle", {
+ get: /**
+ * Returns a random angle between -180 and 180
+ * @method angle
+ */
+ function () {
+ return this.integerInRange(-180, 180);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return RandomDataGenerator;
+ })();
+ Phaser.RandomDataGenerator = RandomDataGenerator;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/math/RandomDataGenerator.ts b/TS Source/math/RandomDataGenerator.ts
similarity index 100%
rename from Phaser/math/RandomDataGenerator.ts
rename to TS Source/math/RandomDataGenerator.ts
diff --git a/TS Source/math/Vec2.js b/TS Source/math/Vec2.js
new file mode 100644
index 00000000..255763ef
--- /dev/null
+++ b/TS Source/math/Vec2.js
@@ -0,0 +1,232 @@
+///
+/**
+* Phaser - Vec2
+*
+* A Vector 2
+*/
+var Phaser;
+(function (Phaser) {
+ var Vec2 = (function () {
+ /**
+ * Creates a new Vec2 object.
+ * @class Vec2
+ * @constructor
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
+ **/
+ function Vec2(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ this.x = x;
+ this.y = y;
+ return this;
+ }
+ Vec2.prototype.copyFrom = /**
+ * Copies the x and y properties from any given object to this Vec2.
+ * @method copyFrom
+ * @param {any} source - The object to copy from.
+ * @return {Vec2} This Vec2 object.
+ **/
+ function (source) {
+ return this.setTo(source.x, source.y);
+ };
+ Vec2.prototype.setTo = /**
+ * Sets the x and y properties of the Vector.
+ * @param {Number} x The x position of the vector
+ * @param {Number} y The y position of the vector
+ * @return {Vec2} This object
+ **/
+ function (x, y) {
+ this.x = x;
+ this.y = y;
+ return this;
+ };
+ Vec2.prototype.add = /**
+ * Add another vector to this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (a) {
+ this.x += a.x;
+ this.y += a.y;
+ return this;
+ };
+ Vec2.prototype.subtract = /**
+ * Subtract another vector from this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x -= v.x;
+ this.y -= v.y;
+ return this;
+ };
+ Vec2.prototype.multiply = /**
+ * Multiply another vector with this one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x *= v.x;
+ this.y *= v.y;
+ return this;
+ };
+ Vec2.prototype.divide = /**
+ * Divide this vector by another one.
+ *
+ * @param {Vec2} other The other Vector.
+ * @return {Vec2} This for chaining.
+ */
+ function (v) {
+ this.x /= v.x;
+ this.y /= v.y;
+ return this;
+ };
+ Vec2.prototype.length = /**
+ * Get the length of this vector.
+ *
+ * @return {number} The length of this vector.
+ */
+ function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vec2.prototype.lengthSq = /**
+ * Get the length squared of this vector.
+ *
+ * @return {number} The length^2 of this vector.
+ */
+ function () {
+ return (this.x * this.x) + (this.y * this.y);
+ };
+ Vec2.prototype.normalize = /**
+ * Normalize this vector.
+ *
+ * @return {Vec2} This for chaining.
+ */
+ function () {
+ var inv = (this.x != 0 || this.y != 0) ? 1 / Math.sqrt(this.x * this.x + this.y * this.y) : 0;
+ this.x *= inv;
+ this.y *= inv;
+ return this;
+ };
+ Vec2.prototype.dot = /**
+ * The dot product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return ((this.x * a.x) + (this.y * a.y));
+ };
+ Vec2.prototype.cross = /**
+ * The cross product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return ((this.x * a.y) - (this.y * a.x));
+ };
+ Vec2.prototype.projectionLength = /**
+ * The projection magnitude of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ var den = a.dot(a);
+ if(den == 0) {
+ return 0;
+ } else {
+ return Math.abs(this.dot(a) / den);
+ }
+ };
+ Vec2.prototype.angle = /**
+ * The angle between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function (a) {
+ return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
+ };
+ Vec2.prototype.scale = /**
+ * Scale this vector.
+ *
+ * @param {number} x The scaling factor in the x direction.
+ * @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
+ * @return {Vec2} This for chaining.
+ */
+ function (x, y) {
+ this.x *= x;
+ this.y *= y || x;
+ return this;
+ };
+ Vec2.prototype.multiplyByScalar = /**
+ * Multiply this vector by the given scalar.
+ *
+ * @param {number} scalar
+ * @return {Vec2} This for chaining.
+ */
+ function (scalar) {
+ this.x *= scalar;
+ this.y *= scalar;
+ return this;
+ };
+ Vec2.prototype.multiplyAddByScalar = /**
+ * Adds the given vector to this vector then multiplies by the given scalar.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {number} scalar
+ * @return {Vec2} This for chaining.
+ */
+ function (a, scalar) {
+ this.x += a.x * scalar;
+ this.y += a.y * scalar;
+ return this;
+ };
+ Vec2.prototype.divideByScalar = /**
+ * Divide this vector by the given scalar.
+ *
+ * @param {number} scalar
+ * @return {Vec2} This for chaining.
+ */
+ function (scalar) {
+ this.x /= scalar;
+ this.y /= scalar;
+ return this;
+ };
+ Vec2.prototype.reverse = /**
+ * Reverse this vector.
+ *
+ * @return {Vec2} This for chaining.
+ */
+ function () {
+ this.x = -this.x;
+ this.y = -this.y;
+ return this;
+ };
+ Vec2.prototype.equals = /**
+ * Check if both the x and y of this vector equal the given value.
+ *
+ * @return {bool}
+ */
+ function (value) {
+ return (this.x == value && this.y == value);
+ };
+ Vec2.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ function () {
+ return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ };
+ return Vec2;
+ })();
+ Phaser.Vec2 = Vec2;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/math/Vec2.ts b/TS Source/math/Vec2.ts
similarity index 100%
rename from Phaser/math/Vec2.ts
rename to TS Source/math/Vec2.ts
diff --git a/TS Source/math/Vec2Utils.js b/TS Source/math/Vec2Utils.js
new file mode 100644
index 00000000..06b9d6de
--- /dev/null
+++ b/TS Source/math/Vec2Utils.js
@@ -0,0 +1,343 @@
+///
+/**
+* Phaser - Vec2Utils
+*
+* A collection of methods useful for manipulating and performing operations on 2D vectors.
+*
+*/
+var Phaser;
+(function (Phaser) {
+ var Vec2Utils = (function () {
+ function Vec2Utils() { }
+ Vec2Utils.add = /**
+ * Adds two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the sum of the two vectors.
+ */
+ function add(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x + b.x, a.y + b.y);
+ };
+ Vec2Utils.subtract = /**
+ * Subtracts two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the difference of the two vectors.
+ */
+ function subtract(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x - b.x, a.y - b.y);
+ };
+ Vec2Utils.multiply = /**
+ * Multiplies two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the sum of the two vectors multiplied.
+ */
+ function multiply(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x * b.x, a.y * b.y);
+ };
+ Vec2Utils.divide = /**
+ * Divides two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the sum of the two vectors divided.
+ */
+ function divide(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x / b.x, a.y / b.y);
+ };
+ Vec2Utils.scale = /**
+ * Scales a 2D vector.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {number} s Scaling value.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the scaled vector.
+ */
+ function scale(a, s, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x * s, a.y * s);
+ };
+ Vec2Utils.multiplyAdd = /**
+ * Adds two 2D vectors together and multiplies the result by the given scalar.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {number} s Scaling value.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the sum of the two vectors added and multiplied.
+ */
+ function multiplyAdd(a, b, s, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x + b.x * s, a.y + b.y * s);
+ };
+ Vec2Utils.negative = /**
+ * Return a negative vector.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the negative vector.
+ */
+ function negative(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(-a.x, -a.y);
+ };
+ Vec2Utils.perp = /**
+ * Return a perpendicular vector (90 degrees rotation)
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the scaled vector.
+ */
+ function perp(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(-a.y, a.x);
+ };
+ Vec2Utils.rperp = /**
+ * Return a perpendicular vector (-90 degrees rotation)
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is the scaled vector.
+ */
+ function rperp(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.y, -a.x);
+ };
+ Vec2Utils.equals = /**
+ * Checks if two 2D vectors are equal.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @return {bool}
+ */
+ function equals(a, b) {
+ return a.x == b.x && a.y == b.y;
+ };
+ Vec2Utils.epsilonEquals = /**
+ *
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Vec2} epsilon
+ * @return {bool}
+ */
+ function epsilonEquals(a, b, epsilon) {
+ return Math.abs(a.x - b.x) <= epsilon && Math.abs(a.y - b.y) <= epsilon;
+ };
+ Vec2Utils.distance = /**
+ * Get the distance between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function distance(a, b) {
+ return Math.sqrt(Vec2Utils.distanceSq(a, b));
+ };
+ Vec2Utils.distanceSq = /**
+ * Get the distance squared between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function distanceSq(a, b) {
+ return ((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y));
+ };
+ Vec2Utils.project = /**
+ * Project two 2D vectors onto another vector.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2.
+ */
+ function project(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var amt = a.dot(b) / b.lengthSq();
+ if(amt != 0) {
+ out.setTo(amt * b.x, amt * b.y);
+ }
+ return out;
+ };
+ Vec2Utils.projectUnit = /**
+ * Project this vector onto a vector of unit length.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2.
+ */
+ function projectUnit(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var amt = a.dot(b);
+ if(amt != 0) {
+ out.setTo(amt * b.x, amt * b.y);
+ }
+ return out;
+ };
+ Vec2Utils.normalRightHand = /**
+ * Right-hand normalize (make unit length) a 2D vector.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2.
+ */
+ function normalRightHand(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.y * -1, a.x);
+ };
+ Vec2Utils.normalize = /**
+ * Normalize (make unit length) a 2D vector.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2.
+ */
+ function normalize(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var m = a.length();
+ if(m != 0) {
+ out.setTo(a.x / m, a.y / m);
+ }
+ return out;
+ };
+ Vec2Utils.dot = /**
+ * The dot product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function dot(a, b) {
+ return ((a.x * b.x) + (a.y * b.y));
+ };
+ Vec2Utils.cross = /**
+ * The cross product of two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function cross(a, b) {
+ return ((a.x * b.y) - (a.y * b.x));
+ };
+ Vec2Utils.angle = /**
+ * The angle between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function angle(a, b) {
+ return Math.atan2(a.x * b.y - a.y * b.x, a.x * b.x + a.y * b.y);
+ };
+ Vec2Utils.angleSq = /**
+ * The angle squared between two 2D vectors.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @return {Number}
+ */
+ function angleSq(a, b) {
+ return a.subtract(b).angle(b.subtract(a));
+ };
+ Vec2Utils.rotateAroundOrigin = /**
+ * Rotate a 2D vector around the origin to the given angle (theta).
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Number} theta The angle of rotation in radians.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2.
+ */
+ function rotateAroundOrigin(a, b, theta, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var x = a.x - b.x;
+ var y = a.y - b.y;
+ return out.setTo(x * Math.cos(theta) - y * Math.sin(theta) + b.x, x * Math.sin(theta) + y * Math.cos(theta) + b.y);
+ };
+ Vec2Utils.rotate = /**
+ * Rotate a 2D vector to the given angle (theta).
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} b Reference to a source Vec2 object.
+ * @param {Number} theta The angle of rotation in radians.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2.
+ */
+ function rotate(a, theta, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var c = Math.cos(theta);
+ var s = Math.sin(theta);
+ return out.setTo(a.x * c - a.y * s, a.x * s + a.y * c);
+ };
+ Vec2Utils.clone = /**
+ * Clone a 2D vector.
+ *
+ * @param {Vec2} a Reference to a source Vec2 object.
+ * @param {Vec2} out The output Vec2 that is the result of the operation.
+ * @return {Vec2} A Vec2 that is a copy of the source Vec2.
+ */
+ function clone(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x, a.y);
+ };
+ return Vec2Utils;
+ })();
+ Phaser.Vec2Utils = Vec2Utils;
+ /**
+ * Reflect this vector on an arbitrary axis.
+ *
+ * @param {Vec2} axis The vector representing the axis.
+ * @return {Vec2} This for chaining.
+ */
+ /*
+ static reflect(axis): Vec2 {
+
+ var x = this.x;
+ var y = this.y;
+ this.project(axis).scale(2);
+ this.x -= x;
+ this.y -= y;
+
+ return this;
+
+ }
+ */
+ /**
+ * Reflect this vector on an arbitrary axis (represented by a unit vector)
+ *
+ * @param {Vec2} axis The unit vector representing the axis.
+ * @return {Vec2} This for chaining.
+ */
+ /*
+ static reflectN(axis): Vec2 {
+
+ var x = this.x;
+ var y = this.y;
+ this.projectN(axis).scale(2);
+ this.x -= x;
+ this.y -= y;
+
+ return this;
+
+ }
+
+ static getMagnitude(): number {
+ return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
+ }
+ */
+ })(Phaser || (Phaser = {}));
diff --git a/Phaser/math/Vec2Utils.ts b/TS Source/math/Vec2Utils.ts
similarity index 100%
rename from Phaser/math/Vec2Utils.ts
rename to TS Source/math/Vec2Utils.ts
diff --git a/TS Source/net/Net.js b/TS Source/net/Net.js
new file mode 100644
index 00000000..ba0aaf1c
--- /dev/null
+++ b/TS Source/net/Net.js
@@ -0,0 +1,91 @@
+///
+/**
+* Phaser - Net
+*
+*
+*/
+var Phaser;
+(function (Phaser) {
+ var Net = (function () {
+ /**
+ * Net constructor
+ */
+ function Net(game) {
+ this.game = game;
+ }
+ Net.prototype.checkDomainName = /**
+ * Compares the given domain name against the hostname of the browser containing the game.
+ * If the domain name is found it returns true.
+ * You can specify a part of a domain, for example 'google' would match 'google.com', 'google.co.uk', etc.
+ * Do not include 'http://' at the start.
+ */
+ function (domain) {
+ return window.location.hostname.indexOf(domain) !== -1;
+ };
+ Net.prototype.updateQueryString = /**
+ * Updates a value on the Query String and returns it in full.
+ * If the value doesn't already exist it is set.
+ * If the value exists it is replaced with the new value given. If you don't provide a new value it is removed from the query string.
+ * Optionally you can redirect to the new url, or just return it as a string.
+ */
+ function (key, value, redirect, url) {
+ if (typeof redirect === "undefined") { redirect = false; }
+ if (typeof url === "undefined") { url = ''; }
+ if(url == '') {
+ url = window.location.href;
+ }
+ var output = '';
+ var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
+ if(re.test(url)) {
+ if(typeof value !== 'undefined' && value !== null) {
+ output = url.replace(re, '$1' + key + "=" + value + '$2$3');
+ } else {
+ output = url.replace(re, '$1$3').replace(/(&|\?)$/, '');
+ }
+ } else {
+ if(typeof value !== 'undefined' && value !== null) {
+ var separator = url.indexOf('?') !== -1 ? '&' : '?';
+ var hash = url.split('#');
+ url = hash[0] + separator + key + '=' + value;
+ if(hash[1]) {
+ url += '#' + hash[1];
+ }
+ output = url;
+ } else {
+ output = url;
+ }
+ }
+ if(redirect) {
+ window.location.href = output;
+ } else {
+ return output;
+ }
+ };
+ Net.prototype.getQueryString = /**
+ * Returns the Query String as an object.
+ * If you specify a parameter it will return just the value of that parameter, should it exist.
+ */
+ function (parameter) {
+ if (typeof parameter === "undefined") { parameter = ''; }
+ var output = {
+ };
+ var keyValues = location.search.substring(1).split('&');
+ for(var i in keyValues) {
+ var key = keyValues[i].split('=');
+ if(key.length > 1) {
+ if(parameter && parameter == this.decodeURI(key[0])) {
+ return this.decodeURI(key[1]);
+ } else {
+ output[this.decodeURI(key[0])] = this.decodeURI(key[1]);
+ }
+ }
+ }
+ return output;
+ };
+ Net.prototype.decodeURI = function (value) {
+ return decodeURIComponent(value.replace(/\+/g, " "));
+ };
+ return Net;
+ })();
+ Phaser.Net = Net;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/net/Net.ts b/TS Source/net/Net.ts
similarity index 100%
rename from Phaser/net/Net.ts
rename to TS Source/net/Net.ts
diff --git a/TS Source/particles/Emitter.js b/TS Source/particles/Emitter.js
new file mode 100644
index 00000000..050537d8
--- /dev/null
+++ b/TS Source/particles/Emitter.js
@@ -0,0 +1,288 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var Emitter = (function () {
+ /**
+ * You can use this emit particles.
+ *
+ * It will dispatch follow events:
+ * Proton.PARTICLE_CREATED
+ * Proton.PARTICLE_UPDATA
+ * Proton.PARTICLE_DEAD
+ *
+ * @class Proton.Emitter
+ * @constructor
+ * @param {Object} pObj the parameters object;
+ * for example {damping:0.01,bindEmitter:false}
+ */
+ function Emitter(pObj) {
+ this.initializes = [];
+ this.particles = [];
+ this.behaviours = [];
+ this.emitTime = 0;
+ this.emitTotalTimes = -1;
+ this.initializes = [];
+ this.particles = [];
+ this.behaviours = [];
+ this.emitTime = 0;
+ this.emitTotalTimes = -1;
+ /**
+ * The friction coefficient for all particle emit by This;
+ * @property damping
+ * @type {Number}
+ * @default 0.006
+ */
+ this.damping = .006;
+ /**
+ * If bindEmitter the particles can bind this emitter's property;
+ * @property bindEmitter
+ * @type {bool}
+ * @default true
+ */
+ this.bindEmitter = true;
+ /**
+ * The number of particles per second emit (a [particle]/b [s]);
+ * @property rate
+ * @type {Proton.Rate}
+ * @default Proton.Rate(1, .1)
+ */
+ this.rate = new Phaser.Particles.Initializers.Rate(1, .1);
+ //Emitter._super_.call(this, pObj);
+ /**
+ * The emitter's id;
+ * @property id
+ * @type {String} id
+ */
+ this.id = 'emitter_' + Emitter.ID++;
+ }
+ Emitter.ID = 0;
+ Emitter.prototype.emit = /**
+ * start emit particle
+ * @method emit
+ * @param {Number} emitTime begin emit time;
+ * @param {String} life the life of this emitter
+ */
+ function (emitTime, life) {
+ this.emitTime = 0;
+ this.emitTotalTimes = Particles.ParticleUtils.initValue(emitTime, Infinity);
+ if(life == true || life == 'life' || life == 'destroy') {
+ if(emitTime == 'once') {
+ this.life = 1;
+ } else {
+ this.life = this.emitTotalTimes;
+ }
+ } else if(!isNaN(life)) {
+ this.life = life;
+ }
+ this.rate.init();
+ };
+ Emitter.prototype.stopEmit = /**
+ * stop emiting
+ * @method stopEmit
+ */
+ function () {
+ this.emitTotalTimes = -1;
+ this.emitTime = 0;
+ };
+ Emitter.prototype.removeAllParticles = /**
+ * remove current all particles
+ * @method removeAllParticles
+ */
+ function () {
+ for(var i = 0; i < this.particles.length; i++) {
+ this.particles[i].dead = true;
+ }
+ };
+ Emitter.prototype.createParticle = /**
+ * create single particle;
+ *
+ * can use emit({x:10},new Gravity(10),{'particleUpdate',fun}) or emit([{x:10},new Initialize],new Gravity(10),{'particleUpdate',fun})
+ * @method removeAllParticles
+ */
+ function (initialize, behaviour) {
+ if (typeof initialize === "undefined") { initialize = null; }
+ if (typeof behaviour === "undefined") { behaviour = null; }
+ var particle = Particles.ParticleManager.pool.get();
+ this.setupParticle(particle, initialize, behaviour);
+ //this.dispatchEvent(new Proton.Event({
+ // type: Proton.PARTICLE_CREATED,
+ // particle: particle
+ //}));
+ return particle;
+ };
+ Emitter.prototype.addSelfInitialize = /**
+ * add initialize to this emitter
+ * @method addSelfInitialize
+ */
+ function (pObj) {
+ if(pObj['init']) {
+ pObj.init(this);
+ } else {
+ //this.initAll();
+ }
+ };
+ Emitter.prototype.addInitialize = /**
+ * add the Initialize to particles;
+ *
+ * you can use initializes array:for example emitter.addInitialize(initialize1,initialize2,initialize3);
+ * @method addInitialize
+ * @param {Proton.Initialize} initialize like this new Proton.Radius(1, 12)
+ */
+ function () {
+ var length = arguments.length, i;
+ for(i = 0; i < length; i++) {
+ this.initializes.push(arguments[i]);
+ }
+ };
+ Emitter.prototype.removeInitialize = /**
+ * remove the Initialize
+ * @method removeInitialize
+ * @param {Proton.Initialize} initialize a initialize
+ */
+ function (initializer) {
+ var index = this.initializes.indexOf(initializer);
+ if(index > -1) {
+ this.initializes.splice(index, 1);
+ }
+ };
+ Emitter.prototype.removeInitializers = /**
+ * remove all Initializes
+ * @method removeInitializers
+ */
+ function () {
+ Particles.ParticleUtils.destroyArray(this.initializes);
+ };
+ Emitter.prototype.addBehaviour = /**
+ * add the Behaviour to particles;
+ *
+ * you can use Behaviours array:emitter.addBehaviour(Behaviour1,Behaviour2,Behaviour3);
+ * @method addBehaviour
+ * @param {Proton.Behaviour} behaviour like this new Proton.Color('random')
+ */
+ function () {
+ var length = arguments.length, i;
+ for(i = 0; i < length; i++) {
+ this.behaviours.push(arguments[i]);
+ if(arguments[i].hasOwnProperty("parents")) {
+ arguments[i].parents.push(this);
+ }
+ }
+ };
+ Emitter.prototype.removeBehaviour = /**
+ * remove the Behaviour
+ * @method removeBehaviour
+ * @param {Proton.Behaviour} behaviour a behaviour
+ */
+ function (behaviour) {
+ var index = this.behaviours.indexOf(behaviour);
+ if(index > -1) {
+ this.behaviours.splice(index, 1);
+ }
+ };
+ Emitter.prototype.removeAllBehaviours = /**
+ * remove all behaviours
+ * @method removeAllBehaviours
+ */
+ function () {
+ Particles.ParticleUtils.destroyArray(this.behaviours);
+ };
+ Emitter.prototype.integrate = function (time) {
+ var damping = 1 - this.damping;
+ Particles.ParticleManager.integrator.integrate(this, time, damping);
+ var length = this.particles.length, i;
+ for(i = 0; i < length; i++) {
+ var particle = this.particles[i];
+ particle.update(time, i);
+ Particles.ParticleManager.integrator.integrate(particle, time, damping);
+ //this.dispatchEvent(new Proton.Event({
+ // type: Proton.PARTICLE_UPDATE,
+ // particle: particle
+ //}));
+ }
+ };
+ Emitter.prototype.emitting = function (time) {
+ if(this.emitTotalTimes == 1) {
+ var length = this.rate.getValue(99999), i;
+ for(i = 0; i < length; i++) {
+ this.createParticle();
+ }
+ this.emitTotalTimes = 0;
+ } else if(!isNaN(this.emitTotalTimes)) {
+ this.emitTime += time;
+ if(this.emitTime < this.emitTotalTimes) {
+ var length = this.rate.getValue(time), i;
+ for(i = 0; i < length; i++) {
+ this.createParticle();
+ }
+ }
+ }
+ };
+ Emitter.prototype.update = function (time) {
+ this.age += time;
+ if(this.age >= this.life || this.dead) {
+ this.destroy();
+ }
+ this.emitting(time);
+ this.integrate(time);
+ var particle;
+ var length = this.particles.length, k;
+ for(k = length - 1; k >= 0; k--) {
+ particle = this.particles[k];
+ if(particle.dead) {
+ Particles.ParticleManager.pool.set(particle);
+ this.particles.splice(k, 1);
+ //this.dispatchEvent(new Proton.Event({
+ // type: Proton.PARTICLE_DEAD,
+ // particle: particle
+ //}));
+ }
+ }
+ };
+ Emitter.prototype.setupParticle = function (particle, initialize, behaviour) {
+ var initializes = this.initializes;
+ var behaviours = this.behaviours;
+ if(initialize) {
+ if(initialize instanceof Array) {
+ initializes = initialize;
+ } else {
+ initializes = [
+ initialize
+ ];
+ }
+ }
+ if(behaviour) {
+ if(behaviour instanceof Array) {
+ behaviours = behaviour;
+ } else {
+ behaviours = [
+ behaviour
+ ];
+ }
+ }
+ //Proton.InitializeUtil.initialize(this, particle, initializes);
+ particle.addBehaviours(behaviours);
+ particle.parent = this;
+ this.particles.push(particle);
+ };
+ Emitter.prototype.destroy = /**
+ * Destory this Emitter
+ * @method destory
+ */
+ function () {
+ this.dead = true;
+ this.emitTotalTimes = -1;
+ if(this.particles.length == 0) {
+ this.removeInitializers();
+ this.removeAllBehaviours();
+ if(this.parent) {
+ this.parent.removeEmitter(this);
+ }
+ }
+ };
+ return Emitter;
+ })();
+ Particles.Emitter = Emitter;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/Emitter.ts b/TS Source/particles/Emitter.ts
similarity index 100%
rename from Phaser/particles/Emitter.ts
rename to TS Source/particles/Emitter.ts
diff --git a/TS Source/particles/NumericalIntegration.js b/TS Source/particles/NumericalIntegration.js
new file mode 100644
index 00000000..dd5129e6
--- /dev/null
+++ b/TS Source/particles/NumericalIntegration.js
@@ -0,0 +1,30 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var NumericalIntegration = (function () {
+ function NumericalIntegration(type) {
+ this.type = Particles.ParticleUtils.initValue(type, Particles.ParticleManager.EULER);
+ }
+ NumericalIntegration.prototype.integrate = function (particles, time, damping) {
+ this.eulerIntegrate(particles, time, damping);
+ };
+ NumericalIntegration.prototype.eulerIntegrate = function (particle, time, damping) {
+ if(!particle.sleep) {
+ particle.old.p.copy(particle.p);
+ particle.old.v.copy(particle.v);
+ particle.a.multiplyScalar(1 / particle.mass);
+ particle.v.add(particle.a.multiplyScalar(time));
+ particle.p.add(particle.old.v.multiplyScalar(time));
+ if(damping) {
+ particle.v.multiplyScalar(damping);
+ }
+ particle.a.clear();
+ }
+ };
+ return NumericalIntegration;
+ })();
+ Particles.NumericalIntegration = NumericalIntegration;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/NumericalIntegration.ts b/TS Source/particles/NumericalIntegration.ts
similarity index 100%
rename from Phaser/particles/NumericalIntegration.ts
rename to TS Source/particles/NumericalIntegration.ts
diff --git a/TS Source/particles/Particle.js b/TS Source/particles/Particle.js
new file mode 100644
index 00000000..d882cccc
--- /dev/null
+++ b/TS Source/particles/Particle.js
@@ -0,0 +1,151 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var Particle = (function () {
+ /**
+ * the Particle class
+ *
+ * @class Proton.Particle
+ * @constructor
+ * @param {Object} pObj the parameters object;
+ * for example {life:3,dead:false}
+ */
+ function Particle() {
+ this.life = Infinity;
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.sleep = false;
+ this.target = null;
+ this.sprite = null;
+ this.parent = null;
+ this.mass = 1;
+ this.radius = 10;
+ this.alpha = 1;
+ this.scale = 1;
+ this.rotation = 0;
+ this.color = null;
+ this.easing = Phaser.Easing.Linear.None;
+ this.p = new Phaser.Vec2();
+ this.v = new Phaser.Vec2();
+ this.a = new Phaser.Vec2();
+ this.old = {
+ p: new Phaser.Vec2(),
+ v: new Phaser.Vec2(),
+ a: new Phaser.Vec2()
+ };
+ this.behaviours = [];
+ /**
+ * The particle's id;
+ * @property id
+ * @type {String} id
+ */
+ this.id = 'particle_' + Particle.ID++;
+ this.reset(true);
+ }
+ Particle.ID = 0;
+ Particle.prototype.getDirection = function () {
+ return Math.atan2(this.v.x, -this.v.y) * (180 / Math.PI);
+ };
+ Particle.prototype.reset = function (init) {
+ this.life = Infinity;
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.sleep = false;
+ this.target = null;
+ this.sprite = null;
+ this.parent = null;
+ this.mass = 1;
+ this.radius = 10;
+ this.alpha = 1;
+ this.scale = 1;
+ this.rotation = 0;
+ this.color = null;
+ this.easing = Phaser.Easing.Linear.None;
+ if(init) {
+ this.transform = {
+ };
+ this.p = new Phaser.Vec2();
+ this.v = new Phaser.Vec2();
+ this.a = new Phaser.Vec2();
+ this.old = {
+ p: new Phaser.Vec2(),
+ v: new Phaser.Vec2(),
+ a: new Phaser.Vec2()
+ };
+ this.behaviours = [];
+ } else {
+ Particles.ParticleUtils.destroyObject(this.transform);
+ this.p.setTo(0, 0);
+ this.v.setTo(0, 0);
+ this.a.setTo(0, 0);
+ this.old.p.setTo(0, 0);
+ this.old.v.setTo(0, 0);
+ this.old.a.setTo(0, 0);
+ this.removeAllBehaviours();
+ }
+ this.transform.rgb = {
+ r: 255,
+ g: 255,
+ b: 255
+ };
+ return this;
+ };
+ Particle.prototype.update = function (time, index) {
+ if(!this.sleep) {
+ this.age += time;
+ var length = this.behaviours.length, i;
+ for(i = 0; i < length; i++) {
+ if(this.behaviours[i]) {
+ this.behaviours[i].applyBehaviour(this, time, index);
+ }
+ }
+ }
+ if(this.age >= this.life) {
+ this.destroy();
+ } else {
+ var scale = this.easing(this.age / this.life);
+ this.energy = Math.max(1 - scale, 0);
+ }
+ };
+ Particle.prototype.addBehaviour = function (behaviour) {
+ this.behaviours.push(behaviour);
+ if(behaviour.hasOwnProperty('parents')) {
+ behaviour.parents.push(this);
+ }
+ behaviour.initialize(this);
+ };
+ Particle.prototype.addBehaviours = function (behaviours) {
+ var length = behaviours.length, i;
+ for(i = 0; i < length; i++) {
+ this.addBehaviour(behaviours[i]);
+ }
+ };
+ Particle.prototype.removeBehaviour = function (behaviour) {
+ var index = this.behaviours.indexOf(behaviour);
+ if(index > -1) {
+ var outBehaviour = this.behaviours.splice(index, 1);
+ //outBehaviour.parents = null;
+ }
+ };
+ Particle.prototype.removeAllBehaviours = function () {
+ Particles.ParticleUtils.destroyArray(this.behaviours);
+ };
+ Particle.prototype.destroy = /**
+ * Destory this particle
+ * @method destory
+ */
+ function () {
+ this.removeAllBehaviours();
+ this.energy = 0;
+ this.dead = true;
+ this.parent = null;
+ };
+ return Particle;
+ })();
+ Particles.Particle = Particle;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/Particle.ts b/TS Source/particles/Particle.ts
similarity index 100%
rename from Phaser/particles/Particle.ts
rename to TS Source/particles/Particle.ts
diff --git a/TS Source/particles/ParticleManager.js b/TS Source/particles/ParticleManager.js
new file mode 100644
index 00000000..e443755f
--- /dev/null
+++ b/TS Source/particles/ParticleManager.js
@@ -0,0 +1,122 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var ParticleManager = (function () {
+ function ParticleManager(proParticleCount, integrationType) {
+ this.PARTICLE_CREATED = 'partilcleCreated';
+ this.PARTICLE_UPDATE = 'partilcleUpdate';
+ this.PARTICLE_SLEEP = 'particleSleep';
+ this.PARTICLE_DEAD = 'partilcleDead';
+ this.PROTON_UPDATE = 'protonUpdate';
+ this.PROTON_UPDATE_AFTER = 'protonUpdateAfter';
+ this.EMITTER_ADDED = 'emitterAdded';
+ this.EMITTER_REMOVED = 'emitterRemoved';
+ this.emitters = [];
+ this.renderers = [];
+ this.time = 0;
+ this.oldTime = 0;
+ this.amendChangeTabsBug = true;
+ this.TextureBuffer = {
+ };
+ this.TextureCanvasBuffer = {
+ };
+ this.proParticleCount = Particles.ParticleUtils.initValue(proParticleCount, ParticleManager.POOL_MAX);
+ this.integrationType = Particles.ParticleUtils.initValue(integrationType, ParticleManager.EULER);
+ this.emitters = [];
+ this.renderers = [];
+ this.time = 0;
+ this.oldTime = 0;
+ ParticleManager.pool = new Phaser.Particles.ParticlePool(proParticleCount);
+ ParticleManager.integrator = new Phaser.Particles.NumericalIntegration(this.integrationType);
+ }
+ ParticleManager.POOL_MAX = 1000;
+ ParticleManager.TIME_STEP = 60;
+ ParticleManager.MEASURE = 100;
+ ParticleManager.EULER = 'euler';
+ ParticleManager.RK2 = 'runge-kutta2';
+ ParticleManager.RK4 = 'runge-kutta4';
+ ParticleManager.VERLET = 'verlet';
+ ParticleManager.prototype.addRender = /**
+ * add a type of Renderer
+ *
+ * @method addRender
+ * @param {Renderer} render
+ */
+ function (render) {
+ render.proton = this;
+ this.renderers.push(render.proton);
+ };
+ ParticleManager.prototype.addEmitter = /**
+ * add the Emitter
+ *
+ * @method addEmitter
+ * @param {Emitter} emitter
+ */
+ function (emitter) {
+ this.emitters.push(emitter);
+ emitter.parent = this;
+ //this.dispatchEvent(new Proton.Event({
+ // type: Proton.EMITTER_ADDED,
+ // emitter: emitter
+ //}));
+ };
+ ParticleManager.prototype.removeEmitter = function (emitter) {
+ var index = this.emitters.indexOf(emitter);
+ this.emitters.splice(index, 1);
+ emitter.parent = null;
+ //this.dispatchEvent(new Proton.Event({
+ // type: Proton.EMITTER_REMOVED,
+ // emitter: emitter
+ //}));
+ };
+ ParticleManager.prototype.update = function () {
+ //this.dispatchEvent(new Proton.Event({
+ // type: Proton.PROTON_UPDATE
+ //}));
+ if(!this.oldTime) {
+ this.oldTime = new Date().getTime();
+ }
+ var time = new Date().getTime();
+ this.elapsed = (time - this.oldTime) / 1000;
+ //if (ParticleUtils.amendChangeTabsBug)
+ // this.amendChangeTabsBugHandler();
+ this.oldTime = time;
+ if(this.elapsed > 0) {
+ for(var i = 0; i < this.emitters.length; i++) {
+ this.emitters[i].update(this.elapsed);
+ }
+ }
+ //this.dispatchEvent(new Proton.Event({
+ // type: Proton.PROTON_UPDATE_AFTER
+ //}));
+ };
+ ParticleManager.prototype.amendChangeTabsBugHandler = function () {
+ if(this.elapsed > .5) {
+ this.oldTime = new Date().getTime();
+ this.elapsed = 0;
+ }
+ };
+ ParticleManager.prototype.getParticleNumber = function () {
+ var total = 0;
+ for(var i = 0; i < this.emitters.length; i++) {
+ total += this.emitters[i].particles.length;
+ }
+ return total;
+ };
+ ParticleManager.prototype.destroy = function () {
+ for(var i = 0; i < this.emitters.length; i++) {
+ this.emitters[i].destory();
+ delete this.emitters[i];
+ }
+ this.emitters = [];
+ this.time = 0;
+ this.oldTime = 0;
+ ParticleManager.pool.release();
+ };
+ return ParticleManager;
+ })();
+ Particles.ParticleManager = ParticleManager;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/ParticleManager.ts b/TS Source/particles/ParticleManager.ts
similarity index 100%
rename from Phaser/particles/ParticleManager.ts
rename to TS Source/particles/ParticleManager.ts
diff --git a/TS Source/particles/ParticlePool.js b/TS Source/particles/ParticlePool.js
new file mode 100644
index 00000000..303f137d
--- /dev/null
+++ b/TS Source/particles/ParticlePool.js
@@ -0,0 +1,62 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var ParticlePool = (function () {
+ function ParticlePool(num, releaseTime) {
+ if (typeof releaseTime === "undefined") { releaseTime = 0; }
+ this.poolList = [];
+ this.timeoutID = 0;
+ this.proParticleCount = Particles.ParticleUtils.initValue(num, 0);
+ this.releaseTime = Particles.ParticleUtils.initValue(releaseTime, -1);
+ this.poolList = [];
+ this.timeoutID = 0;
+ for(var i = 0; i < this.proParticleCount; i++) {
+ this.add();
+ }
+ if(this.releaseTime > 0) {
+ // TODO - Hook to game clock so Pause works
+ this.timeoutID = setTimeout(this.release, this.releaseTime / 1000);
+ }
+ }
+ ParticlePool.prototype.create = function (newTypeParticleClass) {
+ if (typeof newTypeParticleClass === "undefined") { newTypeParticleClass = null; }
+ if(newTypeParticleClass) {
+ return new newTypeParticleClass();
+ } else {
+ return new Phaser.Particles.Particle();
+ }
+ };
+ ParticlePool.prototype.getCount = function () {
+ return this.poolList.length;
+ };
+ ParticlePool.prototype.add = function () {
+ return this.poolList.push(this.create());
+ };
+ ParticlePool.prototype.get = function () {
+ if(this.poolList.length === 0) {
+ return this.create();
+ } else {
+ return this.poolList.pop().reset();
+ }
+ };
+ ParticlePool.prototype.set = function (particle) {
+ if(this.poolList.length < Particles.ParticleManager.POOL_MAX) {
+ return this.poolList.push(particle);
+ }
+ };
+ ParticlePool.prototype.release = function () {
+ for(var i = 0; i < this.poolList.length; i++) {
+ if(this.poolList[i]['destroy']) {
+ this.poolList[i].destroy();
+ }
+ delete this.poolList[i];
+ }
+ this.poolList = [];
+ };
+ return ParticlePool;
+ })();
+ Particles.ParticlePool = ParticlePool;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/ParticlePool.ts b/TS Source/particles/ParticlePool.ts
similarity index 100%
rename from Phaser/particles/ParticlePool.ts
rename to TS Source/particles/ParticlePool.ts
diff --git a/TS Source/particles/ParticleUtils.js b/TS Source/particles/ParticleUtils.js
new file mode 100644
index 00000000..d9c12f04
--- /dev/null
+++ b/TS Source/particles/ParticleUtils.js
@@ -0,0 +1,146 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var ParticleUtils = (function () {
+ function ParticleUtils() { }
+ ParticleUtils.initValue = function initValue(value, defaults) {
+ var value = (value != null && value != undefined) ? value : defaults;
+ return value;
+ };
+ ParticleUtils.isArray = function isArray(value) {
+ return typeof value === 'object' && value.hasOwnProperty('length');
+ };
+ ParticleUtils.destroyArray = function destroyArray(array) {
+ array.length = 0;
+ };
+ ParticleUtils.destroyObject = function destroyObject(obj) {
+ for(var o in obj) {
+ delete obj[o];
+ }
+ };
+ ParticleUtils.setSpanValue = function setSpanValue(a, b, c) {
+ if (typeof b === "undefined") { b = null; }
+ if (typeof c === "undefined") { c = null; }
+ if(a instanceof Phaser.Particles.Span) {
+ return a;
+ } else {
+ if(!b) {
+ return new Phaser.Particles.Span(a);
+ } else {
+ if(!c) {
+ return new Phaser.Particles.Span(a, b);
+ } else {
+ return new Phaser.Particles.Span(a, b, c);
+ }
+ }
+ }
+ };
+ ParticleUtils.getSpanValue = function getSpanValue(pan) {
+ if(pan instanceof Phaser.Particles.Span) {
+ return pan.getValue();
+ } else {
+ return pan;
+ }
+ };
+ ParticleUtils.randomAToB = function randomAToB(a, b, INT) {
+ if (typeof INT === "undefined") { INT = null; }
+ if(!INT) {
+ return a + Math.random() * (b - a);
+ } else {
+ return Math.floor(Math.random() * (b - a)) + a;
+ }
+ };
+ ParticleUtils.randomFloating = function randomFloating(center, f, INT) {
+ return ParticleUtils.randomAToB(center - f, center + f, INT);
+ };
+ ParticleUtils.randomZone = function randomZone(display) {
+ };
+ ParticleUtils.degreeTransform = function degreeTransform(a) {
+ return a * Math.PI / 180;
+ };
+ ParticleUtils.randomColor = //static toColor16 getRGB(num) {
+ // return "#" + num.toString(16);
+ //}
+ function randomColor() {
+ return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
+ };
+ ParticleUtils.setEasingByName = function setEasingByName(name) {
+ switch(name) {
+ case 'easeLinear':
+ return Phaser.Easing.Linear.None;
+ break;
+ case 'easeInQuad':
+ return Phaser.Easing.Quadratic.In;
+ break;
+ case 'easeOutQuad':
+ return Phaser.Easing.Quadratic.Out;
+ break;
+ case 'easeInOutQuad':
+ return Phaser.Easing.Quadratic.InOut;
+ break;
+ case 'easeInCubic':
+ return Phaser.Easing.Cubic.In;
+ break;
+ case 'easeOutCubic':
+ return Phaser.Easing.Cubic.Out;
+ break;
+ case 'easeInOutCubic':
+ return Phaser.Easing.Cubic.InOut;
+ break;
+ case 'easeInQuart':
+ return Phaser.Easing.Quartic.In;
+ break;
+ case 'easeOutQuart':
+ return Phaser.Easing.Quartic.Out;
+ break;
+ case 'easeInOutQuart':
+ return Phaser.Easing.Quartic.InOut;
+ break;
+ case 'easeInSine':
+ return Phaser.Easing.Sinusoidal.In;
+ break;
+ case 'easeOutSine':
+ return Phaser.Easing.Sinusoidal.Out;
+ break;
+ case 'easeInOutSine':
+ return Phaser.Easing.Sinusoidal.InOut;
+ break;
+ case 'easeInExpo':
+ return Phaser.Easing.Exponential.In;
+ break;
+ case 'easeOutExpo':
+ return Phaser.Easing.Exponential.Out;
+ break;
+ case 'easeInOutExpo':
+ return Phaser.Easing.Exponential.InOut;
+ break;
+ case 'easeInCirc':
+ return Phaser.Easing.Circular.In;
+ break;
+ case 'easeOutCirc':
+ return Phaser.Easing.Circular.Out;
+ break;
+ case 'easeInOutCirc':
+ return Phaser.Easing.Circular.InOut;
+ break;
+ case 'easeInBack':
+ return Phaser.Easing.Back.In;
+ break;
+ case 'easeOutBack':
+ return Phaser.Easing.Back.Out;
+ break;
+ case 'easeInOutBack':
+ return Phaser.Easing.Back.InOut;
+ break;
+ default:
+ return Phaser.Easing.Linear.None;
+ break;
+ }
+ };
+ return ParticleUtils;
+ })();
+ Particles.ParticleUtils = ParticleUtils;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/ParticleUtils.ts b/TS Source/particles/ParticleUtils.ts
similarity index 100%
rename from Phaser/particles/ParticleUtils.ts
rename to TS Source/particles/ParticleUtils.ts
diff --git a/TS Source/particles/Polar2D.js b/TS Source/particles/Polar2D.js
new file mode 100644
index 00000000..f7aa8908
--- /dev/null
+++ b/TS Source/particles/Polar2D.js
@@ -0,0 +1,63 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var Polar2D = (function () {
+ function Polar2D(r, tha) {
+ this.r = Math.abs(r) || 0;
+ this.tha = tha || 0;
+ }
+ Polar2D.prototype.set = function (r, tha) {
+ this.r = r;
+ this.tha = tha;
+ return this;
+ };
+ Polar2D.prototype.setR = function (r) {
+ this.r = r;
+ return this;
+ };
+ Polar2D.prototype.setTha = function (tha) {
+ this.tha = tha;
+ return this;
+ };
+ Polar2D.prototype.copy = function (p) {
+ this.r = p.r;
+ this.tha = p.tha;
+ return this;
+ };
+ Polar2D.prototype.toVector = function () {
+ return new Phaser.Vec2(this.getX(), this.getY());
+ };
+ Polar2D.prototype.getX = function () {
+ return this.r * Math.sin(this.tha);
+ };
+ Polar2D.prototype.getY = function () {
+ return -this.r * Math.cos(this.tha);
+ };
+ Polar2D.prototype.normalize = function () {
+ this.r = 1;
+ return this;
+ };
+ Polar2D.prototype.equals = function (v) {
+ return ((v.r === this.r) && (v.tha === this.tha));
+ };
+ Polar2D.prototype.toArray = function () {
+ return [
+ this.r,
+ this.tha
+ ];
+ };
+ Polar2D.prototype.clear = function () {
+ this.r = 0.0;
+ this.tha = 0.0;
+ return this;
+ };
+ Polar2D.prototype.clone = function () {
+ return new Polar2D(this.r, this.tha);
+ };
+ return Polar2D;
+ })();
+ Particles.Polar2D = Polar2D;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/Polar2D.ts b/TS Source/particles/Polar2D.ts
similarity index 100%
rename from Phaser/particles/Polar2D.ts
rename to TS Source/particles/Polar2D.ts
diff --git a/TS Source/particles/Span.js b/TS Source/particles/Span.js
new file mode 100644
index 00000000..e20d6d7c
--- /dev/null
+++ b/TS Source/particles/Span.js
@@ -0,0 +1,39 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ (function (Particles) {
+ var Span = (function () {
+ function Span(a, b, center) {
+ if (typeof b === "undefined") { b = null; }
+ if (typeof center === "undefined") { center = null; }
+ this.isArray = false;
+ if(Particles.ParticleUtils.isArray(a)) {
+ this.isArray = true;
+ this.a = a;
+ } else {
+ this.a = Particles.ParticleUtils.initValue(a, 1);
+ this.b = Particles.ParticleUtils.initValue(b, this.a);
+ this.center = Particles.ParticleUtils.initValue(center, false);
+ }
+ }
+ Span.prototype.getValue = function (INT) {
+ if (typeof INT === "undefined") { INT = null; }
+ if(this.isArray) {
+ return this.a[Math.floor(this.a.length * Math.random())];
+ } else {
+ if(!this.center) {
+ return Particles.ParticleUtils.randomAToB(this.a, this.b, INT);
+ } else {
+ return Particles.ParticleUtils.randomFloating(this.a, this.b, INT);
+ }
+ }
+ };
+ Span.getSpan = function getSpan(a, b, center) {
+ return new Span(a, b, center);
+ };
+ return Span;
+ })();
+ Particles.Span = Span;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/Span.ts b/TS Source/particles/Span.ts
similarity index 100%
rename from Phaser/particles/Span.ts
rename to TS Source/particles/Span.ts
diff --git a/TS Source/particles/behaviours/Behaviour.js b/TS Source/particles/behaviours/Behaviour.js
new file mode 100644
index 00000000..724bac92
--- /dev/null
+++ b/TS Source/particles/behaviours/Behaviour.js
@@ -0,0 +1,118 @@
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Behaviours) {
+ var Behaviour = (function () {
+ function Behaviour(life, easing) {
+ /**
+ * The behaviour's id;
+ * @property id
+ * @type {String} id
+ */
+ this.id = 'Behaviour_' + Behaviour.ID++;
+ this.life = Particles.ParticleUtils.initValue(life, Infinity);
+ /**
+ * The behaviour's decaying trend, for example Proton.easeOutQuart;
+ * @property easing
+ * @type {String}
+ * @default Proton.easeLinear
+ */
+ this.easing = Particles.ParticleUtils.setEasingByName(easing);
+ this.age = 0;
+ this.energy = 1;
+ /**
+ * The behaviour is Dead;
+ * @property dead
+ * @type {bool}
+ */
+ this.dead = false;
+ /**
+ * The behaviour's parents array;
+ * @property parents
+ * @type {Array}
+ */
+ this.parents = [];
+ /**
+ * The behaviour name;
+ * @property name
+ * @type {string}
+ */
+ this.name = 'Behaviour';
+ }
+ Behaviour.prototype.normalizeForce = /**
+ * Reset this behaviour's parameters
+ *
+ * @method reset
+ * @param {Number} this behaviour's life
+ * @param {String} this behaviour's easing
+ */
+ //reset (life, easing) {
+ // this.life = ParticleUtils.initValue(life, Infinity);
+ // //this.easing = ParticleUtils.initValue(easing, Proton.ease.setEasingByName(Proton.easeLinear));
+ //}
+ /**
+ * Normalize a force by 1:100;
+ *
+ * @method normalizeForce
+ * @param {Proton.Vector2D} force
+ */
+ function (force) {
+ return force.multiplyScalar(Particles.ParticleManager.MEASURE);
+ };
+ Behaviour.prototype.normalizeValue = /**
+ * Normalize a value by 1:100;
+ *
+ * @method normalizeValue
+ * @param {Number} value
+ */
+ function (value) {
+ return value * Particles.ParticleManager.MEASURE;
+ };
+ Behaviour.prototype.initialize = /**
+ * Initialize the behaviour's parameters for all particles
+ *
+ * @method initialize
+ * @param {Proton.Particle} particle
+ */
+ function (particle) {
+ };
+ Behaviour.prototype.applyBehaviour = /**
+ * Apply this behaviour for all particles every time
+ *
+ * @method applyBehaviour
+ * @param {Proton.Particle} particle
+ * @param {Number} the integrate time 1/ms
+ * @param {Int} the particle index
+ */
+ function (particle, time, index) {
+ this.age += time;
+ if(this.age >= this.life || this.dead) {
+ this.energy = 0;
+ this.dead = true;
+ this.destroy();
+ } else {
+ var scale = this.easing(particle.age / particle.life);
+ this.energy = Math.max(1 - scale, 0);
+ }
+ };
+ Behaviour.prototype.destroy = /**
+ * Destory this behaviour
+ * @method destory
+ */
+ function () {
+ var index;
+ var length = this.parents.length, i;
+ for(i = 0; i < length; i++) {
+ this.parents[i].removeBehaviour(this);
+ }
+ this.parents = [];
+ };
+ return Behaviour;
+ })();
+ Behaviours.Behaviour = Behaviour;
+ })(Particles.Behaviours || (Particles.Behaviours = {}));
+ var Behaviours = Particles.Behaviours;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/behaviours/Behaviour.ts b/TS Source/particles/behaviours/Behaviour.ts
similarity index 100%
rename from Phaser/particles/behaviours/Behaviour.ts
rename to TS Source/particles/behaviours/Behaviour.ts
diff --git a/TS Source/particles/behaviours/RandomDrift.js b/TS Source/particles/behaviours/RandomDrift.js
new file mode 100644
index 00000000..6eda9e12
--- /dev/null
+++ b/TS Source/particles/behaviours/RandomDrift.js
@@ -0,0 +1,45 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Behaviours) {
+ var RandomDrift = (function (_super) {
+ __extends(RandomDrift, _super);
+ function RandomDrift(driftX, driftY, delay, life, easing) {
+ _super.call(this, life, easing);
+ this.reset(driftX, driftY, delay);
+ this.time = 0;
+ this.name = "RandomDrift";
+ }
+ RandomDrift.prototype.reset = function (driftX, driftY, delay, life, easing) {
+ if (typeof life === "undefined") { life = null; }
+ if (typeof easing === "undefined") { easing = null; }
+ this.panFoce = new Phaser.Vec2(driftX, driftY);
+ this.panFoce = this.normalizeForce(this.panFoce);
+ this.delay = delay;
+ if(life) {
+ this.life = Particles.ParticleUtils.initValue(life, Infinity);
+ this.easing = Particles.ParticleUtils.initValue(easing, Phaser.Easing.Linear.None);
+ }
+ };
+ RandomDrift.prototype.applyBehaviour = function (particle, time, index) {
+ _super.prototype.applyBehaviour.call(this, particle, time, index);
+ this.time += time;
+ if(this.time >= this.delay) {
+ particle.a.addXY(Particles.ParticleUtils.randomAToB(-this.panFoce.x, this.panFoce.x), Particles.ParticleUtils.randomAToB(-this.panFoce.y, this.panFoce.y));
+ this.time = 0;
+ }
+ };
+ return RandomDrift;
+ })(Behaviours.Behaviour);
+ Behaviours.RandomDrift = RandomDrift;
+ })(Particles.Behaviours || (Particles.Behaviours = {}));
+ var Behaviours = Particles.Behaviours;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/behaviours/RandomDrift.ts b/TS Source/particles/behaviours/RandomDrift.ts
similarity index 100%
rename from Phaser/particles/behaviours/RandomDrift.ts
rename to TS Source/particles/behaviours/RandomDrift.ts
diff --git a/TS Source/particles/initialize/Initialize.js b/TS Source/particles/initialize/Initialize.js
new file mode 100644
index 00000000..802faf17
--- /dev/null
+++ b/TS Source/particles/initialize/Initialize.js
@@ -0,0 +1,27 @@
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Initializers) {
+ var Initialize = (function () {
+ function Initialize() { }
+ Initialize.prototype.initialize = function (target) {
+ };
+ Initialize.prototype.reset = function (a, b, c) {
+ };
+ Initialize.prototype.init = function (emitter, particle) {
+ if (typeof particle === "undefined") { particle = null; }
+ if(particle) {
+ this.initialize(particle);
+ } else {
+ this.initialize(emitter);
+ }
+ };
+ return Initialize;
+ })();
+ Initializers.Initialize = Initialize;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/initialize/Initialize.ts b/TS Source/particles/initialize/Initialize.ts
similarity index 100%
rename from Phaser/particles/initialize/Initialize.ts
rename to TS Source/particles/initialize/Initialize.ts
diff --git a/TS Source/particles/initialize/Life.js b/TS Source/particles/initialize/Life.js
new file mode 100644
index 00000000..a8b42484
--- /dev/null
+++ b/TS Source/particles/initialize/Life.js
@@ -0,0 +1,31 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Initializers) {
+ var Life = (function (_super) {
+ __extends(Life, _super);
+ function Life(a, b, c) {
+ _super.call(this);
+ this.lifePan = Particles.ParticleUtils.setSpanValue(a, b, c);
+ }
+ Life.prototype.initialize = function (target) {
+ if(this.lifePan.a == Infinity) {
+ target.life = Infinity;
+ } else {
+ target.life = this.lifePan.getValue();
+ }
+ };
+ return Life;
+ })(Initializers.Initialize);
+ Initializers.Life = Life;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/initialize/Life.ts b/TS Source/particles/initialize/Life.ts
similarity index 100%
rename from Phaser/particles/initialize/Life.ts
rename to TS Source/particles/initialize/Life.ts
diff --git a/TS Source/particles/initialize/Mass.js b/TS Source/particles/initialize/Mass.js
new file mode 100644
index 00000000..6fe5963b
--- /dev/null
+++ b/TS Source/particles/initialize/Mass.js
@@ -0,0 +1,27 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Initializers) {
+ var Mass = (function (_super) {
+ __extends(Mass, _super);
+ function Mass(a, b, c) {
+ _super.call(this);
+ this.massPan = Particles.ParticleUtils.setSpanValue(a, b, c);
+ }
+ Mass.prototype.initialize = function (target) {
+ target.mass = this.massPan.getValue();
+ };
+ return Mass;
+ })(Initializers.Initialize);
+ Initializers.Mass = Mass;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/initialize/Mass.ts b/TS Source/particles/initialize/Mass.ts
similarity index 100%
rename from Phaser/particles/initialize/Mass.ts
rename to TS Source/particles/initialize/Mass.ts
diff --git a/TS Source/particles/initialize/Position.js b/TS Source/particles/initialize/Position.js
new file mode 100644
index 00000000..75a4ff16
--- /dev/null
+++ b/TS Source/particles/initialize/Position.js
@@ -0,0 +1,40 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Initializers) {
+ var Position = (function (_super) {
+ __extends(Position, _super);
+ function Position(zone) {
+ _super.call(this);
+ if(zone != null && zone != undefined) {
+ this.zone = zone;
+ } else {
+ this.zone = new Phaser.Particles.Zones.PointZone();
+ }
+ }
+ Position.prototype.reset = function (zone) {
+ if(zone != null && zone != undefined) {
+ this.zone = zone;
+ } else {
+ this.zone = new Phaser.Particles.Zones.PointZone();
+ }
+ };
+ Position.prototype.initialize = function (target) {
+ this.zone.getPosition();
+ target.p.x = this.zone.vector.x;
+ target.p.y = this.zone.vector.y;
+ };
+ return Position;
+ })(Initializers.Initialize);
+ Initializers.Position = Position;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/initialize/Position.ts b/TS Source/particles/initialize/Position.ts
similarity index 100%
rename from Phaser/particles/initialize/Position.ts
rename to TS Source/particles/initialize/Position.ts
diff --git a/Phaser/particles/initialize/Radius.ts b/TS Source/particles/initialize/Radius.ts
similarity index 100%
rename from Phaser/particles/initialize/Radius.ts
rename to TS Source/particles/initialize/Radius.ts
diff --git a/TS Source/particles/initialize/Rate.js b/TS Source/particles/initialize/Rate.js
new file mode 100644
index 00000000..62876d22
--- /dev/null
+++ b/TS Source/particles/initialize/Rate.js
@@ -0,0 +1,51 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Initializers) {
+ var Rate = (function (_super) {
+ __extends(Rate, _super);
+ function Rate(numpan, timepan) {
+ _super.call(this);
+ numpan = Particles.ParticleUtils.initValue(numpan, 1);
+ timepan = Particles.ParticleUtils.initValue(timepan, 1);
+ this.numPan = new Phaser.Particles.Span(numpan);
+ this.timePan = new Phaser.Particles.Span(timepan);
+ this.startTime = 0;
+ this.nextTime = 0;
+ this.init();
+ }
+ Rate.prototype.init = function () {
+ this.startTime = 0;
+ this.nextTime = this.timePan.getValue();
+ };
+ Rate.prototype.getValue = function (time) {
+ this.startTime += time;
+ if(this.startTime >= this.nextTime) {
+ this.startTime = 0;
+ this.nextTime = this.timePan.getValue();
+ if(this.numPan.b == 1) {
+ if(this.numPan.getValue(false) > 0.5) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } else {
+ return this.numPan.getValue(true);
+ }
+ }
+ return 0;
+ };
+ return Rate;
+ })(Initializers.Initialize);
+ Initializers.Rate = Rate;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/initialize/Rate.ts b/TS Source/particles/initialize/Rate.ts
similarity index 100%
rename from Phaser/particles/initialize/Rate.ts
rename to TS Source/particles/initialize/Rate.ts
diff --git a/TS Source/particles/initialize/Velocity.js b/TS Source/particles/initialize/Velocity.js
new file mode 100644
index 00000000..7dc8eed5
--- /dev/null
+++ b/TS Source/particles/initialize/Velocity.js
@@ -0,0 +1,44 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Initializers) {
+ var Velocity = (function (_super) {
+ __extends(Velocity, _super);
+ function Velocity(rpan, thapan, type) {
+ _super.call(this);
+ this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
+ this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
+ this.type = Particles.ParticleUtils.initValue(type, 'vector');
+ }
+ Velocity.prototype.reset = function (rpan, thapan, type) {
+ this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
+ this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
+ this.type = Particles.ParticleUtils.initValue(type, 'vector');
+ };
+ Velocity.prototype.normalizeVelocity = function (vr) {
+ return vr * Particles.ParticleManager.MEASURE;
+ };
+ Velocity.prototype.initialize = function (target) {
+ if(this.type == 'p' || this.type == 'P' || this.type == 'polar') {
+ var polar2d = new Particles.Polar2D(this.normalizeVelocity(this.rPan.getValue()), this.thaPan.getValue() * Math.PI / 180);
+ target.v.x = polar2d.getX();
+ target.v.y = polar2d.getY();
+ } else {
+ target.v.x = this.normalizeVelocity(this.rPan.getValue());
+ target.v.y = this.normalizeVelocity(this.thaPan.getValue());
+ }
+ };
+ return Velocity;
+ })(Initializers.Initialize);
+ Initializers.Velocity = Velocity;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/initialize/Velocity.ts b/TS Source/particles/initialize/Velocity.ts
similarity index 100%
rename from Phaser/particles/initialize/Velocity.ts
rename to TS Source/particles/initialize/Velocity.ts
diff --git a/TS Source/particles/zone/PointZone.js b/TS Source/particles/zone/PointZone.js
new file mode 100644
index 00000000..705282c9
--- /dev/null
+++ b/TS Source/particles/zone/PointZone.js
@@ -0,0 +1,36 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Zones) {
+ var PointZone = (function (_super) {
+ __extends(PointZone, _super);
+ function PointZone(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ _super.call(this);
+ this.x = x;
+ this.y = y;
+ }
+ PointZone.prototype.getPosition = function () {
+ return this.vector.setTo(this.x, this.y);
+ };
+ PointZone.prototype.crossing = function (particle) {
+ if(this.alert) {
+ alert('Sorry PointZone does not support crossing method');
+ this.alert = false;
+ }
+ };
+ return PointZone;
+ })(Zones.Zone);
+ Zones.PointZone = PointZone;
+ })(Particles.Zones || (Particles.Zones = {}));
+ var Zones = Particles.Zones;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/zone/PointZone.ts b/TS Source/particles/zone/PointZone.ts
similarity index 100%
rename from Phaser/particles/zone/PointZone.ts
rename to TS Source/particles/zone/PointZone.ts
diff --git a/TS Source/particles/zone/Zone.js b/TS Source/particles/zone/Zone.js
new file mode 100644
index 00000000..baf57135
--- /dev/null
+++ b/TS Source/particles/zone/Zone.js
@@ -0,0 +1,20 @@
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ ///
+ (function (Zones) {
+ var Zone = (function () {
+ function Zone() {
+ this.vector = new Phaser.Vec2();
+ this.random = 0;
+ this.crossType = "dead";
+ this.alert = true;
+ }
+ return Zone;
+ })();
+ Zones.Zone = Zone;
+ })(Particles.Zones || (Particles.Zones = {}));
+ var Zones = Particles.Zones;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/particles/zone/Zone.ts b/TS Source/particles/zone/Zone.ts
similarity index 100%
rename from Phaser/particles/zone/Zone.ts
rename to TS Source/particles/zone/Zone.ts
diff --git a/TS Source/physics/AABB.js b/TS Source/physics/AABB.js
new file mode 100644
index 00000000..c459f49e
--- /dev/null
+++ b/TS Source/physics/AABB.js
@@ -0,0 +1,365 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Physics - AABB
+ */
+ (function (Physics) {
+ var AABB = (function () {
+ function AABB(game, x, y, width, height) {
+ this.type = 0;
+ this._vx = 0;
+ this._vy = 0;
+ this._deltaX = 0;
+ this._deltaY = 0;
+ this.game = game;
+ this.pos = new Phaser.Vec2(x, y);
+ this.oldpos = new Phaser.Vec2(x, y);
+ this.width = Math.abs(width);
+ this.height = Math.abs(height);
+ this.velocity = new Phaser.Vec2();
+ this.acceleration = new Phaser.Vec2();
+ this.bounce = new Phaser.Vec2(0, 0);
+ //this.drag = new Phaser.Vec2(1, 1);
+ //this.gravity = new Phaser.Vec2(0, 0.2);
+ this.drag = new Phaser.Vec2(0, 0);
+ this.gravity = new Phaser.Vec2(0, 0);
+ this.maxVelocity = new Phaser.Vec2(1000, 1000);
+ this.aabbTileProjections = {
+ };
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.AABB22Deg.CollideS;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.AABB22Deg.CollideB;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.AABB45Deg.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.AABB67Deg.CollideS;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.AABB67Deg.CollideB;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.AABBConcave.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.AABBConvex.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.AABBFull.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.AABBHalf.Collide;
+ }
+ AABB.COL_NONE = 0;
+ AABB.COL_AXIS = 1;
+ AABB.COL_OTHER = 2;
+ AABB.prototype.update = function () {
+ // N+ update loop
+ this.integrateVerlet();
+ if(this.acceleration.x != 0) {
+ this.velocity.x += (this.acceleration.x * this.game.time.physicsElapsed);
+ }
+ if(this.acceleration.y != 0) {
+ this.velocity.y += (this.acceleration.y * this.game.time.physicsElapsed);
+ }
+ this._vx = this.velocity.x * this.game.time.physicsElapsed;
+ this._vy = this.velocity.y * this.game.time.physicsElapsed;
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+ this._deltaX = Math.min(20, Math.max(-20, vx + this._vx));
+ this._deltaY = Math.min(20, Math.max(-20, vy + this._vy));
+ this.pos.x = this.oldpos.x + this._deltaX;
+ this.pos.y = this.oldpos.y + this._deltaY;
+ };
+ AABB.prototype.Nupdate = function () {
+ // N+ update loop
+ this.integrateVerlet();
+ var p = this.pos;
+ var o = this.oldpos;
+ var vx = p.x - o.x;
+ var vy = p.y - o.y;
+ var newx = Math.min(20, Math.max(-20, vx + this._vx));
+ var newy = Math.min(20, Math.max(-20, vy + this._vy));
+ this.pos.x = o.x + newx;
+ this.pos.y = o.y + newy;
+ };
+ AABB.prototype.updateFlixel = function () {
+ // Add 'go to sleep' option
+ this.oldpos.x = this.pos.x//get vector values
+ ;
+ this.oldpos.y = this.pos.y//p = position
+ ;
+ this._vx = (this.game.physics.computeVelocity(this.velocity.x, this.gravity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
+ this.velocity.x += this._vx;
+ //this.pos.x += (this.velocity.x * this.game.time.physicsElapsed) + this.gravity.x;
+ //this.pos.x += (this.velocity.x * this.game.time.physicsElapsed);
+ this._deltaX = this.velocity.x * this.game.time.physicsElapsed;
+ //body.aabb.pos.x += this._delta;
+ this._vy = (this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
+ //this._vy = this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y);
+ this.velocity.y += this._vy;
+ //this.pos.y += (this.velocity.y * this.game.time.physicsElapsed) + this.gravity.y;
+ //this.pos.y += (this.velocity.y * this.game.time.physicsElapsed);
+ this._deltaY = this.velocity.y * this.game.time.physicsElapsed;
+ this.pos.x += this._deltaX;
+ this.pos.y += this._deltaY;
+ //this.integrateVerlet();
+ //var ox = this.oldpos.x;
+ //var oy = this.oldpos.y;
+ };
+ AABB.prototype.FFupdate = function () {
+ this.oldpos.x = this.pos.x//get vector values
+ ;
+ this.oldpos.y = this.pos.y//p = position
+ ;
+ if(this.acceleration.x != 0) {
+ this.velocity.x += (this.acceleration.x / 1000 * this.game.time.delta);
+ }
+ if(this.acceleration.y != 0) {
+ this.velocity.y += (this.acceleration.y / 1000 * this.game.time.delta);
+ }
+ this._vx = ((this.velocity.x / 1000) * this.game.time.delta);
+ this._vy = ((this.velocity.y / 1000) * this.game.time.delta);
+ if(this._vx != 0) {
+ if(this.drag.x != 0) {
+ this._vx * this.drag.x;
+ }
+ if(this.gravity.x != 0) {
+ this._vx * this.gravity.x;
+ }
+ if(this.velocity.x > this.maxVelocity.x) {
+ this.velocity.x = this.maxVelocity.x;
+ } else if(this.velocity.x < -this.maxVelocity.x) {
+ this.velocity.x = -this.maxVelocity.x;
+ }
+ }
+ if(this._vy != 0) {
+ if(this.drag.y != 0) {
+ this._vy * this.drag.y;
+ }
+ if(this.gravity.y != 0) {
+ this._vy * this.gravity.y;
+ }
+ if(this.velocity.y > this.maxVelocity.y) {
+ this.velocity.y = this.maxVelocity.y;
+ } else if(this.velocity.y < -this.maxVelocity.y) {
+ this.velocity.y = -this.maxVelocity.y;
+ }
+ }
+ this.pos.x += this._vx;
+ this.pos.y += this._vy;
+ //this._vx = (this.game.physics.computeVelocity(this.velocity.x, this.gravity.x, this.acceleration.x, this.fdrag.x, this.maxVelocity.x) - this.velocity.x) / 2;
+ //this.velocity.x += this._vx;
+ //this.pos.x += (this.velocity.x * this.game.time.physicsElapsed) + this.gravity.x;
+ //this._vy = (this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.fdrag.y, this.maxVelocity.y) - this.velocity.y) / 2;
+ //this.velocity.y += this._vy;
+ //this.pos.y += (this.velocity.y * this.game.time.physicsElapsed) + this.gravity.y;
+ //this.integrateVerlet();
+ //var ox = this.oldpos.x;
+ //var oy = this.oldpos.y;
+ //this.oldpos.x = this.pos.x; //get vector values
+ //this.oldpos.y = this.pos.y; //p = position
+ //integrate
+ //this.pos.x += (this.drag.x * this.pos.x) - (this.drag.x * ox) + this.gravity.x;
+ //this.pos.y += (this.drag.y * this.pos.y) - (this.drag.y * oy) + this.gravity.y;
+ //this._vx = (this.velocity.x / 1000 * this.game.time.delta);
+ //this._vy = (this.velocity.y / 1000 * this.game.time.delta);
+ //this._vx = 0.2;
+ //this._vy = 0.2;
+ //this.pos.x = this.oldpos.x + Math.min(20, Math.max(-20, this.pos.x - this.oldpos.x + this._vx));
+ //this.pos.y = this.oldpos.y + Math.min(20, Math.max(-20, this.pos.y - this.oldpos.y + this._vy));
+ //this.integrateVerlet();
+ };
+ AABB.prototype.integrateVerlet = function () {
+ var ox = this.oldpos.x;
+ var oy = this.oldpos.y;
+ this.oldpos.x = this.pos.x//get vector values
+ ;
+ this.oldpos.y = this.pos.y//p = position
+ ;
+ //integrate
+ this.pos.x += (this.drag.x * this.pos.x) - (this.drag.x * ox) + this.gravity.x;
+ this.pos.y += (this.drag.y * this.pos.y) - (this.drag.y * oy) + this.gravity.y;
+ };
+ AABB.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ //calc velocity (original way)
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+ //find component of velocity parallel to collision normal
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;//project velocity onto collision normal
+
+ var ny = dp * dy;//nx,ny is normal velocity
+
+ var tx = vx - nx;//px,py is tangent velocity
+
+ var ty = vy - ny;
+ //we only want to apply collision response forces if the object is travelling into, and not out of, the collision
+ // default is moving out of collision, don't apply force
+ var bx = 0;
+ var by = 0;
+ var fx = 0;
+ var fy = 0;
+ if(dp < 0) {
+ // moving into collision, apply forces
+ var f = 0.05;// friction
+
+ fx = tx * f;
+ fy = ty * f;
+ var b = 1 + 0.5;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
+
+ bx = (nx * b);
+ by = (ny * b);
+ }
+ // project object out of collision
+ this.pos.x += px;
+ this.pos.y += py;
+ this.oldpos.x += px + bx + fx;
+ this.oldpos.y += py + by + fy;
+ };
+ AABB.prototype.TWEAKEDreportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ //calc velocity (original way)
+ //this._vx = this.pos.x - this.oldpos.x;
+ //this._vy = this.pos.y - this.oldpos.y;
+ //var vx = this.pos.x - this.oldpos.x;
+ //var vy = this.pos.y - this.oldpos.y;
+ //find component of velocity parallel to collision normal
+ //var dp = (vx * dx + vy * dy);
+ //var nx = dp * dx;//project velocity onto collision normal
+ //var ny = dp * dy;//nx,ny is normal velocity
+ //var tx = vx - nx;//px,py is tangent velocity
+ //var ty = vy - ny;
+ var dp = (this._vx * dx + this._vy * dy);
+ var nx = dp * dx;//project velocity onto collision normal
+
+ var ny = dp * dy;//nx,ny is normal velocity
+
+ var tx = this._vx - nx;//px,py is tangent velocity
+
+ var ty = this._vy - ny;
+ //console.log('nxy', nx, ny);
+ //console.log('nxy', nx, ny);
+ //console.log('txy', tx, ty);
+ this.pos.x += px//project object out of collision
+ ;
+ this.pos.y += py;
+ //this.oldpos.x += px;
+ //this.oldpos.y += py;
+ //this.pos.x += px;
+ //this.pos.y += py;
+ //this.velocity.x += nx;
+ //this.velocity.y += ny;
+ //we only want to apply collision response forces if the object is travelling into, and not out of, the collision
+ if(dp < 0)//if (1 < 0)
+ {
+ // moving into collision, apply forces
+ //var b = 1 + 0.5;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
+ //var b = 0.5;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
+ //var f = 0.05; // friction
+ //var fx = tx * f;
+ //var fy = ty * f;
+ //this.oldpos.x += (nx * b) + fx;//apply bounce+friction impulses which alter velocity
+ //this.oldpos.y += (ny * b) + fy;
+ this.velocity.x += nx;
+ this.velocity.y += ny;
+ if(dx !== 0) {
+ this.velocity.x *= -1 * this.bounce.x;
+ }
+ if(dy !== 0) {
+ this.velocity.y *= -1 * this.bounce.y;
+ }
+ }
+ };
+ AABB.prototype.collideAABBVsTile = function (tile) {
+ var pos = this.pos;
+ var c = tile;
+ var tx = c.pos.x;
+ var ty = c.pos.y;
+ var txw = c.xw;
+ var tyw = c.yw;
+ var dx = pos.x - tx;//tile->obj delta
+
+ var px = (txw + this.width) - Math.abs(dx);//penetration depth in x
+
+ if(0 < px) {
+ var dy = pos.y - ty;//tile->obj delta
+
+ var py = (tyw + this.height) - Math.abs(dy);//pen depth in y
+
+ if(0 < py) {
+ //object may be colliding with tile; call tile-specific collision function
+ //calculate projection vectors
+ if(px < py) {
+ //project in x
+ if(dx < 0) {
+ //project to the left
+ px *= -1;
+ py = 0;
+ } else {
+ //proj to right
+ py = 0;
+ }
+ } else {
+ //project in y
+ if(dy < 0) {
+ //project up
+ px = 0;
+ py *= -1;
+ } else {
+ //project down
+ px = 0;
+ }
+ }
+ this.resolveBoxTile(px, py, this, c);
+ }
+ }
+ };
+ AABB.prototype.collideAABBVsWorldBounds = function () {
+ var p = this.pos;
+ var xw = this.width;
+ var yw = this.height;
+ var XMIN = 0;
+ var XMAX = 800;
+ var YMIN = 0;
+ var YMAX = 600;
+ //collide vs. x-bounds
+ //test XMIN left side
+ var dx = XMIN - (p.x - xw);
+ if(0 < dx) {
+ //object is colliding with XMIN
+ this.reportCollisionVsWorld(dx, 0, 1, 0, null);
+ } else {
+ //test XMAX right side
+ dx = (p.x + xw) - XMAX;
+ if(0 < dx) {
+ //object is colliding with XMAX
+ this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ //collide vs. y-bounds
+ //test YMIN top
+ var dy = YMIN - (p.y - yw);
+ if(0 < dy) {
+ //object is colliding with YMIN
+ this.reportCollisionVsWorld(0, dy, 0, 1, null);
+ } else {
+ //test YMAX bottom
+ dy = (p.y + yw) - YMAX;
+ if(0 < dy) {
+ //object is colliding with YMAX
+ this.reportCollisionVsWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ AABB.prototype.resolveBoxTile = function (x, y, box, t) {
+ if(0 < t.ID) {
+ return this.aabbTileProjections[t.CTYPE](x, y, box, t);
+ } else {
+ //trace("resolveBoxTile() was called with an empty (or unknown) tile!: ID=" + t.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ };
+ AABB.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.strokeRect(this.pos.x - this.width, this.pos.y - this.height, this.width * 2, this.height * 2);
+ context.stroke();
+ context.closePath();
+ context.fillStyle = 'rgb(0,255,0)';
+ context.fillRect(this.pos.x, this.pos.y, 2, 2);
+ };
+ return AABB;
+ })();
+ Physics.AABB = AABB;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/AABB.ts b/TS Source/physics/AABB.ts
similarity index 81%
rename from Phaser/physics/AABB.ts
rename to TS Source/physics/AABB.ts
index e4c402b8..d2414099 100644
--- a/Phaser/physics/AABB.ts
+++ b/TS Source/physics/AABB.ts
@@ -26,7 +26,7 @@ module Phaser.Physics {
//this.gravity = new Phaser.Vec2(0, 0.2);
this.drag = new Phaser.Vec2(0, 0);
- this.gravity = new Phaser.Vec2(0, 2);
+ this.gravity = new Phaser.Vec2(0, 0);
this.maxVelocity = new Phaser.Vec2(1000, 1000);
@@ -73,6 +73,53 @@ module Phaser.Physics {
public update() {
+ // N+ update loop
+ this.integrateVerlet();
+
+ if (this.acceleration.x != 0)
+ {
+ this.velocity.x += (this.acceleration.x * this.game.time.physicsElapsed);
+ }
+
+ if (this.acceleration.y != 0)
+ {
+ this.velocity.y += (this.acceleration.y * this.game.time.physicsElapsed);
+ }
+
+ this._vx = this.velocity.x * this.game.time.physicsElapsed;
+ this._vy = this.velocity.y * this.game.time.physicsElapsed;
+
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+
+ this._deltaX = Math.min(20, Math.max(-20, vx + this._vx));
+ this._deltaY = Math.min(20, Math.max(-20, vy + this._vy));
+
+ this.pos.x = this.oldpos.x + this._deltaX;
+ this.pos.y = this.oldpos.y + this._deltaY;
+
+ }
+
+ public Nupdate() {
+
+ // N+ update loop
+ this.integrateVerlet();
+
+ var p = this.pos;
+ var o = this.oldpos;
+ var vx = p.x - o.x;
+ var vy = p.y - o.y;
+
+ var newx = Math.min(20, Math.max(-20, vx + this._vx));
+ var newy = Math.min(20, Math.max(-20, vy + this._vy));
+
+ this.pos.x = o.x + newx;
+ this.pos.y = o.y + newy;
+
+ }
+
+ public updateFlixel() {
+
// Add 'go to sleep' option
this.oldpos.x = this.pos.x; //get vector values
@@ -201,9 +248,6 @@ module Phaser.Physics {
public integrateVerlet() {
- var px = this.pos.x;
- var py = this.pos.y;
-
var ox = this.oldpos.x;
var oy = this.oldpos.y;
@@ -211,13 +255,57 @@ module Phaser.Physics {
this.oldpos.y = this.pos.y; //p = position
//integrate
- this.pos.x += (this.drag.x * px) - (this.drag.x * ox) + this.gravity.x;
- this.pos.y += (this.drag.y * py) - (this.drag.y * oy) + this.gravity.y;
+ this.pos.x += (this.drag.x * this.pos.x) - (this.drag.x * ox) + this.gravity.x;
+ this.pos.y += (this.drag.y * this.pos.y) - (this.drag.y * oy) + this.gravity.y;
}
public reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: TileMapCell = null) {
+ //calc velocity (original way)
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+
+ //find component of velocity parallel to collision normal
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;//project velocity onto collision normal
+ var ny = dp * dy;//nx,ny is normal velocity
+
+ var tx = vx - nx;//px,py is tangent velocity
+ var ty = vy - ny;
+
+ //we only want to apply collision response forces if the object is travelling into, and not out of, the collision
+
+ // default is moving out of collision, don't apply force
+ var bx = 0;
+ var by = 0;
+ var fx = 0;
+ var fy = 0;
+
+ if (dp < 0)
+ {
+ // moving into collision, apply forces
+ var f = 0.05; // friction
+ fx = tx * f;
+ fy = ty * f;
+
+ var b = 1 + 0.5;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
+
+ bx = (nx * b);
+ by = (ny * b);
+ }
+
+ // project object out of collision
+ this.pos.x += px;
+ this.pos.y += py;
+
+ this.oldpos.x += px + bx + fx;
+ this.oldpos.y += py + by + fy;
+
+ }
+
+ public TWEAKEDreportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: TileMapCell = null) {
+
//calc velocity (original way)
//this._vx = this.pos.x - this.oldpos.x;
//this._vy = this.pos.y - this.oldpos.y;
@@ -272,12 +360,12 @@ module Phaser.Physics {
if (dx !== 0)
{
-// this.velocity.x *= -1 * this.bounce.x;
+ this.velocity.x *= -1 * this.bounce.x;
}
if (dy !== 0)
{
- // this.velocity.y *= -1 * this.bounce.y;
+ this.velocity.y *= -1 * this.bounce.y;
}
}
diff --git a/TS Source/physics/Body.js b/TS Source/physics/Body.js
new file mode 100644
index 00000000..143bc7b4
--- /dev/null
+++ b/TS Source/physics/Body.js
@@ -0,0 +1,173 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Physics - Body
+ * A binding between a Sprite and a physics object (AABB or Circle)
+ */
+ (function (Physics) {
+ var Body = (function () {
+ function Body(sprite, type) {
+ this.angularVelocity = 0;
+ this.angularAcceleration = 0;
+ this.angularDrag = 0;
+ this.maxAngular = 10000;
+ this.deltaX = 0;
+ this.deltaY = 0;
+ this.sprite = sprite;
+ this.game = sprite.game;
+ this.type = type;
+ this.aabb = new Phaser.Physics.AABB(sprite.game, sprite.x, sprite.y, sprite.width, sprite.height);
+ this.velocity = new Phaser.Vec2();
+ this.acceleration = new Phaser.Vec2();
+ this.drag = new Phaser.Vec2();
+ this.gravity = new Phaser.Vec2();
+ this.maxVelocity = new Phaser.Vec2(10000, 10000);
+ this.angularVelocity = 0;
+ this.angularAcceleration = 0;
+ this.angularDrag = 0;
+ this.maxAngular = 10000;
+ //this.touching = Phaser.Types.NONE;
+ //this.wasTouching = Phaser.Types.NONE;
+ this.allowCollisions = Phaser.Types.ANY;
+ //this.position = new Phaser.Vec2(sprite.x + this.bounds.halfWidth, sprite.y + this.bounds.halfHeight);
+ //this.oldPosition = new Phaser.Vec2(sprite.x + this.bounds.halfWidth, sprite.y + this.bounds.halfHeight);
+ //this.offset = new Phaser.Vec2;
+ }
+ return Body;
+ })();
+ Physics.Body = Body;
+ //public wasTouching: number;
+ //public mass: number = 1;
+ //public position: Phaser.Vec2;
+ //public oldPosition: Phaser.Vec2;
+ //public offset: Phaser.Vec2;
+ //public bounds: Phaser.Rectangle;
+ /*
+ private _width: number = 0;
+ private _height: number = 0;
+
+ public get x(): number {
+ return this.sprite.x + this.offset.x;
+ }
+
+ public get y(): number {
+ return this.sprite.y + this.offset.y;
+ }
+
+ public set width(value: number) {
+ this._width = value;
+ }
+
+ public set height(value: number) {
+ this._height = value;
+ }
+
+ public get width(): number {
+ return this._width * this.sprite.transform.scale.x;
+ }
+
+ public get height(): number {
+ return this._height * this.sprite.transform.scale.y;
+ }
+
+ public preUpdate() {
+
+ this.oldPosition.copyFrom(this.position);
+
+ this.bounds.x = this.x;
+ this.bounds.y = this.y;
+ this.bounds.width = this.width;
+ this.bounds.height = this.height;
+
+ }
+
+ // Shall we do this? Or just update the values directly in the separate functions? But then the bounds will be out of sync - as long as
+ // the bounds are updated and used in calculations then we can do one final sprite movement here I guess?
+ public postUpdate() {
+
+ // if this is all it does maybe move elsewhere? Sprite postUpdate?
+ if (this.type !== Phaser.Types.BODY_DISABLED)
+ {
+ //this.game.world.physics.updateMotion(this);
+
+ this.wasTouching = this.touching;
+ this.touching = Phaser.Types.NONE;
+
+ }
+
+ this.position.setTo(this.x, this.y);
+
+ }
+
+ public get hullWidth(): number {
+
+ if (this.deltaX > 0)
+ {
+ return this.bounds.width + this.deltaX;
+ }
+ else
+ {
+ return this.bounds.width - this.deltaX;
+ }
+
+ }
+
+ public get hullHeight(): number {
+
+ if (this.deltaY > 0)
+ {
+ return this.bounds.height + this.deltaY;
+ }
+ else
+ {
+ return this.bounds.height - this.deltaY;
+ }
+
+ }
+
+ public get hullX(): number {
+
+ if (this.position.x < this.oldPosition.x)
+ {
+ return this.position.x;
+ }
+ else
+ {
+ return this.oldPosition.x;
+ }
+
+ }
+
+ public get hullY(): number {
+
+ if (this.position.y < this.oldPosition.y)
+ {
+ return this.position.y;
+ }
+ else
+ {
+ return this.oldPosition.y;
+ }
+
+ }
+
+ public get deltaXAbs(): number {
+ return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
+ }
+
+ public get deltaYAbs(): number {
+ return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
+ }
+
+ public get deltaX(): number {
+ return this.position.x - this.oldPosition.x;
+ }
+
+ public get deltaY(): number {
+ return this.position.y - this.oldPosition.y;
+ }
+ */
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/Body.ts b/TS Source/physics/Body.ts
similarity index 100%
rename from Phaser/physics/Body.ts
rename to TS Source/physics/Body.ts
diff --git a/TS Source/physics/Circle.js b/TS Source/physics/Circle.js
new file mode 100644
index 00000000..d17f7d57
--- /dev/null
+++ b/TS Source/physics/Circle.js
@@ -0,0 +1,217 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Physics - Circle
+ */
+ (function (Physics) {
+ var Circle = (function () {
+ function Circle(game, x, y, radius) {
+ this.type = 1;
+ this.game = game;
+ this.pos = new Phaser.Vec2(x, y);
+ this.oldpos = new Phaser.Vec2(x, y);
+ this.radius = radius;
+ this.circleTileProjections = {
+ };
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.Circle22Deg.CollideS;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.Circle22Deg.CollideB;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.Circle45Deg.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.Circle67Deg.CollideS;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.Circle67Deg.CollideB;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.CircleConcave.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.CircleConvex.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.CircleFull.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.CircleHalf.Collide;
+ }
+ Circle.COL_NONE = 0;
+ Circle.COL_AXIS = 1;
+ Circle.COL_OTHER = 2;
+ Circle.prototype.integrateVerlet = function () {
+ var d = 1;// drag
+
+ var g = 0.2;// gravity
+
+ var p = this.pos;
+ var o = this.oldpos;
+ var px;
+ var py;
+ var ox = o.x;
+ var oy = o.y;
+ //o = oldposition
+ o.x = px = p.x//get vector values
+ ;
+ o.y = py = p.y//p = position
+ ;
+ //integrate
+ p.x += (d * px) - (d * ox);
+ p.y += (d * py) - (d * oy) + g;
+ };
+ Circle.prototype.reportCollisionVsWorld = // px projection vector
+ // dx surface normal
+ function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ var p = this.pos;
+ var o = this.oldpos;
+ //calc velocity
+ var vx = p.x - o.x;
+ var vy = p.y - o.y;
+ //find component of velocity parallel to collision normal
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;//project velocity onto collision normal
+
+ var ny = dp * dy;//nx,ny is normal velocity
+
+ var tx = vx - nx;//px,py is tangent velocity
+
+ var ty = vy - ny;
+ //we only want to apply collision response forces if the object is travelling into, and not out of, the collision
+ var b, bx, by, f, fx, fy;
+ if(dp < 0) {
+ //f = FRICTION;
+ f = 0.05;
+ fx = tx * f;
+ fy = ty * f;
+ //b = 1 + BOUNCE;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
+ b = 1 + 0.3//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
+ ;
+ bx = (nx * b);
+ by = (ny * b);
+ } else {
+ //moving out of collision, do not apply forces
+ bx = by = fx = fy = 0;
+ }
+ p.x += px//project object out of collision
+ ;
+ p.y += py;
+ o.x += px + bx + fx//apply bounce+friction impulses which alter velocity
+ ;
+ o.y += py + by + fy;
+ };
+ Circle.prototype.collideCircleVsWorldBounds = function () {
+ var p = this.pos;
+ var r = this.radius;
+ var XMIN = 0;
+ var XMAX = 800;
+ var YMIN = 0;
+ var YMAX = 600;
+ //collide vs. x-bounds
+ //test XMIN
+ var dx = XMIN - (p.x - r);
+ if(0 < dx) {
+ //object is colliding with XMIN
+ this.reportCollisionVsWorld(dx, 0, 1, 0, null);
+ } else {
+ //test XMAX
+ dx = (p.x + r) - XMAX;
+ if(0 < dx) {
+ //object is colliding with XMAX
+ this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ //collide vs. y-bounds
+ //test YMIN
+ var dy = YMIN - (p.y - r);
+ if(0 < dy) {
+ //object is colliding with YMIN
+ this.reportCollisionVsWorld(0, dy, 0, 1, null);
+ } else {
+ //test YMAX
+ dy = (p.y + r) - YMAX;
+ if(0 < dy) {
+ //object is colliding with YMAX
+ this.reportCollisionVsWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ Circle.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2);
+ context.stroke();
+ context.closePath();
+ if(this.oH == 1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x - this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ } else if(this.oH == -1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x + this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ }
+ if(this.oV == 1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y - this.radius);
+ context.stroke();
+ context.closePath();
+ } else if(this.oV == -1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y + this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ }
+ };
+ Circle.prototype.collideCircleVsTile = function (tile) {
+ var pos = this.pos;
+ var r = this.radius;
+ var c = tile;
+ var tx = c.pos.x;
+ var ty = c.pos.y;
+ var txw = c.xw;
+ var tyw = c.yw;
+ var dx = pos.x - tx;//tile->obj delta
+
+ var px = (txw + r) - Math.abs(dx);//penetration depth in x
+
+ if(0 < px) {
+ var dy = pos.y - ty;//tile->obj delta
+
+ var py = (tyw + r) - Math.abs(dy);//pen depth in y
+
+ if(0 < py) {
+ //object may be colliding with tile
+ //determine grid/voronoi region of circle center
+ this.oH = 0;
+ this.oV = 0;
+ if(dx < -txw) {
+ //circle is on left side of tile
+ this.oH = -1;
+ } else if(txw < dx) {
+ //circle is on right side of tile
+ this.oH = 1;
+ }
+ if(dy < -tyw) {
+ //circle is on top side of tile
+ this.oV = -1;
+ } else if(tyw < dy) {
+ //circle is on bottom side of tile
+ this.oV = 1;
+ }
+ this.resolveCircleTile(px, py, this.oH, this.oV, this, c);
+ }
+ }
+ };
+ Circle.prototype.resolveCircleTile = function (x, y, oH, oV, obj, t) {
+ if(0 < t.ID) {
+ return this.circleTileProjections[t.CTYPE](x, y, oH, oV, obj, t);
+ } else {
+ console.log("resolveCircleTile() was called with an empty (or unknown) tile!: ID=" + t.ID + " (" + t.i + "," + t.j + ")");
+ return false;
+ }
+ };
+ return Circle;
+ })();
+ Physics.Circle = Circle;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/Circle.ts b/TS Source/physics/Circle.ts
similarity index 100%
rename from Phaser/physics/Circle.ts
rename to TS Source/physics/Circle.ts
diff --git a/TS Source/physics/PhysicsManager.js b/TS Source/physics/PhysicsManager.js
new file mode 100644
index 00000000..3779516c
--- /dev/null
+++ b/TS Source/physics/PhysicsManager.js
@@ -0,0 +1,104 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Physics - PhysicsManager
+ */
+ (function (Physics) {
+ var PhysicsManager = (function () {
+ function PhysicsManager(game) {
+ this._length = 0;
+ //public bounds: Rectangle;
+ //public gravity: Vec2;
+ //public drag: Vec2;
+ //public bounce: Vec2;
+ //public angularDrag: number;
+ this.grav = 0.2;
+ this.drag = 1;
+ this.bounce = 0.3;
+ this.friction = 0.05;
+ this.min_f = 0;
+ this.max_f = 1;
+ this.min_b = 0;
+ this.max_b = 1;
+ this.min_g = 0;
+ this.max_g = 1;
+ this.xmin = 0;
+ this.xmax = 800;
+ this.ymin = 0;
+ this.ymax = 600;
+ this.objrad = 24;
+ this.tilerad = 24 * 2;
+ this.objspeed = 0.2;
+ this.maxspeed = 20;
+ this.game = game;
+ //this.gravity = new Vec2;
+ //this.drag = new Vec2;
+ //this.bounce = new Vec2;
+ //this.angularDrag = 0;
+ //this.bounds = new Rectangle(0, 0, width, height);
+ //this._distance = new Vec2;
+ //this._tangent = new Vec2;
+ }
+ PhysicsManager.prototype.update = function () {
+ };
+ PhysicsManager.prototype.updateMotion = function (body) {
+ this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
+ body.angularVelocity += this._velocityDelta;
+ body.sprite.transform.rotation += body.angularVelocity * this.game.time.physicsElapsed;
+ body.angularVelocity += this._velocityDelta;
+ this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
+ body.velocity.x += this._velocityDelta;
+ this._delta = body.velocity.x * this.game.time.physicsElapsed;
+ body.aabb.pos.x += this._delta;
+ body.deltaX = this._delta;
+ this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
+ body.velocity.y += this._velocityDelta;
+ this._delta = body.velocity.y * this.game.time.physicsElapsed;
+ body.aabb.pos.y += this._delta;
+ body.deltaY = this._delta;
+ //body.aabb.integrateVerlet();
+ };
+ PhysicsManager.prototype.computeVelocity = /**
+ * A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
+ *
+ * @param {number} Velocity Any component of velocity (e.g. 20).
+ * @param {number} Acceleration Rate at which the velocity is changing.
+ * @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
+ * @param {number} Max An absolute value cap for the velocity.
+ *
+ * @return {number} The altered Velocity value.
+ */
+ function (velocity, gravity, acceleration, drag, max) {
+ if (typeof gravity === "undefined") { gravity = 0; }
+ if (typeof acceleration === "undefined") { acceleration = 0; }
+ if (typeof drag === "undefined") { drag = 0; }
+ if (typeof max === "undefined") { max = 10000; }
+ if(acceleration !== 0) {
+ velocity += (acceleration + gravity) * this.game.time.physicsElapsed;
+ } else if(drag !== 0) {
+ this._drag = drag * this.game.time.physicsElapsed;
+ if(velocity - this._drag > 0) {
+ velocity = velocity - this._drag;
+ } else if(velocity + this._drag < 0) {
+ velocity += this._drag;
+ } else {
+ velocity = 0;
+ }
+ }
+ //velocity += gravity;
+ if(velocity != 0) {
+ if(velocity > max) {
+ velocity = max;
+ } else if(velocity < -max) {
+ velocity = -max;
+ }
+ }
+ return velocity;
+ };
+ return PhysicsManager;
+ })();
+ Physics.PhysicsManager = PhysicsManager;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/PhysicsManager.ts b/TS Source/physics/PhysicsManager.ts
similarity index 98%
rename from Phaser/physics/PhysicsManager.ts
rename to TS Source/physics/PhysicsManager.ts
index f9ca481c..f683537b 100644
--- a/Phaser/physics/PhysicsManager.ts
+++ b/TS Source/physics/PhysicsManager.ts
@@ -136,11 +136,9 @@ module Phaser.Physics {
{
velocity = 0;
}
-
- //velocity += gravity;
}
- velocity += gravity;
+ //velocity += gravity;
if (velocity != 0)
{
diff --git a/TS Source/physics/TileMapCell.js b/TS Source/physics/TileMapCell.js
new file mode 100644
index 00000000..c8c13d74
--- /dev/null
+++ b/TS Source/physics/TileMapCell.js
@@ -0,0 +1,366 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Physics - TileMapCell
+ */
+ (function (Physics) {
+ var TileMapCell = (function () {
+ function TileMapCell(game, x, y, xw, yw) {
+ this.game = game;
+ this.ID = TileMapCell.TID_EMPTY//all tiles start empty
+ ;
+ this.CTYPE = TileMapCell.CTYPE_EMPTY;
+ this.pos = new Phaser.Vec2(x, y)//setup collision properties
+ ;
+ this.xw = xw;
+ this.yw = yw;
+ this.minx = this.pos.x - this.xw;
+ this.maxx = this.pos.x + this.xw;
+ this.miny = this.pos.y - this.yw;
+ this.maxy = this.pos.y + this.yw;
+ //this stores tile-specific collision information
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ }
+ TileMapCell.TID_EMPTY = 0;
+ TileMapCell.TID_FULL = 1;
+ TileMapCell.TID_45DEGpn = 2;
+ TileMapCell.TID_45DEGnn = 3;
+ TileMapCell.TID_45DEGnp = 4;
+ TileMapCell.TID_45DEGpp = 5;
+ TileMapCell.TID_CONCAVEpn = 6;
+ TileMapCell.TID_CONCAVEnn = 7;
+ TileMapCell.TID_CONCAVEnp = 8;
+ TileMapCell.TID_CONCAVEpp = 9;
+ TileMapCell.TID_CONVEXpn = 10;
+ TileMapCell.TID_CONVEXnn = 11;
+ TileMapCell.TID_CONVEXnp = 12;
+ TileMapCell.TID_CONVEXpp = 13;
+ TileMapCell.TID_22DEGpnS = 14;
+ TileMapCell.TID_22DEGnnS = 15;
+ TileMapCell.TID_22DEGnpS = 16;
+ TileMapCell.TID_22DEGppS = 17;
+ TileMapCell.TID_22DEGpnB = 18;
+ TileMapCell.TID_22DEGnnB = 19;
+ TileMapCell.TID_22DEGnpB = 20;
+ TileMapCell.TID_22DEGppB = 21;
+ TileMapCell.TID_67DEGpnS = 22;
+ TileMapCell.TID_67DEGnnS = 23;
+ TileMapCell.TID_67DEGnpS = 24;
+ TileMapCell.TID_67DEGppS = 25;
+ TileMapCell.TID_67DEGpnB = 26;
+ TileMapCell.TID_67DEGnnB = 27;
+ TileMapCell.TID_67DEGnpB = 28;
+ TileMapCell.TID_67DEGppB = 29;
+ TileMapCell.TID_HALFd = 30;
+ TileMapCell.TID_HALFr = 31;
+ TileMapCell.TID_HALFu = 32;
+ TileMapCell.TID_HALFl = 33;
+ TileMapCell.CTYPE_EMPTY = 0;
+ TileMapCell.CTYPE_FULL = 1;
+ TileMapCell.CTYPE_45DEG = 2;
+ TileMapCell.CTYPE_CONCAVE = 6;
+ TileMapCell.CTYPE_CONVEX = 10;
+ TileMapCell.CTYPE_22DEGs = 14;
+ TileMapCell.CTYPE_22DEGb = 18;
+ TileMapCell.CTYPE_67DEGs = 22;
+ TileMapCell.CTYPE_67DEGb = 26;
+ TileMapCell.CTYPE_HALF = 30;
+ TileMapCell.prototype.SetState = //these functions are used to update the cell
+ //note: ID is assumed to NOT be "empty" state..
+ //if it IS the empty state, the tile clears itself
+ function (ID) {
+ if(ID == TileMapCell.TID_EMPTY) {
+ this.Clear();
+ } else {
+ //set tile state to a non-emtpy value, and update it's edges and those of the neighbors
+ this.ID = ID;
+ this.UpdateType();
+ //this.Draw();
+ }
+ return this;
+ };
+ TileMapCell.prototype.Clear = function () {
+ //tile was on, turn it off
+ this.ID = TileMapCell.TID_EMPTY;
+ this.UpdateType();
+ //this.Draw();
+ };
+ TileMapCell.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,255,0)';
+ context.strokeRect(this.minx, this.miny, this.xw * 2, this.yw * 2);
+ context.strokeRect(this.pos.x, this.pos.y, 2, 2);
+ context.closePath();
+ };
+ TileMapCell.prototype.UpdateType = //this converts a tile from implicitly-defined (via ID), to explicit (via properties)
+ function () {
+ if(0 < this.ID) {
+ //tile is non-empty; collide
+ if(this.ID < TileMapCell.CTYPE_45DEG) {
+ //TID_FULL
+ this.CTYPE = TileMapCell.CTYPE_FULL;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID < TileMapCell.CTYPE_CONCAVE) {
+ //45deg
+ this.CTYPE = TileMapCell.CTYPE_45DEG;
+ if(this.ID == TileMapCell.TID_45DEGpn) {
+ console.log('set tile as 45deg pn');
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = this.signx / Math.SQRT2//get slope _unit_ normal
+ ;
+ this.sy = this.signy / Math.SQRT2//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2)
+ ;
+ } else if(this.ID == TileMapCell.TID_45DEGnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = this.signx / Math.SQRT2//get slope _unit_ normal
+ ;
+ this.sy = this.signy / Math.SQRT2//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2)
+ ;
+ } else if(this.ID == TileMapCell.TID_45DEGnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = this.signx / Math.SQRT2//get slope _unit_ normal
+ ;
+ this.sy = this.signy / Math.SQRT2//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2)
+ ;
+ } else if(this.ID == TileMapCell.TID_45DEGpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = this.signx / Math.SQRT2//get slope _unit_ normal
+ ;
+ this.sy = this.signy / Math.SQRT2//since normal is (1,-1), length is sqrt(1*1 + -1*-1) = sqrt(2)
+ ;
+ } else {
+ //trace("BAAAD TILE!!!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_CONVEX) {
+ //concave
+ this.CTYPE = TileMapCell.CTYPE_CONCAVE;
+ if(this.ID == TileMapCell.TID_CONCAVEpn) {
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else {
+ //trace("BAAAD TILE!!!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_22DEGs) {
+ //convex
+ this.CTYPE = TileMapCell.CTYPE_CONVEX;
+ if(this.ID == TileMapCell.TID_CONVEXpn) {
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else {
+ //trace("BAAAD TILE!!!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_22DEGb) {
+ //22deg small
+ this.CTYPE = TileMapCell.CTYPE_22DEGs;
+ if(this.ID == TileMapCell.TID_22DEGpnS) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnnS) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnpS) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGppS) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else {
+ //trace("BAAAD TILE!!!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_67DEGs) {
+ //22deg big
+ this.CTYPE = TileMapCell.CTYPE_22DEGb;
+ if(this.ID == TileMapCell.TID_22DEGpnB) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnnB) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnpB) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGppB) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else {
+ //trace("BAAAD TILE!!!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_67DEGb) {
+ //67deg small
+ this.CTYPE = TileMapCell.CTYPE_67DEGs;
+ if(this.ID == TileMapCell.TID_67DEGpnS) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnnS) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnpS) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGppS) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else {
+ //trace("BAAAD TILE!!!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_HALF) {
+ //67deg big
+ this.CTYPE = TileMapCell.CTYPE_67DEGb;
+ if(this.ID == TileMapCell.TID_67DEGpnB) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnnB) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnpB) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGppB) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else {
+ //trace("BAAAD TILE!!!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ } else {
+ //half-full tile
+ this.CTYPE = TileMapCell.CTYPE_HALF;
+ if(this.ID == TileMapCell.TID_HALFd) {
+ this.signx = 0;
+ this.signy = -1;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFu) {
+ this.signx = 0;
+ this.signy = 1;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFl) {
+ this.signx = 1;
+ this.signy = 0;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFr) {
+ this.signx = -1;
+ this.signy = 0;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else {
+ //trace("BAAD TILE!!!: ID=" + this.ID + " ("+ t.i + "," + t.j + ")");
+ return false;
+ }
+ }
+ } else {
+ //TID_EMPTY
+ this.CTYPE = TileMapCell.CTYPE_EMPTY;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ }
+ };
+ return TileMapCell;
+ })();
+ Physics.TileMapCell = TileMapCell;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/TileMapCell.ts b/TS Source/physics/TileMapCell.ts
similarity index 100%
rename from Phaser/physics/TileMapCell.ts
rename to TS Source/physics/TileMapCell.ts
diff --git a/TS Source/physics/aabb/ProjAABB22Deg.js b/TS Source/physics/aabb/ProjAABB22Deg.js
new file mode 100644
index 00000000..664937a3
--- /dev/null
+++ b/TS Source/physics/aabb/ProjAABB22Deg.js
@@ -0,0 +1,98 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var AABB22Deg = (function () {
+ function AABB22Deg() { }
+ AABB22Deg.CollideS = function CollideS(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ //first we need to check to make sure we're colliding with the slope at all
+ var py = obj.pos.y - (signy * obj.height);
+ var penY = t.pos.y - py;//this is the vector from the innermost point on the box to the highest point on
+
+ //the tile; if it is positive, this means the box is above the tile and
+ //no collision is occuring
+ if(0 < (penY * signy)) {
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));//point on the AABB, relative to a point on the slope
+
+ var sx = t.sx;//get slope unit normal
+
+ var sy = t.sy;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ var aY = Math.abs(penY);
+ if(lenP < lenN) {
+ if(aY < lenP) {
+ obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ }
+ } else {
+ if(aY < lenN) {
+ obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ }
+ }
+ //if we've reached this point, no collision has occured
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ AABB22Deg.CollideB = function CollideB(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));//point on the AABB, relative to a point on the slope
+
+ var sx = t.sx;//get slope unit normal
+
+ var sy = t.sy;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB22Deg;
+ })();
+ Projection.AABB22Deg = AABB22Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/aabb/ProjAABB22Deg.ts b/TS Source/physics/aabb/ProjAABB22Deg.ts
similarity index 100%
rename from Phaser/physics/aabb/ProjAABB22Deg.ts
rename to TS Source/physics/aabb/ProjAABB22Deg.ts
diff --git a/TS Source/physics/aabb/ProjAABB45Deg.js b/TS Source/physics/aabb/ProjAABB45Deg.js
new file mode 100644
index 00000000..5598e921
--- /dev/null
+++ b/TS Source/physics/aabb/ProjAABB45Deg.js
@@ -0,0 +1,49 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var AABB45Deg = (function () {
+ function AABB45Deg() { }
+ AABB45Deg.Collide = function Collide(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - t.pos.x;//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (signy * obj.height)) - t.pos.y;//point on the AABB, relative to the tile center
+
+ var sx = t.sx;
+ var sy = t.sy;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ //project along axis
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ //project along slope
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB45Deg;
+ })();
+ Projection.AABB45Deg = AABB45Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/aabb/ProjAABB45Deg.ts b/TS Source/physics/aabb/ProjAABB45Deg.ts
similarity index 100%
rename from Phaser/physics/aabb/ProjAABB45Deg.ts
rename to TS Source/physics/aabb/ProjAABB45Deg.ts
diff --git a/TS Source/physics/aabb/ProjAABB67Deg.js b/TS Source/physics/aabb/ProjAABB67Deg.js
new file mode 100644
index 00000000..8e95fb6c
--- /dev/null
+++ b/TS Source/physics/aabb/ProjAABB67Deg.js
@@ -0,0 +1,94 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var AABB67Deg = (function () {
+ function AABB67Deg() { }
+ AABB67Deg.CollideS = function CollideS(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var px = obj.pos.x - (signx * obj.width);
+ var penX = t.pos.x - px;
+ if(0 < (penX * signx)) {
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));//point on the AABB, relative to a point on the slope
+
+ var sx = t.sx;//get slope unit normal
+
+ var sy = t.sy;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
+ //and we need to project it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ var aX = Math.abs(penX);
+ if(lenP < lenN) {
+ if(aX < lenP) {
+ obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ }
+ } else {
+ if(aX < lenN) {
+ obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ }
+ }
+ //if we've reached this point, no collision has occured
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ AABB67Deg.CollideB = function CollideB(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));//point on the AABB, relative to a point on the slope
+
+ var sx = t.sx;//get slope unit normal
+
+ var sy = t.sy;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB67Deg;
+ })();
+ Projection.AABB67Deg = AABB67Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/aabb/ProjAABB67Deg.ts b/TS Source/physics/aabb/ProjAABB67Deg.ts
similarity index 100%
rename from Phaser/physics/aabb/ProjAABB67Deg.ts
rename to TS Source/physics/aabb/ProjAABB67Deg.ts
diff --git a/TS Source/physics/aabb/ProjAABBConcave.js b/TS Source/physics/aabb/ProjAABBConcave.js
new file mode 100644
index 00000000..29f3fd1b
--- /dev/null
+++ b/TS Source/physics/aabb/ProjAABBConcave.js
@@ -0,0 +1,52 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var AABBConcave = (function () {
+ function AABBConcave() { }
+ AABBConcave.Collide = function Collide(x, y, obj, t) {
+ //if distance from "innermost" corner of AABB is further than tile radius,
+ //collision is occuring and we need to project
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (t.pos.x + (signx * t.xw)) - (obj.pos.x - (signx * obj.width));//(ox,oy) is the vector form the innermost AABB corner to the
+
+ var oy = (t.pos.y + (signy * t.yw)) - (obj.pos.y - (signy * obj.height));//circle's center
+
+ var twid = t.xw * 2;
+ var rad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
+
+ //note that this should be precomputed at compile-time since it's constant
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = len - rad;
+ if(0 < pen) {
+ //collision; we need to either project along the axes, or project along corner->circlecenter vector
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < pen) {
+ //it's shorter to move along axis directions
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ //project along corner->circle vector
+ ox /= len//len should never be 0, since if it IS 0, rad should be > than len
+ ;
+ oy /= len//and we should never reach here
+ ;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBConcave;
+ })();
+ Projection.AABBConcave = AABBConcave;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/aabb/ProjAABBConcave.ts b/TS Source/physics/aabb/ProjAABBConcave.ts
similarity index 100%
rename from Phaser/physics/aabb/ProjAABBConcave.ts
rename to TS Source/physics/aabb/ProjAABBConcave.ts
diff --git a/TS Source/physics/aabb/ProjAABBConvex.js b/TS Source/physics/aabb/ProjAABBConvex.js
new file mode 100644
index 00000000..765a315e
--- /dev/null
+++ b/TS Source/physics/aabb/ProjAABBConvex.js
@@ -0,0 +1,48 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var AABBConvex = (function () {
+ function AABBConvex() { }
+ AABBConvex.Collide = function Collide(x, y, obj, t) {
+ //if distance from "innermost" corner of AABB is less than than tile radius,
+ //collision is occuring and we need to project
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the circle center to
+
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));//the AABB
+
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var twid = t.xw * 2;
+ var rad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
+
+ //note that this should be precomputed at compile-time since it's constant
+ var pen = rad - len;
+ if(((signx * ox) < 0) || ((signy * oy) < 0)) {
+ //the test corner is "outside" the 1/4 of the circle we're interested in
+ var lenP = Math.sqrt(x * x + y * y);
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;//we need to report
+
+ } else if(0 < pen) {
+ //project along corner->circle vector
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBConvex;
+ })();
+ Projection.AABBConvex = AABBConvex;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/aabb/ProjAABBConvex.ts b/TS Source/physics/aabb/ProjAABBConvex.ts
similarity index 100%
rename from Phaser/physics/aabb/ProjAABBConvex.ts
rename to TS Source/physics/aabb/ProjAABBConvex.ts
diff --git a/TS Source/physics/aabb/ProjAABBFull.js b/TS Source/physics/aabb/ProjAABBFull.js
new file mode 100644
index 00000000..eea26a42
--- /dev/null
+++ b/TS Source/physics/aabb/ProjAABBFull.js
@@ -0,0 +1,23 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var AABBFull = (function () {
+ function AABBFull() { }
+ AABBFull.Collide = function Collide(x, y, obj, t) {
+ var l = Math.sqrt(x * x + y * y);
+ obj.reportCollisionVsWorld(x, y, x / l, y / l, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ };
+ return AABBFull;
+ })();
+ Projection.AABBFull = AABBFull;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/aabb/ProjAABBFull.ts b/TS Source/physics/aabb/ProjAABBFull.ts
similarity index 100%
rename from Phaser/physics/aabb/ProjAABBFull.ts
rename to TS Source/physics/aabb/ProjAABBFull.ts
diff --git a/TS Source/physics/aabb/ProjAABBHalf.js b/TS Source/physics/aabb/ProjAABBHalf.js
new file mode 100644
index 00000000..398485fe
--- /dev/null
+++ b/TS Source/physics/aabb/ProjAABBHalf.js
@@ -0,0 +1,52 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var AABBHalf = (function () {
+ function AABBHalf() { }
+ AABBHalf.Collide = function Collide(x, y, obj, t) {
+ //calculate the projection vector for the half-edge, and then
+ //(if collision is occuring) pick the minimum
+ var sx = t.signx;
+ var sy = t.signy;
+ var ox = (obj.pos.x - (sx * obj.width)) - t.pos.x;//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (sy * obj.height)) - t.pos.y;//point on the AABB, relative to the tile center
+
+ //we perform operations analogous to the 45deg tile, except we're using
+ //an axis-aligned slope instead of an angled one..
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ //project along axis; note that we're assuming that this tile is horizontal OR vertical
+ //relative to the AABB's current tile, and not diagonal OR the current tile.
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ //note that we could use -= instead of -dp
+ obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBHalf;
+ })();
+ Projection.AABBHalf = AABBHalf;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/aabb/ProjAABBHalf.ts b/TS Source/physics/aabb/ProjAABBHalf.ts
similarity index 100%
rename from Phaser/physics/aabb/ProjAABBHalf.ts
rename to TS Source/physics/aabb/ProjAABBHalf.ts
diff --git a/TS Source/physics/circle/ProjCircle22Deg.js b/TS Source/physics/circle/ProjCircle22Deg.js
new file mode 100644
index 00000000..2d66d7a4
--- /dev/null
+++ b/TS Source/physics/circle/ProjCircle22Deg.js
@@ -0,0 +1,440 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var Circle22Deg = (function () {
+ function Circle22Deg() { }
+ Circle22Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
+ //if the object is in a cell pointed at by signy, no collision will ever occur
+ //otherwise,
+ //
+ //if we're colliding diagonally:
+ // -collide vs. the appropriate vertex
+ //if obj is in this tile: collide vs slope or vertex
+ //if obj is horiz neighb in direction of slope: collide vs. slope or vertex
+ //if obj is horiz neighb against the slope:
+ // if(distance in y from circle to 90deg corner of tile < 1/2 tileheight, collide vs. face)
+ // else(collide vs. corner of slope) (vert collision with a non-grid-aligned vert)
+ //if obj is vert neighb against direction of slope: collide vs. face
+ var signx = t.signx;
+ var signy = t.signy;
+ if(0 < (signy * oV)) {
+ //object will never collide vs tile, it can't reach that far
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current tile
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ var sx = t.sx;
+ var sy = t.sy;
+ var r = obj.radius;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - t.pos.y;//point on the circle, relative to the tile corner
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the vertex, otherwise by the normal or axially.
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = r - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope or vs axis
+ ox -= r * sx//this gives us the vector from
+ ;
+ oy -= r * sy//a point on the slope to the innermost point on the circle
+ ;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP;
+ //find the smallest axial projection vector
+ if(x < y) {
+ //penetration in x is smaller
+ lenP = x;
+ y = 0;
+ //get sign for projection along x-axis
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ //penetration in y is smaller
+ lenP = y;
+ x = 0;
+ //get sign for projection along y-axis
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ //colliding vertically; we can assume that (signy*oV) < 0
+ //due to the first conditional far above
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else if(oV == 0) {
+ //colliding horizontally
+ if((signx * oH) < 0) {
+ //colliding with face/edge OR with corner of wedge, depending on our position vertically
+ //collide vs. vertex
+ //get diag vertex position
+ var vx = t.pos.x - (signx * t.xw);
+ var vy = t.pos.y;
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ if((dy * signy) < 0) {
+ //colliding vs face
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //colliding vs. vertex
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x + (oH * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//point on the circle, relative to the closest tile vert
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the normal, otherwise by the vertex.
+ //(NOTE: this is the opposite logic of the vertical case;
+ // for vertical, if the perp prod and the slope's slope agree, it's outside.
+ // for horizontal, if the perp prod and the slope's slope agree, circle is inside.
+ // ..but this is only a property of flahs' coord system (i.e the rules might swap
+ // in righthanded systems))
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ //colliding diagonally; due to the first conditional above,
+ //obj is vertically offset against slope, and offset in either direction horizontally
+ //collide vs. vertex
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ Circle22Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
+ //if we're colliding diagonally:
+ // -if we're in the cell pointed at by the normal, collide vs slope, else
+ // collide vs. the appropriate corner/vertex
+ //
+ //if obj is in this tile: collide as with aabb
+ //
+ //if obj is horiz or vertical neighbor AGAINST the slope: collide with edge
+ //
+ //if obj is horiz neighb in direction of slope: collide vs. slope or vertex or edge
+ //
+ //if obj is vert neighb in direction of slope: collide vs. slope or vertex
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current cell
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));//point on the AABB, relative to a point on the slope
+
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP;
+ //find the smallest axial projection vector
+ if(x < y) {
+ //penetration in x is smaller
+ lenP = x;
+ y = 0;
+ //get sign for projection along x-axis
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ //penetration in y is smaller
+ lenP = y;
+ x = 0;
+ //get sign for projection along y-axis
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //colliding vertically
+ if((signy * oV) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ sx = t.sx;
+ sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y + (signy * t.yw));//point on the circle, relative to the closest tile vert
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the vertex, otherwise by the normal.
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ //colliding horizontally
+ if((signx * oH) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //colliding with edge, slope, or vertex
+ var ox = obj.pos.x - (t.pos.x + (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - t.pos.y;//point on the circle, relative to the closest tile vert
+
+ if((oy * signy) < 0) {
+ //we're colliding with the halfface
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //colliding with the vertex or slope
+ sx = t.sx;
+ sy = t.sy;
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the slope, otherwise by the vertex.
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else {
+ //colliding diagonally
+ if(0 < ((signx * oH) + (signy * oV))) {
+ //the dotprod of slope normal and cell offset is strictly positive,
+ //therefore obj is in the diagonal neighb pointed at by the normal.
+ //collide vs slope
+ //we should really precalc this at compile time, but for now, fuck it
+ var slen = Math.sqrt(2 * 2 + 1 * 1);//the raw slope is (-2,-1)
+
+ sx = (signx * 1) / slen//get slope _unit_ normal;
+ ;
+ sy = (signy * 2) / slen//raw RH normal is (1,-2)
+ ;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));//point on the circle, relative to a point on the slope
+
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ //(sx,sy)*-dp is the projection vector
+ obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ //collide vs the appropriate vertex
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle22Deg;
+ })();
+ Projection.Circle22Deg = Circle22Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/circle/ProjCircle22Deg.ts b/TS Source/physics/circle/ProjCircle22Deg.ts
similarity index 100%
rename from Phaser/physics/circle/ProjCircle22Deg.ts
rename to TS Source/physics/circle/ProjCircle22Deg.ts
diff --git a/TS Source/physics/circle/ProjCircle45Deg.js b/TS Source/physics/circle/ProjCircle45Deg.js
new file mode 100644
index 00000000..f7bcb8ce
--- /dev/null
+++ b/TS Source/physics/circle/ProjCircle45Deg.js
@@ -0,0 +1,208 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var Circle45Deg = (function () {
+ function Circle45Deg() { }
+ Circle45Deg.Collide = function Collide(x, y, oH, oV, obj, t) {
+ //if we're colliding diagonally:
+ // -if obj is in the diagonal pointed to by the slope normal: we can't collide, do nothing
+ // -else, collide vs. the appropriate vertex
+ //if obj is in this tile: perform collision as for aabb-ve-45deg
+ //if obj is horiz OR very neighb in direction of slope: collide only vs. slope
+ //if obj is horiz or vert neigh against direction of slope: collide vs. face
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current tile
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = (obj.pos.x - (sx * obj.radius)) - t.pos.x;//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (sy * obj.radius)) - t.pos.y;//point on the circle, relative to the tile center
+
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the innermost point is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this as the slope penetration vector
+ sx *= -dp//(sx,sy) is now the penetration vector
+ ;
+ sy *= -dp;
+ //find the smallest axial projection vector
+ if(x < y) {
+ //penetration in x is smaller
+ lenP = x;
+ y = 0;
+ //get sign for projection along x-axis
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ //penetration in y is smaller
+ lenP = y;
+ x = 0;
+ //get sign for projection along y-axis
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //colliding vertically
+ if((signy * oV) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y + (oV * t.yw));//point on the circle, relative to the closest tile vert
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the vertex, otherwise by the normal.
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronoi region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ //colliding horizontally
+ if((signx * oH) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x + (oH * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//point on the circle, relative to the closest tile vert
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the normal, otherwise by the vertex.
+ //(NOTE: this is the opposite logic of the vertical case;
+ // for vertical, if the perp prod and the slope's slope agree, it's outside.
+ // for horizontal, if the perp prod and the slope's slope agree, circle is inside.
+ // ..but this is only a property of flahs' coord system (i.e the rules might swap
+ // in righthanded systems))
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ //colliding diagonally
+ if(0 < ((signx * oH) + (signy * oV))) {
+ //the dotprod of slope normal and cell offset is strictly positive,
+ //therefore obj is in the diagonal neighb pointed at by the normal, and
+ //it cannot possibly reach/touch/penetrate the slope
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ //collide vs. vertex
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle45Deg;
+ })();
+ Projection.Circle45Deg = Circle45Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/circle/ProjCircle45Deg.ts b/TS Source/physics/circle/ProjCircle45Deg.ts
similarity index 100%
rename from Phaser/physics/circle/ProjCircle45Deg.ts
rename to TS Source/physics/circle/ProjCircle45Deg.ts
diff --git a/TS Source/physics/circle/ProjCircle67Deg.js b/TS Source/physics/circle/ProjCircle67Deg.js
new file mode 100644
index 00000000..c4d08924
--- /dev/null
+++ b/TS Source/physics/circle/ProjCircle67Deg.js
@@ -0,0 +1,436 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var Circle67Deg = (function () {
+ function Circle67Deg() { }
+ Circle67Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
+ //if the object is in a cell pointed at by signx, no collision will ever occur
+ //otherwise,
+ //
+ //if we're colliding diagonally:
+ // -collide vs. the appropriate vertex
+ //if obj is in this tile: collide vs slope or vertex or axis
+ //if obj is vert neighb in direction of slope: collide vs. slope or vertex
+ //if obj is vert neighb against the slope:
+ // if(distance in y from circle to 90deg corner of tile < 1/2 tileheight, collide vs. face)
+ // else(collide vs. corner of slope) (vert collision with a non-grid-aligned vert)
+ //if obj is horiz neighb against direction of slope: collide vs. face
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(0 < (signx * oH)) {
+ //object will never collide vs tile, it can't reach that far
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current tile
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = obj.pos.x - t.pos.x;//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//point on the circle, relative to the tile corner
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the normal or axis, otherwise by the corner/vertex
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronoi region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = r - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope or vs axis
+ ox -= r * sx//this gives us the vector from
+ ;
+ oy -= r * sy//a point on the slope to the innermost point on the circle
+ ;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ var lenP;
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ //find the smallest axial projection vector
+ if(x < y) {
+ //penetration in x is smaller
+ lenP = x;
+ y = 0;
+ //get sign for projection along x-axis
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ //penetration in y is smaller
+ lenP = y;
+ x = 0;
+ //get sign for projection along y-axis
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ //colliding vertically
+ if((signy * oV) < 0) {
+ //colliding with face/edge OR with corner of wedge, depending on our position vertically
+ //collide vs. vertex
+ //get diag vertex position
+ var vx = t.pos.x;
+ var vy = t.pos.y - (signy * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ if((dx * signx) < 0) {
+ //colliding vs face
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //colliding vs. vertex
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ sx = t.sx;
+ sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y + (oV * t.yw));//point on the circle, relative to the closest tile vert
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the vertex, otherwise by the normal.
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ //colliding horizontally; we can assume that (signy*oV) < 0
+ //due to the first conditional far above
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //colliding diagonally; due to the first conditional above,
+ //obj is vertically offset against slope, and offset in either direction horizontally
+ //collide vs. vertex
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ Circle67Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
+ //if we're colliding diagonally:
+ // -if we're in the cell pointed at by the normal, collide vs slope, else
+ // collide vs. the appropriate corner/vertex
+ //
+ //if obj is in this tile: collide as with aabb
+ //
+ //if obj is horiz or vertical neighbor AGAINST the slope: collide with edge
+ //
+ //if obj is vert neighb in direction of slope: collide vs. slope or vertex or halfedge
+ //
+ //if obj is horiz neighb in direction of slope: collide vs. slope or vertex
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current cell
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));//point on the AABB, relative to a point on the slope
+
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ var lenP;
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ //find the smallest axial projection vector
+ if(x < y) {
+ //penetration in x is smaller
+ lenP = x;
+ y = 0;
+ //get sign for projection along x-axis
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ //penetration in y is smaller
+ lenP = y;
+ x = 0;
+ //get sign for projection along y-axis
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //colliding vertically
+ if((signy * oV) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //colliding with edge, slope, or vertex
+ var ox = obj.pos.x - t.pos.x;//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y + (signy * t.yw));//point on the circle, relative to the closest tile vert
+
+ if((ox * signx) < 0) {
+ //we're colliding with the halfface
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //colliding with the vertex or slope
+ sx = t.sx;
+ sy = t.sy;
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the vertex, otherwise by the slope.
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ //colliding horizontally
+ if((signx * oH) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //we could only be colliding vs the slope OR a vertex
+ //look at the vector form the closest vert to the circle to decide
+ var slen = Math.sqrt(2 * 2 + 1 * 1);//the raw slope is (-2,-1)
+
+ var sx = (signx * 2) / slen;//get slope _unit_ normal;
+
+ var sy = (signy * 1) / slen;//raw RH normal is (1,-2)
+
+ var ox = obj.pos.x - (t.pos.x + (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//point on the circle, relative to the closest tile vert
+
+ //if the component of (ox,oy) parallel to the normal's righthand normal
+ //has the same sign as the slope of the slope (the sign of the slope's slope is signx*signy)
+ //then we project by the slope, otherwise by the vertex.
+ //note that this is simply a VERY tricky/weird method of determining
+ //if the circle is in side the slope/face's voronio region, or that of the vertex.
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ //collide vs. vertex
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //note: if len=0, then perp=0 and we'll never reach here, so don't worry about div-by-0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. slope
+ //if the component of (ox,oy) parallel to the normal is less than the circle radius, we're
+ //penetrating the slope. note that this method of penetration calculation doesn't hold
+ //in general (i.e it won't work if the circle is in the slope), but works in this case
+ //because we know the circle is in a neighboring cell
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);//note: we don't need the abs because we know the dp will be positive, but just in case..
+
+ if(0 < pen) {
+ //collision; circle out along normal by penetration amount
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ //colliding diagonally
+ if(0 < ((signx * oH) + (signy * oV))) {
+ //the dotprod of slope normal and cell offset is strictly positive,
+ //therefore obj is in the diagonal neighb pointed at by the normal.
+ //collide vs slope
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));//point on the circle, relative to a point on the slope
+
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the point on the circle is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ //(sx,sy)*-dp is the projection vector
+ obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ //collide vs the appropriate vertex
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle67Deg;
+ })();
+ Projection.Circle67Deg = Circle67Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/circle/ProjCircle67Deg.ts b/TS Source/physics/circle/ProjCircle67Deg.ts
similarity index 100%
rename from Phaser/physics/circle/ProjCircle67Deg.ts
rename to TS Source/physics/circle/ProjCircle67Deg.ts
diff --git a/TS Source/physics/circle/ProjCircleConcave.js b/TS Source/physics/circle/ProjCircleConcave.js
new file mode 100644
index 00000000..7f97e7e4
--- /dev/null
+++ b/TS Source/physics/circle/ProjCircleConcave.js
@@ -0,0 +1,170 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var CircleConcave = (function () {
+ function CircleConcave() { }
+ CircleConcave.Collide = function Collide(x, y, oH, oV, obj, t) {
+ //if we're colliding diagonally:
+ // -if obj is in the diagonal pointed to by the slope normal: we can't collide, do nothing
+ // -else, collide vs. the appropriate vertex
+ //if obj is in this tile: perform collision as for aabb
+ //if obj is horiz OR very neighb in direction of slope: collide vs vert
+ //if obj is horiz or vert neigh against direction of slope: collide vs. face
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current tile
+ var ox = (t.pos.x + (signx * t.xw)) - obj.pos.x;//(ox,oy) is the vector from the circle to
+
+ var oy = (t.pos.y + (signy * t.yw)) - obj.pos.y;//tile-circle's center
+
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
+
+ //note that this should be precomputed at compile-time since it's constant
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (len + obj.radius) - trad;
+ if(0 < pen) {
+ //find the smallest axial projection vector
+ if(x < y) {
+ //penetration in x is smaller
+ lenP = x;
+ y = 0;
+ //get sign for projection along x-axis
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ //penetration in y is smaller
+ lenP = y;
+ x = 0;
+ //get sign for projection along y-axis
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //we can assume that len >0, because if we're here then
+ //(len + obj.radius) > trad, and since obj.radius <= trad
+ //len MUST be > 0
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ return Phaser.Physics.Circle.COL_NONE;
+ }
+ } else {
+ //colliding vertically
+ if((signy * oV) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //we could only be colliding vs the vertical tip
+ //get diag vertex position
+ var vx = t.pos.x - (signx * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out vertically
+ dx = 0;
+ dy = oV;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else if(oV == 0) {
+ //colliding horizontally
+ if((signx * oH) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //we could only be colliding vs the horizontal tip
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y - (signy * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out horizontally
+ dx = oH;
+ dy = 0;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //colliding diagonally
+ if(0 < ((signx * oH) + (signy * oV))) {
+ //the dotprod of slope normal and cell offset is strictly positive,
+ //therefore obj is in the diagonal neighb pointed at by the normal, and
+ //it cannot possibly reach/touch/penetrate the slope
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ //collide vs. vertex
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleConcave;
+ })();
+ Projection.CircleConcave = CircleConcave;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/circle/ProjCircleConcave.ts b/TS Source/physics/circle/ProjCircleConcave.ts
similarity index 100%
rename from Phaser/physics/circle/ProjCircleConcave.ts
rename to TS Source/physics/circle/ProjCircleConcave.ts
diff --git a/TS Source/physics/circle/ProjCircleConvex.js b/TS Source/physics/circle/ProjCircleConvex.js
new file mode 100644
index 00000000..389b4898
--- /dev/null
+++ b/TS Source/physics/circle/ProjCircleConvex.js
@@ -0,0 +1,180 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var CircleConvex = (function () {
+ function CircleConvex() { }
+ CircleConvex.Collide = function Collide(x, y, oH, oV, obj, t) {
+ //if the object is horiz AND/OR vertical neighbor in the normal (signx,signy)
+ //direction, collide vs. tile-circle only.
+ //if we're colliding diagonally:
+ // -else, collide vs. the appropriate vertex
+ //if obj is in this tile: perform collision as for aabb
+ //if obj is horiz or vert neigh against direction of slope: collide vs. face
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current tile
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
+
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
+
+ //note that this should be precomputed at compile-time since it's constant
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ //find the smallest axial projection vector
+ if(x < y) {
+ //penetration in x is smaller
+ lenP = x;
+ y = 0;
+ //get sign for projection along x-axis
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ //penetration in y is smaller
+ lenP = y;
+ x = 0;
+ //get sign for projection along y-axis
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //note: len should NEVER be == 0, because if it is,
+ //projeciton by an axis shoudl always be shorter, and we should
+ //never arrive here
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //colliding vertically
+ if((signy * oV) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //obj in neighboring cell pointed at by tile normal;
+ //we could only be colliding vs the tile-circle surface
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
+
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
+
+ //note that this should be precomputed at compile-time since it's constant
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ //note: len should NEVER be == 0, because if it is,
+ //obj is not in a neighboring cell!
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else if(oV == 0) {
+ //colliding horizontally
+ if((signx * oH) < 0) {
+ //colliding with face/edge
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //obj in neighboring cell pointed at by tile normal;
+ //we could only be colliding vs the tile-circle surface
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
+
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
+
+ //note that this should be precomputed at compile-time since it's constant
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ //note: len should NEVER be == 0, because if it is,
+ //obj is not in a neighboring cell!
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //colliding diagonally
+ if(0 < ((signx * oH) + (signy * oV))) {
+ //obj in diag neighb cell pointed at by tile normal;
+ //we could only be colliding vs the tile-circle surface
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));//(ox,oy) is the vector from the tile-circle to
+
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));//the circle's center
+
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);//this gives us the radius of a circle centered on the tile's corner and extending to the opposite edge of the tile;
+
+ //note that this should be precomputed at compile-time since it's constant
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ //note: len should NEVER be == 0, because if it is,
+ //obj is not in a neighboring cell!
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ //collide vs. vertex
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleConvex;
+ })();
+ Projection.CircleConvex = CircleConvex;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/circle/ProjCircleConvex.ts b/TS Source/physics/circle/ProjCircleConvex.ts
similarity index 100%
rename from Phaser/physics/circle/ProjCircleConvex.ts
rename to TS Source/physics/circle/ProjCircleConvex.ts
diff --git a/TS Source/physics/circle/ProjCircleFull.js b/TS Source/physics/circle/ProjCircleFull.js
new file mode 100644
index 00000000..5669e565
--- /dev/null
+++ b/TS Source/physics/circle/ProjCircleFull.js
@@ -0,0 +1,86 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var CircleFull = (function () {
+ function CircleFull() { }
+ CircleFull.Collide = function Collide(x, y, oH, oV, obj, t) {
+ //if we're colliding vs. the current cell, we need to project along the
+ //smallest penetration vector.
+ //if we're colliding vs. horiz. or vert. neighb, we simply project horiz/vert
+ //if we're colliding diagonally, we need to collide vs. tile corner
+ if(oH == 0) {
+ if(oV == 0) {
+ //collision with current cell
+ if(x < y) {
+ //penetration in x is smaller; project in x
+ var dx = obj.pos.x - t.pos.x;//get sign for projection along x-axis
+
+ //NOTE: should we handle the delta == 0 case?! and how? (project towards oldpos?)
+ if(dx < 0) {
+ obj.reportCollisionVsWorld(-x, 0, -1, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(x, 0, 1, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else {
+ //penetration in y is smaller; project in y
+ var dy = obj.pos.y - t.pos.y;//get sign for projection along y-axis
+
+ //NOTE: should we handle the delta == 0 case?! and how? (project towards oldpos?)
+ if(dy < 0) {
+ obj.reportCollisionVsWorld(0, -y, 0, -1, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(0, y, 0, 1, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ }
+ } else {
+ //collision with vertical neighbor
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else if(oV == 0) {
+ //collision with horizontal neighbor
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //diagonal collision
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleFull;
+ })();
+ Projection.CircleFull = CircleFull;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/circle/ProjCircleFull.ts b/TS Source/physics/circle/ProjCircleFull.ts
similarity index 100%
rename from Phaser/physics/circle/ProjCircleFull.ts
rename to TS Source/physics/circle/ProjCircleFull.ts
diff --git a/TS Source/physics/circle/ProjCircleHalf.js b/TS Source/physics/circle/ProjCircleHalf.js
new file mode 100644
index 00000000..44557847
--- /dev/null
+++ b/TS Source/physics/circle/ProjCircleHalf.js
@@ -0,0 +1,171 @@
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ ///
+ /**
+ * Phaser - Physics - Projection
+ */
+ (function (Projection) {
+ var CircleHalf = (function () {
+ function CircleHalf() { }
+ CircleHalf.Collide = function Collide(x, y, oH, oV, obj, t) {
+ //if obj is in a neighbor pointed at by the halfedge normal,
+ //we'll never collide (i.e if the normal is (0,1) and the obj is in the DL.D, or R neighbors)
+ //
+ //if obj is in a neigbor perpendicular to the halfedge normal, it might
+ //collide with the halfedge-vertex, or with the halfedge side.
+ //
+ //if obj is in a neigb pointing opposite the halfedge normal, obj collides with edge
+ //
+ //if obj is in a diagonal (pointing away from the normal), obj collides vs vertex
+ //
+ //if obj is in the halfedge cell, it collides as with aabb
+ var signx = t.signx;
+ var signy = t.signy;
+ var celldp = (oH * signx + oV * signy);//this tells us about the configuration of cell-offset relative to tile normal
+
+ if(0 < celldp) {
+ //obj is in "far" (pointed-at-by-normal) neighbor of halffull tile, and will never hit
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ //colliding with current tile
+ var r = obj.radius;
+ var ox = (obj.pos.x - (signx * r)) - t.pos.x;//this gives is the coordinates of the innermost
+
+ var oy = (obj.pos.y - (signy * r)) - t.pos.y;//point on the circle, relative to the tile center
+
+ //we perform operations analogous to the 45deg tile, except we're using
+ //an axis-aligned slope instead of an angled one..
+ var sx = signx;
+ var sy = signy;
+ //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
+ //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ //collision; project delta onto slope and use this to displace the object
+ sx *= -dp//(sx,sy) is now the projection vector
+ ;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //colliding vertically
+ if(celldp == 0) {
+ var r = obj.radius;
+ var dx = obj.pos.x - t.pos.x;
+ //we're in a cell perpendicular to the normal, and can collide vs. halfedge vertex
+ //or halfedge side
+ if((dx * signx) < 0) {
+ //collision with halfedge side
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //collision with halfedge vertex
+ var dy = obj.pos.y - (t.pos.y + oV * t.yw);//(dx,dy) is now the vector from the appropriate halfedge vertex to the circle
+
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = signx / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //due to the first conditional (celldp >0), we know we're in the cell "opposite" the normal, and so
+ //we can only collide with the cell edge
+ //collision with vertical neighbor
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ }
+ } else if(oV == 0) {
+ //colliding horizontally
+ if(celldp == 0) {
+ var r = obj.radius;
+ var dy = obj.pos.y - t.pos.y;
+ //we're in a cell perpendicular to the normal, and can collide vs. halfedge vertex
+ //or halfedge side
+ if((dy * signy) < 0) {
+ //collision with halfedge side
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ //collision with halfedge vertex
+ var dx = obj.pos.x - (t.pos.x + oH * t.xw);//(dx,dy) is now the vector from the appropriate halfedge vertex to the circle
+
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = signx / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ //due to the first conditional (celldp >0), we know w're in the cell "opposite" the normal, and so
+ //we can only collide with the cell edge
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else {
+ //colliding diagonally; we know, due to the initial (celldp >0) test which has failed
+ //if we've reached this point, that we're in a diagonal neighbor on the non-normal side, so
+ //we could only be colliding with the cell vertex, if at all.
+ //get diag vertex position
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;//calc vert->circle vector
+
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ //vertex is in the circle; project outward
+ if(len == 0) {
+ //project out by 45deg
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleHalf;
+ })();
+ Projection.CircleHalf = CircleHalf;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/physics/circle/ProjCircleHalf.ts b/TS Source/physics/circle/ProjCircleHalf.ts
similarity index 100%
rename from Phaser/physics/circle/ProjCircleHalf.ts
rename to TS Source/physics/circle/ProjCircleHalf.ts
diff --git a/TS Source/renderers/HeadlessRenderer.js b/TS Source/renderers/HeadlessRenderer.js
new file mode 100644
index 00000000..fa81de71
--- /dev/null
+++ b/TS Source/renderers/HeadlessRenderer.js
@@ -0,0 +1,23 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Headless) {
+ var HeadlessRenderer = (function () {
+ function HeadlessRenderer(game) {
+ this.game = game;
+ }
+ HeadlessRenderer.prototype.render = function () {
+ // Nothing, headless remember?
+ };
+ HeadlessRenderer.prototype.renderGameObject = function (camera, object) {
+ // Nothing, headless remember?
+ };
+ return HeadlessRenderer;
+ })();
+ Headless.HeadlessRenderer = HeadlessRenderer;
+ })(Renderer.Headless || (Renderer.Headless = {}));
+ var Headless = Renderer.Headless;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/HeadlessRenderer.ts b/TS Source/renderers/HeadlessRenderer.ts
similarity index 100%
rename from Phaser/renderers/HeadlessRenderer.ts
rename to TS Source/renderers/HeadlessRenderer.ts
diff --git a/Phaser/renderers/IRenderer.ts b/TS Source/renderers/IRenderer.ts
similarity index 100%
rename from Phaser/renderers/IRenderer.ts
rename to TS Source/renderers/IRenderer.ts
diff --git a/TS Source/renderers/canvas/CameraRenderer.js b/TS Source/renderers/canvas/CameraRenderer.js
new file mode 100644
index 00000000..400f50b1
--- /dev/null
+++ b/TS Source/renderers/canvas/CameraRenderer.js
@@ -0,0 +1,144 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Canvas) {
+ var CameraRenderer = (function () {
+ function CameraRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._tx = 0;
+ this._ty = 0;
+ this._gac = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ CameraRenderer.prototype.preRender = function (camera) {
+ if(camera.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
+ return false;
+ }
+ if(this.game.device.patchAndroidClearRectBug) {
+ camera.texture.context.fillStyle = 'rgb(0,0,0)';
+ camera.texture.context.fillRect(0, 0, camera.width, camera.height);
+ } else {
+ camera.texture.context.clearRect(0, 0, camera.width, camera.height);
+ }
+ // Alpha
+ if(camera.texture.alpha !== 1 && camera.texture.context.globalAlpha != camera.texture.alpha) {
+ this._ga = camera.texture.context.globalAlpha;
+ camera.texture.context.globalAlpha = camera.texture.alpha;
+ }
+ if(camera.texture.opaque) {
+ camera.texture.context.fillStyle = camera.texture.backgroundColor;
+ camera.texture.context.fillRect(0, 0, camera.width, camera.height);
+ }
+ //if (camera.texture.loaded)
+ //{
+ // camera.texture.context.drawImage(
+ // camera.texture.texture, // Source Image
+ // this._sx, // Source X (location within the source image)
+ // this._sy, // Source Y
+ // this._sw, // Source Width
+ // this._sh, // Source Height
+ // 0, // Destination X (where on the canvas it'll be drawn)
+ // 0, // Destination Y
+ // this._dw, // Destination Width (always same as Source Width unless scaled)
+ // this._dh // Destination Height (always same as Source Height unless scaled)
+ // );
+ //}
+ // Global Composite Ops
+ if(camera.texture.globalCompositeOperation) {
+ camera.texture.context.globalCompositeOperation = camera.texture.globalCompositeOperation;
+ }
+ camera.plugins.preRender();
+ };
+ CameraRenderer.prototype.postRender = function (camera) {
+ // This could have been over-written by a sprite, need to store elsewhere
+ if(this._ga > -1) {
+ camera.texture.context.globalAlpha = this._ga;
+ }
+ camera.plugins.postRender();
+ // Reset our temp vars
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = camera.width;
+ this._sh = camera.height;
+ this._fx = camera.transform.scale.x;
+ this._fy = camera.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = camera.screenView.x;
+ this._dy = camera.screenView.y;
+ this._dw = camera.width;
+ this._dh = camera.height;
+ this.game.stage.context.save();
+ // Flip X
+ if(camera.texture.flippedX) {
+ this._fx = -camera.transform.scale.x;
+ }
+ // Flip Y
+ if(camera.texture.flippedY) {
+ this._fy = -camera.transform.scale.y;
+ }
+ // Rotation and Flipped
+ if(camera.modified) {
+ if(camera.transform.rotation !== 0 || camera.transform.rotationOffset !== 0) {
+ this._sin = Math.sin(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
+ this._cos = Math.cos(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
+ }
+ this.game.stage.context.setTransform(this._cos * this._fx, // scale x
+ (this._sin * this._fx) + camera.transform.skew.x, // skew x
+ -(this._sin * this._fy) + camera.transform.skew.y, // skew y
+ this._cos * this._fy, // scale y
+ this._dx, // translate x
+ this._dy);
+ // translate y
+ this._dx = camera.transform.origin.x * -this._dw;
+ this._dy = camera.transform.origin.y * -this._dh;
+ } else {
+ this._dx -= (this._dw * camera.transform.origin.x);
+ this._dy -= (this._dh * camera.transform.origin.y);
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
+ this.game.stage.context.restore();
+ return false;
+ }
+ this.game.stage.context.drawImage(camera.texture.canvas, // Source Image
+ this._sx, // Source X (location within the source image)
+ this._sy, // Source Y
+ this._sw, // Source Width
+ this._sh, // Source Height
+ this._dx, // Destination X (where on the canvas it'll be drawn)
+ this._dy, // Destination Y
+ this._dw, // Destination Width (always same as Source Width unless scaled)
+ this._dh);
+ // Destination Height (always same as Source Height unless scaled)
+ this.game.stage.context.restore();
+ };
+ return CameraRenderer;
+ })();
+ Canvas.CameraRenderer = CameraRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/canvas/CameraRenderer.ts b/TS Source/renderers/canvas/CameraRenderer.ts
similarity index 100%
rename from Phaser/renderers/canvas/CameraRenderer.ts
rename to TS Source/renderers/canvas/CameraRenderer.ts
diff --git a/TS Source/renderers/canvas/CanvasRenderer.js b/TS Source/renderers/canvas/CanvasRenderer.js
new file mode 100644
index 00000000..7dfc658b
--- /dev/null
+++ b/TS Source/renderers/canvas/CanvasRenderer.js
@@ -0,0 +1,46 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Canvas) {
+ var CanvasRenderer = (function () {
+ function CanvasRenderer(game) {
+ this._c = 0;
+ this.game = game;
+ this.cameraRenderer = new Phaser.Renderer.Canvas.CameraRenderer(game);
+ this.groupRenderer = new Phaser.Renderer.Canvas.GroupRenderer(game);
+ this.spriteRenderer = new Phaser.Renderer.Canvas.SpriteRenderer(game);
+ this.geometryRenderer = new Phaser.Renderer.Canvas.GeometryRenderer(game);
+ this.scrollZoneRenderer = new Phaser.Renderer.Canvas.ScrollZoneRenderer(game);
+ this.tilemapRenderer = new Phaser.Renderer.Canvas.TilemapRenderer(game);
+ }
+ CanvasRenderer.prototype.render = function () {
+ this._cameraList = this.game.world.getAllCameras();
+ this.renderCount = 0;
+ // Then iterate through world.group on them all (where not blacklisted, etc)
+ for(this._c = 0; this._c < this._cameraList.length; this._c++) {
+ if(this._cameraList[this._c].visible) {
+ this.cameraRenderer.preRender(this._cameraList[this._c]);
+ this.game.world.group.render(this._cameraList[this._c]);
+ this.cameraRenderer.postRender(this._cameraList[this._c]);
+ }
+ }
+ this.renderTotal = this.renderCount;
+ };
+ CanvasRenderer.prototype.renderGameObject = function (camera, object) {
+ if(object.type == Phaser.Types.SPRITE || object.type == Phaser.Types.BUTTON) {
+ this.spriteRenderer.render(camera, object);
+ } else if(object.type == Phaser.Types.SCROLLZONE) {
+ this.scrollZoneRenderer.render(camera, object);
+ } else if(object.type == Phaser.Types.TILEMAP) {
+ this.tilemapRenderer.render(camera, object);
+ }
+ };
+ return CanvasRenderer;
+ })();
+ Canvas.CanvasRenderer = CanvasRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/canvas/CanvasRenderer.ts b/TS Source/renderers/canvas/CanvasRenderer.ts
similarity index 100%
rename from Phaser/renderers/canvas/CanvasRenderer.ts
rename to TS Source/renderers/canvas/CanvasRenderer.ts
diff --git a/TS Source/renderers/canvas/GeometryRenderer.js b/TS Source/renderers/canvas/GeometryRenderer.js
new file mode 100644
index 00000000..f0c7e9f6
--- /dev/null
+++ b/TS Source/renderers/canvas/GeometryRenderer.js
@@ -0,0 +1,76 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Canvas) {
+ var GeometryRenderer = (function () {
+ function GeometryRenderer(game) {
+ // Local rendering related temp vars to help avoid gc spikes through constant var creation
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ GeometryRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) {
+ if (typeof outline === "undefined") { outline = false; }
+ if (typeof fill === "undefined") { fill = true; }
+ if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; }
+ if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; }
+ if (typeof lineWidth === "undefined") { lineWidth = 1; }
+ // Reset our temp vars
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = circle.diameter;
+ this._sh = circle.diameter;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = camera.screenView.x + circle.x - camera.worldView.x;
+ this._dy = camera.screenView.y + circle.y - camera.worldView.y;
+ this._dw = circle.diameter;
+ this._dh = circle.diameter;
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ this.game.stage.saveCanvasValues();
+ context.save();
+ context.lineWidth = lineWidth;
+ context.strokeStyle = lineColor;
+ context.fillStyle = fillColor;
+ context.beginPath();
+ context.arc(this._dx, this._dy, circle.radius, 0, Math.PI * 2);
+ context.closePath();
+ if(outline) {
+ //context.stroke();
+ }
+ if(fill) {
+ context.fill();
+ }
+ context.restore();
+ this.game.stage.restoreCanvasValues();
+ return true;
+ };
+ return GeometryRenderer;
+ })();
+ Canvas.GeometryRenderer = GeometryRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/canvas/GeometryRenderer.ts b/TS Source/renderers/canvas/GeometryRenderer.ts
similarity index 100%
rename from Phaser/renderers/canvas/GeometryRenderer.ts
rename to TS Source/renderers/canvas/GeometryRenderer.ts
diff --git a/TS Source/renderers/canvas/GroupRenderer.js b/TS Source/renderers/canvas/GroupRenderer.js
new file mode 100644
index 00000000..5d5b1056
--- /dev/null
+++ b/TS Source/renderers/canvas/GroupRenderer.js
@@ -0,0 +1,125 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Canvas) {
+ var GroupRenderer = (function () {
+ function GroupRenderer(game) {
+ // Local rendering related temp vars to help avoid gc spikes through var creation
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ GroupRenderer.prototype.preRender = function (camera, group) {
+ if(group.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
+ return false;
+ }
+ // Reset our temp vars
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = group.texture.width;
+ this._sh = group.texture.height;
+ this._fx = group.transform.scale.x;
+ this._fy = group.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ //this._dx = (camera.screenView.x * camera.scrollFactor.x) + camera.frameBounds.x - (camera.worldView.x * camera.scrollFactor.x);
+ //this._dy = (camera.screenView.y * camera.scrollFactor.y) + camera.frameBounds.y - (camera.worldView.y * camera.scrollFactor.y);
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = group.texture.width;
+ this._dh = group.texture.height;
+ // Global Composite Ops
+ if(group.texture.globalCompositeOperation) {
+ group.texture.context.save();
+ group.texture.context.globalCompositeOperation = group.texture.globalCompositeOperation;
+ }
+ // Alpha
+ if(group.texture.alpha !== 1 && group.texture.context.globalAlpha !== group.texture.alpha) {
+ this._ga = group.texture.context.globalAlpha;
+ group.texture.context.globalAlpha = group.texture.alpha;
+ }
+ // Flip X
+ if(group.texture.flippedX) {
+ this._fx = -group.transform.scale.x;
+ }
+ // Flip Y
+ if(group.texture.flippedY) {
+ this._fy = -group.transform.scale.y;
+ }
+ // Rotation and Flipped
+ if(group.modified) {
+ if(group.transform.rotation !== 0 || group.transform.rotationOffset !== 0) {
+ this._sin = Math.sin(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
+ this._cos = Math.cos(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
+ }
+ group.texture.context.save();
+ group.texture.context.setTransform(this._cos * this._fx, // scale x
+ (this._sin * this._fx) + group.transform.skew.x, // skew x
+ -(this._sin * this._fy) + group.transform.skew.y, // skew y
+ this._cos * this._fy, // scale y
+ this._dx, // translate x
+ this._dy);
+ // translate y
+ this._dx = -group.transform.origin.x;
+ this._dy = -group.transform.origin.y;
+ } else {
+ if(!group.transform.origin.equals(0)) {
+ this._dx -= group.transform.origin.x;
+ this._dy -= group.transform.origin.y;
+ }
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(group.texture.opaque) {
+ group.texture.context.fillStyle = group.texture.backgroundColor;
+ group.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
+ }
+ if(group.texture.loaded) {
+ group.texture.context.drawImage(group.texture.texture, // Source Image
+ this._sx, // Source X (location within the source image)
+ this._sy, // Source Y
+ this._sw, // Source Width
+ this._sh, // Source Height
+ this._dx, // Destination X (where on the canvas it'll be drawn)
+ this._dy, // Destination Y
+ this._dw, // Destination Width (always same as Source Width unless scaled)
+ this._dh);
+ // Destination Height (always same as Source Height unless scaled)
+ }
+ return true;
+ };
+ GroupRenderer.prototype.postRender = function (camera, group) {
+ if(group.modified || group.texture.globalCompositeOperation) {
+ group.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ group.texture.context.globalAlpha = this._ga;
+ }
+ };
+ return GroupRenderer;
+ })();
+ Canvas.GroupRenderer = GroupRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/canvas/GroupRenderer.ts b/TS Source/renderers/canvas/GroupRenderer.ts
similarity index 100%
rename from Phaser/renderers/canvas/GroupRenderer.ts
rename to TS Source/renderers/canvas/GroupRenderer.ts
diff --git a/TS Source/renderers/canvas/ScrollZoneRenderer.js b/TS Source/renderers/canvas/ScrollZoneRenderer.js
new file mode 100644
index 00000000..c31cb6c2
--- /dev/null
+++ b/TS Source/renderers/canvas/ScrollZoneRenderer.js
@@ -0,0 +1,121 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Canvas) {
+ var ScrollZoneRenderer = (function () {
+ function ScrollZoneRenderer(game) {
+ // Local rendering related temp vars to help avoid gc spikes through constant var creation
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ ScrollZoneRenderer.prototype.inCamera = /**
+ * Check whether this object is visible in a specific camera Rectangle.
+ * @param camera {Rectangle} The Rectangle you want to check.
+ * @return {bool} Return true if bounds of this sprite intersects the given Rectangle, otherwise return false.
+ */
+ function (camera, scrollZone) {
+ // Object fixed in place regardless of the camera scrolling? Then it's always visible
+ if(scrollZone.transform.scrollFactor.equals(0)) {
+ return true;
+ }
+ //return RectangleUtils.intersects(sprite.cameraView, camera.screenView);
+ return true;
+ };
+ ScrollZoneRenderer.prototype.render = function (camera, scrollZone) {
+ if(scrollZone.transform.scale.x == 0 || scrollZone.transform.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false) {
+ return false;
+ }
+ // Reset our temp vars
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = scrollZone.width;
+ this._sh = scrollZone.height;
+ this._fx = scrollZone.transform.scale.x;
+ this._fy = scrollZone.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = (camera.screenView.x * scrollZone.transform.scrollFactor.x) + scrollZone.x - (camera.worldView.x * scrollZone.transform.scrollFactor.x);
+ this._dy = (camera.screenView.y * scrollZone.transform.scrollFactor.y) + scrollZone.y - (camera.worldView.y * scrollZone.transform.scrollFactor.y);
+ this._dw = scrollZone.width;
+ this._dh = scrollZone.height;
+ // Alpha
+ if(scrollZone.texture.alpha !== 1) {
+ this._ga = scrollZone.texture.context.globalAlpha;
+ scrollZone.texture.context.globalAlpha = scrollZone.texture.alpha;
+ }
+ // Sprite Flip X
+ if(scrollZone.texture.flippedX) {
+ this._fx = -scrollZone.transform.scale.x;
+ }
+ // Sprite Flip Y
+ if(scrollZone.texture.flippedY) {
+ this._fy = -scrollZone.transform.scale.y;
+ }
+ // Rotation and Flipped
+ if(scrollZone.modified) {
+ if(scrollZone.texture.renderRotation == true && (scrollZone.rotation !== 0 || scrollZone.transform.rotationOffset !== 0)) {
+ this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
+ this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
+ }
+ scrollZone.texture.context.save();
+ scrollZone.texture.context.setTransform(this._cos * this._fx, // scale x
+ (this._sin * this._fx) + scrollZone.transform.skew.x, // skew x
+ -(this._sin * this._fy) + scrollZone.transform.skew.y, // skew y
+ this._cos * this._fy, // scale y
+ this._dx, // translate x
+ this._dy);
+ // translate y
+ this._dx = -scrollZone.transform.origin.x;
+ this._dy = -scrollZone.transform.origin.y;
+ } else {
+ if(!scrollZone.transform.origin.equals(0)) {
+ this._dx -= scrollZone.transform.origin.x;
+ this._dy -= scrollZone.transform.origin.y;
+ }
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ for(var i = 0; i < scrollZone.regions.length; i++) {
+ if(scrollZone.texture.isDynamic) {
+ scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
+ } else {
+ scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
+ }
+ }
+ if(scrollZone.modified) {
+ scrollZone.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ scrollZone.texture.context.globalAlpha = this._ga;
+ }
+ this.game.renderer.renderCount++;
+ return true;
+ };
+ return ScrollZoneRenderer;
+ })();
+ Canvas.ScrollZoneRenderer = ScrollZoneRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/canvas/ScrollZoneRenderer.ts b/TS Source/renderers/canvas/ScrollZoneRenderer.ts
similarity index 100%
rename from Phaser/renderers/canvas/ScrollZoneRenderer.ts
rename to TS Source/renderers/canvas/ScrollZoneRenderer.ts
diff --git a/TS Source/renderers/canvas/SpriteRenderer.js b/TS Source/renderers/canvas/SpriteRenderer.js
new file mode 100644
index 00000000..3c88615b
--- /dev/null
+++ b/TS Source/renderers/canvas/SpriteRenderer.js
@@ -0,0 +1,147 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Canvas) {
+ var SpriteRenderer = (function () {
+ function SpriteRenderer(game) {
+ // Local rendering related temp vars to help avoid gc spikes through constant var creation
+ //private _c: number = 0;
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this.game = game;
+ }
+ SpriteRenderer.prototype.inCamera = /**
+ * Check whether this object is visible in a specific camera Rectangle.
+ * @param camera {Rectangle} The Rectangle you want to check.
+ * @return {bool} Return true if bounds of this sprite intersects the given Rectangle, otherwise return false.
+ */
+ function (camera, sprite) {
+ // Object fixed in place regardless of the camera scrolling? Then it's always visible
+ if(sprite.transform.scrollFactor.equals(0)) {
+ return true;
+ }
+ return Phaser.RectangleUtils.intersects(sprite.cameraView, camera.screenView);
+ //return true;
+ };
+ SpriteRenderer.prototype.render = /**
+ * Render this sprite to specific camera. Called by game loop after update().
+ * @param camera {Camera} Camera this sprite will be rendered to.
+ * @return {bool} Return false if not rendered, otherwise return true.
+ */
+ function (camera, sprite) {
+ Phaser.SpriteUtils.updateCameraView(camera, sprite);
+ if(sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
+ return false;
+ }
+ // Reset our temp vars
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = sprite.texture.width;
+ this._sh = sprite.texture.height;
+ //this._dx = camera.screenView.x + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
+ //this._dy = camera.screenView.y + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
+ this._dx = sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
+ this._dy = sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
+ this._dw = sprite.texture.width;
+ this._dh = sprite.texture.height;
+ if(sprite.animations.currentFrame !== null) {
+ this._sx = sprite.animations.currentFrame.x;
+ this._sy = sprite.animations.currentFrame.y;
+ if(sprite.animations.currentFrame.trimmed) {
+ this._dx += sprite.animations.currentFrame.spriteSourceSizeX;
+ this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
+ this._sw = sprite.animations.currentFrame.spriteSourceSizeW;
+ this._sh = sprite.animations.currentFrame.spriteSourceSizeH;
+ this._dw = sprite.animations.currentFrame.spriteSourceSizeW;
+ this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
+ }
+ }
+ if(sprite.modified) {
+ camera.texture.context.save();
+ camera.texture.context.setTransform(sprite.transform.local.data[0], // scale x
+ sprite.transform.local.data[3], // skew x
+ sprite.transform.local.data[1], // skew y
+ sprite.transform.local.data[4], // scale y
+ this._dx, // translate x
+ this._dy);
+ // translate y
+ this._dx = sprite.transform.origin.x * -this._dw;
+ this._dy = sprite.transform.origin.y * -this._dh;
+ } else {
+ this._dx -= (this._dw * sprite.transform.origin.x);
+ this._dy -= (this._dh * sprite.transform.origin.y);
+ }
+ if(sprite.crop) {
+ this._sx += sprite.crop.x * sprite.transform.scale.x;
+ this._sy += sprite.crop.y * sprite.transform.scale.y;
+ this._sw = sprite.crop.width * sprite.transform.scale.x;
+ this._sh = sprite.crop.height * sprite.transform.scale.y;
+ this._dx += sprite.crop.x * sprite.transform.scale.x;
+ this._dy += sprite.crop.y * sprite.transform.scale.y;
+ this._dw = sprite.crop.width * sprite.transform.scale.x;
+ this._dh = sprite.crop.height * sprite.transform.scale.y;
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
+ return false;
+ }
+ // Global Composite Ops
+ if(sprite.texture.globalCompositeOperation) {
+ camera.texture.context.save();
+ camera.texture.context.globalCompositeOperation = sprite.texture.globalCompositeOperation;
+ }
+ // Alpha
+ if(sprite.texture.alpha !== 1 && camera.texture.context.globalAlpha != sprite.texture.alpha) {
+ this._ga = sprite.texture.context.globalAlpha;
+ camera.texture.context.globalAlpha = sprite.texture.alpha;
+ }
+ if(sprite.texture.opaque) {
+ camera.texture.context.fillStyle = sprite.texture.backgroundColor;
+ camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
+ }
+ if(sprite.texture.loaded) {
+ camera.texture.context.drawImage(sprite.texture.texture, // Source Image
+ this._sx, // Source X (location within the source image)
+ this._sy, // Source Y
+ this._sw, // Source Width
+ this._sh, // Source Height
+ this._dx, // Destination X (where on the canvas it'll be drawn)
+ this._dy, // Destination Y
+ this._dw, // Destination Width (always same as Source Width unless scaled)
+ this._dh);
+ // Destination Height (always same as Source Height unless scaled)
+ }
+ if(sprite.modified || sprite.texture.globalCompositeOperation) {
+ camera.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ camera.texture.context.globalAlpha = this._ga;
+ }
+ sprite.renderOrderID = this.game.renderer.renderCount;
+ this.game.renderer.renderCount++;
+ return true;
+ };
+ return SpriteRenderer;
+ })();
+ Canvas.SpriteRenderer = SpriteRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/canvas/SpriteRenderer.ts b/TS Source/renderers/canvas/SpriteRenderer.ts
similarity index 99%
rename from Phaser/renderers/canvas/SpriteRenderer.ts
rename to TS Source/renderers/canvas/SpriteRenderer.ts
index 53b43325..aa65f5bd 100644
--- a/Phaser/renderers/canvas/SpriteRenderer.ts
+++ b/TS Source/renderers/canvas/SpriteRenderer.ts
@@ -39,7 +39,6 @@ module Phaser.Renderer.Canvas {
}
return RectangleUtils.intersects(sprite.cameraView, camera.screenView);
- //return true;
}
diff --git a/TS Source/renderers/canvas/TilemapRenderer.js b/TS Source/renderers/canvas/TilemapRenderer.js
new file mode 100644
index 00000000..99119090
--- /dev/null
+++ b/TS Source/renderers/canvas/TilemapRenderer.js
@@ -0,0 +1,100 @@
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ ///
+ (function (Canvas) {
+ var TilemapRenderer = (function () {
+ function TilemapRenderer(game) {
+ // Local rendering related temp vars to help avoid gc spikes through constant var creation
+ this._ga = 1;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._tx = 0;
+ this._ty = 0;
+ this._tl = 0;
+ this._maxX = 0;
+ this._maxY = 0;
+ this._startX = 0;
+ this._startY = 0;
+ this.game = game;
+ }
+ TilemapRenderer.prototype.render = /**
+ * 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
+ this._tl = tilemap.layers.length;
+ for(var i = 0; i < this._tl; i++) {
+ if(tilemap.layers[i].visible == false || tilemap.layers[i].alpha < 0.1) {
+ continue;
+ }
+ var layer = tilemap.layers[i];
+ // 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 TilemapRenderer;
+ })();
+ Canvas.TilemapRenderer = TilemapRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/renderers/canvas/TilemapRenderer.ts b/TS Source/renderers/canvas/TilemapRenderer.ts
similarity index 100%
rename from Phaser/renderers/canvas/TilemapRenderer.ts
rename to TS Source/renderers/canvas/TilemapRenderer.ts
diff --git a/TS Source/sound/Sound.js b/TS Source/sound/Sound.js
new file mode 100644
index 00000000..51dc4c48
--- /dev/null
+++ b/TS Source/sound/Sound.js
@@ -0,0 +1,374 @@
+///
+/**
+* Phaser - Sound
+*
+* A Sound file, used by the Game.SoundManager for playback.
+*/
+var Phaser;
+(function (Phaser) {
+ var Sound = (function () {
+ /**
+ * Sound constructor
+ * @param [volume] {number} volume of this sound when playing.
+ * @param [loop] {bool} loop this sound when playing? (Default to false)
+ */
+ function Sound(game, key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ /**
+ * Reference to AudioContext instance.
+ */
+ this.context = null;
+ /**
+ * Decoded data buffer / Audio tag.
+ */
+ this._buffer = null;
+ this._muted = false;
+ this.usingWebAudio = false;
+ this.usingAudioTag = false;
+ this.name = '';
+ this.autoplay = false;
+ this.totalDuration = 0;
+ this.startTime = 0;
+ this.currentTime = 0;
+ this.duration = 0;
+ this.stopTime = 0;
+ this.paused = false;
+ this.loop = false;
+ this.isPlaying = false;
+ this.currentMarker = '';
+ this.pendingPlayback = false;
+ this.override = false;
+ this.game = game;
+ this.usingWebAudio = this.game.sound.usingWebAudio;
+ this.usingAudioTag = this.game.sound.usingAudioTag;
+ this.key = key;
+ if(this.usingWebAudio) {
+ this.context = this.game.sound.context;
+ this.masterGainNode = this.game.sound.masterGain;
+ if(typeof this.context.createGain === 'undefined') {
+ this.gainNode = this.context.createGainNode();
+ } else {
+ this.gainNode = this.context.createGain();
+ }
+ this.gainNode.gain.value = volume * this.game.sound.volume;
+ this.gainNode.connect(this.masterGainNode);
+ } else {
+ if(this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false) {
+ this._sound = this.game.cache.getSoundData(key);
+ this.totalDuration = this._sound.duration;
+ } else {
+ this.game.cache.onSoundUnlock.add(this.soundHasUnlocked, this);
+ }
+ }
+ this._volume = volume;
+ this.loop = loop;
+ this.markers = {
+ };
+ this.onDecoded = new Phaser.Signal();
+ this.onPlay = new Phaser.Signal();
+ this.onPause = new Phaser.Signal();
+ this.onResume = new Phaser.Signal();
+ this.onLoop = new Phaser.Signal();
+ this.onStop = new Phaser.Signal();
+ this.onMute = new Phaser.Signal();
+ this.onMarkerComplete = new Phaser.Signal();
+ }
+ Sound.prototype.soundHasUnlocked = function (key) {
+ if(key == this.key) {
+ this._sound = this.game.cache.getSoundData(this.key);
+ this.totalDuration = this._sound.duration;
+ //console.log('sound has unlocked', this._sound);
+ }
+ };
+ Object.defineProperty(Sound.prototype, "isDecoding", {
+ get: function () {
+ return this.game.cache.getSound(this.key).isDecoding;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sound.prototype, "isDecoded", {
+ get: function () {
+ return this.game.cache.isSoundDecoded(this.key);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sound.prototype.addMarker = function (name, start, stop, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.markers[name] = {
+ name: name,
+ start: start,
+ stop: stop,
+ volume: volume,
+ duration: stop - start,
+ loop: loop
+ };
+ };
+ Sound.prototype.removeMarker = function (name) {
+ delete this.markers[name];
+ };
+ Sound.prototype.update = function () {
+ if(this.pendingPlayback && this.game.cache.isSoundReady(this.key)) {
+ this.pendingPlayback = false;
+ this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
+ }
+ if(this.isPlaying) {
+ this.currentTime = this.game.time.now - this.startTime;
+ if(this.currentTime >= this.duration) {
+ //console.log(this.currentMarker, 'has hit duration');
+ if(this.usingWebAudio) {
+ if(this.loop) {
+ //console.log('loop1');
+ // won't work with markers, needs to reset the position
+ this.onLoop.dispatch(this);
+ if(this.currentMarker == '') {
+ //console.log('loop2');
+ this.currentTime = 0;
+ this.startTime = this.game.time.now;
+ } else {
+ //console.log('loop3');
+ this.play(this.currentMarker, 0, this.volume, true, true);
+ }
+ } else {
+ //console.log('stopping, no loop for marker');
+ this.stop();
+ }
+ } else {
+ if(this.loop) {
+ this.onLoop.dispatch(this);
+ this.play(this.currentMarker, 0, this.volume, true, true);
+ } else {
+ this.stop();
+ }
+ }
+ }
+ }
+ };
+ Sound.prototype.play = /**
+ * Play this sound, or a marked section of it.
+ * @param marker {string} Assets key of the sound you want to play.
+ * @param [volume] {number} volume of the sound you want to play.
+ * @param [loop] {bool} loop when it finished playing? (Default to false)
+ * @return {Sound} The playing sound object.
+ */
+ function (marker, position, volume, loop, forceRestart) {
+ if (typeof marker === "undefined") { marker = ''; }
+ if (typeof position === "undefined") { position = 0; }
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof forceRestart === "undefined") { forceRestart = false; }
+ //console.log('play', marker, 'current is', this.currentMarker);
+ if(this.isPlaying == true && forceRestart == false && this.override == false) {
+ // Use Restart instead
+ return;
+ }
+ if(this.isPlaying && this.override) {
+ //console.log('asked to play', marker, 'but already playing', this.currentMarker);
+ if(this.usingWebAudio) {
+ if(typeof this._sound.stop === 'undefined') {
+ this._sound.noteOff(0);
+ } else {
+ this._sound.stop(0);
+ }
+ } else if(this.usingAudioTag) {
+ this._sound.pause();
+ this._sound.currentTime = 0;
+ }
+ }
+ this.currentMarker = marker;
+ if(marker !== '' && this.markers[marker]) {
+ this.position = this.markers[marker].start;
+ this.volume = this.markers[marker].volume;
+ this.loop = this.markers[marker].loop;
+ this.duration = this.markers[marker].duration * 1000;
+ //console.log('marker info loaded', this.loop, this.duration);
+ this._tempMarker = marker;
+ this._tempPosition = this.position;
+ this._tempVolume = this.volume;
+ this._tempLoop = this.loop;
+ } else {
+ this.position = position;
+ this.volume = volume;
+ this.loop = loop;
+ this.duration = 0;
+ this._tempMarker = marker;
+ this._tempPosition = position;
+ this._tempVolume = volume;
+ this._tempLoop = loop;
+ }
+ if(this.usingWebAudio) {
+ // Does the sound need decoding?
+ if(this.game.cache.isSoundDecoded(this.key)) {
+ // Do we need to do this every time we play? How about just if the buffer is empty?
+ if(this._buffer == null) {
+ this._buffer = this.game.cache.getSoundData(this.key);
+ }
+ //if (this._sound == null)
+ //{
+ this._sound = this.context.createBufferSource();
+ this._sound.buffer = this._buffer;
+ this._sound.connect(this.gainNode);
+ this.totalDuration = this._sound.buffer.duration;
+ //}
+ if(this.duration == 0) {
+ this.duration = this.totalDuration * 1000;
+ }
+ if(this.loop && marker == '') {
+ this._sound.loop = true;
+ }
+ // Useful to cache this somewhere perhaps?
+ if(typeof this._sound.start === 'undefined') {
+ this._sound.noteGrainOn(0, this.position, this.duration / 1000);
+ //this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
+ } else {
+ this._sound.start(0, this.position, this.duration / 1000);
+ }
+ this.isPlaying = true;
+ this.startTime = this.game.time.now;
+ this.currentTime = 0;
+ this.stopTime = this.startTime + this.duration;
+ this.onPlay.dispatch(this);
+ //console.log('playing, start', this.startTime, 'stop');
+ } else {
+ this.pendingPlayback = true;
+ if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false) {
+ this.game.sound.decode(this.key, this);
+ }
+ }
+ } else {
+ //console.log('Sound play Audio');
+ if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).locked) {
+ //console.log('tried playing locked sound, pending set, reload started');
+ this.game.cache.reloadSound(this.key);
+ this.pendingPlayback = true;
+ } else {
+ //console.log('sound not locked, state?', this._sound.readyState);
+ if(this._sound && this._sound.readyState == 4) {
+ if(this.duration == 0) {
+ this.duration = this.totalDuration * 1000;
+ }
+ //console.log('playing', this._sound);
+ this._sound.currentTime = this.position;
+ this._sound.muted = this._muted;
+ if(this._muted) {
+ this._sound.volume = 0;
+ } else {
+ this._sound.volume = this._volume;
+ }
+ this._sound.play();
+ this.isPlaying = true;
+ this.startTime = this.game.time.now;
+ this.currentTime = 0;
+ this.stopTime = this.startTime + this.duration;
+ this.onPlay.dispatch(this);
+ } else {
+ this.pendingPlayback = true;
+ }
+ }
+ }
+ };
+ Sound.prototype.restart = function (marker, position, volume, loop) {
+ if (typeof marker === "undefined") { marker = ''; }
+ if (typeof position === "undefined") { position = 0; }
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.play(marker, position, volume, loop, true);
+ };
+ Sound.prototype.pause = function () {
+ if(this.isPlaying && this._sound) {
+ this.stop();
+ this.isPlaying = false;
+ this.paused = true;
+ this.onPause.dispatch(this);
+ }
+ };
+ Sound.prototype.resume = function () {
+ if(this.paused && this._sound) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.start === 'undefined') {
+ this._sound.noteGrainOn(0, this.position, this.duration);
+ //this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
+ } else {
+ this._sound.start(0, this.position, this.duration);
+ }
+ } else {
+ this._sound.play();
+ }
+ this.isPlaying = true;
+ this.paused = false;
+ this.onResume.dispatch(this);
+ }
+ };
+ Sound.prototype.stop = /**
+ * Stop playing this sound.
+ */
+ function () {
+ if(this.isPlaying && this._sound) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.stop === 'undefined') {
+ this._sound.noteOff(0);
+ } else {
+ this._sound.stop(0);
+ }
+ } else if(this.usingAudioTag) {
+ this._sound.pause();
+ this._sound.currentTime = 0;
+ }
+ }
+ this.isPlaying = false;
+ var prevMarker = this.currentMarker;
+ this.currentMarker = '';
+ this.onStop.dispatch(this, prevMarker);
+ };
+ Object.defineProperty(Sound.prototype, "mute", {
+ get: /**
+ * Mute sounds.
+ */
+ function () {
+ return this._muted;
+ },
+ set: function (value) {
+ if(value) {
+ this._muted = true;
+ if(this.usingWebAudio) {
+ this._muteVolume = this.gainNode.gain.value;
+ this.gainNode.gain.value = 0;
+ } else if(this.usingAudioTag && this._sound) {
+ this._muteVolume = this._sound.volume;
+ this._sound.volume = 0;
+ }
+ } else {
+ this._muted = false;
+ if(this.usingWebAudio) {
+ this.gainNode.gain.value = this._muteVolume;
+ } else if(this.usingAudioTag && this._sound) {
+ this._sound.volume = this._muteVolume;
+ }
+ }
+ this.onMute.dispatch(this);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sound.prototype, "volume", {
+ get: function () {
+ return this._volume;
+ },
+ set: function (value) {
+ this._volume = value;
+ if(this.usingWebAudio) {
+ this.gainNode.gain.value = value;
+ } else if(this.usingAudioTag && this._sound) {
+ this._sound.volume = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Sound;
+ })();
+ Phaser.Sound = Sound;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/sound/Sound.ts b/TS Source/sound/Sound.ts
similarity index 100%
rename from Phaser/sound/Sound.ts
rename to TS Source/sound/Sound.ts
diff --git a/TS Source/sound/SoundManager.js b/TS Source/sound/SoundManager.js
new file mode 100644
index 00000000..39f5d647
--- /dev/null
+++ b/TS Source/sound/SoundManager.js
@@ -0,0 +1,238 @@
+///
+/**
+* Phaser - SoundManager
+*
+*/
+var Phaser;
+(function (Phaser) {
+ var SoundManager = (function () {
+ /**
+ * SoundManager constructor
+ * Create a new SoundManager.
+ */
+ function SoundManager(game) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = false;
+ this.noAudio = false;
+ /**
+ * Reference to AudioContext instance.
+ */
+ this.context = null;
+ this._muted = false;
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.onSoundDecode = new Phaser.Signal();
+ this.game = game;
+ this._volume = 1;
+ this._muted = false;
+ this._sounds = [];
+ if(this.game.device.iOS && this.game.device.webAudio == false) {
+ this.channels = 1;
+ }
+ if(this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) {
+ this.game.input.touch.callbackContext = this;
+ this.game.input.touch.touchStartCallback = this.unlock;
+ this.game.input.mouse.callbackContext = this;
+ this.game.input.mouse.mouseDownCallback = this.unlock;
+ this.touchLocked = true;
+ } else {
+ // What about iOS5?
+ this.touchLocked = false;
+ }
+ if(window['PhaserGlobal']) {
+ // Check to see if all audio playback is disabled (i.e. handled by a 3rd party class)
+ if(window['PhaserGlobal'].disableAudio == true) {
+ this.usingWebAudio = false;
+ this.noAudio = true;
+ return;
+ }
+ // Check if the Web Audio API is disabled (for testing Audio Tag playback during development)
+ if(window['PhaserGlobal'].disableWebAudio == true) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = true;
+ this.noAudio = false;
+ return;
+ }
+ }
+ this.usingWebAudio = true;
+ this.noAudio = false;
+ if(!!window['AudioContext']) {
+ this.context = new window['AudioContext']();
+ } else if(!!window['webkitAudioContext']) {
+ this.context = new window['webkitAudioContext']();
+ } else if(!!window['Audio']) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = true;
+ } else {
+ this.usingWebAudio = false;
+ this.noAudio = true;
+ }
+ if(this.context !== null) {
+ if(typeof this.context.createGain === 'undefined') {
+ this.masterGain = this.context.createGainNode();
+ } else {
+ this.masterGain = this.context.createGain();
+ }
+ this.masterGain.gain.value = 1;
+ this.masterGain.connect(this.context.destination);
+ }
+ }
+ SoundManager.prototype.unlock = function () {
+ if(this.touchLocked == false) {
+ return;
+ }
+ //console.log('SoundManager touch unlocked');
+ if(this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false)) {
+ // Create empty buffer and play it
+ var buffer = this.context.createBuffer(1, 1, 22050);
+ this._unlockSource = this.context.createBufferSource();
+ this._unlockSource.buffer = buffer;
+ this._unlockSource.connect(this.context.destination);
+ this._unlockSource.noteOn(0);
+ } else {
+ // Create an Audio tag?
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.game.input.touch.callbackContext = null;
+ this.game.input.touch.touchStartCallback = null;
+ this.game.input.mouse.callbackContext = null;
+ this.game.input.mouse.mouseDownCallback = null;
+ }
+ };
+ Object.defineProperty(SoundManager.prototype, "mute", {
+ get: /**
+ * A global audio mute toggle.
+ */
+ function () {
+ return this._muted;
+ },
+ set: function (value) {
+ if(value) {
+ if(this._muted) {
+ return;
+ }
+ this._muted = true;
+ if(this.usingWebAudio) {
+ this._muteVolume = this.masterGain.gain.value;
+ this.masterGain.gain.value = 0;
+ }
+ // Loop through sounds
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].mute = true;
+ }
+ }
+ } else {
+ if(this._muted == false) {
+ return;
+ }
+ this._muted = false;
+ if(this.usingWebAudio) {
+ this.masterGain.gain.value = this._muteVolume;
+ }
+ // Loop through sounds
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].mute = false;
+ }
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(SoundManager.prototype, "volume", {
+ get: function () {
+ if(this.usingWebAudio) {
+ return this.masterGain.gain.value;
+ } else {
+ return this._volume;
+ }
+ },
+ set: /**
+ * The global audio volume. A value between 0 (silence) and 1 (full volume)
+ */
+ function (value) {
+ value = this.game.math.clamp(value, 1, 0);
+ this._volume = value;
+ if(this.usingWebAudio) {
+ this.masterGain.gain.value = value;
+ }
+ // Loop through the sound cache and change the volume of all html audio tags
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].volume = this._sounds[i].volume * value;
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ SoundManager.prototype.stopAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].stop();
+ }
+ }
+ };
+ SoundManager.prototype.pauseAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].pause();
+ }
+ }
+ };
+ SoundManager.prototype.resumeAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].resume();
+ }
+ }
+ };
+ SoundManager.prototype.decode = /**
+ * Decode a sound with its assets key.
+ * @param key {string} Assets key of the sound to be decoded.
+ * @param [sound] {Sound} its bufer will be set to decoded data.
+ */
+ function (key, sound) {
+ if (typeof sound === "undefined") { sound = null; }
+ var soundData = this.game.cache.getSoundData(key);
+ if(soundData) {
+ if(this.game.cache.isSoundDecoded(key) === false) {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+ var that = this;
+ this.context.decodeAudioData(soundData, function (buffer) {
+ that.game.cache.decodedSound(key, buffer);
+ if(sound) {
+ that.onSoundDecode.dispatch(sound);
+ }
+ });
+ }
+ }
+ };
+ SoundManager.prototype.update = function () {
+ if(this.touchLocked) {
+ if(this.game.device.webAudio && this._unlockSource !== null) {
+ if((this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.game.input.touch.callbackContext = null;
+ this.game.input.touch.touchStartCallback = null;
+ }
+ }
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ this._sounds[i].update();
+ }
+ };
+ SoundManager.prototype.add = function (key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ var sound = new Phaser.Sound(this.game, key, volume, loop);
+ this._sounds.push(sound);
+ return sound;
+ };
+ return SoundManager;
+ })();
+ Phaser.SoundManager = SoundManager;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/sound/SoundManager.ts b/TS Source/sound/SoundManager.ts
similarity index 100%
rename from Phaser/sound/SoundManager.ts
rename to TS Source/sound/SoundManager.ts
diff --git a/TS Source/system/Device.js b/TS Source/system/Device.js
new file mode 100644
index 00000000..8648b004
--- /dev/null
+++ b/TS Source/system/Device.js
@@ -0,0 +1,402 @@
+///
+/**
+* Phaser - Device
+*
+* Detects device support capabilities. Using some elements from System.js by MrDoob and Modernizr
+* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/audio.js
+*/
+var Phaser;
+(function (Phaser) {
+ var Device = (function () {
+ /**
+ * Device constructor
+ */
+ function Device() {
+ /**
+ * An optional 'fix' for the horrendous Android stock browser bug
+ * https://code.google.com/p/android/issues/detail?id=39247
+ * @type {bool}
+ */
+ this.patchAndroidClearRectBug = false;
+ // Operating System
+ /**
+ * Is running desktop?
+ * @type {bool}
+ */
+ this.desktop = false;
+ /**
+ * Is running on iOS?
+ * @type {bool}
+ */
+ this.iOS = false;
+ /**
+ * Is running on android?
+ * @type {bool}
+ */
+ this.android = false;
+ /**
+ * Is running on chromeOS?
+ * @type {bool}
+ */
+ this.chromeOS = false;
+ /**
+ * Is running on linux?
+ * @type {bool}
+ */
+ this.linux = false;
+ /**
+ * Is running on maxOS?
+ * @type {bool}
+ */
+ this.macOS = false;
+ /**
+ * Is running on windows?
+ * @type {bool}
+ */
+ this.windows = false;
+ // Features
+ /**
+ * Is canvas available?
+ * @type {bool}
+ */
+ this.canvas = false;
+ /**
+ * Is file available?
+ * @type {bool}
+ */
+ this.file = false;
+ /**
+ * Is fileSystem available?
+ * @type {bool}
+ */
+ this.fileSystem = false;
+ /**
+ * Is localStorage available?
+ * @type {bool}
+ */
+ this.localStorage = false;
+ /**
+ * Is webGL available?
+ * @type {bool}
+ */
+ this.webGL = false;
+ /**
+ * Is worker available?
+ * @type {bool}
+ */
+ this.worker = false;
+ /**
+ * Is touch available?
+ * @type {bool}
+ */
+ this.touch = false;
+ /**
+ * Is mspointer available?
+ * @type {bool}
+ */
+ this.mspointer = false;
+ /**
+ * Is css3D available?
+ * @type {bool}
+ */
+ this.css3D = false;
+ // Browser
+ /**
+ * Is running in arora?
+ * @type {bool}
+ */
+ this.arora = false;
+ /**
+ * Is running in chrome?
+ * @type {bool}
+ */
+ this.chrome = false;
+ /**
+ * Is running in epiphany?
+ * @type {bool}
+ */
+ this.epiphany = false;
+ /**
+ * Is running in firefox?
+ * @type {bool}
+ */
+ this.firefox = false;
+ /**
+ * Is running in ie?
+ * @type {bool}
+ */
+ this.ie = false;
+ /**
+ * Version of ie?
+ * @type Number
+ */
+ this.ieVersion = 0;
+ /**
+ * Is running in mobileSafari?
+ * @type {bool}
+ */
+ this.mobileSafari = false;
+ /**
+ * Is running in midori?
+ * @type {bool}
+ */
+ this.midori = false;
+ /**
+ * Is running in opera?
+ * @type {bool}
+ */
+ this.opera = false;
+ /**
+ * Is running in safari?
+ * @type {bool}
+ */
+ this.safari = false;
+ this.webApp = false;
+ // Audio
+ /**
+ * Are Audio tags available?
+ * @type {bool}
+ */
+ this.audioData = false;
+ /**
+ * Is the WebAudio API available?
+ * @type {bool}
+ */
+ this.webAudio = false;
+ /**
+ * Can this device play ogg files?
+ * @type {bool}
+ */
+ this.ogg = false;
+ /**
+ * Can this device play opus files?
+ * @type {bool}
+ */
+ this.opus = false;
+ /**
+ * Can this device play mp3 files?
+ * @type {bool}
+ */
+ this.mp3 = false;
+ /**
+ * Can this device play wav files?
+ * @type {bool}
+ */
+ this.wav = false;
+ /**
+ * Can this device play m4a files?
+ * @type {bool}
+ */
+ this.m4a = false;
+ /**
+ * Can this device play webm files?
+ * @type {bool}
+ */
+ this.webm = false;
+ // Device
+ /**
+ * Is running on iPhone?
+ * @type {bool}
+ */
+ this.iPhone = false;
+ /**
+ * Is running on iPhone4?
+ * @type {bool}
+ */
+ this.iPhone4 = false;
+ /**
+ * Is running on iPad?
+ * @type {bool}
+ */
+ this.iPad = false;
+ /**
+ * PixelRatio of the host device?
+ * @type Number
+ */
+ this.pixelRatio = 0;
+ this._checkAudio();
+ this._checkBrowser();
+ this._checkCSS3D();
+ this._checkDevice();
+ this._checkFeatures();
+ this._checkOS();
+ }
+ Device.prototype._checkOS = /**
+ * Check which OS is game running on.
+ * @private
+ */
+ function () {
+ var ua = navigator.userAgent;
+ if(/Android/.test(ua)) {
+ this.android = true;
+ } else if(/CrOS/.test(ua)) {
+ this.chromeOS = true;
+ } else if(/iP[ao]d|iPhone/i.test(ua)) {
+ this.iOS = true;
+ } else if(/Linux/.test(ua)) {
+ this.linux = true;
+ } else if(/Mac OS/.test(ua)) {
+ this.macOS = true;
+ } else if(/Windows/.test(ua)) {
+ this.windows = true;
+ }
+ if(this.windows || this.macOS || this.linux) {
+ this.desktop = true;
+ }
+ };
+ Device.prototype._checkFeatures = /**
+ * Check HTML5 features of the host environment.
+ * @private
+ */
+ function () {
+ this.canvas = !!window['CanvasRenderingContext2D'];
+ try {
+ this.localStorage = !!localStorage.getItem;
+ } catch (error) {
+ this.localStorage = false;
+ }
+ this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
+ this.fileSystem = !!window['requestFileSystem'];
+ this.webGL = !!window['WebGLRenderingContext'];
+ this.worker = !!window['Worker'];
+ if('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
+ this.touch = true;
+ }
+ if(window.navigator.msPointerEnabled) {
+ this.mspointer = true;
+ }
+ };
+ Device.prototype._checkBrowser = /**
+ * Check what browser is game running in.
+ * @private
+ */
+ function () {
+ var ua = navigator.userAgent;
+ if(/Arora/.test(ua)) {
+ this.arora = true;
+ } else if(/Chrome/.test(ua)) {
+ this.chrome = true;
+ } else if(/Epiphany/.test(ua)) {
+ this.epiphany = true;
+ } else if(/Firefox/.test(ua)) {
+ this.firefox = true;
+ } else if(/Mobile Safari/.test(ua)) {
+ this.mobileSafari = true;
+ } else if(/MSIE (\d+\.\d+);/.test(ua)) {
+ this.ie = true;
+ this.ieVersion = parseInt(RegExp.$1);
+ } else if(/Midori/.test(ua)) {
+ this.midori = true;
+ } else if(/Opera/.test(ua)) {
+ this.opera = true;
+ } else if(/Safari/.test(ua)) {
+ this.safari = true;
+ }
+ // WebApp mode in iOS
+ if(navigator['standalone']) {
+ this.webApp = true;
+ }
+ };
+ Device.prototype.canPlayAudio = function (type) {
+ if(type == 'mp3' && this.mp3) {
+ return true;
+ } else if(type == 'ogg' && (this.ogg || this.opus)) {
+ return true;
+ } else if(type == 'm4a' && this.m4a) {
+ return true;
+ } else if(type == 'wav' && this.wav) {
+ return true;
+ } else if(type == 'webm' && this.webm) {
+ return true;
+ }
+ return false;
+ };
+ Device.prototype._checkAudio = /**
+ * Check audio support.
+ * @private
+ */
+ function () {
+ this.audioData = !!(window['Audio']);
+ this.webAudio = !!(window['webkitAudioContext'] || window['AudioContext']);
+ var audioElement = document.createElement('audio');
+ var result = false;
+ try {
+ if(result = !!audioElement.canPlayType) {
+ if(audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
+ this.ogg = true;
+ }
+ if(audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '')) {
+ this.opus = true;
+ }
+ if(audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
+ this.mp3 = true;
+ }
+ // Mimetypes accepted:
+ // developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
+ // bit.ly/iphoneoscodecs
+ if(audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
+ this.wav = true;
+ }
+ if(audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
+ this.m4a = true;
+ }
+ if(audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
+ this.webm = true;
+ }
+ }
+ } catch (e) {
+ }
+ };
+ Device.prototype._checkDevice = /**
+ * Check PixelRatio of devices.
+ * @private
+ */
+ function () {
+ this.pixelRatio = window['devicePixelRatio'] || 1;
+ this.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
+ this.iPhone4 = (this.pixelRatio == 2 && this.iPhone);
+ this.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
+ };
+ Device.prototype._checkCSS3D = /**
+ * Check whether the host environment support 3D CSS.
+ * @private
+ */
+ function () {
+ var el = document.createElement('p');
+ var has3d;
+ var transforms = {
+ 'webkitTransform': '-webkit-transform',
+ 'OTransform': '-o-transform',
+ 'msTransform': '-ms-transform',
+ 'MozTransform': '-moz-transform',
+ 'transform': 'transform'
+ };
+ // Add it to the body to get the computed style.
+ document.body.insertBefore(el, null);
+ for(var t in transforms) {
+ if(el.style[t] !== undefined) {
+ el.style[t] = "translate3d(1px,1px,1px)";
+ has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
+ }
+ }
+ document.body.removeChild(el);
+ this.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
+ };
+ Device.prototype.isConsoleOpen = function () {
+ if(window.console && window.console['firebug']) {
+ return true;
+ }
+ if(window.console) {
+ console.profile();
+ console.profileEnd();
+ if(console.clear) {
+ console.clear();
+ }
+ return console['profiles'].length > 0;
+ }
+ return false;
+ };
+ return Device;
+ })();
+ Phaser.Device = Device;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/system/Device.ts b/TS Source/system/Device.ts
similarity index 100%
rename from Phaser/system/Device.ts
rename to TS Source/system/Device.ts
diff --git a/TS Source/system/RequestAnimationFrame.js b/TS Source/system/RequestAnimationFrame.js
new file mode 100644
index 00000000..ff41756f
--- /dev/null
+++ b/TS Source/system/RequestAnimationFrame.js
@@ -0,0 +1,130 @@
+///
+/**
+* Phaser - RequestAnimationFrame
+*
+* Abstracts away the use of RAF or setTimeOut for the core game update loop. The callback can be re-mapped on the fly.
+*/
+var Phaser;
+(function (Phaser) {
+ var RequestAnimationFrame = (function () {
+ /**
+ * Constructor
+ * @param {Any} callback
+ * @return {RequestAnimationFrame} This object.
+ */
+ function RequestAnimationFrame(game, callback) {
+ /**
+ *
+ * @property _isSetTimeOut
+ * @type bool
+ * @private
+ **/
+ this._isSetTimeOut = false;
+ /**
+ *
+ * @property isRunning
+ * @type bool
+ **/
+ this.isRunning = false;
+ this.game = game;
+ this.callback = callback;
+ var vendors = [
+ 'ms',
+ 'moz',
+ 'webkit',
+ 'o'
+ ];
+ for(var x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
+ window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
+ window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
+ }
+ this.start();
+ }
+ RequestAnimationFrame.prototype.isUsingSetTimeOut = /**
+ *
+ * @method usingSetTimeOut
+ * @return bool
+ **/
+ function () {
+ return this._isSetTimeOut;
+ };
+ RequestAnimationFrame.prototype.isUsingRAF = /**
+ *
+ * @method usingRAF
+ * @return bool
+ **/
+ function () {
+ return this._isSetTimeOut === true;
+ };
+ RequestAnimationFrame.prototype.start = /**
+ * Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
+ * @method start
+ * @param {Any} [callback]
+ **/
+ function (callback) {
+ if (typeof callback === "undefined") { callback = null; }
+ var _this = this;
+ if(callback) {
+ this.callback = callback;
+ }
+ if(!window.requestAnimationFrame) {
+ this._isSetTimeOut = true;
+ this._onLoop = function () {
+ return _this.SetTimeoutUpdate();
+ };
+ this._timeOutID = window.setTimeout(this._onLoop, 0);
+ } else {
+ this._isSetTimeOut = false;
+ this._onLoop = function () {
+ return _this.RAFUpdate(0);
+ };
+ window.requestAnimationFrame(this._onLoop);
+ }
+ this.isRunning = true;
+ };
+ RequestAnimationFrame.prototype.stop = /**
+ * Stops the requestAnimationFrame from running
+ * @method stop
+ **/
+ function () {
+ if(this._isSetTimeOut) {
+ clearTimeout(this._timeOutID);
+ } else {
+ window.cancelAnimationFrame;
+ }
+ this.isRunning = false;
+ };
+ RequestAnimationFrame.prototype.RAFUpdate = /**
+ * The update method for the requestAnimationFrame
+ * @method RAFUpdate
+ **/
+ function (time) {
+ var _this = this;
+ this.game.time.update(time);
+ if(this.callback) {
+ this.callback.call(this.game);
+ }
+ this._onLoop = function (time) {
+ return _this.RAFUpdate(time);
+ };
+ window.requestAnimationFrame(this._onLoop);
+ };
+ RequestAnimationFrame.prototype.SetTimeoutUpdate = /**
+ * The update method for the setTimeout
+ * @method SetTimeoutUpdate
+ **/
+ function () {
+ var _this = this;
+ this.game.time.update(Date.now());
+ this._onLoop = function () {
+ return _this.SetTimeoutUpdate();
+ };
+ this._timeOutID = window.setTimeout(this._onLoop, 16);
+ if(this.callback) {
+ this.callback.call(this.game);
+ }
+ };
+ return RequestAnimationFrame;
+ })();
+ Phaser.RequestAnimationFrame = RequestAnimationFrame;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/system/RequestAnimationFrame.ts b/TS Source/system/RequestAnimationFrame.ts
similarity index 100%
rename from Phaser/system/RequestAnimationFrame.ts
rename to TS Source/system/RequestAnimationFrame.ts
diff --git a/TS Source/system/StageScaleMode.js b/TS Source/system/StageScaleMode.js
new file mode 100644
index 00000000..2155fb69
--- /dev/null
+++ b/TS Source/system/StageScaleMode.js
@@ -0,0 +1,344 @@
+///
+/**
+* Phaser - StageScaleMode
+*
+* This class controls the scaling of your game. On mobile devices it will also remove the URL bar and allow
+* you to maintain proportion and aspect ratio.
+* The resizing method is based on a technique taken from Viewporter v2.0 by Zynga Inc. http://github.com/zynga/viewporter
+*/
+var Phaser;
+(function (Phaser) {
+ var StageScaleMode = (function () {
+ /**
+ * StageScaleMode constructor
+ */
+ function StageScaleMode(game, width, height) {
+ var _this = this;
+ /**
+ * Stage height when start the game.
+ * @type {number}
+ */
+ this._startHeight = 0;
+ /**
+ * If the game should be forced to use Landscape mode, this is set to true by Game.Stage
+ * @type {bool}
+ */
+ this.forceLandscape = false;
+ /**
+ * If the game should be forced to use Portrait mode, this is set to true by Game.Stage
+ * @type {bool}
+ */
+ this.forcePortrait = false;
+ /**
+ * If the game should be forced to use a specific orientation and the device currently isn't in that orientation this is set to true.
+ * @type {bool}
+ */
+ this.incorrectOrientation = false;
+ /**
+ * If you wish to align your game in the middle of the page then you can set this value to true.
+ * It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
+ * It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
+ * @type {bool}
+ */
+ this.pageAlignHorizontally = false;
+ /**
+ * If you wish to align your game in the middle of the page then you can set this value to true.
+ * It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
+ * It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
+ * @type {bool}
+ */
+ this.pageAlignVeritcally = false;
+ /**
+ * Minimum width the canvas should be scaled to (in pixels)
+ * @type {number}
+ */
+ this.minWidth = null;
+ /**
+ * Maximum width the canvas should be scaled to (in pixels).
+ * If null it will scale to whatever width the browser can handle.
+ * @type {number}
+ */
+ this.maxWidth = null;
+ /**
+ * Minimum height the canvas should be scaled to (in pixels)
+ * @type {number}
+ */
+ this.minHeight = null;
+ /**
+ * Maximum height the canvas should be scaled to (in pixels).
+ * If null it will scale to whatever height the browser can handle.
+ * @type {number}
+ */
+ this.maxHeight = null;
+ /**
+ * Width of the stage after calculation.
+ * @type {number}
+ */
+ this.width = 0;
+ /**
+ * Height of the stage after calculation.
+ * @type {number}
+ */
+ this.height = 0;
+ /**
+ * The maximum number of times it will try to resize the canvas to fill the browser (default is 5)
+ * @type {number}
+ */
+ this.maxIterations = 5;
+ this.game = game;
+ this.enterLandscape = new Phaser.Signal();
+ this.enterPortrait = new Phaser.Signal();
+ if(window['orientation']) {
+ this.orientation = window['orientation'];
+ } else {
+ if(window.outerWidth > window.outerHeight) {
+ this.orientation = 90;
+ } else {
+ this.orientation = 0;
+ }
+ }
+ this.scaleFactor = new Phaser.Vec2(1, 1);
+ this.aspectRatio = 0;
+ this.minWidth = width;
+ this.minHeight = height;
+ this.maxWidth = width;
+ this.maxHeight = height;
+ window.addEventListener('orientationchange', function (event) {
+ return _this.checkOrientation(event);
+ }, false);
+ window.addEventListener('resize', function (event) {
+ return _this.checkResize(event);
+ }, false);
+ }
+ StageScaleMode.EXACT_FIT = 0;
+ StageScaleMode.NO_SCALE = 1;
+ StageScaleMode.SHOW_ALL = 2;
+ Object.defineProperty(StageScaleMode.prototype, "isFullScreen", {
+ get: // Full Screen API calls
+ function () {
+ if(document['fullscreenElement'] === null || document['mozFullScreenElement'] === null || document['webkitFullscreenElement'] === null) {
+ return false;
+ }
+ return true;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ StageScaleMode.prototype.startFullScreen = function () {
+ if(this.isFullScreen) {
+ return;
+ }
+ var element = this.game.stage.canvas;
+ if(element['requestFullScreen']) {
+ element['requestFullScreen']();
+ } else if(element['mozRequestFullScreen']) {
+ element['mozRequestFullScreen']();
+ } else if(element['webkitRequestFullScreen']) {
+ element['webkitRequestFullScreen']();
+ }
+ };
+ StageScaleMode.prototype.stopFullScreen = function () {
+ if(document['cancelFullScreen']) {
+ document['cancelFullScreen']();
+ } else if(document['mozCancelFullScreen']) {
+ document['mozCancelFullScreen']();
+ } else if(document['webkitCancelFullScreen']) {
+ document['webkitCancelFullScreen']();
+ }
+ };
+ StageScaleMode.prototype.update = /**
+ * The core update loop, called by Phaser.Stage
+ */
+ function () {
+ if(this.forceLandscape || this.forcePortrait) {
+ this.checkOrientationState();
+ }
+ /*
+ if (this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height))
+ {
+ this.refresh();
+ }
+
+ if (this.forceLandscape || this.forcePortrait)
+ {
+ this.checkOrientationState();
+ }
+ */
+ };
+ StageScaleMode.prototype.checkOrientationState = function () {
+ // They are in the wrong orientation
+ if(this.incorrectOrientation) {
+ if((this.forceLandscape && window.innerWidth > window.innerHeight) || (this.forcePortrait && window.innerHeight > window.innerWidth)) {
+ // Back to normal
+ this.game.paused = false;
+ this.incorrectOrientation = false;
+ this.refresh();
+ }
+ } else {
+ if((this.forceLandscape && window.innerWidth < window.innerHeight) || (this.forcePortrait && window.innerHeight < window.innerWidth)) {
+ // Show orientation screen
+ this.game.paused = true;
+ this.incorrectOrientation = true;
+ this.refresh();
+ }
+ }
+ };
+ Object.defineProperty(StageScaleMode.prototype, "isPortrait", {
+ get: function () {
+ return this.orientation == 0 || this.orientation == 180;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(StageScaleMode.prototype, "isLandscape", {
+ get: function () {
+ return this.orientation === 90 || this.orientation === -90;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ StageScaleMode.prototype.checkOrientation = /**
+ * Handle window.orientationchange events
+ */
+ function (event) {
+ this.orientation = window['orientation'];
+ if(this.isLandscape) {
+ this.enterLandscape.dispatch(this.orientation, true, false);
+ } else {
+ this.enterPortrait.dispatch(this.orientation, false, true);
+ }
+ if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
+ this.refresh();
+ }
+ };
+ StageScaleMode.prototype.checkResize = /**
+ * Handle window.resize events
+ */
+ function (event) {
+ if(window.outerWidth > window.outerHeight) {
+ this.orientation = 90;
+ } else {
+ this.orientation = 0;
+ }
+ if(this.isLandscape) {
+ this.enterLandscape.dispatch(this.orientation, true, false);
+ } else {
+ this.enterPortrait.dispatch(this.orientation, false, true);
+ }
+ if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
+ this.refresh();
+ }
+ };
+ StageScaleMode.prototype.refresh = /**
+ * Re-calculate scale mode and update screen size.
+ */
+ function () {
+ var _this = this;
+ // We can't do anything about the status bars in iPads, web apps or desktops
+ if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
+ document.documentElement['style'].minHeight = '2000px';
+ this._startHeight = window.innerHeight;
+ if(this.game.device.android && this.game.device.chrome == false) {
+ window.scrollTo(0, 1);
+ } else {
+ window.scrollTo(0, 0);
+ }
+ }
+ if(this._check == null && this.maxIterations > 0) {
+ this._iterations = this.maxIterations;
+ this._check = window.setInterval(function () {
+ return _this.setScreenSize();
+ }, 10);
+ this.setScreenSize();
+ }
+ };
+ StageScaleMode.prototype.setScreenSize = /**
+ * Set screen size automatically based on the scaleMode.
+ */
+ function (force) {
+ if (typeof force === "undefined") { force = false; }
+ if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
+ if(this.game.device.android && this.game.device.chrome == false) {
+ window.scrollTo(0, 1);
+ } else {
+ window.scrollTo(0, 0);
+ }
+ }
+ this._iterations--;
+ if(force || window.innerHeight > this._startHeight || this._iterations < 0) {
+ // Set minimum height of content to new window height
+ document.documentElement['style'].minHeight = window.innerHeight + 'px';
+ if(this.incorrectOrientation == true) {
+ this.setMaximum();
+ } else if(this.game.stage.scaleMode == StageScaleMode.EXACT_FIT) {
+ this.setExactFit();
+ } else if(this.game.stage.scaleMode == StageScaleMode.SHOW_ALL) {
+ this.setShowAll();
+ }
+ this.setSize();
+ clearInterval(this._check);
+ this._check = null;
+ }
+ };
+ StageScaleMode.prototype.setSize = function () {
+ if(this.incorrectOrientation == false) {
+ if(this.maxWidth && this.width > this.maxWidth) {
+ this.width = this.maxWidth;
+ }
+ if(this.maxHeight && this.height > this.maxHeight) {
+ this.height = this.maxHeight;
+ }
+ if(this.minWidth && this.width < this.minWidth) {
+ this.width = this.minWidth;
+ }
+ if(this.minHeight && this.height < this.minHeight) {
+ this.height = this.minHeight;
+ }
+ }
+ this.game.stage.canvas.style.width = this.width + 'px';
+ this.game.stage.canvas.style.height = this.height + 'px';
+ this.game.input.scale.setTo(this.game.stage.width / this.width, this.game.stage.height / this.height);
+ if(this.pageAlignHorizontally) {
+ if(this.width < window.innerWidth && this.incorrectOrientation == false) {
+ this.game.stage.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px';
+ } else {
+ this.game.stage.canvas.style.marginLeft = '0px';
+ }
+ }
+ if(this.pageAlignVeritcally) {
+ if(this.height < window.innerHeight && this.incorrectOrientation == false) {
+ this.game.stage.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px';
+ } else {
+ this.game.stage.canvas.style.marginTop = '0px';
+ }
+ }
+ this.game.stage.getOffset(this.game.stage.canvas);
+ this.aspectRatio = this.width / this.height;
+ this.scaleFactor.x = this.game.stage.width / this.width;
+ this.scaleFactor.y = this.game.stage.height / this.height;
+ };
+ StageScaleMode.prototype.setMaximum = function () {
+ this.width = window.innerWidth;
+ this.height = window.innerHeight;
+ };
+ StageScaleMode.prototype.setShowAll = function () {
+ var multiplier = Math.min((window.innerHeight / this.game.stage.height), (window.innerWidth / this.game.stage.width));
+ this.width = Math.round(this.game.stage.width * multiplier);
+ this.height = Math.round(this.game.stage.height * multiplier);
+ };
+ StageScaleMode.prototype.setExactFit = function () {
+ if(this.maxWidth && window.innerWidth > this.maxWidth) {
+ this.width = this.maxWidth;
+ } else {
+ this.width = window.innerWidth;
+ }
+ if(this.maxHeight && window.innerHeight > this.maxHeight) {
+ this.height = this.maxHeight;
+ } else {
+ this.height = window.innerHeight;
+ }
+ };
+ return StageScaleMode;
+ })();
+ Phaser.StageScaleMode = StageScaleMode;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/system/StageScaleMode.ts b/TS Source/system/StageScaleMode.ts
similarity index 100%
rename from Phaser/system/StageScaleMode.ts
rename to TS Source/system/StageScaleMode.ts
diff --git a/TS Source/system/screens/BootScreen.js b/TS Source/system/screens/BootScreen.js
new file mode 100644
index 00000000..e3081bc9
--- /dev/null
+++ b/TS Source/system/screens/BootScreen.js
@@ -0,0 +1,106 @@
+///
+/**
+* Phaser - BootScreen
+*
+* The BootScreen is displayed when Phaser is started without any default functions or State
+*/
+var Phaser;
+(function (Phaser) {
+ var BootScreen = (function () {
+ /**
+ * BootScreen constructor
+ * Create a new BootScreen with specific width and height.
+ *
+ * @param width {number} Screen canvas width.
+ * @param height {number} Screen canvas height.
+ */
+ function BootScreen(game) {
+ /**
+ * Engine logo image data.
+ */
+ this._logoData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAAZCAYAAADdYmvFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAstJREFUeNrsWlFuwjAMbavdZGcAcRm4AXzvCPuGG8BlEJxhZ+l4TJ48z3actGGthqUI1MaO/V6cmIT2/fW10eTt46NvKshtvDZlG31yfOL9a/ldU6x4IZ0GQs0gS217enMkJYr5ixXkYrFoVqtV1kDn8/n+KfXw/Hq9Nin7h8MhScB2u3Xtav2ivsNWrh7XLcWMYqA4eUZ1kj0MAifHJEeKFojWzyIH+rL/0Cwif2AX9nN1oQOgrTg8XcTFx+ScdEOJ4WBxXQ1EjRyrn0cOzzQLzFyQSQcgw/5Qkkr0JVEQpNIdhL4vm4DL5fLulNTHcy6Uxl4/6iMLiePx2KzX6/v30+n0aynUlrnSeNq2/VN9bgM4dFPdNPmsJnIg/PuQbJmLdFN3UNu0SzbyJ0GOWJVWZE/QMkY+owrqXxGEdZA37BVyX6lJTipT6J1lf7fbqc+xh8nYeIvikatP+PGW0nEJ4jOydHYOIcfKnmgWoZDQSIIeio4Sf1IthYWskCO4vqQ6lFYjl8tl9L1H67PZbMz3VO3t93uVXHofmUjReLyMwHi5eCb3ICwJj5ZU9nCg+SzUgPYyif+2epTk4pkkyDp+eXTlZu2BkUybEkklePZfK9lPuTnc07vbmt1bYulHBeNQgx18SsH4ni/cV2rSLtqNDNUH2JQ2SsXS57Y9PHlfumkwCdICt5rnkNdPjpMiIEWgRlAJSdF4SvCQMWj+VyfI0h8D/EgWSYKiJKXi8VrOhJUxaFiFCOKKUJAtR78k9eX4USLHXqLGXOIiWUT4Vj9JiP4W0io3VDz8AJXblNWQrOimLjIGy/9uLICH6mrVmFbxEFHauzmc0fGJJmPg/v+6D0oB7N2bj0FsNHtSWTQniWTR931QlHXvasDTHXLjqY0/1/8hSDxACD+lAGH8dKQbQk5N3TFtzDmLWutvV0+pL5FVoHvCNG35FGAAayS4KUoKC9QAAAAASUVORK5CYII=";
+ /**
+ * Background gradient effect color 1.
+ */
+ this._color1 = {
+ r: 20,
+ g: 20,
+ b: 20
+ };
+ /**
+ * Background gradient effect color 2.
+ */
+ this._color2 = {
+ r: 200,
+ g: 200,
+ b: 200
+ };
+ /**
+ * Fade effect tween.
+ * @type {Phaser.Tween}
+ */
+ this._fade = null;
+ this.game = game;
+ this._logo = new Image();
+ this._logo.src = this._logoData;
+ }
+ BootScreen.prototype.update = /**
+ * Update color and fade.
+ */
+ function () {
+ if(this._fade == null) {
+ this.colorCycle();
+ }
+ this._color1.r = Math.round(this._color1.r);
+ this._color1.g = Math.round(this._color1.g);
+ this._color1.b = Math.round(this._color1.b);
+ this._color2.r = Math.round(this._color2.r);
+ this._color2.g = Math.round(this._color2.g);
+ this._color2.b = Math.round(this._color2.b);
+ };
+ BootScreen.prototype.render = /**
+ * Render BootScreen.
+ */
+ function () {
+ var grd = this.game.stage.context.createLinearGradient(0, 0, 0, this.game.stage.height);
+ grd.addColorStop(0, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
+ grd.addColorStop(0.5, 'rgb(' + this._color2.r + ', ' + this._color2.g + ', ' + this._color2.b + ')');
+ grd.addColorStop(1, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
+ this.game.stage.context.fillStyle = grd;
+ this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
+ this.game.stage.context.shadowOffsetX = 0;
+ this.game.stage.context.shadowOffsetY = 0;
+ if(this._logo) {
+ this.game.stage.context.drawImage(this._logo, 32, 32);
+ }
+ this.game.stage.context.shadowColor = 'rgb(0,0,0)';
+ this.game.stage.context.shadowOffsetX = 1;
+ this.game.stage.context.shadowOffsetY = 1;
+ this.game.stage.context.shadowBlur = 0;
+ this.game.stage.context.fillStyle = 'rgb(255,255,255)';
+ this.game.stage.context.font = 'bold 18px Arial';
+ this.game.stage.context.textBaseline = 'top';
+ this.game.stage.context.fillText(Phaser.VERSION, 32, 64 + 32);
+ this.game.stage.context.fillText('Game Size: ' + this.game.stage.width + ' x ' + this.game.stage.height, 32, 64 + 64);
+ this.game.stage.context.fillText('www.photonstorm.com', 32, 64 + 96);
+ this.game.stage.context.font = '16px Arial';
+ this.game.stage.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 64 + 160);
+ this.game.stage.context.fillText('functions in the Game constructor or use Game.switchState()', 32, 64 + 184);
+ };
+ BootScreen.prototype.colorCycle = /**
+ * Start color fading cycle.
+ */
+ function () {
+ this._fade = this.game.add.tween(this._color2);
+ this._fade.to({
+ r: Math.random() * 250,
+ g: Math.random() * 250,
+ b: Math.random() * 250
+ }, 3000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.colorCycle, this);
+ this._fade.start();
+ };
+ return BootScreen;
+ })();
+ Phaser.BootScreen = BootScreen;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/system/screens/BootScreen.ts b/TS Source/system/screens/BootScreen.ts
similarity index 100%
rename from Phaser/system/screens/BootScreen.ts
rename to TS Source/system/screens/BootScreen.ts
diff --git a/TS Source/system/screens/OrientationScreen.js b/TS Source/system/screens/OrientationScreen.js
new file mode 100644
index 00000000..38673832
--- /dev/null
+++ b/TS Source/system/screens/OrientationScreen.js
@@ -0,0 +1,43 @@
+///
+/**
+* Phaser - OrientationScreen
+*
+* The Orientation Screen is displayed whenever the device is turned to an unsupported orientation.
+*/
+var Phaser;
+(function (Phaser) {
+ var OrientationScreen = (function () {
+ /**
+ * OrientationScreen constructor
+ * Create a new OrientationScreen.
+ */
+ function OrientationScreen(game) {
+ this._enabled = false;
+ this.game = game;
+ }
+ OrientationScreen.prototype.enable = /**
+ * Enable the orientation screen. An image that is displayed whenever the device enters an unsupported orientation.
+ * Set this to be the key of an image previously loaded into the Game.Cache.
+ * @type {Cache Reference}
+ */
+ function (imageKey) {
+ this._enabled = true;
+ this.image = this.game.cache.getImage(imageKey);
+ };
+ OrientationScreen.prototype.update = /**
+ * Update (can be overridden)
+ */
+ function () {
+ };
+ OrientationScreen.prototype.render = /**
+ * Render
+ */
+ function () {
+ if(this._enabled) {
+ this.game.stage.context.drawImage(this.image, 0, 0, this.image.width, this.image.height, 0, 0, this.game.stage.width, this.game.stage.height);
+ }
+ };
+ return OrientationScreen;
+ })();
+ Phaser.OrientationScreen = OrientationScreen;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/system/screens/OrientationScreen.ts b/TS Source/system/screens/OrientationScreen.ts
similarity index 100%
rename from Phaser/system/screens/OrientationScreen.ts
rename to TS Source/system/screens/OrientationScreen.ts
diff --git a/TS Source/system/screens/PauseScreen.js b/TS Source/system/screens/PauseScreen.js
new file mode 100644
index 00000000..dc3383e8
--- /dev/null
+++ b/TS Source/system/screens/PauseScreen.js
@@ -0,0 +1,102 @@
+///
+/**
+* Phaser - PauseScreen
+*
+* The PauseScreen is displayed whenever the game loses focus or the player switches to another browser tab.
+*/
+var Phaser;
+(function (Phaser) {
+ var PauseScreen = (function () {
+ /**
+ * PauseScreen constructor
+ * Create a new PauseScreen with specific width and height.
+ *
+ * @param width {number} Screen canvas width.
+ * @param height {number} Screen canvas height.
+ */
+ function PauseScreen(game, width, height) {
+ this.game = game;
+ this._canvas = document.createElement('canvas');
+ this._canvas.width = width;
+ this._canvas.height = height;
+ this._context = this._canvas.getContext('2d');
+ }
+ PauseScreen.prototype.onPaused = /**
+ * Called when the game enters pause mode.
+ */
+ function () {
+ // Take a grab of the current canvas to our temporary one
+ this._context.clearRect(0, 0, this._canvas.width, this._canvas.height);
+ this._context.drawImage(this.game.stage.canvas, 0, 0);
+ this._color = {
+ r: 255,
+ g: 255,
+ b: 255
+ };
+ this.fadeOut();
+ };
+ PauseScreen.prototype.onResume = /**
+ * Called when the game resume from pause mode.
+ */
+ function () {
+ this._fade.stop();
+ this.game.tweens.remove(this._fade);
+ };
+ PauseScreen.prototype.update = /**
+ * Update background color.
+ */
+ function () {
+ this._color.r = Math.round(this._color.r);
+ this._color.g = Math.round(this._color.g);
+ this._color.b = Math.round(this._color.b);
+ };
+ PauseScreen.prototype.render = /**
+ * Render PauseScreen.
+ */
+ function () {
+ this.game.stage.context.drawImage(this._canvas, 0, 0);
+ this.game.stage.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
+ this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
+ // Draw a 'play' arrow
+ var arrowWidth = Math.round(this.game.stage.width / 2);
+ var arrowHeight = Math.round(this.game.stage.height / 2);
+ var sx = this.game.stage.centerX - arrowWidth / 2;
+ var sy = this.game.stage.centerY - arrowHeight / 2;
+ this.game.stage.context.beginPath();
+ this.game.stage.context.moveTo(sx, sy);
+ this.game.stage.context.lineTo(sx, sy + arrowHeight);
+ this.game.stage.context.lineTo(sx + arrowWidth, this.game.stage.centerY);
+ this.game.stage.context.fillStyle = 'rgba(' + this._color.r + ', ' + this._color.g + ', ' + this._color.b + ', 0.8)';
+ this.game.stage.context.fill();
+ this.game.stage.context.closePath();
+ };
+ PauseScreen.prototype.fadeOut = /**
+ * Start fadeOut effect.
+ */
+ function () {
+ this._fade = this.game.add.tween(this._color);
+ this._fade.to({
+ r: 50,
+ g: 50,
+ b: 50
+ }, 1000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.fadeIn, this);
+ this._fade.start();
+ };
+ PauseScreen.prototype.fadeIn = /**
+ * Start fadeIn effect.
+ */
+ function () {
+ this._fade = this.game.add.tween(this._color);
+ this._fade.to({
+ r: 255,
+ g: 255,
+ b: 255
+ }, 1000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.fadeOut, this);
+ this._fade.start();
+ };
+ return PauseScreen;
+ })();
+ Phaser.PauseScreen = PauseScreen;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/system/screens/PauseScreen.ts b/TS Source/system/screens/PauseScreen.ts
similarity index 100%
rename from Phaser/system/screens/PauseScreen.ts
rename to TS Source/system/screens/PauseScreen.ts
diff --git a/TS Source/tilemap/Tile.js b/TS Source/tilemap/Tile.js
new file mode 100644
index 00000000..8c1104bf
--- /dev/null
+++ b/TS Source/tilemap/Tile.js
@@ -0,0 +1,123 @@
+///
+/**
+* Phaser - Tile
+*
+* A Tile is a single representation of a tile within a Tilemap
+*/
+var Phaser;
+(function (Phaser) {
+ var Tile = (function () {
+ /**
+ * Tile constructor
+ * Create a new Tile.
+ *
+ * @param tilemap {Tilemap} the tilemap this tile belongs to.
+ * @param index {number} The index of this tile type in the core map data.
+ * @param width {number} Width of the tile.
+ * @param height number} Height of the tile.
+ */
+ function Tile(game, tilemap, index, width, height) {
+ /**
+ * The virtual mass of the tile.
+ * @type {number}
+ */
+ this.mass = 1.0;
+ /**
+ * Indicating collide with any object on the left.
+ * @type {bool}
+ */
+ this.collideLeft = false;
+ /**
+ * Indicating collide with any object on the right.
+ * @type {bool}
+ */
+ this.collideRight = false;
+ /**
+ * Indicating collide with any object on the top.
+ * @type {bool}
+ */
+ this.collideUp = false;
+ /**
+ * Indicating collide with any object on the bottom.
+ * @type {bool}
+ */
+ this.collideDown = false;
+ /**
+ * Enable separation at x-axis.
+ * @type {bool}
+ */
+ this.separateX = true;
+ /**
+ * Enable separation at y-axis.
+ * @type {bool}
+ */
+ this.separateY = true;
+ this.game = game;
+ this.tilemap = tilemap;
+ this.index = index;
+ this.width = width;
+ this.height = height;
+ this.allowCollisions = Phaser.Types.NONE;
+ }
+ Tile.prototype.destroy = /**
+ * Clean up memory.
+ */
+ function () {
+ this.tilemap = null;
+ };
+ Tile.prototype.setCollision = /**
+ * Set collision configs.
+ * @param collision {number} Bit field of flags. (see Tile.allowCollision)
+ * @param resetCollisions {bool} Reset collision flags before set.
+ * @param separateX {bool} Enable seprate at x-axis.
+ * @param separateY {bool} Enable seprate at y-axis.
+ */
+ function (collision, resetCollisions, separateX, separateY) {
+ if(resetCollisions) {
+ this.resetCollision();
+ }
+ this.separateX = separateX;
+ this.separateY = separateY;
+ this.allowCollisions = collision;
+ if(collision & Phaser.Types.ANY) {
+ this.collideLeft = true;
+ this.collideRight = true;
+ this.collideUp = true;
+ this.collideDown = true;
+ return;
+ }
+ if(collision & Phaser.Types.LEFT || collision & Phaser.Types.WALL) {
+ this.collideLeft = true;
+ }
+ if(collision & Phaser.Types.RIGHT || collision & Phaser.Types.WALL) {
+ this.collideRight = true;
+ }
+ if(collision & Phaser.Types.UP || collision & Phaser.Types.CEILING) {
+ this.collideUp = true;
+ }
+ if(collision & Phaser.Types.DOWN || collision & Phaser.Types.CEILING) {
+ this.collideDown = true;
+ }
+ };
+ Tile.prototype.resetCollision = /**
+ * Reset collision status flags.
+ */
+ function () {
+ this.allowCollisions = Phaser.Types.NONE;
+ this.collideLeft = false;
+ this.collideRight = false;
+ this.collideUp = false;
+ this.collideDown = false;
+ };
+ Tile.prototype.toString = /**
+ * Returns a string representation of this object.
+ * @method toString
+ * @return {string} a string representation of the object.
+ **/
+ function () {
+ return "[{Tile (index=" + this.index + " collisions=" + this.allowCollisions + " width=" + this.width + " height=" + this.height + ")}]";
+ };
+ return Tile;
+ })();
+ Phaser.Tile = Tile;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tilemap/Tile.ts b/TS Source/tilemap/Tile.ts
similarity index 100%
rename from Phaser/tilemap/Tile.ts
rename to TS Source/tilemap/Tile.ts
diff --git a/TS Source/tilemap/Tilemap.js b/TS Source/tilemap/Tilemap.js
new file mode 100644
index 00000000..8fdea412
--- /dev/null
+++ b/TS Source/tilemap/Tilemap.js
@@ -0,0 +1,329 @@
+///
+/**
+* Phaser - Tilemap
+*
+* This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size.
+* Internally it creates a TilemapLayer for each layer in the tilemap.
+*/
+var Phaser;
+(function (Phaser) {
+ var Tilemap = (function () {
+ /**
+ * Tilemap constructor
+ * Create a new Tilemap.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param key {string} Asset key for this map.
+ * @param mapData {string} Data of this map. (a big 2d array, normally in csv)
+ * @param format {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
+ * @param resizeWorld {bool} Resize the world bound automatically based on this tilemap?
+ * @param tileWidth {number} Width of tiles in this map.
+ * @param tileHeight {number} Height of tiles in this map.
+ */
+ function Tilemap(game, key, mapData, format, resizeWorld, tileWidth, tileHeight) {
+ if (typeof resizeWorld === "undefined") { resizeWorld = true; }
+ if (typeof tileWidth === "undefined") { tileWidth = 0; }
+ if (typeof tileHeight === "undefined") { tileHeight = 0; }
+ /**
+ * z order value of the object.
+ */
+ this.z = -1;
+ /**
+ * Render iteration counter
+ */
+ this.renderOrderID = 0;
+ /**
+ * Tilemap collision callback.
+ * @type {function}
+ */
+ this.collisionCallback = null;
+ this.game = game;
+ this.type = Phaser.Types.TILEMAP;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.tiles = [];
+ this.layers = [];
+ this.mapFormat = format;
+ switch(format) {
+ case Tilemap.FORMAT_CSV:
+ this.parseCSV(game.cache.getText(mapData), key, tileWidth, tileHeight);
+ break;
+ case Tilemap.FORMAT_TILED_JSON:
+ this.parseTiledJSON(game.cache.getText(mapData), key);
+ break;
+ }
+ if(this.currentLayer && resizeWorld) {
+ this.game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
+ }
+ }
+ Tilemap.FORMAT_CSV = 0;
+ Tilemap.FORMAT_TILED_JSON = 1;
+ Tilemap.prototype.parseCSV = /**
+ * Parset csv map data and generate tiles.
+ * @param data {string} CSV map data.
+ * @param key {string} Asset key for tileset image.
+ * @param tileWidth {number} Width of its tile.
+ * @param tileHeight {number} Height of its tile.
+ */
+ function (data, key, tileWidth, tileHeight) {
+ var layer = new Phaser.TilemapLayer(this, 0, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
+ // Trim any rogue whitespace from the data
+ data = data.trim();
+ var rows = data.split("\n");
+ for(var i = 0; i < rows.length; i++) {
+ var column = rows[i].split(",");
+ if(column.length > 0) {
+ layer.addColumn(column);
+ }
+ }
+ layer.updateBounds();
+ var tileQuantity = layer.parseTileOffsets();
+ this.currentLayer = layer;
+ this.collisionLayer = layer;
+ this.layers.push(layer);
+ this.generateTiles(tileQuantity);
+ };
+ Tilemap.prototype.parseTiledJSON = /**
+ * Parse JSON map data and generate tiles.
+ * @param data {string} JSON map data.
+ * @param key {string} Asset key for tileset image.
+ */
+ function (data, key) {
+ // Trim any rogue whitespace from the data
+ data = data.trim();
+ var json = JSON.parse(data);
+ for(var i = 0; i < json.layers.length; i++) {
+ var layer = new Phaser.TilemapLayer(this, i, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
+ // Check it's a data layer
+ if(!json.layers[i].data) {
+ continue;
+ }
+ layer.alpha = json.layers[i].opacity;
+ layer.visible = json.layers[i].visible;
+ layer.tileMargin = json.tilesets[0].margin;
+ layer.tileSpacing = json.tilesets[0].spacing;
+ var c = 0;
+ var row;
+ for(var t = 0; t < json.layers[i].data.length; t++) {
+ if(c == 0) {
+ row = [];
+ }
+ row.push(json.layers[i].data[t]);
+ c++;
+ if(c == json.layers[i].width) {
+ layer.addColumn(row);
+ c = 0;
+ }
+ }
+ layer.updateBounds();
+ var tileQuantity = layer.parseTileOffsets();
+ this.currentLayer = layer;
+ this.collisionLayer = layer;
+ this.layers.push(layer);
+ }
+ this.generateTiles(tileQuantity);
+ };
+ Tilemap.prototype.generateTiles = /**
+ * Create tiles of given quantity.
+ * @param qty {number} Quentity of tiles to be generated.
+ */
+ function (qty) {
+ for(var i = 0; i < qty; i++) {
+ this.tiles.push(new Phaser.Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
+ }
+ };
+ Object.defineProperty(Tilemap.prototype, "widthInPixels", {
+ get: function () {
+ return this.currentLayer.widthInPixels;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tilemap.prototype, "heightInPixels", {
+ get: function () {
+ return this.currentLayer.heightInPixels;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Tilemap.prototype.setCollisionCallback = // Tile Collision
+ /**
+ * Set callback to be called when this tilemap collides.
+ * @param context {object} Callback will be called with this context.
+ * @param callback {function} Callback function.
+ */
+ function (context, callback) {
+ this.collisionCallbackContext = context;
+ this.collisionCallback = callback;
+ };
+ Tilemap.prototype.setCollisionRange = /**
+ * Set collision configs of tiles in a range index.
+ * @param start {number} First index of tiles.
+ * @param end {number} Last index of tiles.
+ * @param collision {number} Bit field of flags. (see Tile.allowCollision)
+ * @param resetCollisions {bool} Reset collision flags before set.
+ * @param separateX {bool} Enable seprate at x-axis.
+ * @param separateY {bool} Enable seprate at y-axis.
+ */
+ function (start, end, collision, resetCollisions, separateX, separateY) {
+ if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
+ if (typeof resetCollisions === "undefined") { resetCollisions = false; }
+ if (typeof separateX === "undefined") { separateX = true; }
+ if (typeof separateY === "undefined") { separateY = true; }
+ for(var i = start; i < end; i++) {
+ this.tiles[i].setCollision(collision, resetCollisions, separateX, separateY);
+ }
+ };
+ Tilemap.prototype.setCollisionByIndex = /**
+ * Set collision configs of tiles with given index.
+ * @param values {number[]} Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters.
+ * @param collision {number} Bit field of flags. (see Tile.allowCollision)
+ * @param resetCollisions {bool} Reset collision flags before set.
+ * @param separateX {bool} Enable seprate at x-axis.
+ * @param separateY {bool} Enable seprate at y-axis.
+ */
+ function (values, collision, resetCollisions, separateX, separateY) {
+ if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
+ if (typeof resetCollisions === "undefined") { resetCollisions = false; }
+ if (typeof separateX === "undefined") { separateX = true; }
+ if (typeof separateY === "undefined") { separateY = true; }
+ for(var i = 0; i < values.length; i++) {
+ this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
+ }
+ };
+ Tilemap.prototype.getTileByIndex = // Tile Management
+ /**
+ * Get the tile by its index.
+ * @param value {number} Index of the tile you want to get.
+ * @return {Tile} The tile with given index.
+ */
+ function (value) {
+ if(this.tiles[value]) {
+ return this.tiles[value];
+ }
+ return null;
+ };
+ Tilemap.prototype.getTile = /**
+ * Get the tile located at specific position and layer.
+ * @param x {number} X position of this tile located.
+ * @param y {number} Y position of this tile located.
+ * @param [layer] {number} layer of this tile located.
+ * @return {Tile} The tile with specific properties.
+ */
+ function (x, y, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileIndex(x, y)];
+ };
+ Tilemap.prototype.getTileFromWorldXY = /**
+ * Get the tile located at specific position (in world coordinate) and layer. (thus you give a position of a point which is within the tile)
+ * @param x {number} X position of the point in target tile.
+ * @param x {number} Y position of the point in target tile.
+ * @param [layer] {number} layer of this tile located.
+ * @return {Tile} The tile with specific properties.
+ */
+ function (x, y, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
+ };
+ Tilemap.prototype.getTileFromInputXY = /**
+ * Gets the tile underneath the Input.x/y position
+ * @param layer The layer to check, defaults to 0
+ * @returns {Tile}
+ */
+ function (layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.worldX, this.game.input.worldY)];
+ };
+ Tilemap.prototype.getTileOverlaps = /**
+ * Get tiles overlaps the given object.
+ * @param object {GameObject} Tiles you want to get that overlaps this.
+ * @return {array} Array with tiles information. (Each contains x, y and the tile.)
+ */
+ function (object) {
+ return this.currentLayer.getTileOverlaps(object);
+ };
+ Tilemap.prototype.collide = // COLLIDE
+ /**
+ * Check whether this tilemap collides with the given game object or group of objects.
+ * @param objectOrGroup {function} Target object of group you want to check.
+ * @param callback {function} This is called if objectOrGroup collides the tilemap.
+ * @param context {object} Callback will be called with this context.
+ * @return {bool} Return true if this collides with given object, otherwise return false.
+ */
+ function (objectOrGroup, callback, context) {
+ if (typeof objectOrGroup === "undefined") { objectOrGroup = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof context === "undefined") { context = null; }
+ if(callback !== null && context !== null) {
+ this.collisionCallback = callback;
+ this.collisionCallbackContext = context;
+ }
+ if(objectOrGroup == null) {
+ objectOrGroup = this.game.world.group;
+ }
+ // Group?
+ if(objectOrGroup.isGroup == false) {
+ this.collideGameObject(objectOrGroup);
+ } else {
+ objectOrGroup.forEachAlive(this, this.collideGameObject, true);
+ }
+ };
+ Tilemap.prototype.collideGameObject = /**
+ * Check whether this tilemap collides with the given game object.
+ * @param object {GameObject} Target object you want to check.
+ * @return {bool} Return true if this collides with given object, otherwise return false.
+ */
+ function (object) {
+ if(object.body.type == Phaser.Types.BODY_DYNAMIC && object.exists == true && object.body.allowCollisions != Phaser.Types.NONE) {
+ this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
+ if(this.collisionCallback !== null && this._tempCollisionData.length > 0) {
+ this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Tilemap.prototype.putTile = /**
+ * Set a tile to a specific layer.
+ * @param x {number} X position of this tile.
+ * @param y {number} Y position of this tile.
+ * @param index {number} The index of this tile type in the core map data.
+ * @param [layer] {number} which layer you want to set the tile to.
+ */
+ function (x, y, index, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ this.layers[layer].putTile(x, y, index);
+ };
+ Tilemap.prototype.preUpdate = /**
+ * Can be over-ridden if required
+ */
+ function () {
+ };
+ Tilemap.prototype.update = /**
+ * Can be over-ridden if required
+ */
+ function () {
+ };
+ Tilemap.prototype.postUpdate = /**
+ * Can be over-ridden if required
+ */
+ function () {
+ };
+ Tilemap.prototype.destroy = function () {
+ this.texture = null;
+ this.transform = null;
+ this.tiles.length = 0;
+ this.layers.length = 0;
+ };
+ return Tilemap;
+ })();
+ Phaser.Tilemap = Tilemap;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tilemap/Tilemap.ts b/TS Source/tilemap/Tilemap.ts
similarity index 100%
rename from Phaser/tilemap/Tilemap.ts
rename to TS Source/tilemap/Tilemap.ts
diff --git a/TS Source/tilemap/TilemapLayer.js b/TS Source/tilemap/TilemapLayer.js
new file mode 100644
index 00000000..20046537
--- /dev/null
+++ b/TS Source/tilemap/TilemapLayer.js
@@ -0,0 +1,369 @@
+///
+/**
+* Phaser - TilemapLayer
+*
+* A Tilemap Layer. Tiled format maps can have multiple overlapping layers.
+*/
+var Phaser;
+(function (Phaser) {
+ var TilemapLayer = (function () {
+ /**
+ * TilemapLayer constructor
+ * Create a new TilemapLayer.
+ *
+ * @param parent {Tilemap} The tilemap that contains this layer.
+ * @param id {number} The ID of this layer within the Tilemap array.
+ * @param key {string} Asset key for this map.
+ * @param mapFormat {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
+ * @param name {string} Name of this layer, so you can get this layer by its name.
+ * @param tileWidth {number} Width of tiles in this map.
+ * @param tileHeight {number} Height of tiles in this map.
+ */
+ function TilemapLayer(parent, id, key, mapFormat, name, tileWidth, tileHeight) {
+ /**
+ * Controls whether update() and draw() are automatically called.
+ * @type {bool}
+ */
+ this.exists = true;
+ /**
+ * Controls whether draw() are automatically called.
+ * @type {bool}
+ */
+ this.visible = true;
+ /**
+ * How many tiles in each row.
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
+ this.widthInTiles = 0;
+ /**
+ * How many tiles in each column.
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
+ this.heightInTiles = 0;
+ /**
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
+ this.widthInPixels = 0;
+ /**
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
+ this.heightInPixels = 0;
+ /**
+ * Distance between REAL tiles to the tileset texture bound.
+ * @type {number}
+ */
+ this.tileMargin = 0;
+ /**
+ * Distance between every 2 neighbor tile in the tileset texture.
+ * @type {number}
+ */
+ this.tileSpacing = 0;
+ this.parent = parent;
+ this.game = parent.game;
+ this.ID = id;
+ this.name = name;
+ this.mapFormat = mapFormat;
+ this.tileWidth = tileWidth;
+ this.tileHeight = tileHeight;
+ this.boundsInTiles = new Phaser.Rectangle();
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(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 = [];
+ }
+ TilemapLayer.prototype.putTileWorldXY = /**
+ * Set a specific tile with its x and y in tiles.
+ * @param x {number} X position of this tile in world coordinates.
+ * @param y {number} Y position of this tile in world coordinates.
+ * @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;
+ if(y >= 0 && y < this.mapData.length) {
+ if(x >= 0 && x < this.mapData[y].length) {
+ this.mapData[y][x] = index;
+ }
+ }
+ };
+ TilemapLayer.prototype.putTile = /**
+ * Set a specific tile with its x and y in tiles.
+ * @param x {number} X position of this tile.
+ * @param y {number} Y position of this tile.
+ * @param index {number} The index of this tile type in the core map data.
+ */
+ function (x, y, index) {
+ if(y >= 0 && y < this.mapData.length) {
+ if(x >= 0 && x < this.mapData[y].length) {
+ this.mapData[y][x] = index;
+ }
+ }
+ };
+ TilemapLayer.prototype.swapTile = /**
+ * Swap tiles with 2 kinds of indexes.
+ * @param tileA {number} First tile index.
+ * @param tileB {number} Second tile index.
+ * @param [x] {number} specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
+ * @param [y] {number} specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
+ * @param [width] {number} specify a Rectangle of tiles to operate. The width in tiles.
+ * @param [height] {number} specify a Rectangle of tiles to operate. The height in tiles.
+ */
+ function (tileA, tileB, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ if (typeof height === "undefined") { height = this.heightInTiles; }
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ // First sweep marking tileA as needing a new index
+ if(this._tempTileBlock[r].tile.index == tileA) {
+ this._tempTileBlock[r].newIndex = true;
+ }
+ // In the same pass we can swap tileB to tileA
+ if(this._tempTileBlock[r].tile.index == tileB) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileA;
+ }
+ }
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ // And now swap our newIndex tiles for tileB
+ if(this._tempTileBlock[r].newIndex == true) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
+ }
+ }
+ };
+ TilemapLayer.prototype.fillTile = /**
+ * Fill a tile block with a specific tile index.
+ * @param index {number} Index of tiles you want to fill with.
+ * @param [x] {number} x position (in tiles) of block's left-top corner.
+ * @param [y] {number} y position (in tiles) of block's left-top corner.
+ * @param [width] {number} width of block.
+ * @param [height] {number} height of block.
+ */
+ function (index, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ 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] = index;
+ }
+ };
+ TilemapLayer.prototype.randomiseTiles = /**
+ * Set random tiles to a specific tile block.
+ * @param tiles {number[]} Tiles with indexes in this array will be randomly set to the given block.
+ * @param [x] {number} x position (in tiles) of block's left-top corner.
+ * @param [y] {number} y position (in tiles) of block's left-top corner.
+ * @param [width] {number} width of block.
+ * @param [height] {number} height of block.
+ */
+ function (tiles, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ 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);
+ }
+ };
+ TilemapLayer.prototype.replaceTile = /**
+ * Replace one kind of tiles to another kind.
+ * @param tileA {number} Index of tiles you want to replace.
+ * @param tileB {number} Index of tiles you want to set.
+ * @param [x] {number} x position (in tiles) of block's left-top corner.
+ * @param [y] {number} y position (in tiles) of block's left-top corner.
+ * @param [width] {number} width of block.
+ * @param [height] {number} height of block.
+ */
+ function (tileA, tileB, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ if (typeof height === "undefined") { height = this.heightInTiles; }
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ if(this._tempTileBlock[r].tile.index == tileA) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
+ }
+ }
+ };
+ TilemapLayer.prototype.getTileBlock = /**
+ * Get a tile block with specific position and size.(both are in tiles)
+ * @param x {number} X position of block's left-top corner.
+ * @param y {number} Y position of block's left-top corner.
+ * @param width {number} Width of block.
+ * @param height {number} Height of block.
+ */
+ function (x, y, width, height) {
+ var output = [];
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ output.push({
+ x: this._tempTileBlock[r].x,
+ y: this._tempTileBlock[r].y,
+ tile: this._tempTileBlock[r].tile
+ });
+ }
+ return output;
+ };
+ TilemapLayer.prototype.getTileFromWorldXY = /**
+ * Get a tile with specific position (in world coordinate). (thus you give a position of a point which is within the tile)
+ * @param x {number} X position of the point in target tile.
+ * @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;
+ return this.getTileIndex(x, y);
+ };
+ TilemapLayer.prototype.getTileOverlaps = /**
+ * Get tiles overlaps the given object.
+ * @param object {GameObject} Tiles you want to get that overlaps this.
+ * @return {array} Array with tiles informations. (Each contains x, y and the tile.)
+ */
+ function (object) {
+ // If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
+ if(object.body.bounds.x < 0 || object.body.bounds.x > this.widthInPixels || object.body.bounds.y < 0 || object.body.bounds.bottom > this.heightInPixels) {
+ 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;
+ // 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)
+ {
+ this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
+ }
+ }
+ */
+ return this._tempBlockResults;
+ };
+ TilemapLayer.prototype.getTempBlock = /**
+ * Get a tile block with its position and size. (This method does not return, it'll set result to _tempTileBlock)
+ * @param x {number} X position of block's left-top corner.
+ * @param y {number} Y position of block's left-top corner.
+ * @param width {number} Width of block.
+ * @param height {number} Height of block.
+ * @param collisionOnly {bool} Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE).
+ */
+ function (x, y, width, height, collisionOnly) {
+ if (typeof collisionOnly === "undefined") { collisionOnly = false; }
+ if(x < 0) {
+ x = 0;
+ }
+ if(y < 0) {
+ y = 0;
+ }
+ if(width > this.widthInTiles) {
+ width = this.widthInTiles;
+ }
+ if(height > this.heightInTiles) {
+ height = this.heightInTiles;
+ }
+ this._tempTileBlock = [];
+ for(var ty = y; ty < y + height; ty++) {
+ 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) {
+ 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]]
+ });
+ }
+ }
+ }
+ }
+ };
+ TilemapLayer.prototype.getTileIndex = /**
+ * Get the tile index of specific position (in tiles).
+ * @param x {number} X position of the tile.
+ * @param y {number} Y position of the tile.
+ * @return {number} Index of the tile at that position. Return null if there isn't a tile there.
+ */
+ function (x, y) {
+ if(y >= 0 && y < this.mapData.length) {
+ if(x >= 0 && x < this.mapData[y].length) {
+ return this.mapData[y][x];
+ }
+ }
+ return null;
+ };
+ TilemapLayer.prototype.addColumn = /**
+ * Add a column of tiles into the layer.
+ * @param column {string[]/number[]} An array of tile indexes to be added.
+ */
+ function (column) {
+ var data = [];
+ for(var c = 0; c < column.length; c++) {
+ data[c] = parseInt(column[c]);
+ }
+ if(this.widthInTiles == 0) {
+ this.widthInTiles = data.length;
+ this.widthInPixels = this.widthInTiles * this.tileWidth;
+ }
+ this.mapData.push(data);
+ this.heightInTiles++;
+ this.heightInPixels += this.tileHeight;
+ };
+ TilemapLayer.prototype.updateBounds = /**
+ * Update boundsInTiles with widthInTiles and heightInTiles.
+ */
+ function () {
+ this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
+ };
+ TilemapLayer.prototype.parseTileOffsets = /**
+ * Parse tile offsets from map data.
+ * @return {number} length of tileOffsets array.
+ */
+ function () {
+ 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;
+ 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] = {
+ x: tx,
+ y: ty
+ };
+ i++;
+ }
+ }
+ return this.tileOffsets.length;
+ };
+ return TilemapLayer;
+ })();
+ Phaser.TilemapLayer = TilemapLayer;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tilemap/TilemapLayer.ts b/TS Source/tilemap/TilemapLayer.ts
similarity index 100%
rename from Phaser/tilemap/TilemapLayer.ts
rename to TS Source/tilemap/TilemapLayer.ts
diff --git a/TS Source/time/TimeManager.js b/TS Source/time/TimeManager.js
new file mode 100644
index 00000000..67509ecf
--- /dev/null
+++ b/TS Source/time/TimeManager.js
@@ -0,0 +1,221 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var TimeManager = (function () {
+ /**
+ * This is the core internal game clock. It manages the elapsed time and calculation of delta values,
+ * used for game object motion and tweens.
+ *
+ * @class TimeManager
+ * @constructor
+ * @param {Phaser.Game} game A reference to the currently running game.
+ */
+ function TimeManager(game) {
+ /**
+ * Number of milliseconds elapsed since the last frame update.
+ * @property elapsed
+ * @public
+ * @type {Number}
+ */
+ //public elapsed: number = 0;
+ /**
+ * The elapsed time calculated for the physics motion updates.
+ * @property physicsElapsed
+ * @public
+ * @type {Number}
+ */
+ this.physicsElapsed = 0;
+ /**
+ * Game time counter.
+ * @property time
+ * @public
+ * @type {Number}
+ */
+ this.time = 0;
+ /**
+ * Records how long the game has been paused for. Is reset each time the game pauses.
+ * @property pausedTime
+ * @public
+ * @type {Number}
+ */
+ this.pausedTime = 0;
+ /**
+ * The time right now.
+ * @property now
+ * @public
+ * @type {Number}
+ */
+ this.now = 0;
+ /**
+ * Elapsed time since the last frame.
+ * @property delta
+ * @public
+ * @type {Number}
+ */
+ this.delta = 0;
+ /**
+ * Frames per second.
+ * @property fps
+ * @public
+ * @type {Number}
+ */
+ this.fps = 0;
+ /**
+ * The lowest rate the fps has dropped to.
+ * @property fpsMin
+ * @public
+ * @type {Number}
+ */
+ this.fpsMin = 1000;
+ /**
+ * The highest rate the fps has reached (usually no higher than 60fps).
+ * @property fpsMax
+ * @public
+ * @type {Number}
+ */
+ this.fpsMax = 0;
+ /**
+ * The minimum amount of time the game has taken between two frames.
+ * @property msMin
+ * @public
+ * @type {Number}
+ */
+ this.msMin = 1000;
+ /**
+ * The maximum amount of time the game has taken between two frames.
+ * @property msMax
+ * @public
+ * @type {Number}
+ */
+ this.msMax = 0;
+ /**
+ * The number of frames record in the last second.
+ * @property frames
+ * @public
+ * @type {Number}
+ */
+ this.frames = 0;
+ /**
+ * The time (in ms) that the last second counter ticked over.
+ * @property _timeLastSecond
+ * @private
+ * @type {Number}
+ */
+ this._timeLastSecond = 0;
+ /**
+ * Records how long the game was paused for in miliseconds.
+ * @property pauseDuration
+ * @public
+ * @type {Number}
+ */
+ this.pauseDuration = 0;
+ /**
+ * The time the game started being paused.
+ * @property _pauseStarted
+ * @private
+ * @type {Number}
+ */
+ this._pauseStarted = 0;
+ this.game = game;
+ this._started = 0;
+ this._timeLastSecond = this._started;
+ this.time = this._started;
+ this.game.onPause.add(this.gamePaused, this);
+ this.game.onResume.add(this.gameResumed, this);
+ }
+ Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", {
+ get: /**
+ * The number of seconds that have elapsed since the game was started.
+ * @method totalElapsedSeconds
+ * @return {Number}
+ */
+ function () {
+ return (this.now - this._started) * 0.001;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TimeManager.prototype.update = /**
+ * Update clock and calculate the fps.
+ * This is called automatically by Game._raf
+ * @method update
+ * @param {Number} raf The current timestamp, either performance.now or Date.now
+ */
+ function (raf) {
+ this.now = raf// mark
+ ;
+ this.delta = this.now - this.time// elapsedMS
+ ;
+ this.msMin = Math.min(this.msMin, this.delta);
+ this.msMax = Math.max(this.msMax, this.delta);
+ this.frames++;
+ if(this.now > this._timeLastSecond + 1000) {
+ this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
+ this.fpsMin = Math.min(this.fpsMin, this.fps);
+ this.fpsMax = Math.max(this.fpsMax, this.fps);
+ this._timeLastSecond = this.now;
+ this.frames = 0;
+ }
+ this.time = this.now// _total
+ ;
+ this.physicsElapsed = 1.0 * (this.delta / 1000);
+ // Paused?
+ if(this.game.paused) {
+ this.pausedTime = this.now - this._pauseStarted;
+ }
+ };
+ TimeManager.prototype.gamePaused = /**
+ * Called when the game enters a paused state.
+ * @method gamePaused
+ * @private
+ */
+ function () {
+ this._pauseStarted = this.now;
+ };
+ TimeManager.prototype.gameResumed = /**
+ * Called when the game resumes from a paused state.
+ * @method gameResumed
+ * @private
+ */
+ function () {
+ // Level out the delta timer to avoid spikes
+ this.delta = 0;
+ this.physicsElapsed = 0;
+ this.time = Date.now();
+ this.pauseDuration = this.pausedTime;
+ };
+ TimeManager.prototype.elapsedSince = /**
+ * How long has passed since the given time.
+ * @method elapsedSince
+ * @param {Number} since The time you want to measure against.
+ * @return {Number} The difference between the given time and now.
+ */
+ function (since) {
+ return this.now - since;
+ };
+ TimeManager.prototype.elapsedSecondsSince = /**
+ * How long has passed since the given time (in seconds).
+ * @method elapsedSecondsSince
+ * @param {Number} since The time you want to measure (in seconds).
+ * @return {Number} Duration between given time and now (in seconds).
+ */
+ function (since) {
+ return (this.now - since) * 0.001;
+ };
+ TimeManager.prototype.reset = /**
+ * Resets the private _started value to now.
+ * @method reset
+ */
+ function () {
+ this._started = this.now;
+ };
+ return TimeManager;
+ })();
+ Phaser.TimeManager = TimeManager;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/time/TimeManager.ts b/TS Source/time/TimeManager.ts
similarity index 100%
rename from Phaser/time/TimeManager.ts
rename to TS Source/time/TimeManager.ts
diff --git a/TS Source/tweens/Tween.js b/TS Source/tweens/Tween.js
new file mode 100644
index 00000000..880c2eec
--- /dev/null
+++ b/TS Source/tweens/Tween.js
@@ -0,0 +1,305 @@
+///
+/**
+* Phaser - Tween
+*
+* Based heavily on tween.js by sole (https://github.com/sole/tween.js) converted to TypeScript and integrated into Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ var Tween = (function () {
+ /**
+ * Tween constructor
+ * Create a new Tween.
+ *
+ * @param object {object} Target object will be affected by this tween.
+ * @param game {Phaser.Game} Current game instance.
+ */
+ function Tween(object, game) {
+ /**
+ * Reference to the target object.
+ * @type {object}
+ */
+ this._object = null;
+ this._pausedTime = 0;
+ /**
+ * Start values container.
+ * @type {object}
+ */
+ this._valuesStart = {
+ };
+ /**
+ * End values container.
+ * @type {object}
+ */
+ this._valuesEnd = {
+ };
+ /**
+ * How long this tween will perform.
+ * @type {number}
+ */
+ this._duration = 1000;
+ this._delayTime = 0;
+ this._startTime = null;
+ /**
+ * Will this tween automatically restart when it completes?
+ * @type {bool}
+ */
+ this._loop = false;
+ /**
+ * A yoyo tween is one that plays once fully, then reverses back to the original tween values before completing.
+ * @type {bool}
+ */
+ this._yoyo = false;
+ this._yoyoCount = 0;
+ /**
+ * Contains chained tweens.
+ * @type {Tweens[]}
+ */
+ this._chainedTweens = [];
+ this.isRunning = false;
+ this._object = object;
+ this.game = game;
+ this._manager = this.game.tweens;
+ this._interpolationFunction = this.game.math.linearInterpolation;
+ this._easingFunction = Phaser.Easing.Linear.None;
+ this._chainedTweens = [];
+ this.onStart = new Phaser.Signal();
+ this.onUpdate = new Phaser.Signal();
+ this.onComplete = new Phaser.Signal();
+ }
+ Tween.prototype.to = /**
+ * Configure the Tween
+ * @param properties {object} Propertis you want to tween.
+ * @param [duration] {number} duration of this tween.
+ * @param [ease] {any} Easing function.
+ * @param [autoStart] {bool} Whether this tween will start automatically or not.
+ * @param [delay] {number} delay before this tween will start, defaults to 0 (no delay)
+ * @param [loop] {bool} Should the tween automatically restart once complete? (ignores any chained tweens)
+ * @return {Tween} Itself.
+ */
+ function (properties, duration, ease, autoStart, delay, loop, yoyo) {
+ if (typeof duration === "undefined") { duration = 1000; }
+ if (typeof ease === "undefined") { ease = null; }
+ if (typeof autoStart === "undefined") { autoStart = false; }
+ if (typeof delay === "undefined") { delay = 0; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof yoyo === "undefined") { yoyo = false; }
+ this._duration = duration;
+ // If properties isn't an object this will fail, sanity check it here somehow?
+ this._valuesEnd = properties;
+ if(ease !== null) {
+ this._easingFunction = ease;
+ }
+ if(delay > 0) {
+ this._delayTime = delay;
+ }
+ this._loop = loop;
+ this._yoyo = yoyo;
+ this._yoyoCount = 0;
+ if(autoStart === true) {
+ return this.start();
+ } else {
+ return this;
+ }
+ };
+ Tween.prototype.loop = function (value) {
+ this._loop = value;
+ return this;
+ };
+ Tween.prototype.yoyo = function (value) {
+ this._yoyo = value;
+ this._yoyoCount = 0;
+ return this;
+ };
+ Tween.prototype.start = /**
+ * Start to tween.
+ */
+ function (looped) {
+ if (typeof looped === "undefined") { looped = false; }
+ if(this.game === null || this._object === null) {
+ return;
+ }
+ if(looped == false) {
+ this._manager.add(this);
+ 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)) {
+ throw Error('Phaser.Tween interpolation of null value of non-existing property');
+ continue;
+ }
+ // check if an Array was provided as property value
+ if(this._valuesEnd[property] instanceof Array) {
+ if(this._valuesEnd[property].length === 0) {
+ continue;
+ }
+ // create a local copy of the Array with the start value at the front
+ this._valuesEnd[property] = [
+ this._object[property]
+ ].concat(this._valuesEnd[property]);
+ }
+ if(looped == false) {
+ this._valuesStart[property] = this._object[property];
+ }
+ }
+ return this;
+ };
+ Tween.prototype.reverse = function () {
+ var tempObj = {
+ };
+ for(var property in this._valuesStart) {
+ tempObj[property] = this._valuesStart[property];
+ this._valuesStart[property] = this._valuesEnd[property];
+ this._valuesEnd[property] = tempObj[property];
+ }
+ this._yoyoCount++;
+ return this.start(true);
+ };
+ Tween.prototype.reset = function () {
+ // Reset the properties back to what they were before
+ for(var property in this._valuesStart) {
+ this._object[property] = this._valuesStart[property];
+ }
+ return this.start(true);
+ };
+ Tween.prototype.clear = function () {
+ this._chainedTweens = [];
+ this.onStart.removeAll();
+ this.onUpdate.removeAll();
+ this.onComplete.removeAll();
+ return this;
+ };
+ Tween.prototype.stop = /**
+ * Stop tweening.
+ */
+ function () {
+ if(this._manager !== null) {
+ this._manager.remove(this);
+ }
+ this.isRunning = false;
+ this.onComplete.dispose();
+ return this;
+ };
+ Object.defineProperty(Tween.prototype, "parent", {
+ set: function (value) {
+ this.game = value;
+ this._manager = this.game.tweens;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "delay", {
+ get: function () {
+ return this._delayTime;
+ },
+ set: function (amount) {
+ this._delayTime = amount;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "easing", {
+ get: function () {
+ return this._easingFunction;
+ },
+ set: function (easing) {
+ this._easingFunction = easing;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "interpolation", {
+ get: function () {
+ return this._interpolationFunction;
+ },
+ set: function (interpolation) {
+ this._interpolationFunction = interpolation;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Tween.prototype.chain = /**
+ * Add another chained tween, which will start automatically when the one before it completes.
+ * @param tween {Phaser.Tween} Tween object you want to chain with this.
+ * @return {Phaser.Tween} Itselfe.
+ */
+ function (tween) {
+ this._chainedTweens.push(tween);
+ return this;
+ };
+ Tween.prototype.pause = function () {
+ this._paused = true;
+ };
+ Tween.prototype.resume = function () {
+ this._paused = false;
+ this._startTime += this.game.time.pauseDuration;
+ };
+ Tween.prototype.update = /**
+ * Update tweening.
+ * @param time {number} Current time from game clock.
+ * @return {bool} Return false if this completed and no need to update, otherwise return true.
+ */
+ function (time) {
+ if(this._paused || time < this._startTime) {
+ return true;
+ }
+ this._tempElapsed = (time - this._startTime) / this._duration;
+ this._tempElapsed = this._tempElapsed > 1 ? 1 : this._tempElapsed;
+ this._tempValue = this._easingFunction(this._tempElapsed);
+ for(var property in this._valuesStart) {
+ // Add checks for object, array, numeric up front
+ if(this._valuesEnd[property] instanceof Array) {
+ this._object[property] = this._interpolationFunction(this._valuesEnd[property], this._tempValue);
+ } else {
+ this._object[property] = this._valuesStart[property] + (this._valuesEnd[property] - this._valuesStart[property]) * this._tempValue;
+ }
+ }
+ this.onUpdate.dispatch(this._object, this._tempValue);
+ if(this._tempElapsed == 1) {
+ // Yoyo?
+ if(this._yoyo) {
+ if(this._yoyoCount == 0) {
+ // Reverse the tween
+ this.reverse();
+ return true;
+ } else {
+ // We've yoyo'd once already, quit?
+ if(this._loop == false) {
+ this.onComplete.dispatch(this._object);
+ for(var i = 0; i < this._chainedTweens.length; i++) {
+ this._chainedTweens[i].start();
+ }
+ return false;
+ } else {
+ // YoYo and Loop are both on
+ this._yoyoCount = 0;
+ this.reverse();
+ return true;
+ }
+ }
+ }
+ // Loop?
+ if(this._loop) {
+ this._yoyoCount = 0;
+ this.reset();
+ return true;
+ } else {
+ this.onComplete.dispatch(this._object);
+ for(var i = 0; i < this._chainedTweens.length; i++) {
+ this._chainedTweens[i].start();
+ }
+ if(this._chainedTweens.length == 0) {
+ this.isRunning = false;
+ }
+ return false;
+ }
+ }
+ return true;
+ };
+ return Tween;
+ })();
+ Phaser.Tween = Tween;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/Tween.ts b/TS Source/tweens/Tween.ts
similarity index 100%
rename from Phaser/tweens/Tween.ts
rename to TS Source/tweens/Tween.ts
diff --git a/TS Source/tweens/TweenManager.js b/TS Source/tweens/TweenManager.js
new file mode 100644
index 00000000..fb9a39db
--- /dev/null
+++ b/TS Source/tweens/TweenManager.js
@@ -0,0 +1,121 @@
+///
+/**
+* Phaser - TweenManager
+*
+* The Game has a single instance of the TweenManager through which all Tween objects are created and updated.
+* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
+* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
+* I converted it to TypeScript, swapped the callbacks for signals and patched a few issues with regard
+* to properties and completion errors. Please see https://github.com/sole/tween.js for a full list of contributors.
+*/
+var Phaser;
+(function (Phaser) {
+ var TweenManager = (function () {
+ /**
+ * TweenManager constructor
+ * @param game {Game} A reference to the current Game.
+ */
+ function TweenManager(game) {
+ this.game = game;
+ this._tweens = [];
+ this.game.onPause.add(this.pauseAll, this);
+ this.game.onResume.add(this.resumeAll, this);
+ }
+ TweenManager.prototype.getAll = /**
+ * Get all the tween objects in an array.
+ * @return {Phaser.Tween[]} Array with all tween objects.
+ */
+ function () {
+ return this._tweens;
+ };
+ TweenManager.prototype.removeAll = /**
+ * Remove all tween objects.
+ */
+ function () {
+ this._tweens.length = 0;
+ };
+ TweenManager.prototype.create = /**
+ * Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
+ *
+ * @param obj {object} Object the tween will be run on.
+ * @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
+ * @return {Phaser.Tween} The newly created tween object.
+ */
+ function (object, localReference) {
+ if (typeof localReference === "undefined") { localReference = false; }
+ if(localReference) {
+ object['tween'] = new Phaser.Tween(object, this.game);
+ return object['tween'];
+ } else {
+ return new Phaser.Tween(object, this.game);
+ }
+ };
+ TweenManager.prototype.add = /**
+ * Add a new tween into the TweenManager.
+ *
+ * @param tween {Phaser.Tween} The tween object you want to add.
+ * @return {Phaser.Tween} The tween object you added to the manager.
+ */
+ function (tween) {
+ tween.parent = this.game;
+ this._tweens.push(tween);
+ return tween;
+ };
+ TweenManager.prototype.remove = /**
+ * Remove a tween from this manager.
+ *
+ * @param tween {Phaser.Tween} The tween object you want to remove.
+ */
+ function (tween) {
+ var i = this._tweens.indexOf(tween);
+ if(i !== -1) {
+ this._tweens.splice(i, 1);
+ }
+ };
+ TweenManager.prototype.update = /**
+ * Update all the tween objects you added to this manager.
+ *
+ * @return {bool} Return false if there's no tween to update, otherwise return true.
+ */
+ function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ if(this._tweens[i].update(this.game.time.now)) {
+ i++;
+ } else {
+ this._tweens.splice(i, 1);
+ numTweens--;
+ }
+ }
+ return true;
+ };
+ TweenManager.prototype.pauseAll = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ this._tweens[i].pause();
+ i++;
+ }
+ };
+ TweenManager.prototype.resumeAll = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ this._tweens[i].resume();
+ i++;
+ }
+ };
+ return TweenManager;
+ })();
+ Phaser.TweenManager = TweenManager;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/TweenManager.ts b/TS Source/tweens/TweenManager.ts
similarity index 100%
rename from Phaser/tweens/TweenManager.ts
rename to TS Source/tweens/TweenManager.ts
diff --git a/TS Source/tweens/easing/Back.js b/TS Source/tweens/easing/Back.js
new file mode 100644
index 00000000..2338405e
--- /dev/null
+++ b/TS Source/tweens/easing/Back.js
@@ -0,0 +1,60 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Back easing methods.
+ *
+ * @class Back
+ */
+ var Back = (function () {
+ function Back() { }
+ Back.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ var s = 1.70158;
+ return k * k * ((s + 1) * k - s);
+ };
+ Back.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ var s = 1.70158;
+ return --k * k * ((s + 1) * k + s) + 1;
+ };
+ Back.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ var s = 1.70158 * 1.525;
+ if((k *= 2) < 1) {
+ return 0.5 * (k * k * ((s + 1) * k - s));
+ }
+ return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
+ };
+ return Back;
+ })();
+ Easing.Back = Back;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Back.ts b/TS Source/tweens/easing/Back.ts
similarity index 100%
rename from Phaser/tweens/easing/Back.ts
rename to TS Source/tweens/easing/Back.ts
diff --git a/TS Source/tweens/easing/Bounce.js b/TS Source/tweens/easing/Bounce.js
new file mode 100644
index 00000000..739968da
--- /dev/null
+++ b/TS Source/tweens/easing/Bounce.js
@@ -0,0 +1,65 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Bounce easing methods.
+ *
+ * @class Bounce
+ */
+ var Bounce = (function () {
+ function Bounce() { }
+ Bounce.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ return 1 - Phaser.Easing.Bounce.Out(1 - k);
+ };
+ Bounce.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ if(k < (1 / 2.75)) {
+ return 7.5625 * k * k;
+ } else if(k < (2 / 2.75)) {
+ return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
+ } else if(k < (2.5 / 2.75)) {
+ return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
+ } else {
+ return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
+ }
+ };
+ Bounce.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ if(k < 0.5) {
+ return Phaser.Easing.Bounce.In(k * 2) * 0.5;
+ }
+ return Phaser.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
+ };
+ return Bounce;
+ })();
+ Easing.Bounce = Bounce;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Bounce.ts b/TS Source/tweens/easing/Bounce.ts
similarity index 100%
rename from Phaser/tweens/easing/Bounce.ts
rename to TS Source/tweens/easing/Bounce.ts
diff --git a/TS Source/tweens/easing/Circular.js b/TS Source/tweens/easing/Circular.js
new file mode 100644
index 00000000..b5452143
--- /dev/null
+++ b/TS Source/tweens/easing/Circular.js
@@ -0,0 +1,29 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - Easing - Circular
+ *
+ * For use with Phaser.Tween
+ */
+ (function (Easing) {
+ var Circular = (function () {
+ function Circular() { }
+ Circular.In = function In(k) {
+ return 1 - Math.sqrt(1 - k * k);
+ };
+ Circular.Out = function Out(k) {
+ return Math.sqrt(1 - (--k * k));
+ };
+ Circular.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return -0.5 * (Math.sqrt(1 - k * k) - 1);
+ }
+ return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
+ };
+ return Circular;
+ })();
+ Easing.Circular = Circular;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Circular.ts b/TS Source/tweens/easing/Circular.ts
similarity index 100%
rename from Phaser/tweens/easing/Circular.ts
rename to TS Source/tweens/easing/Circular.ts
diff --git a/TS Source/tweens/easing/Cubic.js b/TS Source/tweens/easing/Cubic.js
new file mode 100644
index 00000000..269c129b
--- /dev/null
+++ b/TS Source/tweens/easing/Cubic.js
@@ -0,0 +1,57 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Cubic easing methods.
+ *
+ * @class Cubic
+ */
+ var Cubic = (function () {
+ function Cubic() { }
+ Cubic.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ return k * k * k;
+ };
+ Cubic.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ return --k * k * k + 1;
+ };
+ Cubic.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k;
+ }
+ return 0.5 * ((k -= 2) * k * k + 2);
+ };
+ return Cubic;
+ })();
+ Easing.Cubic = Cubic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Cubic.ts b/TS Source/tweens/easing/Cubic.ts
similarity index 100%
rename from Phaser/tweens/easing/Cubic.ts
rename to TS Source/tweens/easing/Cubic.ts
diff --git a/TS Source/tweens/easing/Elastic.js b/TS Source/tweens/easing/Elastic.js
new file mode 100644
index 00000000..9aa6d057
--- /dev/null
+++ b/TS Source/tweens/easing/Elastic.js
@@ -0,0 +1,96 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Elastic easing methods.
+ *
+ * @class Elastic
+ */
+ var Elastic = (function () {
+ function Elastic() { }
+ Elastic.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
+ };
+ Elastic.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
+ };
+ Elastic.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ if((k *= 2) < 1) {
+ return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
+ }
+ return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
+ };
+ return Elastic;
+ })();
+ Easing.Elastic = Elastic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Elastic.ts b/TS Source/tweens/easing/Elastic.ts
similarity index 100%
rename from Phaser/tweens/easing/Elastic.ts
rename to TS Source/tweens/easing/Elastic.ts
diff --git a/TS Source/tweens/easing/Exponential.js b/TS Source/tweens/easing/Exponential.js
new file mode 100644
index 00000000..b55ee4c3
--- /dev/null
+++ b/TS Source/tweens/easing/Exponential.js
@@ -0,0 +1,63 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Exponential easing methods.
+ *
+ * @class Exponential
+ */
+ var Exponential = (function () {
+ function Exponential() { }
+ Exponential.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ return k === 0 ? 0 : Math.pow(1024, k - 1);
+ };
+ Exponential.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
+ };
+ Exponential.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if((k *= 2) < 1) {
+ return 0.5 * Math.pow(1024, k - 1);
+ }
+ return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
+ };
+ return Exponential;
+ })();
+ Easing.Exponential = Exponential;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Exponential.ts b/TS Source/tweens/easing/Exponential.ts
similarity index 100%
rename from Phaser/tweens/easing/Exponential.ts
rename to TS Source/tweens/easing/Exponential.ts
diff --git a/TS Source/tweens/easing/Linear.js b/TS Source/tweens/easing/Linear.js
new file mode 100644
index 00000000..e0b46f4f
--- /dev/null
+++ b/TS Source/tweens/easing/Linear.js
@@ -0,0 +1,34 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Linear easing methods.
+ *
+ * @class Linear
+ */
+ var Linear = (function () {
+ function Linear() { }
+ Linear.None = /**
+ * A Linear Ease only has a None method.
+ *
+ * @method None
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function None(k) {
+ return k;
+ };
+ return Linear;
+ })();
+ Easing.Linear = Linear;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Linear.ts b/TS Source/tweens/easing/Linear.ts
similarity index 100%
rename from Phaser/tweens/easing/Linear.ts
rename to TS Source/tweens/easing/Linear.ts
diff --git a/TS Source/tweens/easing/Quadratic.js b/TS Source/tweens/easing/Quadratic.js
new file mode 100644
index 00000000..b0c12e30
--- /dev/null
+++ b/TS Source/tweens/easing/Quadratic.js
@@ -0,0 +1,57 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Quadratic easing methods.
+ *
+ * @class Quadratic
+ */
+ var Quadratic = (function () {
+ function Quadratic() { }
+ Quadratic.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ return k * k;
+ };
+ Quadratic.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ return k * (2 - k);
+ };
+ Quadratic.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k;
+ }
+ return -0.5 * (--k * (k - 2) - 1);
+ };
+ return Quadratic;
+ })();
+ Easing.Quadratic = Quadratic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Quadratic.ts b/TS Source/tweens/easing/Quadratic.ts
similarity index 100%
rename from Phaser/tweens/easing/Quadratic.ts
rename to TS Source/tweens/easing/Quadratic.ts
diff --git a/TS Source/tweens/easing/Quartic.js b/TS Source/tweens/easing/Quartic.js
new file mode 100644
index 00000000..53c8c575
--- /dev/null
+++ b/TS Source/tweens/easing/Quartic.js
@@ -0,0 +1,57 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Quartic easing methods.
+ *
+ * @class Quartic
+ */
+ var Quartic = (function () {
+ function Quartic() { }
+ Quartic.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ return k * k * k * k;
+ };
+ Quartic.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ return 1 - (--k * k * k * k);
+ };
+ Quartic.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k * k;
+ }
+ return -0.5 * ((k -= 2) * k * k * k - 2);
+ };
+ return Quartic;
+ })();
+ Easing.Quartic = Quartic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Quartic.ts b/TS Source/tweens/easing/Quartic.ts
similarity index 100%
rename from Phaser/tweens/easing/Quartic.ts
rename to TS Source/tweens/easing/Quartic.ts
diff --git a/TS Source/tweens/easing/Quintic.js b/TS Source/tweens/easing/Quintic.js
new file mode 100644
index 00000000..4638e9a3
--- /dev/null
+++ b/TS Source/tweens/easing/Quintic.js
@@ -0,0 +1,57 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Quintic easing methods.
+ *
+ * @class Quintic
+ */
+ var Quintic = (function () {
+ function Quintic() { }
+ Quintic.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ return k * k * k * k * k;
+ };
+ Quintic.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ return --k * k * k * k * k + 1;
+ };
+ Quintic.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k * k * k;
+ }
+ return 0.5 * ((k -= 2) * k * k * k * k + 2);
+ };
+ return Quintic;
+ })();
+ Easing.Quintic = Quintic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Quintic.ts b/TS Source/tweens/easing/Quintic.ts
similarity index 100%
rename from Phaser/tweens/easing/Quintic.ts
rename to TS Source/tweens/easing/Quintic.ts
diff --git a/TS Source/tweens/easing/Sinusoidal.js b/TS Source/tweens/easing/Sinusoidal.js
new file mode 100644
index 00000000..b7f0ff84
--- /dev/null
+++ b/TS Source/tweens/easing/Sinusoidal.js
@@ -0,0 +1,54 @@
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * @author Richard Davey
+ * @author sole (http://soledadpenades.com), tween.js
+ * @copyright 2013 Photon Storm Ltd.
+ * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+ * @module Phaser
+ */
+ (function (Easing) {
+ /**
+ * Sinusoidal easing methods.
+ *
+ * @class Sinusoidal
+ */
+ var Sinusoidal = (function () {
+ function Sinusoidal() { }
+ Sinusoidal.In = /**
+ * The In ease method.
+ *
+ * @method In
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function In(k) {
+ return 1 - Math.cos(k * Math.PI / 2);
+ };
+ Sinusoidal.Out = /**
+ * The Out ease method.
+ *
+ * @method Out
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function Out(k) {
+ return Math.sin(k * Math.PI / 2);
+ };
+ Sinusoidal.InOut = /**
+ * The InOut ease method.
+ *
+ * @method InOut
+ * @param {Number} k The value to ease.
+ * @return {Number} The eased value.
+ */
+ function InOut(k) {
+ return 0.5 * (1 - Math.cos(Math.PI * k));
+ };
+ return Sinusoidal;
+ })();
+ Easing.Sinusoidal = Sinusoidal;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/tweens/easing/Sinusoidal.ts b/TS Source/tweens/easing/Sinusoidal.ts
similarity index 100%
rename from Phaser/tweens/easing/Sinusoidal.ts
rename to TS Source/tweens/easing/Sinusoidal.ts
diff --git a/TS Source/ui/Button.js b/TS Source/ui/Button.js
new file mode 100644
index 00000000..a151053d
--- /dev/null
+++ b/TS Source/ui/Button.js
@@ -0,0 +1,151 @@
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ ///
+ /**
+ * Phaser - UI - Button
+ */
+ (function (UI) {
+ var Button = (function (_super) {
+ __extends(Button, _super);
+ /**
+ * Create a new Button object.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param [x] {number} X position of the button.
+ * @param [y] {number} Y position of the button.
+ * @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button.
+ * @param [callback] {function} The function to call when this button is pressed
+ * @param [callbackContext] {object} The context in which the callback will be called (usually 'this')
+ * @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
+ * @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
+ * @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
+ */
+ function Button(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof callbackContext === "undefined") { callbackContext = null; }
+ if (typeof overFrame === "undefined") { overFrame = null; }
+ if (typeof outFrame === "undefined") { outFrame = null; }
+ if (typeof downFrame === "undefined") { downFrame = null; }
+ _super.call(this, game, x, y, key, outFrame);
+ this._onOverFrameName = null;
+ this._onOutFrameName = null;
+ this._onDownFrameName = null;
+ this._onUpFrameName = null;
+ this._onOverFrameID = null;
+ this._onOutFrameID = null;
+ this._onDownFrameID = null;
+ this._onUpFrameID = null;
+ this.type = Phaser.Types.BUTTON;
+ if(typeof overFrame == 'string') {
+ this._onOverFrameName = overFrame;
+ } else {
+ this._onOverFrameID = overFrame;
+ }
+ if(typeof outFrame == 'string') {
+ this._onOutFrameName = outFrame;
+ this._onUpFrameName = outFrame;
+ } else {
+ this._onOutFrameID = outFrame;
+ this._onUpFrameID = outFrame;
+ }
+ if(typeof downFrame == 'string') {
+ this._onDownFrameName = downFrame;
+ } else {
+ this._onDownFrameID = downFrame;
+ }
+ // These are the signals the game will subscribe to
+ this.onInputOver = new Phaser.Signal();
+ this.onInputOut = new Phaser.Signal();
+ this.onInputDown = new Phaser.Signal();
+ this.onInputUp = new Phaser.Signal();
+ // Set a default signal for them
+ if(callback) {
+ this.onInputUp.add(callback, callbackContext);
+ }
+ this.input.start(0, false, true);
+ // Redirect the input events to here so we can handle animation updates, etc
+ this.events.onInputOver.add(this.onInputOverHandler, this);
+ this.events.onInputOut.add(this.onInputOutHandler, this);
+ this.events.onInputDown.add(this.onInputDownHandler, this);
+ this.events.onInputUp.add(this.onInputUpHandler, this);
+ }
+ Button.prototype.onInputOverHandler = // TODO
+ //public tabIndex: number;
+ //public tabEnabled: bool;
+ // ENTER or SPACE can activate this button if it has focus
+ function (pointer) {
+ if(this._onOverFrameName != null) {
+ this.frameName = this._onOverFrameName;
+ } else if(this._onOverFrameID != null) {
+ this.frame = this._onOverFrameID;
+ }
+ if(this.onInputOver) {
+ this.onInputOver.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputOutHandler = function (pointer) {
+ if(this._onOutFrameName != null) {
+ this.frameName = this._onOutFrameName;
+ } else if(this._onOutFrameID != null) {
+ this.frame = this._onOutFrameID;
+ }
+ if(this.onInputOut) {
+ this.onInputOut.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputDownHandler = function (pointer) {
+ //console.log('Button onInputDownHandler: ' + Date.now());
+ if(this._onDownFrameName != null) {
+ this.frameName = this._onDownFrameName;
+ } else if(this._onDownFrameID != null) {
+ this.frame = this._onDownFrameID;
+ }
+ if(this.onInputDown) {
+ this.onInputDown.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputUpHandler = function (pointer) {
+ //console.log('Button onInputUpHandler: ' + Date.now());
+ if(this._onUpFrameName != null) {
+ this.frameName = this._onUpFrameName;
+ } else if(this._onUpFrameID != null) {
+ this.frame = this._onUpFrameID;
+ }
+ if(this.onInputUp) {
+ this.onInputUp.dispatch(this, pointer);
+ }
+ };
+ Object.defineProperty(Button.prototype, "priorityID", {
+ get: function () {
+ return this.input.priorityID;
+ },
+ set: function (value) {
+ this.input.priorityID = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Button.prototype, "useHandCursor", {
+ get: function () {
+ return this.input.useHandCursor;
+ },
+ set: function (value) {
+ this.input.useHandCursor = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Button;
+ })(Phaser.Sprite);
+ UI.Button = Button;
+ })(Phaser.UI || (Phaser.UI = {}));
+ var UI = Phaser.UI;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/ui/Button.ts b/TS Source/ui/Button.ts
similarity index 100%
rename from Phaser/ui/Button.ts
rename to TS Source/ui/Button.ts
diff --git a/TS Source/utils/CanvasUtils.js b/TS Source/utils/CanvasUtils.js
new file mode 100644
index 00000000..059c4255
--- /dev/null
+++ b/TS Source/utils/CanvasUtils.js
@@ -0,0 +1,146 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ /**
+ * A collection of methods useful for manipulating canvas objects.
+ *
+ * @class CanvasUtils
+ */
+ var CanvasUtils = (function () {
+ function CanvasUtils() { }
+ CanvasUtils.getAspectRatio = /**
+ * Returns the aspect ratio of the given canvas.
+ *
+ * @method getAspectRatio
+ * @param {HTMLCanvasElement} canvas The canvas to get the aspect ratio from.
+ * @return {Number} Returns true on success
+ */
+ function getAspectRatio(canvas) {
+ return canvas.width / canvas.height;
+ };
+ CanvasUtils.setBackgroundColor = /**
+ * Sets the background color behind the canvas. This changes the canvas style property.
+ *
+ * @method setBackgroundColor
+ * @param {HTMLCanvasElement} canvas The canvas to set the background color on.
+ * @param {String} color The color to set. Can be in the format 'rgb(r,g,b)', or '#RRGGBB' or any valid CSS color.
+ * @return {HTMLCanvasElement} Returns the source canvas.
+ */
+ function setBackgroundColor(canvas, color) {
+ if (typeof color === "undefined") { color = 'rgb(0,0,0)'; }
+ canvas.style.backgroundColor = color;
+ return canvas;
+ };
+ CanvasUtils.setTouchAction = /**
+ * Sets the touch-action property on the canvas style. Can be used to disable default browser touch actions.
+ *
+ * @method setTouchAction
+ * @param {HTMLCanvasElement} canvas The canvas to set the touch action on.
+ * @param {String} value The touch action to set. Defaults to 'none'.
+ * @return {HTMLCanvasElement} Returns the source canvas.
+ */
+ function setTouchAction(canvas, value) {
+ if (typeof value === "undefined") { value = 'none'; }
+ canvas.style.msTouchAction = value;
+ canvas.style['ms-touch-action'] = value;
+ canvas.style['touch-action'] = value;
+ return canvas;
+ };
+ CanvasUtils.addToDOM = /**
+ * Adds the given canvas element to the DOM. The canvas will be added as a child of the given parent.
+ * If no parent is given it will be added as a child of the document.body.
+ *
+ * @method addToDOM
+ * @param {HTMLCanvasElement} canvas The canvas to set the touch action on.
+ * @param {String} parent The DOM element to add the canvas to. Defaults to ''.
+ * @param {bool} overflowHidden If set to true it will add the overflow='hidden' style to the parent DOM element.
+ * @return {HTMLCanvasElement} Returns the source canvas.
+ */
+ function addToDOM(canvas, parent, overflowHidden) {
+ if (typeof parent === "undefined") { parent = ''; }
+ if (typeof overflowHidden === "undefined") { overflowHidden = true; }
+ if((parent !== '' || parent !== null) && document.getElementById(parent)) {
+ document.getElementById(parent).appendChild(canvas);
+ if(overflowHidden) {
+ document.getElementById(parent).style.overflow = 'hidden';
+ }
+ } else {
+ document.body.appendChild(canvas);
+ }
+ return canvas;
+ };
+ CanvasUtils.setTransform = /**
+ * Sets the transform of the given canvas to the matrix values provided.
+ *
+ * @method setTransform
+ * @param {CanvasRenderingContext2D} context The context to set the transform on.
+ * @param {Number} translateX The value to translate horizontally by.
+ * @param {Number} translateY The value to translate vertically by.
+ * @param {Number} scaleX The value to scale horizontally by.
+ * @param {Number} scaleY The value to scale vertically by.
+ * @param {Number} skewX The value to skew horizontaly by.
+ * @param {Number} skewY The value to skew vertically by.
+ * @return {CanvasRenderingContext2D} Returns the source context.
+ */
+ function setTransform(context, translateX, translateY, scaleX, scaleY, skewX, skewY) {
+ context.setTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
+ return context;
+ };
+ CanvasUtils.setSmoothingEnabled = /**
+ * Sets the Image Smoothing property on the given context. Set to false to disable image smoothing.
+ * By default browsers have image smoothing enabled, which isn't always what you visually want, especially
+ * when using pixel art in a game. Note that this sets the property on the context itself, so that any image
+ * drawn to the context will be affected. This sets the property across all current browsers but support is
+ * patchy on earlier browsers, especially on mobile.
+ *
+ * @method setSmoothingEnabled
+ * @param {CanvasRenderingContext2D} context The context to enable or disable the image smoothing on.
+ * @param {bool} overflowHidden If set to true it will enable image smoothing, false will disable it.
+ * @return {CanvasRenderingContext2D} Returns the source context.
+ */
+ function setSmoothingEnabled(context, value) {
+ context['imageSmoothingEnabled'] = value;
+ context['mozImageSmoothingEnabled'] = value;
+ context['oImageSmoothingEnabled'] = value;
+ context['webkitImageSmoothingEnabled'] = value;
+ context['msImageSmoothingEnabled'] = value;
+ return context;
+ };
+ CanvasUtils.setImageRenderingCrisp = /**
+ * Sets the CSS image-rendering property on the given canvas to be 'crisp' (aka 'optimize contrast on webkit').
+ * Note that if this doesn't given the desired result then see the CanvasUtils.setSmoothingEnabled method.
+ *
+ * @method setImageRenderingCrisp
+ * @param {HTMLCanvasElement} canvas The canvas to set image-rendering crisp on.
+ * @return {HTMLCanvasElement} Returns the source canvas.
+ */
+ function setImageRenderingCrisp(canvas) {
+ canvas.style['image-rendering'] = 'crisp-edges';
+ canvas.style['image-rendering'] = '-moz-crisp-edges';
+ canvas.style['image-rendering'] = '-webkit-optimize-contrast';
+ canvas.style.msInterpolationMode = 'nearest-neighbor';
+ return canvas;
+ };
+ CanvasUtils.setImageRenderingBicubic = /**
+ * Sets the CSS image-rendering property on the given canvas to be 'bicubic' (aka 'auto').
+ * Note that if this doesn't given the desired result then see the CanvasUtils.setSmoothingEnabled method.
+ *
+ * @method setImageRenderingBicubic
+ * @param {HTMLCanvasElement} canvas The canvas to set image-rendering bicubic on.
+ * @return {HTMLCanvasElement} Returns the source canvas.
+ */
+ function setImageRenderingBicubic(canvas) {
+ canvas.style['image-rendering'] = 'auto';
+ canvas.style.msInterpolationMode = 'bicubic';
+ return canvas;
+ };
+ return CanvasUtils;
+ })();
+ Phaser.CanvasUtils = CanvasUtils;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/utils/CanvasUtils.ts b/TS Source/utils/CanvasUtils.ts
similarity index 100%
rename from Phaser/utils/CanvasUtils.ts
rename to TS Source/utils/CanvasUtils.ts
diff --git a/TS Source/utils/CircleUtils.js b/TS Source/utils/CircleUtils.js
new file mode 100644
index 00000000..1d8cbc51
--- /dev/null
+++ b/TS Source/utils/CircleUtils.js
@@ -0,0 +1,154 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ /**
+ * A collection of methods useful for manipulating and comparing Circle objects.
+ *
+ * @class CircleUtils
+ */
+ var CircleUtils = (function () {
+ function CircleUtils() { }
+ CircleUtils.clone = /**
+ * Returns a new Circle object with the same values for the x, y, width, and height properties as the given Circle object.
+ * @method clone
+ * @param {Phaser.Circle} a The Circle object to be cloned.
+ * @param {Phaser.Circle} out Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
+ * @return {Phaser.Circle} The cloned Circle object.
+ */
+ function clone(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Circle(); }
+ return out.setTo(a.x, a.y, a.diameter);
+ };
+ CircleUtils.contains = /**
+ * Return true if the given x/y coordinates are within the Circle object.
+ * @method contains
+ * @param {Phaser.Circle} a The Circle to be checked.
+ * @param {Number} x The X value of the coordinate to test.
+ * @param {Number} y The Y value of the coordinate to test.
+ * @return {bool} True if the coordinates are within this circle, otherwise false.
+ */
+ function contains(a, x, y) {
+ // Check if x/y are within the bounds first
+ if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
+ var dx = (a.x - x) * (a.x - x);
+ var dy = (a.y - y) * (a.y - y);
+ return (dx + dy) <= (a.radius * a.radius);
+ }
+ return false;
+ };
+ CircleUtils.containsPoint = /**
+ * Return true if the coordinates of the given Point object are within this Circle object.
+ * @method containsPoint
+ * @param {Phaser.Circle} a The Circle object.
+ * @param {Phaser.Point} point The Point object to test.
+ * @return {bool} True if the coordinates are within this circle, otherwise false.
+ */
+ function containsPoint(a, point) {
+ return CircleUtils.contains(a, point.x, point.y);
+ };
+ CircleUtils.containsCircle = /**
+ * Return true if the given Circle is contained entirely within this Circle object.
+ * @method containsCircle
+ * @param {Phaser.Circle} a The Circle object to test.
+ * @param {Phaser.Circle} b The Circle object to test.
+ * @return {bool} True if Circle B is contained entirely inside of Circle A, otherwise false.
+ */
+ function containsCircle(a, b) {
+ //return ((a.radius + b.radius) * (a.radius + b.radius)) >= Collision.distanceSquared(a.x, a.y, b.x, b.y);
+ return true;
+ };
+ CircleUtils.distanceBetween = /**
+ * Returns the distance from the center of the Circle object to the given object
+ * (can be Circle, Point or anything with x/y properties)
+ * @method distanceBetween
+ * @param {Phaser.Circle} a The Circle object.
+ * @param {Phaser.Circle} b The target object. Must have visible x and y properties that represent the center of the object.
+ * @param {bool} [optional] round Round the distance to the nearest integer (default false)
+ * @return {Number} The distance between this Point object and the destination Point object.
+ */
+ function distanceBetween(a, target, round) {
+ if (typeof round === "undefined") { round = false; }
+ var dx = a.x - target.x;
+ var dy = a.y - target.y;
+ if(round === true) {
+ return Math.round(Math.sqrt(dx * dx + dy * dy));
+ } else {
+ return Math.sqrt(dx * dx + dy * dy);
+ }
+ };
+ CircleUtils.equals = /**
+ * Determines whether the two Circle objects match. This method compares the x, y and diameter properties.
+ * @method equals
+ * @param {Phaser.Circle} a The first Circle object.
+ * @param {Phaser.Circle} b The second Circle object.
+ * @return {bool} A value of true if the object has exactly the same values for the x, y and diameter properties as this Circle object; otherwise false.
+ */
+ function equals(a, b) {
+ return (a.x == b.x && a.y == b.y && a.diameter == b.diameter);
+ };
+ CircleUtils.intersects = /**
+ * Determines whether the two Circle objects intersect.
+ * This method checks the radius distances between the two Circle objects to see if they intersect.
+ * @method intersects
+ * @param {Phaser.Circle} a The first Circle object.
+ * @param {Phaser.Circle} b The second Circle object.
+ * @return {bool} A value of true if the specified object intersects with this Circle object; otherwise false.
+ */
+ function intersects(a, b) {
+ return (Phaser.CircleUtils.distanceBetween(a, b) <= (a.radius + b.radius));
+ };
+ CircleUtils.circumferencePoint = /**
+ * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
+ * @method circumferencePoint
+ * @param {Phaser.Circle} a The first Circle object.
+ * @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from.
+ * @param {bool} asDegrees Is the given angle in radians (false) or degrees (true)?
+ * @param {Phaser.Point} [optional] output An optional Point object to put the result in to. If none specified a new Point object will be created.
+ * @return {Phaser.Point} The Point object holding the result.
+ */
+ function circumferencePoint(a, angle, asDegrees, out) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ if(asDegrees === true) {
+ angle = angle * Phaser.GameMath.DEG_TO_RAD;
+ }
+ return out.setTo(a.x + a.radius * Math.cos(angle), a.y + a.radius * Math.sin(angle));
+ };
+ CircleUtils.intersectsRectangle = /**
+ * Checks if the given Circle and Rectangle objects intersect.
+ * @method intersectsRectangle
+ * @param {Phaser.Circle} c The Circle object to test.
+ * @param {Phaser.Rectangle} r The Rectangle object to test.
+ * @return {bool} True if the two objects intersect, otherwise false.
+ */
+ function intersectsRectangle(c, r) {
+ var cx = Math.abs(c.x - r.x - r.halfWidth);
+ var xDist = r.halfWidth + c.radius;
+ if(cx > xDist) {
+ return false;
+ }
+ var cy = Math.abs(c.y - r.y - r.halfHeight);
+ var yDist = r.halfHeight + c.radius;
+ if(cy > yDist) {
+ return false;
+ }
+ if(cx <= r.halfWidth || cy <= r.halfHeight) {
+ return true;
+ }
+ var xCornerDist = cx - r.halfWidth;
+ var yCornerDist = cy - r.halfHeight;
+ var xCornerDistSq = xCornerDist * xCornerDist;
+ var yCornerDistSq = yCornerDist * yCornerDist;
+ var maxCornerDistSq = c.radius * c.radius;
+ return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
+ };
+ return CircleUtils;
+ })();
+ Phaser.CircleUtils = CircleUtils;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/utils/CircleUtils.ts b/TS Source/utils/CircleUtils.ts
similarity index 100%
rename from Phaser/utils/CircleUtils.ts
rename to TS Source/utils/CircleUtils.ts
diff --git a/TS Source/utils/ColorUtils.js b/TS Source/utils/ColorUtils.js
new file mode 100644
index 00000000..d3d66cc8
--- /dev/null
+++ b/TS Source/utils/ColorUtils.js
@@ -0,0 +1,485 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ /**
+ * A collection of methods useful for manipulating and comparing colors.
+ *
+ * @class ColorUtils
+ */
+ var ColorUtils = (function () {
+ function ColorUtils() { }
+ ColorUtils.getColor32 = /**
+ * Given an alpha and 3 color values this will return an integer representation of it
+ *
+ * @method getColor32
+ * @param {Number} alpha The Alpha value (between 0 and 255)
+ * @param {Number} red The Red channel value (between 0 and 255)
+ * @param {Number} green The Green channel value (between 0 and 255)
+ * @param {Number} blue The Blue channel value (between 0 and 255)
+ * @return {Number} A native color value integer (format: 0xAARRGGBB)
+ */
+ function getColor32(alpha, red, green, blue) {
+ return alpha << 24 | red << 16 | green << 8 | blue;
+ };
+ ColorUtils.getColor = /**
+ * Given 3 color values this will return an integer representation of it.
+ *
+ * @method getColor
+ * @param {Number} red The Red channel value (between 0 and 255)
+ * @param {Number} green The Green channel value (between 0 and 255)
+ * @param {Number} blue The Blue channel value (between 0 and 255)
+ * @return {Number} A native color value integer (format: 0xRRGGBB)
+ */
+ function getColor(red, green, blue) {
+ return red << 16 | green << 8 | blue;
+ };
+ ColorUtils.getHSVColorWheel = /**
+ * Get HSV color wheel values in an array which will be 360 elements in size.
+ *
+ * @method getHSVColorWheel
+ * @param {Number} alpha Alpha value for each color of the color wheel, between 0 (transparent) and 255 (opaque)
+ * @return {Array} An array containing 360 elements corresponding to the HSV color wheel.
+ */
+ function getHSVColorWheel(alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var colors = [];
+ for(var c = 0; c <= 359; c++) {
+ colors[c] = Phaser.ColorUtils.getWebRGB(Phaser.ColorUtils.HSVtoRGB(c, 1.0, 1.0, alpha));
+ }
+ return colors;
+ };
+ ColorUtils.hexToRGB = /**
+ * Converts the given hex string into an object containing the RGB values.
+ *
+ * @method hexToRGB
+ * @param {String} The string hex color to convert.
+ * @return {Object} An object with 3 properties: r,g and b.
+ */
+ function hexToRGB(h) {
+ var hex16 = (h.charAt(0) == "#") ? h.substring(1, 7) : h;
+ var r = parseInt(hex16.substring(0, 2), 16);
+ var g = parseInt(hex16.substring(2, 4), 16);
+ var b = parseInt(hex16.substring(4, 6), 16);
+ return {
+ r: r,
+ g: g,
+ b: b
+ };
+ };
+ ColorUtils.getComplementHarmony = /**
+ * Returns a Complementary Color Harmony for the given color.
+ * A complementary hue is one directly opposite the color given on the color wheel
+ * Value returned in 0xAARRGGBB format with Alpha set to 255.
+ *
+ * @method getComplementHarmony
+ * @param {Number} color The color to base the harmony on.
+ * @return {Number} 0xAARRGGBB format color value.
+ */
+ function getComplementHarmony(color) {
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
+ return Phaser.ColorUtils.HSVtoRGB(opposite, 1.0, 1.0);
+ };
+ ColorUtils.getAnalogousHarmony = /**
+ * Returns an Analogous Color Harmony for the given color.
+ * An Analogous harmony are hues adjacent to each other on the color wheel
+ * Values returned in 0xAARRGGBB format with Alpha set to 255.
+ *
+ * @method getAnalogousHarmony
+ * @param {Number} color The color to base the harmony on.
+ * @param {Number} threshold Control how adjacent the colors will be (default +- 30 degrees)
+ * @return {Object} Object containing 3 properties: color1 (the original color), color2 (the warmer analogous color) and color3 (the colder analogous color)
+ */
+ function getAnalogousHarmony(color, threshold) {
+ if (typeof threshold === "undefined") { threshold = 30; }
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ if(threshold > 359 || threshold < 0) {
+ throw Error("Color Warning: Invalid threshold given to getAnalogousHarmony()");
+ }
+ var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 359 - threshold, 359);
+ var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, threshold, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(warmer, 1.0, 1.0),
+ color3: Phaser.ColorUtils.HSVtoRGB(colder, 1.0, 1.0),
+ hue1: hsv.hue,
+ hue2: warmer,
+ hue3: colder
+ };
+ };
+ ColorUtils.getSplitComplementHarmony = /**
+ * Returns an Split Complement Color Harmony for the given color.
+ * A Split Complement harmony are the two hues on either side of the color's Complement
+ * Values returned in 0xAARRGGBB format with Alpha set to 255.
+ *
+ * @method getSplitComplementHarmony
+ * @param {Number} color The color to base the harmony on
+ * @param {Number} threshold Control how adjacent the colors will be to the Complement (default +- 30 degrees)
+ * @return {Object} An object containing 3 properties: color1 (the original color), color2 (the warmer analogous color) and color3 (the colder analogous color)
+ */
+ function getSplitComplementHarmony(color, threshold) {
+ if (typeof threshold === "undefined") { threshold = 30; }
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ if(threshold >= 359 || threshold <= 0) {
+ throw Error("Phaser.ColorUtils Warning: Invalid threshold given to getSplitComplementHarmony()");
+ }
+ var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
+ var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite - threshold, 359);
+ var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite + threshold, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(warmer, hsv.saturation, hsv.value),
+ color3: Phaser.ColorUtils.HSVtoRGB(colder, hsv.saturation, hsv.value),
+ hue1: hsv.hue,
+ hue2: warmer,
+ hue3: colder
+ };
+ };
+ ColorUtils.getTriadicHarmony = /**
+ * Returns a Triadic Color Harmony for the given color.
+ * A Triadic harmony are 3 hues equidistant from each other on the color wheel
+ * Values returned in 0xAARRGGBB format with Alpha set to 255.
+ *
+ * @method getTriadicHarmony
+ * @param {Number} color The color to base the harmony on.
+ * @return {Object} An Object containing 3 properties: color1 (the original color), color2 and color3 (the equidistant colors)
+ */
+ function getTriadicHarmony(color) {
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ var triadic1 = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 120, 359);
+ var triadic2 = Phaser.ColorUtils.game.math.wrapValue(triadic1, 120, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(triadic1, 1.0, 1.0),
+ color3: Phaser.ColorUtils.HSVtoRGB(triadic2, 1.0, 1.0)
+ };
+ };
+ ColorUtils.getColorInfo = /**
+ * Returns a string containing handy information about the given color including string hex value,
+ * RGB format information and HSL information. Each section starts on a newline, 3 lines in total.
+ *
+ * @method getColorInfo
+ * @param {Number} color A color value in the format 0xAARRGGBB
+ * @return {String} string containing the 3 lines of information
+ */
+ function getColorInfo(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ var hsl = Phaser.ColorUtils.RGBtoHSV(color);
+ // Hex format
+ var result = Phaser.ColorUtils.RGBtoHexstring(color) + "\n";
+ // RGB format
+ result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n";
+ // HSL info
+ result = result.concat("Hue: " + hsl.hue + " Saturation: " + hsl.saturation + " Lightnes: " + hsl.lightness);
+ return result;
+ };
+ ColorUtils.RGBtoHexstring = /**
+ * Return a string representation of the color in the format 0xAARRGGBB
+ *
+ * @method RGBtoHexstring
+ * @param {Number} color The color to get the string representation for
+ * @return {String A string of length 10 characters in the format 0xAARRGGBB
+ */
+ function RGBtoHexstring(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ return "0x" + Phaser.ColorUtils.colorToHexstring(argb.alpha) + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
+ };
+ ColorUtils.RGBtoWebstring = /**
+ * Return a string representation of the color in the format #RRGGBB
+ *
+ * @method RGBtoWebstring
+ * @param {Number} color The color to get the string representation for
+ * @return {String} A string of length 10 characters in the format 0xAARRGGBB
+ */
+ function RGBtoWebstring(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ return "#" + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
+ };
+ ColorUtils.colorToHexstring = /**
+ * Return a string containing a hex representation of the given color
+ *
+ * @method colorToHexstring
+ * @param {Number} color The color channel to get the hex value for, must be a value between 0 and 255)
+ * @return {String} A string of length 2 characters, i.e. 255 = FF, 0 = 00
+ */
+ function colorToHexstring(color) {
+ var digits = "0123456789ABCDEF";
+ var lsd = color % 16;
+ var msd = (color - lsd) / 16;
+ var hexified = digits.charAt(msd) + digits.charAt(lsd);
+ return hexified;
+ };
+ ColorUtils.HSVtoRGB = /**
+ * Convert a HSV (hue, saturation, lightness) color space value to an RGB color
+ *
+ * @method HSVtoRGB
+ * @param {Number} h Hue degree, between 0 and 359
+ * @param {Number} s Saturation, between 0.0 (grey) and 1.0
+ * @param {Number} v Value, between 0.0 (black) and 1.0
+ * @param {Number} alpha Alpha value to set per color (between 0 and 255)
+ * @return {Number} 32-bit ARGB color value (0xAARRGGBB)
+ */
+ function HSVtoRGB(h, s, v, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var result;
+ if(s == 0.0) {
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, v * 255, v * 255);
+ } else {
+ h = h / 60.0;
+ var f = h - Math.floor(h);
+ var p = v * (1.0 - s);
+ var q = v * (1.0 - s * f);
+ var t = v * (1.0 - s * (1.0 - f));
+ switch(Math.floor(h)) {
+ case 0:
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, t * 255, p * 255);
+ break;
+ case 1:
+ result = Phaser.ColorUtils.getColor32(alpha, q * 255, v * 255, p * 255);
+ break;
+ case 2:
+ result = Phaser.ColorUtils.getColor32(alpha, p * 255, v * 255, t * 255);
+ break;
+ case 3:
+ result = Phaser.ColorUtils.getColor32(alpha, p * 255, q * 255, v * 255);
+ break;
+ case 4:
+ result = Phaser.ColorUtils.getColor32(alpha, t * 255, p * 255, v * 255);
+ break;
+ case 5:
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, p * 255, q * 255);
+ break;
+ default:
+ throw new Error("Phaser.ColorUtils.HSVtoRGB : Unknown color");
+ }
+ }
+ return result;
+ };
+ ColorUtils.RGBtoHSV = /**
+ * Convert an RGB color value to an object containing the HSV color space values: Hue, Saturation and Lightness
+ *
+ * @method RGBtoHSV
+ * @param {Number} color In format 0xRRGGBB
+ * @return {Object} An Object with the properties hue (from 0 to 360), saturation (from 0 to 1.0) and lightness (from 0 to 1.0, also available under .value)
+ */
+ function RGBtoHSV(color) {
+ var rgb = Phaser.ColorUtils.getRGB(color);
+ var red = rgb.red / 255;
+ var green = rgb.green / 255;
+ var blue = rgb.blue / 255;
+ var min = Math.min(red, green, blue);
+ var max = Math.max(red, green, blue);
+ var delta = max - min;
+ var lightness = (max + min) / 2;
+ var hue;
+ var saturation;
+ // Grey color, no chroma
+ if(delta == 0) {
+ hue = 0;
+ saturation = 0;
+ } else {
+ if(lightness < 0.5) {
+ saturation = delta / (max + min);
+ } else {
+ saturation = delta / (2 - max - min);
+ }
+ var delta_r = (((max - red) / 6) + (delta / 2)) / delta;
+ var delta_g = (((max - green) / 6) + (delta / 2)) / delta;
+ var delta_b = (((max - blue) / 6) + (delta / 2)) / delta;
+ if(red == max) {
+ hue = delta_b - delta_g;
+ } else if(green == max) {
+ hue = (1 / 3) + delta_r - delta_b;
+ } else if(blue == max) {
+ hue = (2 / 3) + delta_g - delta_r;
+ }
+ if(hue < 0) {
+ hue += 1;
+ }
+ if(hue > 1) {
+ hue -= 1;
+ }
+ }
+ // Keep the value with 0 to 359
+ hue *= 360;
+ hue = Math.round(hue);
+ return {
+ hue: hue,
+ saturation: saturation,
+ lightness: lightness,
+ value: lightness
+ };
+ };
+ ColorUtils.interpolateColor = /**
+ * Interpolates the two given colours based on the supplied step and currentStep properties.
+ * @method interpolateColor
+ * @param {Number} color1
+ * @param {Number} color2
+ * @param {Number} steps
+ * @param {Number} currentStep
+ * @param {Number} alpha
+ * @return {Number} The interpolated color value.
+ */
+ function interpolateColor(color1, color2, steps, currentStep, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var src1 = Phaser.ColorUtils.getRGB(color1);
+ var src2 = Phaser.ColorUtils.getRGB(color2);
+ var r = (((src2.red - src1.red) * currentStep) / steps) + src1.red;
+ var g = (((src2.green - src1.green) * currentStep) / steps) + src1.green;
+ var b = (((src2.blue - src1.blue) * currentStep) / steps) + src1.blue;
+ return Phaser.ColorUtils.getColor32(alpha, r, g, b);
+ };
+ ColorUtils.interpolateColorWithRGB = /**
+ * Interpolates the two given colours based on the supplied step and currentStep properties.
+ * @method interpolateColorWithRGB
+ * @param {Number} color
+ * @param {Number} r
+ * @param {Number} g
+ * @param {Number} b
+ * @param {Number} steps
+ * @param {Number} currentStep
+ * @return {Number} The interpolated color value.
+ */
+ function interpolateColorWithRGB(color, r, g, b, steps, currentStep) {
+ var src = Phaser.ColorUtils.getRGB(color);
+ var or = (((r - src.red) * currentStep) / steps) + src.red;
+ var og = (((g - src.green) * currentStep) / steps) + src.green;
+ var ob = (((b - src.blue) * currentStep) / steps) + src.blue;
+ return Phaser.ColorUtils.getColor(or, og, ob);
+ };
+ ColorUtils.interpolateRGB = /**
+ * Interpolates the two given colours based on the supplied step and currentStep properties.
+ * @method interpolateRGB
+ * @param {Number} r1
+ * @param {Number} g1
+ * @param {Number} b1
+ * @param {Number} r2
+ * @param {Number} g2
+ * @param {Number} b2
+ * @param {Number} steps
+ * @param {Number} currentStep
+ * @return {Number} The interpolated color value.
+ */
+ function interpolateRGB(r1, g1, b1, r2, g2, b2, steps, currentStep) {
+ var r = (((r2 - r1) * currentStep) / steps) + r1;
+ var g = (((g2 - g1) * currentStep) / steps) + g1;
+ var b = (((b2 - b1) * currentStep) / steps) + b1;
+ return Phaser.ColorUtils.getColor(r, g, b);
+ };
+ ColorUtils.getRandomColor = /**
+ * Returns a random color value between black and white
+ * Set the min value to start each channel from the given offset.
+ * Set the max value to restrict the maximum color used per channel
+ *
+ * @method getRandomColor
+ * @param {Number} min The lowest value to use for the color
+ * @param {Number} max The highest value to use for the color
+ * @param {Number} alpha The alpha value of the returning color (default 255 = fully opaque)
+ * @return {Number} 32-bit color value with alpha
+ */
+ function getRandomColor(min, max, alpha) {
+ if (typeof min === "undefined") { min = 0; }
+ if (typeof max === "undefined") { max = 255; }
+ if (typeof alpha === "undefined") { alpha = 255; }
+ // Sanity checks
+ if(max > 255) {
+ return Phaser.ColorUtils.getColor(255, 255, 255);
+ }
+ if(min > max) {
+ return Phaser.ColorUtils.getColor(255, 255, 255);
+ }
+ var red = min + Math.round(Math.random() * (max - min));
+ var green = min + Math.round(Math.random() * (max - min));
+ var blue = min + Math.round(Math.random() * (max - min));
+ return Phaser.ColorUtils.getColor32(alpha, red, green, blue);
+ };
+ ColorUtils.getRGB = /**
+ * Return the component parts of a color as an Object with the properties alpha, red, green, blue
+ *
+ * Alpha will only be set if it exist in the given color (0xAARRGGBB)
+ *
+ * @method getRGB
+ * @param {Number} color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB)
+ * @return {Object} An Object with properties: alpha, red, green, blue
+ */
+ function getRGB(color) {
+ return {
+ alpha: color >>> 24,
+ red: color >> 16 & 0xFF,
+ green: color >> 8 & 0xFF,
+ blue: color & 0xFF
+ };
+ };
+ ColorUtils.getWebRGB = /**
+ * Returns a CSS friendly string value from the given color.
+ * @method getWebRGB
+ * @param {Number} color
+ * @return {String} A string in the format: 'rgba(r,g,b,a)'
+ */
+ function getWebRGB(color) {
+ var alpha = (color >>> 24) / 255;
+ var red = color >> 16 & 0xFF;
+ var green = color >> 8 & 0xFF;
+ var blue = color & 0xFF;
+ return 'rgba(' + red.toString() + ',' + green.toString() + ',' + blue.toString() + ',' + alpha.toString() + ')';
+ };
+ ColorUtils.getAlpha = /**
+ * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component, as a value between 0 and 255
+ *
+ * @method getAlpha
+ * @param {Number} color In the format 0xAARRGGBB
+ * @return {Number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent))
+ */
+ function getAlpha(color) {
+ return color >>> 24;
+ };
+ ColorUtils.getAlphaFloat = /**
+ * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component as a value between 0 and 1
+ *
+ * @method getAlphaFloat
+ * @param {Number} color In the format 0xAARRGGBB
+ * @return {Number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent))
+ */
+ function getAlphaFloat(color) {
+ return (color >>> 24) / 255;
+ };
+ ColorUtils.getRed = /**
+ * Given a native color value (in the format 0xAARRGGBB) this will return the Red component, as a value between 0 and 255
+ *
+ * @method getRed
+ * @param {Number} color In the format 0xAARRGGBB
+ * @return {Number} The Red component of the color, will be between 0 and 255 (0 being no color, 255 full Red)
+ */
+ function getRed(color) {
+ return color >> 16 & 0xFF;
+ };
+ ColorUtils.getGreen = /**
+ * Given a native color value (in the format 0xAARRGGBB) this will return the Green component, as a value between 0 and 255
+ *
+ * @method getGreen
+ * @param {Number} color In the format 0xAARRGGBB
+ * @return {Number} The Green component of the color, will be between 0 and 255 (0 being no color, 255 full Green)
+ */
+ function getGreen(color) {
+ return color >> 8 & 0xFF;
+ };
+ ColorUtils.getBlue = /**
+ * Given a native color value (in the format 0xAARRGGBB) this will return the Blue component, as a value between 0 and 255
+ *
+ * @method getBlue
+ * @param {Number} color In the format 0xAARRGGBB
+ * @return {Number} The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue)
+ */
+ function getBlue(color) {
+ return color & 0xFF;
+ };
+ return ColorUtils;
+ })();
+ Phaser.ColorUtils = ColorUtils;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/utils/ColorUtils.ts b/TS Source/utils/ColorUtils.ts
similarity index 100%
rename from Phaser/utils/ColorUtils.ts
rename to TS Source/utils/ColorUtils.ts
diff --git a/TS Source/utils/DebugUtils.js b/TS Source/utils/DebugUtils.js
new file mode 100644
index 00000000..6ccaf2d5
--- /dev/null
+++ b/TS Source/utils/DebugUtils.js
@@ -0,0 +1,323 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ /**
+ * A collection of methods for displaying debug information about game objects.
+ *
+ * @class DebugUtils
+ */
+ var DebugUtils = (function () {
+ function DebugUtils() { }
+ DebugUtils.font = '14px Courier';
+ DebugUtils.lineHeight = 16;
+ DebugUtils.renderShadow = true;
+ DebugUtils.start = /**
+ * Internal method that resets the debug output values.
+ * @method start
+ * @param {Number} x The X value the debug info will start from.
+ * @param {Number} y The Y value the debug info will start from.
+ * @param {String} color The color the debug info will drawn in.
+ */
+ function start(x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.currentX = x;
+ Phaser.DebugUtils.currentY = y;
+ Phaser.DebugUtils.currentColor = color;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.font = Phaser.DebugUtils.font;
+ };
+ DebugUtils.line = /**
+ * Internal method that outputs a single line of text.
+ * @method line
+ * @param {String} text The line of text to draw.
+ * @param {Number} x The X value the debug info will start from.
+ * @param {Number} y The Y value the debug info will start from.
+ */
+ function line(text, x, y) {
+ if (typeof x === "undefined") { x = null; }
+ if (typeof y === "undefined") { y = null; }
+ if(x !== null) {
+ Phaser.DebugUtils.currentX = x;
+ }
+ if(y !== null) {
+ Phaser.DebugUtils.currentY = y;
+ }
+ if(Phaser.DebugUtils.renderShadow) {
+ Phaser.DebugUtils.context.fillStyle = 'rgb(0,0,0)';
+ Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX + 1, Phaser.DebugUtils.currentY + 1);
+ Phaser.DebugUtils.context.fillStyle = Phaser.DebugUtils.currentColor;
+ }
+ Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX, Phaser.DebugUtils.currentY);
+ Phaser.DebugUtils.currentY += Phaser.DebugUtils.lineHeight;
+ };
+ DebugUtils.renderSpriteCorners = function renderSpriteCorners(sprite, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,0,255)'; }
+ Phaser.DebugUtils.start(0, 0, color);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperLeft.x) + ' y: ' + Math.floor(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperRight.x) + ' y: ' + Math.floor(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomLeft.x) + ' y: ' + Math.floor(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomRight.x) + ' y: ' + Math.floor(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
+ };
+ DebugUtils.renderSoundInfo = /**
+ * Render debug infos. (including id, position, rotation, scrolling factor, worldBounds and some other properties)
+ * @param x {number} X position of the debug info to be rendered.
+ * @param y {number} Y position of the debug info to be rendered.
+ * @param [color] {number} color of the debug info to be rendered. (format is css color string)
+ */
+ function renderSoundInfo(sound, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback);
+ Phaser.DebugUtils.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding);
+ Phaser.DebugUtils.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying);
+ Phaser.DebugUtils.line('Time: ' + sound.currentTime);
+ Phaser.DebugUtils.line('Volume: ' + sound.volume + ' Muted: ' + sound.mute);
+ Phaser.DebugUtils.line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag);
+ if(sound.currentMarker !== '') {
+ Phaser.DebugUtils.line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration);
+ Phaser.DebugUtils.line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop);
+ Phaser.DebugUtils.line('Position: ' + sound.position);
+ }
+ };
+ DebugUtils.renderCameraInfo = /**
+ * Render debug infos. (including id, position, rotation, scrolling factor, worldBounds and some other properties)
+ * @param x {number} X position of the debug info to be rendered.
+ * @param y {number} Y position of the debug info to be rendered.
+ * @param [color] {number} color of the debug info to be rendered. (format is css color string)
+ */
+ function renderCameraInfo(camera, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Camera ID: ' + camera.ID + ' (' + camera.screenView.width + ' x ' + camera.screenView.height + ')');
+ Phaser.DebugUtils.line('X: ' + camera.x + ' Y: ' + camera.y + ' Rotation: ' + camera.transform.rotation);
+ Phaser.DebugUtils.line('WorldView X: ' + camera.worldView.x + ' Y: ' + camera.worldView.y + ' W: ' + camera.worldView.width + ' H: ' + camera.worldView.height);
+ Phaser.DebugUtils.line('ScreenView X: ' + camera.screenView.x + ' Y: ' + camera.screenView.y + ' W: ' + camera.screenView.width + ' H: ' + camera.screenView.height);
+ if(camera.worldBounds) {
+ Phaser.DebugUtils.line('Bounds: ' + camera.worldBounds.width + ' x ' + camera.worldBounds.height);
+ }
+ };
+ DebugUtils.renderPointer = /**
+ * Renders the Pointer.circle object onto the stage in green if down or red if up.
+ * @method renderDebug
+ */
+ function renderPointer(pointer, hideIfUp, downColor, upColor, color) {
+ if (typeof hideIfUp === "undefined") { hideIfUp = false; }
+ if (typeof downColor === "undefined") { downColor = 'rgba(0,255,0,0.5)'; }
+ if (typeof upColor === "undefined") { upColor = 'rgba(255,0,0,0.5)'; }
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ if(hideIfUp == true && pointer.isUp == true) {
+ return;
+ }
+ Phaser.DebugUtils.context.beginPath();
+ Phaser.DebugUtils.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2);
+ if(pointer.active) {
+ Phaser.DebugUtils.context.fillStyle = downColor;
+ } else {
+ Phaser.DebugUtils.context.fillStyle = upColor;
+ }
+ Phaser.DebugUtils.context.fill();
+ Phaser.DebugUtils.context.closePath();
+ // Render the points
+ Phaser.DebugUtils.context.beginPath();
+ Phaser.DebugUtils.context.moveTo(pointer.positionDown.x, pointer.positionDown.y);
+ Phaser.DebugUtils.context.lineTo(pointer.position.x, pointer.position.y);
+ Phaser.DebugUtils.context.lineWidth = 2;
+ Phaser.DebugUtils.context.stroke();
+ Phaser.DebugUtils.context.closePath();
+ // Render the text
+ Phaser.DebugUtils.start(pointer.x, pointer.y - 100, color);
+ Phaser.DebugUtils.line('ID: ' + pointer.id + " Active: " + pointer.active);
+ Phaser.DebugUtils.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY);
+ Phaser.DebugUtils.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y);
+ Phaser.DebugUtils.line('Duration: ' + pointer.duration + " ms");
+ };
+ DebugUtils.renderSpriteInputInfo = /**
+ * Render Sprite Input Debug information
+ * @param x {number} X position of the debug info to be rendered.
+ * @param y {number} Y position of the debug info to be rendered.
+ * @param [color] {number} color of the debug info to be rendered. (format is css color string)
+ */
+ function renderSpriteInputInfo(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')');
+ Phaser.DebugUtils.line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1));
+ Phaser.DebugUtils.line('over: ' + sprite.input.pointerOver() + ' duration: ' + sprite.input.overDuration().toFixed(0));
+ Phaser.DebugUtils.line('down: ' + sprite.input.pointerDown() + ' duration: ' + sprite.input.downDuration().toFixed(0));
+ Phaser.DebugUtils.line('just over: ' + sprite.input.justOver() + ' just out: ' + sprite.input.justOut());
+ };
+ DebugUtils.renderInputInfo = /**
+ * Render debug information about the Input object.
+ * @param x {number} X position of the debug info to be rendered.
+ * @param y {number} Y position of the debug info to be rendered.
+ * @param [color] {number} color of the debug info to be rendered. (format is css color string)
+ */
+ function renderInputInfo(x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ if(Phaser.DebugUtils.game.input.camera) {
+ Phaser.DebugUtils.line('Input - Camera: ' + Phaser.DebugUtils.game.input.camera.ID);
+ } else {
+ Phaser.DebugUtils.line('Input - Camera: null');
+ }
+ Phaser.DebugUtils.line('X: ' + Phaser.DebugUtils.game.input.x + ' Y: ' + Phaser.DebugUtils.game.input.y);
+ Phaser.DebugUtils.line('World X: ' + Phaser.DebugUtils.game.input.worldX + ' World Y: ' + Phaser.DebugUtils.game.input.worldY);
+ Phaser.DebugUtils.line('Scale X: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1) + ' Scale Y: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1));
+ Phaser.DebugUtils.line('Screen X: ' + Phaser.DebugUtils.game.input.activePointer.screenX + ' Screen Y: ' + Phaser.DebugUtils.game.input.activePointer.screenY);
+ };
+ DebugUtils.renderSpriteWorldView = function renderSpriteWorldView(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')');
+ Phaser.DebugUtils.line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y);
+ Phaser.DebugUtils.line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1));
+ };
+ DebugUtils.renderSpriteWorldViewBounds = function renderSpriteWorldViewBounds(sprite, color) {
+ if (typeof color === "undefined") { color = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.renderRectangle(sprite.worldView, color);
+ };
+ DebugUtils.renderSpriteInfo = /**
+ * Render debug infos. (including name, bounds info, position and some other properties)
+ * @param x {number} X position of the debug info to be rendered.
+ * @param y {number} Y position of the debug info to be rendered.
+ * @param [color] {number} color of the debug info to be rendered. (format is css color string)
+ */
+ function renderSpriteInfo(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y);
+ Phaser.DebugUtils.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
+ Phaser.DebugUtils.line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
+ Phaser.DebugUtils.line('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1));
+ Phaser.DebugUtils.line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
+ Phaser.DebugUtils.line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
+ Phaser.DebugUtils.line('cameraView x: ' + sprite.cameraView.x + ' y: ' + sprite.cameraView.y + ' width: ' + sprite.cameraView.width + ' height: ' + sprite.cameraView.height);
+ Phaser.DebugUtils.line('inCamera: ' + Phaser.DebugUtils.game.renderer.spriteRenderer.inCamera(Phaser.DebugUtils.game.camera, sprite));
+ };
+ DebugUtils.renderSpriteBounds = function renderSpriteBounds(sprite, camera, color) {
+ if (typeof camera === "undefined") { camera = null; }
+ if (typeof color === "undefined") { color = 'rgba(0,255,0,0.2)'; }
+ if(camera == null) {
+ camera = Phaser.DebugUtils.game.camera;
+ }
+ var dx = sprite.worldView.x;
+ var dy = sprite.worldView.y;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
+ };
+ DebugUtils.renderPixel = function renderPixel(x, y, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(x, y, 1, 1);
+ };
+ DebugUtils.renderPoint = function renderPoint(point, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(point.x, point.y, 1, 1);
+ };
+ DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
+ DebugUtils.renderCircle = function renderCircle(circle, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
+ Phaser.DebugUtils.context.fill();
+ };
+ DebugUtils.renderText = /**
+ * Render text
+ * @param x {number} X position of the debug info to be rendered.
+ * @param y {number} Y position of the debug info to be rendered.
+ * @param [color] {number} color of the debug info to be rendered. (format is css color string)
+ */
+ function renderText(text, x, y, color, font) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ if (typeof font === "undefined") { font = '16px Courier'; }
+ Phaser.DebugUtils.context.font = font;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.fillText(text, x, y);
+ };
+ return DebugUtils;
+ })();
+ Phaser.DebugUtils = DebugUtils;
+ /*
+ public render(context:CanvasRenderingContext2D) {
+
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.strokeRect(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight, this.bounds.width, this.bounds.height);
+ context.stroke();
+ context.closePath();
+
+ // center point
+ context.fillStyle = 'rgb(0,255,0)';
+ context.fillRect(this.position.x, this.position.y, 2, 2);
+
+ if (this.touching & Phaser.Types.LEFT)
+ {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
+ context.lineTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
+ context.stroke();
+ context.closePath();
+ }
+ if (this.touching & Phaser.Types.RIGHT)
+ {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
+ context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
+ context.stroke();
+ context.closePath();
+ }
+
+ if (this.touching & Phaser.Types.UP)
+ {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
+ context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
+ context.stroke();
+ context.closePath();
+ }
+ if (this.touching & Phaser.Types.DOWN)
+ {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
+ context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
+ context.stroke();
+ context.closePath();
+ }
+
+ }
+ */
+ /**
+ * Render debug infos. (including name, bounds info, position and some other properties)
+ * @param x {number} X position of the debug info to be rendered.
+ * @param y {number} Y position of the debug info to be rendered.
+ * @param [color] {number} color of the debug info to be rendered. (format is css color string)
+ */
+ /*
+ public renderDebugInfo(x: number, y: number, color: string = 'rgb(255,255,255)') {
+
+ this.sprite.texture.context.fillStyle = color;
+ this.sprite.texture.context.fillText('Sprite: (' + this.sprite.width + ' x ' + this.sprite.height + ')', x, y);
+ //this.sprite.texture.context.fillText('x: ' + this._sprite.frameBounds.x.toFixed(1) + ' y: ' + this._sprite.frameBounds.y.toFixed(1) + ' rotation: ' + this._sprite.rotation.toFixed(1), x, y + 14);
+ this.sprite.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.sprite.transform.rotation.toFixed(0), x, y + 14);
+ this.sprite.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
+ this.sprite.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
+ this.sprite.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
+
+ }
+ */
+ })(Phaser || (Phaser = {}));
diff --git a/Phaser/utils/DebugUtils.ts b/TS Source/utils/DebugUtils.ts
similarity index 100%
rename from Phaser/utils/DebugUtils.ts
rename to TS Source/utils/DebugUtils.ts
diff --git a/TS Source/utils/PointUtils.js b/TS Source/utils/PointUtils.js
new file mode 100644
index 00000000..23d02659
--- /dev/null
+++ b/TS Source/utils/PointUtils.js
@@ -0,0 +1,203 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ /**
+ * A collection of methods useful for manipulating and comparing Point objects.
+ *
+ * @class PointUtils
+ */
+ var PointUtils = (function () {
+ function PointUtils() { }
+ PointUtils.add = /**
+ * Adds the coordinates of two points together to create a new point.
+ * @method add
+ * @param {Phaser.Point} a The first Point object.
+ * @param {Phaser.Point} b The second Point object.
+ * @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Phaser.Point} The new Point object.
+ */
+ function add(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x + b.x, a.y + b.y);
+ };
+ PointUtils.subtract = /**
+ * Subtracts the coordinates of two points to create a new point.
+ * @method subtract
+ * @param {Phaser.Point} a The first Point object.
+ * @param {Phaser.Point} b The second Point object.
+ * @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Phaser.Point} The new Point object.
+ */
+ function subtract(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x - b.x, a.y - b.y);
+ };
+ PointUtils.multiply = /**
+ * Multiplies the coordinates of two points to create a new point.
+ * @method subtract
+ * @param {Phaser.Point} a The first Point object.
+ * @param {Phaser.Point} b The second Point object.
+ * @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Phaser.Point} The new Point object.
+ */
+ function multiply(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x * b.x, a.y * b.y);
+ };
+ PointUtils.divide = /**
+ * Divides the coordinates of two points to create a new point.
+ * @method subtract
+ * @param {Phaser.Point} a The first Point object.
+ * @param {Phaser.Point} b The second Point object.
+ * @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Phaser.Point} The new Point object.
+ */
+ function divide(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x / b.x, a.y / b.y);
+ };
+ PointUtils.clamp = /**
+ * Clamps the Point object values to be between the given min and max
+ * @method clamp
+ * @param {Phaser.Point} a The point.
+ * @param {Number} min The minimum value to clamp this Point to
+ * @param {Number} max The maximum value to clamp this Point to
+ * @return {Phaser.Point} This Point object.
+ */
+ function clamp(a, min, max) {
+ Phaser.PointUtils.clampX(a, min, max);
+ Phaser.PointUtils.clampY(a, min, max);
+ return a;
+ };
+ PointUtils.clampX = /**
+ * Clamps the x value of the given Point object to be between the min and max values.
+ * @method clampX
+ * @param {Phaser.Point} a The point.
+ * @param {Number} min The minimum value to clamp this Point to
+ * @param {Number} max The maximum value to clamp this Point to
+ * @return {Phaser.Point} This Point object.
+ */
+ function clampX(a, min, max) {
+ a.x = Math.max(Math.min(a.x, max), min);
+ return a;
+ };
+ PointUtils.clampY = /**
+ * Clamps the y value of the given Point object to be between the min and max values.
+ * @method clampY
+ * @param {Phaser.Point} a The point.
+ * @param {Number} min The minimum value to clamp this Point to
+ * @param {Number} max The maximum value to clamp this Point to
+ * @return {Phaser.Point} This Point object.
+ */
+ function clampY(a, min, max) {
+ a.y = Math.max(Math.min(a.y, max), min);
+ return a;
+ };
+ PointUtils.clone = /**
+ * Creates a copy of the given Point.
+ * @method clone
+ * @param {Phaser.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 {Phaser.Point} The new Point object.
+ */
+ function clone(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Point(); }
+ return output.setTo(a.x, a.y);
+ };
+ PointUtils.distanceBetween = /**
+ * Returns the distance between the two given Point objects.
+ * @method distanceBetween
+ * @param {Phaser.Point} a The first Point object.
+ * @param {Phaser.Point} b The second Point object.
+ * @param {bool} round Round the distance to the nearest integer (default false)
+ * @return {Number} The distance between the two Point objects.
+ */
+ function distanceBetween(a, b, round) {
+ if (typeof round === "undefined") { round = false; }
+ var dx = a.x - b.x;
+ var dy = a.y - b.y;
+ if(round === true) {
+ return Math.round(Math.sqrt(dx * dx + dy * dy));
+ } else {
+ return Math.sqrt(dx * dx + dy * dy);
+ }
+ };
+ PointUtils.equals = /**
+ * 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 {Phaser.Point} a The first Point object.
+ * @param {Phaser.Point} b The second Point object.
+ * @return {bool} A value of true if the Points are equal, otherwise false.
+ */
+ function equals(a, b) {
+ return (a.x == b.x && a.y == b.y);
+ };
+ PointUtils.rotate = /**
+ * Determines a point between two specified points. The parameter f determines where the new interpolated point is located relative to the two end points specified by parameters pt1 and pt2.
+ * The closer the value of the parameter f is to 1.0, the closer the interpolated point is to the first point (parameter pt1). The closer the value of the parameter f is to 0, the closer the interpolated point is to the second point (parameter pt2).
+ * @method interpolate
+ * @param {Phaser.Point} pointA The first Point object.
+ * @param {Phaser.Point} pointB The second Point object.
+ * @param {Number} f The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned.
+ * @return {Phaser.Point} The new interpolated Point object.
+ */
+ //public static interpolate(pointA, pointB, f) {
+ // TODO!
+ //}
+ /**
+ * Converts a pair of polar coordinates to a Cartesian point coordinate.
+ * @method polar
+ * @param {Number} length The length coordinate of the polar pair.
+ * @param {Number} angle The angle, in radians, of the polar pair.
+ * @return {Phaser.Point} The new Cartesian Point object.
+ */
+ //public static polar(length, angle) {
+ // TODO!
+ //}
+ /**
+ * Rotates a Point around the x/y coordinates given to the desired angle.
+ * @method rotate
+ * @param {Phaser.Point} a The Point object to rotate.
+ * @param {Number} x The x coordinate of the anchor point
+ * @param {Number} y The y coordinate of the anchor point
+ * @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to.
+ * @param {bool} 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 {Phaser.Point} The modified point object
+ */
+ function rotate(a, x, y, angle, asDegrees, distance) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof distance === "undefined") { distance = null; }
+ if(asDegrees) {
+ angle = angle * Phaser.GameMath.DEG_TO_RAD;
+ }
+ // Get distance from origin (cx/cy) to this point
+ if(distance === null) {
+ distance = Math.sqrt(((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y)));
+ }
+ return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
+ };
+ PointUtils.rotateAroundPoint = /**
+ * Rotates a Point around the given Point to the desired angle.
+ * @method rotateAroundPoint
+ * @param {Phaser.Point} a The Point object to rotate.
+ * @param {Phaser.Point} b The Point object to serve as point of rotation.
+ * @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to.
+ * @param {bool} 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 {Phaser.Point} The modified point object
+ */
+ function rotateAroundPoint(a, b, angle, asDegrees, distance) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof distance === "undefined") { distance = null; }
+ return Phaser.PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
+ };
+ return PointUtils;
+ })();
+ Phaser.PointUtils = PointUtils;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/utils/PointUtils.ts b/TS Source/utils/PointUtils.ts
similarity index 100%
rename from Phaser/utils/PointUtils.ts
rename to TS Source/utils/PointUtils.ts
diff --git a/TS Source/utils/RectangleUtils.js b/TS Source/utils/RectangleUtils.js
new file mode 100644
index 00000000..1e3614a8
--- /dev/null
+++ b/TS Source/utils/RectangleUtils.js
@@ -0,0 +1,193 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ /**
+ * A collection of methods useful for manipulating and comparing Rectangle objects.
+ *
+ * @class RectangleUtils
+ */
+ var RectangleUtils = (function () {
+ function RectangleUtils() { }
+ RectangleUtils.getTopLeftAsPoint = /**
+ * Get the location of the Rectangles top-left corner as a Point object.
+ * @method getTopLeftAsPoint
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Phaser.Point} The new Point object.
+ */
+ function getTopLeftAsPoint(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x, a.y);
+ };
+ RectangleUtils.getBottomRightAsPoint = /**
+ * Get the location of the Rectangles bottom-right corner as a Point object.
+ * @method getTopLeftAsPoint
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created.
+ * @return {Phaser.Point} The new Point object.
+ **/
+ function getBottomRightAsPoint(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.right, a.bottom);
+ };
+ RectangleUtils.inflate = /**
+ * Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
+ * @method inflate
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Number} dx The amount to be added to the left side of the Rectangle.
+ * @param {Number} dy The amount to be added to the bottom side of the Rectangle.
+ * @return {Phaser.Rectangle} This Rectangle object.
+ */
+ function inflate(a, dx, dy) {
+ a.x -= dx;
+ a.width += 2 * dx;
+ a.y -= dy;
+ a.height += 2 * dy;
+ return a;
+ };
+ RectangleUtils.inflatePoint = /**
+ * Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.
+ * @method inflatePoint
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Phaser.Point} point The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.
+ * @return {Phaser.Rectangle} The Rectangle object.
+ */
+ function inflatePoint(a, point) {
+ return Phaser.RectangleUtils.inflate(a, point.x, point.y);
+ };
+ RectangleUtils.size = /**
+ * The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
+ * @method size
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Phaser.Point} output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
+ * @return {Phaser.Point} The size of the Rectangle object
+ */
+ function size(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Point(); }
+ return output.setTo(a.width, a.height);
+ };
+ RectangleUtils.clone = /**
+ * Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
+ * @method clone
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Phaser.Rectangle} output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
+ * @return {Phaser.Rectangle}
+ */
+ function clone(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Rectangle(); }
+ return output.setTo(a.x, a.y, a.width, a.height);
+ };
+ RectangleUtils.contains = /**
+ * Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
+ * @method contains
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Number} x The x coordinate of the point to test.
+ * @param {Number} y The y coordinate of the point to test.
+ * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false.
+ */
+ function contains(a, x, y) {
+ return (x >= a.x && x <= a.right && y >= a.y && y <= a.bottom);
+ };
+ RectangleUtils.containsPoint = /**
+ * Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter.
+ * @method containsPoint
+ * @param {Phaser.Rectangle} a The Rectangle object.
+ * @param {Phaser.Point} point The point object being checked. Can be Point or any object with .x and .y values.
+ * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false.
+ */
+ function containsPoint(a, point) {
+ return Phaser.RectangleUtils.contains(a, point.x, point.y);
+ };
+ RectangleUtils.containsRect = /**
+ * Determines whether the first Rectangle object is fully contained within the second Rectangle object.
+ * A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
+ * @method containsRect
+ * @param {Phaser.Rectangle} a The first Rectangle object.
+ * @param {Phaser.Rectangle} b The second Rectangle object.
+ * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false.
+ */
+ function containsRect(a, b) {
+ // If the given rect has a larger volume than this one then it can never contain it
+ if(a.volume > b.volume) {
+ return false;
+ }
+ return (a.x >= b.x && a.y >= b.y && a.right <= b.right && a.bottom <= b.bottom);
+ };
+ RectangleUtils.equals = /**
+ * Determines whether the two Rectangles are equal.
+ * This method compares the x, y, width and height properties of each Rectangle.
+ * @method equals
+ * @param {Phaser.Rectangle} a The first Rectangle object.
+ * @param {Phaser.Rectangle} b The second Rectangle object.
+ * @return {bool} A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
+ */
+ function equals(a, b) {
+ return (a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height);
+ };
+ RectangleUtils.intersection = /**
+ * If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
+ * @method intersection
+ * @param {Phaser.Rectangle} a The first Rectangle object.
+ * @param {Phaser.Rectangle} b The second Rectangle object.
+ * @param {Phaser.Rectangle} output Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
+ * @return {Phaser.Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
+ */
+ function intersection(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
+ if(Phaser.RectangleUtils.intersects(a, b)) {
+ out.x = Math.max(a.x, b.x);
+ out.y = Math.max(a.y, b.y);
+ out.width = Math.min(a.right, b.right) - out.x;
+ out.height = Math.min(a.bottom, b.bottom) - out.y;
+ }
+ return out;
+ };
+ RectangleUtils.intersects = /**
+ * Determines whether the two Rectangles intersect with each other.
+ * This method checks the x, y, width, and height properties of the Rectangles.
+ * @method intersects
+ * @param {Phaser.Rectangle} a The first Rectangle object.
+ * @param {Phaser.Rectangle} b The second Rectangle object.
+ * @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
+ * @return {bool} A value of true if the specified object intersects with this Rectangle object; otherwise false.
+ */
+ function intersects(a, b, tolerance) {
+ if (typeof tolerance === "undefined") { tolerance = 0; }
+ return !(a.left > b.right + tolerance || a.right < b.left - tolerance || a.top > b.bottom + tolerance || a.bottom < b.top - tolerance);
+ };
+ RectangleUtils.intersectsRaw = /**
+ * Determines whether the object specified intersects (overlaps) with the given values.
+ * @method intersectsRaw
+ * @param {Number} left
+ * @param {Number} right
+ * @param {Number} top
+ * @param {Number} bottomt
+ * @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
+ * @return {bool} A value of true if the specified object intersects with the Rectangle; otherwise false.
+ */
+ function intersectsRaw(a, left, right, top, bottom, tolerance) {
+ if (typeof tolerance === "undefined") { tolerance = 0; }
+ return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
+ };
+ RectangleUtils.union = /**
+ * Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
+ * @method union
+ * @param {Phaser.Rectangle} a The first Rectangle object.
+ * @param {Phaser.Rectangle} b The second Rectangle object.
+ * @param {Phaser.Rectangle} output Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
+ * @return {Phaser.Rectangle} A Rectangle object that is the union of the two Rectangles.
+ */
+ function union(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
+ return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
+ };
+ return RectangleUtils;
+ })();
+ Phaser.RectangleUtils = RectangleUtils;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/utils/RectangleUtils.ts b/TS Source/utils/RectangleUtils.ts
similarity index 100%
rename from Phaser/utils/RectangleUtils.ts
rename to TS Source/utils/RectangleUtils.ts
diff --git a/TS Source/utils/SpriteUtils.js b/TS Source/utils/SpriteUtils.js
new file mode 100644
index 00000000..aef7e1a2
--- /dev/null
+++ b/TS Source/utils/SpriteUtils.js
@@ -0,0 +1,270 @@
+///
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser
+*/
+var Phaser;
+(function (Phaser) {
+ /**
+ * A collection of methods useful for manipulating and comparing Sprites.
+ *
+ * @class SpriteUtils
+ */
+ var SpriteUtils = (function () {
+ function SpriteUtils() { }
+ SpriteUtils.updateCameraView = /**
+ * Updates a Sprites cameraView Rectangle based on the given camera, sprite world position and rotation.
+ * @method updateCameraView
+ * @param {Camera} camera The Camera to use in the view
+ * @param {Sprite} sprite The Sprite that will have its cameraView property modified
+ * @return {Rectangle} A reference to the Sprite.cameraView property
+ */
+ function updateCameraView(camera, sprite) {
+ if(sprite.rotation == 0 || sprite.texture.renderRotation == false) {
+ // Easy out
+ sprite.cameraView.x = Math.floor(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.width * sprite.transform.origin.x));
+ sprite.cameraView.y = Math.floor(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.height * sprite.transform.origin.y));
+ sprite.cameraView.width = sprite.width;
+ sprite.cameraView.height = sprite.height;
+ } else {
+ // If the sprite is rotated around its center we can use this quicker method:
+ if(sprite.transform.origin.x == 0.5 && sprite.transform.origin.y == 0.5) {
+ Phaser.SpriteUtils._sin = sprite.transform.sin;
+ Phaser.SpriteUtils._cos = sprite.transform.cos;
+ if(Phaser.SpriteUtils._sin < 0) {
+ Phaser.SpriteUtils._sin = -Phaser.SpriteUtils._sin;
+ }
+ if(Phaser.SpriteUtils._cos < 0) {
+ Phaser.SpriteUtils._cos = -Phaser.SpriteUtils._cos;
+ }
+ sprite.cameraView.width = Math.round(sprite.height * Phaser.SpriteUtils._sin + sprite.width * Phaser.SpriteUtils._cos);
+ sprite.cameraView.height = Math.round(sprite.height * Phaser.SpriteUtils._cos + sprite.width * Phaser.SpriteUtils._sin);
+ sprite.cameraView.x = Math.round(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.cameraView.width * sprite.transform.origin.x));
+ sprite.cameraView.y = Math.round(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.cameraView.height * sprite.transform.origin.y));
+ } else {
+ sprite.cameraView.x = Math.min(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x);
+ sprite.cameraView.y = Math.min(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y);
+ sprite.cameraView.width = Math.max(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x) - sprite.cameraView.x;
+ sprite.cameraView.height = Math.max(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y) - sprite.cameraView.y;
+ }
+ }
+ return sprite.cameraView;
+ };
+ SpriteUtils.getAsPoints = /**
+ * Returns an array containing 4 Point objects corresponding to the 4 corners of the sprite bounds.
+ * @method getAsPoints
+ * @param {Sprite} sprite The Sprite that will have its cameraView property modified
+ * @return {Array} An array of Point objects.
+ */
+ function getAsPoints(sprite) {
+ var out = [];
+ // top left
+ out.push(new Phaser.Point(sprite.x, sprite.y));
+ // top right
+ out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y));
+ // bottom right
+ out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y + sprite.height));
+ // bottom left
+ out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
+ return out;
+ };
+ SpriteUtils.overlapsPointer = /**
+ * Checks to see if some GameObject overlaps this GameObject or Group.
+ * If the group has a LOT of things in it, it might be faster to use Collision.overlaps().
+ * WARNING: Currently tilemaps do NOT support screen space overlap checks!
+ *
+ * @param objectOrGroup {object} The object or group being tested.
+ * @param inScreenSpace {bool} Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
+ * @param camera {Camera} Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
+ *
+ * @return {bool} Whether or not the objects overlap this.
+ */
+ /*
+ static overlaps(objectOrGroup, inScreenSpace: bool = false, camera: Camera = null): bool {
+
+ if (objectOrGroup.isGroup)
+ {
+ var results: bool = false;
+ var i: number = 0;
+ var members = objectOrGroup.members;
+
+ while (i < length)
+ {
+ if (this.overlaps(members[i++], inScreenSpace, camera))
+ {
+ results = true;
+ }
+ }
+
+ return results;
+
+ }
+
+ if (!inScreenSpace)
+ {
+ return (objectOrGroup.x + objectOrGroup.width > this.x) && (objectOrGroup.x < this.x + this.width) &&
+ (objectOrGroup.y + objectOrGroup.height > this.y) && (objectOrGroup.y < this.y + this.height);
+ }
+
+ if (camera == null)
+ {
+ camera = this.game.camera;
+ }
+
+ var objectScreenPos: Point = objectOrGroup.getScreenXY(null, camera);
+
+ this.getScreenXY(this._point, camera);
+
+ return (objectScreenPos.x + objectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
+ (objectScreenPos.y + objectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
+ }
+ */
+ function overlapsPointer(sprite, pointer) {
+ if(sprite.transform.scrollFactor.equals(1)) {
+ // We can do a world vs. world check
+ return Phaser.SpriteUtils.overlapsXY(sprite, pointer.worldX, pointer.worldY);
+ } else if(sprite.transform.scrollFactor.equals(0)) {
+ // scroll factor 0 means a screen view check, as the sprite will be absolutely positioned
+ return Phaser.SpriteUtils.overlapsXY(sprite, pointer.x, pointer.y);
+ } else {
+ // If the sprite has a scroll factor other than 0 or 1 then we need to work out
+ // what the pointers scroll factor values would be
+ var px = pointer.worldX * sprite.transform.scrollFactor.x;
+ var py = pointer.worldY * sprite.transform.scrollFactor.y;
+ return Phaser.SpriteUtils.overlapsXY(sprite, px, py);
+ }
+ };
+ SpriteUtils.overlapsXY = /**
+ * Checks to see if the given x and y coordinates overlaps this Sprite, taking scaling and rotation into account.
+ * The coordinates must be given in world space, not local or camera space.
+ *
+ * @method overlapsXY
+ * @param {Sprite} sprite The Sprite to check. It will take scaling and rotation into account, but NOT scroll factor.
+ * @param {Number} x The x coordinate in world space.
+ * @param {Number} y The y coordinate in world space.
+ * @return {bool} Whether or not the point overlaps this object.
+ */
+ function overlapsXY(sprite, x, y) {
+ // if rotation == 0 then just do a rect check instead!
+ //if (sprite.transform.rotation == 0)
+ //{
+ // return Phaser.RectangleUtils.contains(sprite.worldView, x, y);
+ //}
+ if((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0) {
+ return false;
+ }
+ if((x - sprite.transform.upperRight.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperRight.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) > 0) {
+ return false;
+ }
+ if((x - sprite.transform.upperLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) < 0) {
+ return false;
+ }
+ if((x - sprite.transform.bottomLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.bottomLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) > 0) {
+ return false;
+ }
+ return true;
+ };
+ SpriteUtils.overlapsPoint = /**
+ * Checks to see if the given point overlaps this Sprite, taking scaling and rotation into account.
+ * The point must be given in world space, not local or camera space.
+ *
+ * @method overlapsPoint
+ * @param {Sprite} sprite The Sprite to check. It will take scaling and rotation into account.
+ * @param {Point} point The point in world space you want to check.
+ * @return {bool} Whether or not the point overlaps this object.
+ */
+ function overlapsPoint(sprite, point) {
+ return Phaser.SpriteUtils.overlapsXY(sprite, point.x, point.y);
+ };
+ SpriteUtils.onScreen = /**
+ * Check and see if this object is currently on screen.
+ *
+ * @method onScreen
+ * @param {Sprite} sprite The Sprite to check. It will take scaling and rotation into account.
+ * @param {Camera} camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
+ * @return {bool} Whether the object is on screen or not.
+ */
+ function onScreen(sprite, camera) {
+ if (typeof camera === "undefined") { camera = null; }
+ if(camera == null) {
+ camera = sprite.game.camera;
+ }
+ Phaser.SpriteUtils.getScreenXY(sprite, SpriteUtils._tempPoint, camera);
+ return (Phaser.SpriteUtils._tempPoint.x + sprite.width > 0) && (Phaser.SpriteUtils._tempPoint.x < camera.width) && (Phaser.SpriteUtils._tempPoint.y + sprite.height > 0) && (Phaser.SpriteUtils._tempPoint.y < camera.height);
+ };
+ SpriteUtils.getScreenXY = /**
+ * Call this to figure out the on-screen position of the object.
+ *
+ * @method getScreenXY
+ * @param {Sprite} sprite The Sprite to check.
+ * @param {Point} point Takes a Point object and assigns the post-scrolled X and Y values of this object to it.
+ * @param {Camera} camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
+ * @return {Point} The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.
+ */
+ function getScreenXY(sprite, point, camera) {
+ if (typeof point === "undefined") { point = null; }
+ if (typeof camera === "undefined") { camera = null; }
+ if(point == null) {
+ point = new Phaser.Point();
+ }
+ if(camera == null) {
+ camera = sprite.game.camera;
+ }
+ point.x = sprite.x - camera.x * sprite.transform.scrollFactor.x;
+ point.y = sprite.y - camera.y * sprite.transform.scrollFactor.y;
+ point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
+ point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
+ return point;
+ };
+ SpriteUtils.reset = /**
+ * Set the world bounds that this GameObject can exist within based on the size of the current game world.
+ *
+ * @param action {number} The action to take if the object hits the world bounds, either OUT_OF_BOUNDS_KILL or OUT_OF_BOUNDS_STOP
+ */
+ /*
+ static setBoundsFromWorld(action: number = GameObject.OUT_OF_BOUNDS_STOP) {
+
+ this.setBounds(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height);
+ this.outOfBoundsAction = action;
+
+ }
+ */
+ /**
+ * Handy for reviving game objects. Resets their existence flags and position.
+ *
+ * @method reset
+ * @param {Sprite} sprite The Sprite to reset.
+ * @param {number} x The new X position of this object.
+ * @param {number} y The new Y position of this object.
+ * @return {Sprite} The reset Sprite object.
+ */
+ function reset(sprite, x, y) {
+ sprite.revive();
+ sprite.x = x;
+ sprite.y = y;
+ //sprite.body.velocity.x = 0;
+ //sprite.body.velocity.y = 0;
+ //sprite.body.position.x = x;
+ //sprite.body.position.y = y;
+ return sprite;
+ };
+ SpriteUtils.setBounds = /**
+ * Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
+ * in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
+ * it can be stopped from leaving the world, or a section of it.
+ *
+ * @method setBounds
+ * @param {number} x x position of the bound
+ * @param {number} y y position of the bound
+ * @param {number} width width of its bound
+ * @param {number} height height of its bound
+ */
+ function setBounds(x, y, width, height) {
+ // Needed?
+ };
+ return SpriteUtils;
+ })();
+ Phaser.SpriteUtils = SpriteUtils;
+})(Phaser || (Phaser = {}));
diff --git a/Phaser/utils/SpriteUtils.ts b/TS Source/utils/SpriteUtils.ts
similarity index 100%
rename from Phaser/utils/SpriteUtils.ts
rename to TS Source/utils/SpriteUtils.ts
diff --git a/Phaser/yuidoc.json b/TS Source/yuidoc.json
similarity index 100%
rename from Phaser/yuidoc.json
rename to TS Source/yuidoc.json
diff --git a/Tests/.gitignore b/TS Tests/.gitignore
similarity index 100%
rename from Tests/.gitignore
rename to TS Tests/.gitignore
diff --git a/Tests/Phaser Tests.sublime-project b/TS Tests/Phaser Tests.sublime-project
similarity index 100%
rename from Tests/Phaser Tests.sublime-project
rename to TS Tests/Phaser Tests.sublime-project
diff --git a/Tests/Tests.csproj b/TS Tests/Tests.csproj
similarity index 100%
rename from Tests/Tests.csproj
rename to TS Tests/Tests.csproj
diff --git a/Tests/audio/audio sprites 1.js b/TS Tests/audio/audio sprites 1.js
similarity index 100%
rename from Tests/audio/audio sprites 1.js
rename to TS Tests/audio/audio sprites 1.js
diff --git a/Tests/audio/audio sprites 1.ts b/TS Tests/audio/audio sprites 1.ts
similarity index 100%
rename from Tests/audio/audio sprites 1.ts
rename to TS Tests/audio/audio sprites 1.ts
diff --git a/Tests/audio/play sound 1.js b/TS Tests/audio/play sound 1.js
similarity index 100%
rename from Tests/audio/play sound 1.js
rename to TS Tests/audio/play sound 1.js
diff --git a/Tests/audio/play sound 1.ts b/TS Tests/audio/play sound 1.ts
similarity index 100%
rename from Tests/audio/play sound 1.ts
rename to TS Tests/audio/play sound 1.ts
diff --git a/Tests/buttons/basic button 2.js b/TS Tests/buttons/basic button 2.js
similarity index 100%
rename from Tests/buttons/basic button 2.js
rename to TS Tests/buttons/basic button 2.js
diff --git a/Tests/buttons/basic button 2.ts b/TS Tests/buttons/basic button 2.ts
similarity index 100%
rename from Tests/buttons/basic button 2.ts
rename to TS Tests/buttons/basic button 2.ts
diff --git a/Tests/buttons/basic button.js b/TS Tests/buttons/basic button.js
similarity index 100%
rename from Tests/buttons/basic button.js
rename to TS Tests/buttons/basic button.js
diff --git a/Tests/buttons/basic button.ts b/TS Tests/buttons/basic button.ts
similarity index 100%
rename from Tests/buttons/basic button.ts
rename to TS Tests/buttons/basic button.ts
diff --git a/Tests/buttons/camera buttons.js b/TS Tests/buttons/camera buttons.js
similarity index 100%
rename from Tests/buttons/camera buttons.js
rename to TS Tests/buttons/camera buttons.js
diff --git a/Tests/buttons/camera buttons.ts b/TS Tests/buttons/camera buttons.ts
similarity index 100%
rename from Tests/buttons/camera buttons.ts
rename to TS Tests/buttons/camera buttons.ts
diff --git a/Tests/buttons/rotated buttons.js b/TS Tests/buttons/rotated buttons.js
similarity index 100%
rename from Tests/buttons/rotated buttons.js
rename to TS Tests/buttons/rotated buttons.js
diff --git a/Tests/buttons/rotated buttons.ts b/TS Tests/buttons/rotated buttons.ts
similarity index 100%
rename from Tests/buttons/rotated buttons.ts
rename to TS Tests/buttons/rotated buttons.ts
diff --git a/Tests/camera fx/fade.js b/TS Tests/camera fx/fade.js
similarity index 100%
rename from Tests/camera fx/fade.js
rename to TS Tests/camera fx/fade.js
diff --git a/Tests/camera fx/fade.ts b/TS Tests/camera fx/fade.ts
similarity index 100%
rename from Tests/camera fx/fade.ts
rename to TS Tests/camera fx/fade.ts
diff --git a/Tests/camera fx/mirror.js b/TS Tests/camera fx/mirror.js
similarity index 100%
rename from Tests/camera fx/mirror.js
rename to TS Tests/camera fx/mirror.js
diff --git a/Tests/camera fx/mirror.ts b/TS Tests/camera fx/mirror.ts
similarity index 100%
rename from Tests/camera fx/mirror.ts
rename to TS Tests/camera fx/mirror.ts
diff --git a/Tests/camera fx/scanlines.js b/TS Tests/camera fx/scanlines.js
similarity index 100%
rename from Tests/camera fx/scanlines.js
rename to TS Tests/camera fx/scanlines.js
diff --git a/Tests/camera fx/scanlines.ts b/TS Tests/camera fx/scanlines.ts
similarity index 100%
rename from Tests/camera fx/scanlines.ts
rename to TS Tests/camera fx/scanlines.ts
diff --git a/Tests/cameras/basic camera 1.js b/TS Tests/cameras/basic camera 1.js
similarity index 100%
rename from Tests/cameras/basic camera 1.js
rename to TS Tests/cameras/basic camera 1.js
diff --git a/Tests/cameras/basic camera 1.ts b/TS Tests/cameras/basic camera 1.ts
similarity index 100%
rename from Tests/cameras/basic camera 1.ts
rename to TS Tests/cameras/basic camera 1.ts
diff --git a/Tests/cameras/basic follow.js b/TS Tests/cameras/basic follow.js
similarity index 100%
rename from Tests/cameras/basic follow.js
rename to TS Tests/cameras/basic follow.js
diff --git a/Tests/cameras/basic follow.ts b/TS Tests/cameras/basic follow.ts
similarity index 100%
rename from Tests/cameras/basic follow.ts
rename to TS Tests/cameras/basic follow.ts
diff --git a/Tests/cameras/camera alpha.js b/TS Tests/cameras/camera alpha.js
similarity index 100%
rename from Tests/cameras/camera alpha.js
rename to TS Tests/cameras/camera alpha.js
diff --git a/Tests/cameras/camera alpha.ts b/TS Tests/cameras/camera alpha.ts
similarity index 100%
rename from Tests/cameras/camera alpha.ts
rename to TS Tests/cameras/camera alpha.ts
diff --git a/Tests/cameras/camera fx 1.js b/TS Tests/cameras/camera fx 1.js
similarity index 100%
rename from Tests/cameras/camera fx 1.js
rename to TS Tests/cameras/camera fx 1.js
diff --git a/Tests/cameras/camera fx 1.ts b/TS Tests/cameras/camera fx 1.ts
similarity index 100%
rename from Tests/cameras/camera fx 1.ts
rename to TS Tests/cameras/camera fx 1.ts
diff --git a/Tests/cameras/camera fx 2.js b/TS Tests/cameras/camera fx 2.js
similarity index 100%
rename from Tests/cameras/camera fx 2.js
rename to TS Tests/cameras/camera fx 2.js
diff --git a/Tests/cameras/camera fx 2.ts b/TS Tests/cameras/camera fx 2.ts
similarity index 100%
rename from Tests/cameras/camera fx 2.ts
rename to TS Tests/cameras/camera fx 2.ts
diff --git a/Tests/cameras/camera fx 3.js b/TS Tests/cameras/camera fx 3.js
similarity index 100%
rename from Tests/cameras/camera fx 3.js
rename to TS Tests/cameras/camera fx 3.js
diff --git a/Tests/cameras/camera fx 3.ts b/TS Tests/cameras/camera fx 3.ts
similarity index 100%
rename from Tests/cameras/camera fx 3.ts
rename to TS Tests/cameras/camera fx 3.ts
diff --git a/Tests/cameras/camera rotation.js b/TS Tests/cameras/camera rotation.js
similarity index 100%
rename from Tests/cameras/camera rotation.js
rename to TS Tests/cameras/camera rotation.js
diff --git a/Tests/cameras/camera rotation.ts b/TS Tests/cameras/camera rotation.ts
similarity index 100%
rename from Tests/cameras/camera rotation.ts
rename to TS Tests/cameras/camera rotation.ts
diff --git a/Tests/cameras/camera scale.js b/TS Tests/cameras/camera scale.js
similarity index 100%
rename from Tests/cameras/camera scale.js
rename to TS Tests/cameras/camera scale.js
diff --git a/Tests/cameras/camera scale.ts b/TS Tests/cameras/camera scale.ts
similarity index 100%
rename from Tests/cameras/camera scale.ts
rename to TS Tests/cameras/camera scale.ts
diff --git a/Tests/cameras/camera texture.js b/TS Tests/cameras/camera texture.js
similarity index 100%
rename from Tests/cameras/camera texture.js
rename to TS Tests/cameras/camera texture.js
diff --git a/Tests/cameras/camera texture.ts b/TS Tests/cameras/camera texture.ts
similarity index 100%
rename from Tests/cameras/camera texture.ts
rename to TS Tests/cameras/camera texture.ts
diff --git a/Tests/cameras/follow styles.js b/TS Tests/cameras/follow styles.js
similarity index 100%
rename from Tests/cameras/follow styles.js
rename to TS Tests/cameras/follow styles.js
diff --git a/Tests/cameras/follow styles.ts b/TS Tests/cameras/follow styles.ts
similarity index 100%
rename from Tests/cameras/follow styles.ts
rename to TS Tests/cameras/follow styles.ts
diff --git a/Tests/cameras/hide from camera.js b/TS Tests/cameras/hide from camera.js
similarity index 100%
rename from Tests/cameras/hide from camera.js
rename to TS Tests/cameras/hide from camera.js
diff --git a/Tests/cameras/hide from camera.ts b/TS Tests/cameras/hide from camera.ts
similarity index 100%
rename from Tests/cameras/hide from camera.ts
rename to TS Tests/cameras/hide from camera.ts
diff --git a/Tests/cameras/multi camera.js b/TS Tests/cameras/multi camera.js
similarity index 100%
rename from Tests/cameras/multi camera.js
rename to TS Tests/cameras/multi camera.js
diff --git a/Tests/cameras/multi camera.ts b/TS Tests/cameras/multi camera.ts
similarity index 100%
rename from Tests/cameras/multi camera.ts
rename to TS Tests/cameras/multi camera.ts
diff --git a/Tests/cameras/scrollfactor 1.js b/TS Tests/cameras/scrollfactor 1.js
similarity index 100%
rename from Tests/cameras/scrollfactor 1.js
rename to TS Tests/cameras/scrollfactor 1.js
diff --git a/Tests/cameras/scrollfactor 1.ts b/TS Tests/cameras/scrollfactor 1.ts
similarity index 100%
rename from Tests/cameras/scrollfactor 1.ts
rename to TS Tests/cameras/scrollfactor 1.ts
diff --git a/Tests/cameras/scrollfactor 2.js b/TS Tests/cameras/scrollfactor 2.js
similarity index 100%
rename from Tests/cameras/scrollfactor 2.js
rename to TS Tests/cameras/scrollfactor 2.js
diff --git a/Tests/cameras/scrollfactor 2.ts b/TS Tests/cameras/scrollfactor 2.ts
similarity index 100%
rename from Tests/cameras/scrollfactor 2.ts
rename to TS Tests/cameras/scrollfactor 2.ts
diff --git a/Tests/cameras/scrollfactor compare.js b/TS Tests/cameras/scrollfactor compare.js
similarity index 100%
rename from Tests/cameras/scrollfactor compare.js
rename to TS Tests/cameras/scrollfactor compare.js
diff --git a/Tests/cameras/scrollfactor compare.ts b/TS Tests/cameras/scrollfactor compare.ts
similarity index 100%
rename from Tests/cameras/scrollfactor compare.ts
rename to TS Tests/cameras/scrollfactor compare.ts
diff --git a/Tests/cameras/world sprite.js b/TS Tests/cameras/world sprite.js
similarity index 100%
rename from Tests/cameras/world sprite.js
rename to TS Tests/cameras/world sprite.js
diff --git a/Tests/cameras/world sprite.ts b/TS Tests/cameras/world sprite.ts
similarity index 100%
rename from Tests/cameras/world sprite.ts
rename to TS Tests/cameras/world sprite.ts
diff --git a/Tests/display/render crisp.js b/TS Tests/display/render crisp.js
similarity index 100%
rename from Tests/display/render crisp.js
rename to TS Tests/display/render crisp.js
diff --git a/Tests/display/render crisp.ts b/TS Tests/display/render crisp.ts
similarity index 100%
rename from Tests/display/render crisp.ts
rename to TS Tests/display/render crisp.ts
diff --git a/Tests/groups/add to group 1.js b/TS Tests/groups/add to group 1.js
similarity index 100%
rename from Tests/groups/add to group 1.js
rename to TS Tests/groups/add to group 1.js
diff --git a/Tests/groups/add to group 1.ts b/TS Tests/groups/add to group 1.ts
similarity index 100%
rename from Tests/groups/add to group 1.ts
rename to TS Tests/groups/add to group 1.ts
diff --git a/Tests/groups/add to group 2.js b/TS Tests/groups/add to group 2.js
similarity index 100%
rename from Tests/groups/add to group 2.js
rename to TS Tests/groups/add to group 2.js
diff --git a/Tests/groups/add to group 2.ts b/TS Tests/groups/add to group 2.ts
similarity index 100%
rename from Tests/groups/add to group 2.ts
rename to TS Tests/groups/add to group 2.ts
diff --git a/Tests/groups/bring to top 1.js b/TS Tests/groups/bring to top 1.js
similarity index 100%
rename from Tests/groups/bring to top 1.js
rename to TS Tests/groups/bring to top 1.js
diff --git a/Tests/groups/bring to top 1.ts b/TS Tests/groups/bring to top 1.ts
similarity index 100%
rename from Tests/groups/bring to top 1.ts
rename to TS Tests/groups/bring to top 1.ts
diff --git a/Tests/groups/bring to top.js b/TS Tests/groups/bring to top.js
similarity index 100%
rename from Tests/groups/bring to top.js
rename to TS Tests/groups/bring to top.js
diff --git a/Tests/groups/bring to top.ts b/TS Tests/groups/bring to top.ts
similarity index 100%
rename from Tests/groups/bring to top.ts
rename to TS Tests/groups/bring to top.ts
diff --git a/Tests/groups/call all.js b/TS Tests/groups/call all.js
similarity index 100%
rename from Tests/groups/call all.js
rename to TS Tests/groups/call all.js
diff --git a/Tests/groups/call all.ts b/TS Tests/groups/call all.ts
similarity index 100%
rename from Tests/groups/call all.ts
rename to TS Tests/groups/call all.ts
diff --git a/Tests/groups/create group 1.js b/TS Tests/groups/create group 1.js
similarity index 100%
rename from Tests/groups/create group 1.js
rename to TS Tests/groups/create group 1.js
diff --git a/Tests/groups/create group 1.ts b/TS Tests/groups/create group 1.ts
similarity index 100%
rename from Tests/groups/create group 1.ts
rename to TS Tests/groups/create group 1.ts
diff --git a/Tests/groups/direct render.js b/TS Tests/groups/direct render.js
similarity index 100%
rename from Tests/groups/direct render.js
rename to TS Tests/groups/direct render.js
diff --git a/Tests/groups/direct render.ts b/TS Tests/groups/direct render.ts
similarity index 100%
rename from Tests/groups/direct render.ts
rename to TS Tests/groups/direct render.ts
diff --git a/Tests/groups/display order.js b/TS Tests/groups/display order.js
similarity index 100%
rename from Tests/groups/display order.js
rename to TS Tests/groups/display order.js
diff --git a/Tests/groups/display order.ts b/TS Tests/groups/display order.ts
similarity index 100%
rename from Tests/groups/display order.ts
rename to TS Tests/groups/display order.ts
diff --git a/Tests/groups/for each.js b/TS Tests/groups/for each.js
similarity index 100%
rename from Tests/groups/for each.js
rename to TS Tests/groups/for each.js
diff --git a/Tests/groups/for each.ts b/TS Tests/groups/for each.ts
similarity index 100%
rename from Tests/groups/for each.ts
rename to TS Tests/groups/for each.ts
diff --git a/Tests/groups/get first 1.js b/TS Tests/groups/get first 1.js
similarity index 100%
rename from Tests/groups/get first 1.js
rename to TS Tests/groups/get first 1.js
diff --git a/Tests/groups/get first 1.ts b/TS Tests/groups/get first 1.ts
similarity index 100%
rename from Tests/groups/get first 1.ts
rename to TS Tests/groups/get first 1.ts
diff --git a/Tests/groups/get first 2.js b/TS Tests/groups/get first 2.js
similarity index 100%
rename from Tests/groups/get first 2.js
rename to TS Tests/groups/get first 2.js
diff --git a/Tests/groups/get first 2.ts b/TS Tests/groups/get first 2.ts
similarity index 100%
rename from Tests/groups/get first 2.ts
rename to TS Tests/groups/get first 2.ts
diff --git a/Tests/groups/get first 3.js b/TS Tests/groups/get first 3.js
similarity index 100%
rename from Tests/groups/get first 3.js
rename to TS Tests/groups/get first 3.js
diff --git a/Tests/groups/get first 3.ts b/TS Tests/groups/get first 3.ts
similarity index 100%
rename from Tests/groups/get first 3.ts
rename to TS Tests/groups/get first 3.ts
diff --git a/Tests/groups/group as layer.js b/TS Tests/groups/group as layer.js
similarity index 100%
rename from Tests/groups/group as layer.js
rename to TS Tests/groups/group as layer.js
diff --git a/Tests/groups/group as layer.ts b/TS Tests/groups/group as layer.ts
similarity index 100%
rename from Tests/groups/group as layer.ts
rename to TS Tests/groups/group as layer.ts
diff --git a/Tests/groups/group texture.js b/TS Tests/groups/group texture.js
similarity index 100%
rename from Tests/groups/group texture.js
rename to TS Tests/groups/group texture.js
diff --git a/Tests/groups/group transform 1.js b/TS Tests/groups/group transform 1.js
similarity index 100%
rename from Tests/groups/group transform 1.js
rename to TS Tests/groups/group transform 1.js
diff --git a/Tests/groups/group transform 1.ts b/TS Tests/groups/group transform 1.ts
similarity index 100%
rename from Tests/groups/group transform 1.ts
rename to TS Tests/groups/group transform 1.ts
diff --git a/Tests/groups/group transform 2.js b/TS Tests/groups/group transform 2.js
similarity index 100%
rename from Tests/groups/group transform 2.js
rename to TS Tests/groups/group transform 2.js
diff --git a/Tests/groups/group transform 2.ts b/TS Tests/groups/group transform 2.ts
similarity index 100%
rename from Tests/groups/group transform 2.ts
rename to TS Tests/groups/group transform 2.ts
diff --git a/Tests/groups/group transform 3.js b/TS Tests/groups/group transform 3.js
similarity index 100%
rename from Tests/groups/group transform 3.js
rename to TS Tests/groups/group transform 3.js
diff --git a/Tests/groups/group transform 3.ts b/TS Tests/groups/group transform 3.ts
similarity index 100%
rename from Tests/groups/group transform 3.ts
rename to TS Tests/groups/group transform 3.ts
diff --git a/Tests/groups/recycle 1.js b/TS Tests/groups/recycle 1.js
similarity index 100%
rename from Tests/groups/recycle 1.js
rename to TS Tests/groups/recycle 1.js
diff --git a/Tests/groups/recycle 1.ts b/TS Tests/groups/recycle 1.ts
similarity index 100%
rename from Tests/groups/recycle 1.ts
rename to TS Tests/groups/recycle 1.ts
diff --git a/Tests/groups/recycle 2.js b/TS Tests/groups/recycle 2.js
similarity index 100%
rename from Tests/groups/recycle 2.js
rename to TS Tests/groups/recycle 2.js
diff --git a/Tests/groups/recycle 2.ts b/TS Tests/groups/recycle 2.ts
similarity index 100%
rename from Tests/groups/recycle 2.ts
rename to TS Tests/groups/recycle 2.ts
diff --git a/Tests/groups/remove.js b/TS Tests/groups/remove.js
similarity index 100%
rename from Tests/groups/remove.js
rename to TS Tests/groups/remove.js
diff --git a/Tests/groups/remove.ts b/TS Tests/groups/remove.ts
similarity index 100%
rename from Tests/groups/remove.ts
rename to TS Tests/groups/remove.ts
diff --git a/Tests/groups/replace.js b/TS Tests/groups/replace.js
similarity index 100%
rename from Tests/groups/replace.js
rename to TS Tests/groups/replace.js
diff --git a/Tests/groups/replace.ts b/TS Tests/groups/replace.ts
similarity index 100%
rename from Tests/groups/replace.ts
rename to TS Tests/groups/replace.ts
diff --git a/Tests/groups/set all.js b/TS Tests/groups/set all.js
similarity index 100%
rename from Tests/groups/set all.js
rename to TS Tests/groups/set all.js
diff --git a/Tests/groups/set all.ts b/TS Tests/groups/set all.ts
similarity index 100%
rename from Tests/groups/set all.ts
rename to TS Tests/groups/set all.ts
diff --git a/Tests/groups/sort 1.js b/TS Tests/groups/sort 1.js
similarity index 100%
rename from Tests/groups/sort 1.js
rename to TS Tests/groups/sort 1.js
diff --git a/Tests/groups/sort 1.ts b/TS Tests/groups/sort 1.ts
similarity index 100%
rename from Tests/groups/sort 1.ts
rename to TS Tests/groups/sort 1.ts
diff --git a/Tests/groups/sort 2.js b/TS Tests/groups/sort 2.js
similarity index 100%
rename from Tests/groups/sort 2.js
rename to TS Tests/groups/sort 2.js
diff --git a/Tests/groups/sort 2.ts b/TS Tests/groups/sort 2.ts
similarity index 100%
rename from Tests/groups/sort 2.ts
rename to TS Tests/groups/sort 2.ts
diff --git a/Tests/groups/sub groups.js b/TS Tests/groups/sub groups.js
similarity index 100%
rename from Tests/groups/sub groups.js
rename to TS Tests/groups/sub groups.js
diff --git a/Tests/groups/sub groups.ts b/TS Tests/groups/sub groups.ts
similarity index 100%
rename from Tests/groups/sub groups.ts
rename to TS Tests/groups/sub groups.ts
diff --git a/Tests/groups/swap children.js b/TS Tests/groups/swap children.js
similarity index 100%
rename from Tests/groups/swap children.js
rename to TS Tests/groups/swap children.js
diff --git a/Tests/groups/swap children.ts b/TS Tests/groups/swap children.ts
similarity index 100%
rename from Tests/groups/swap children.ts
rename to TS Tests/groups/swap children.ts
diff --git a/Tests/index.php b/TS Tests/index.php
similarity index 100%
rename from Tests/index.php
rename to TS Tests/index.php
diff --git a/Tests/input/bring to top.js b/TS Tests/input/bring to top.js
similarity index 100%
rename from Tests/input/bring to top.js
rename to TS Tests/input/bring to top.js
diff --git a/Tests/input/bring to top.ts b/TS Tests/input/bring to top.ts
similarity index 100%
rename from Tests/input/bring to top.ts
rename to TS Tests/input/bring to top.ts
diff --git a/Tests/input/drag sprite 1.js b/TS Tests/input/drag sprite 1.js
similarity index 100%
rename from Tests/input/drag sprite 1.js
rename to TS Tests/input/drag sprite 1.js
diff --git a/Tests/input/drag sprite 1.ts b/TS Tests/input/drag sprite 1.ts
similarity index 100%
rename from Tests/input/drag sprite 1.ts
rename to TS Tests/input/drag sprite 1.ts
diff --git a/Tests/input/drag sprite 2.js b/TS Tests/input/drag sprite 2.js
similarity index 100%
rename from Tests/input/drag sprite 2.js
rename to TS Tests/input/drag sprite 2.js
diff --git a/Tests/input/drag sprite 2.ts b/TS Tests/input/drag sprite 2.ts
similarity index 100%
rename from Tests/input/drag sprite 2.ts
rename to TS Tests/input/drag sprite 2.ts
diff --git a/Tests/input/drag sprite 3.js b/TS Tests/input/drag sprite 3.js
similarity index 100%
rename from Tests/input/drag sprite 3.js
rename to TS Tests/input/drag sprite 3.js
diff --git a/Tests/input/drag sprite 3.ts b/TS Tests/input/drag sprite 3.ts
similarity index 100%
rename from Tests/input/drag sprite 3.ts
rename to TS Tests/input/drag sprite 3.ts
diff --git a/Tests/input/drop limitation.js b/TS Tests/input/drop limitation.js
similarity index 100%
rename from Tests/input/drop limitation.js
rename to TS Tests/input/drop limitation.js
diff --git a/Tests/input/drop limitation.ts b/TS Tests/input/drop limitation.ts
similarity index 100%
rename from Tests/input/drop limitation.ts
rename to TS Tests/input/drop limitation.ts
diff --git a/Tests/input/game scale 1.js b/TS Tests/input/game scale 1.js
similarity index 100%
rename from Tests/input/game scale 1.js
rename to TS Tests/input/game scale 1.js
diff --git a/Tests/input/game scale 1.ts b/TS Tests/input/game scale 1.ts
similarity index 100%
rename from Tests/input/game scale 1.ts
rename to TS Tests/input/game scale 1.ts
diff --git a/Tests/input/keyboard 1.js b/TS Tests/input/keyboard 1.js
similarity index 100%
rename from Tests/input/keyboard 1.js
rename to TS Tests/input/keyboard 1.js
diff --git a/Tests/input/keyboard 1.ts b/TS Tests/input/keyboard 1.ts
similarity index 100%
rename from Tests/input/keyboard 1.ts
rename to TS Tests/input/keyboard 1.ts
diff --git a/Tests/input/keyboard 2.js b/TS Tests/input/keyboard 2.js
similarity index 100%
rename from Tests/input/keyboard 2.js
rename to TS Tests/input/keyboard 2.js
diff --git a/Tests/input/keyboard 2.ts b/TS Tests/input/keyboard 2.ts
similarity index 100%
rename from Tests/input/keyboard 2.ts
rename to TS Tests/input/keyboard 2.ts
diff --git a/Tests/input/motion lock 2.js b/TS Tests/input/motion lock 2.js
similarity index 100%
rename from Tests/input/motion lock 2.js
rename to TS Tests/input/motion lock 2.js
diff --git a/Tests/input/motion lock 2.ts b/TS Tests/input/motion lock 2.ts
similarity index 100%
rename from Tests/input/motion lock 2.ts
rename to TS Tests/input/motion lock 2.ts
diff --git a/Tests/input/motion lock.js b/TS Tests/input/motion lock.js
similarity index 100%
rename from Tests/input/motion lock.js
rename to TS Tests/input/motion lock.js
diff --git a/Tests/input/motion lock.ts b/TS Tests/input/motion lock.ts
similarity index 100%
rename from Tests/input/motion lock.ts
rename to TS Tests/input/motion lock.ts
diff --git a/Tests/input/multitouch.js b/TS Tests/input/multitouch.js
similarity index 100%
rename from Tests/input/multitouch.js
rename to TS Tests/input/multitouch.js
diff --git a/Tests/input/multitouch.ts b/TS Tests/input/multitouch.ts
similarity index 100%
rename from Tests/input/multitouch.ts
rename to TS Tests/input/multitouch.ts
diff --git a/Tests/input/over sprite 1.js b/TS Tests/input/over sprite 1.js
similarity index 100%
rename from Tests/input/over sprite 1.js
rename to TS Tests/input/over sprite 1.js
diff --git a/Tests/input/over sprite 1.ts b/TS Tests/input/over sprite 1.ts
similarity index 100%
rename from Tests/input/over sprite 1.ts
rename to TS Tests/input/over sprite 1.ts
diff --git a/Tests/input/over sprite 2.js b/TS Tests/input/over sprite 2.js
similarity index 100%
rename from Tests/input/over sprite 2.js
rename to TS Tests/input/over sprite 2.js
diff --git a/Tests/input/over sprite 2.ts b/TS Tests/input/over sprite 2.ts
similarity index 100%
rename from Tests/input/over sprite 2.ts
rename to TS Tests/input/over sprite 2.ts
diff --git a/Tests/input/point in rotated sprite.js b/TS Tests/input/point in rotated sprite.js
similarity index 100%
rename from Tests/input/point in rotated sprite.js
rename to TS Tests/input/point in rotated sprite.js
diff --git a/Tests/input/point in rotated sprite.ts b/TS Tests/input/point in rotated sprite.ts
similarity index 100%
rename from Tests/input/point in rotated sprite.ts
rename to TS Tests/input/point in rotated sprite.ts
diff --git a/Tests/input/rotated sprites.js b/TS Tests/input/rotated sprites.js
similarity index 100%
rename from Tests/input/rotated sprites.js
rename to TS Tests/input/rotated sprites.js
diff --git a/Tests/input/rotated sprites.ts b/TS Tests/input/rotated sprites.ts
similarity index 100%
rename from Tests/input/rotated sprites.ts
rename to TS Tests/input/rotated sprites.ts
diff --git a/Tests/input/snap 1.js b/TS Tests/input/snap 1.js
similarity index 100%
rename from Tests/input/snap 1.js
rename to TS Tests/input/snap 1.js
diff --git a/Tests/input/snap 1.ts b/TS Tests/input/snap 1.ts
similarity index 100%
rename from Tests/input/snap 1.ts
rename to TS Tests/input/snap 1.ts
diff --git a/Tests/input/touch priority.js b/TS Tests/input/touch priority.js
similarity index 100%
rename from Tests/input/touch priority.js
rename to TS Tests/input/touch priority.js
diff --git a/Tests/input/touch priority.ts b/TS Tests/input/touch priority.ts
similarity index 100%
rename from Tests/input/touch priority.ts
rename to TS Tests/input/touch priority.ts
diff --git a/Tests/input/world coordinates.js b/TS Tests/input/world coordinates.js
similarity index 100%
rename from Tests/input/world coordinates.js
rename to TS Tests/input/world coordinates.js
diff --git a/Tests/input/world coordinates.ts b/TS Tests/input/world coordinates.ts
similarity index 100%
rename from Tests/input/world coordinates.ts
rename to TS Tests/input/world coordinates.ts
diff --git a/Tests/input/world drag.js b/TS Tests/input/world drag.js
similarity index 100%
rename from Tests/input/world drag.js
rename to TS Tests/input/world drag.js
diff --git a/Tests/input/world drag.ts b/TS Tests/input/world drag.ts
similarity index 100%
rename from Tests/input/world drag.ts
rename to TS Tests/input/world drag.ts
diff --git a/Tests/misc/boot screen.js b/TS Tests/misc/boot screen.js
similarity index 100%
rename from Tests/misc/boot screen.js
rename to TS Tests/misc/boot screen.js
diff --git a/Tests/misc/boot screen.ts b/TS Tests/misc/boot screen.ts
similarity index 100%
rename from Tests/misc/boot screen.ts
rename to TS Tests/misc/boot screen.ts
diff --git a/Tests/misc/color utils 1.js b/TS Tests/misc/color utils 1.js
similarity index 100%
rename from Tests/misc/color utils 1.js
rename to TS Tests/misc/color utils 1.js
diff --git a/Tests/misc/color utils 1.ts b/TS Tests/misc/color utils 1.ts
similarity index 100%
rename from Tests/misc/color utils 1.ts
rename to TS Tests/misc/color utils 1.ts
diff --git a/Tests/misc/color utils 2.js b/TS Tests/misc/color utils 2.js
similarity index 100%
rename from Tests/misc/color utils 2.js
rename to TS Tests/misc/color utils 2.js
diff --git a/Tests/misc/color utils 2.ts b/TS Tests/misc/color utils 2.ts
similarity index 100%
rename from Tests/misc/color utils 2.ts
rename to TS Tests/misc/color utils 2.ts
diff --git a/Tests/misc/color utils 3.js b/TS Tests/misc/color utils 3.js
similarity index 100%
rename from Tests/misc/color utils 3.js
rename to TS Tests/misc/color utils 3.js
diff --git a/Tests/misc/color utils 3.ts b/TS Tests/misc/color utils 3.ts
similarity index 100%
rename from Tests/misc/color utils 3.ts
rename to TS Tests/misc/color utils 3.ts
diff --git a/Tests/misc/dynamic texture 1.js b/TS Tests/misc/dynamic texture 1.js
similarity index 100%
rename from Tests/misc/dynamic texture 1.js
rename to TS Tests/misc/dynamic texture 1.js
diff --git a/Tests/misc/dynamic texture 1.ts b/TS Tests/misc/dynamic texture 1.ts
similarity index 100%
rename from Tests/misc/dynamic texture 1.ts
rename to TS Tests/misc/dynamic texture 1.ts
diff --git a/Tests/misc/dynamic texture 2.js b/TS Tests/misc/dynamic texture 2.js
similarity index 100%
rename from Tests/misc/dynamic texture 2.js
rename to TS Tests/misc/dynamic texture 2.js
diff --git a/Tests/misc/dynamic texture 2.ts b/TS Tests/misc/dynamic texture 2.ts
similarity index 100%
rename from Tests/misc/dynamic texture 2.ts
rename to TS Tests/misc/dynamic texture 2.ts
diff --git a/Tests/misc/dynamic texture 3.js b/TS Tests/misc/dynamic texture 3.js
similarity index 100%
rename from Tests/misc/dynamic texture 3.js
rename to TS Tests/misc/dynamic texture 3.js
diff --git a/Tests/misc/dynamic texture 3.ts b/TS Tests/misc/dynamic texture 3.ts
similarity index 100%
rename from Tests/misc/dynamic texture 3.ts
rename to TS Tests/misc/dynamic texture 3.ts
diff --git a/Tests/misc/point1.js b/TS Tests/misc/point1.js
similarity index 100%
rename from Tests/misc/point1.js
rename to TS Tests/misc/point1.js
diff --git a/Tests/misc/point1.ts b/TS Tests/misc/point1.ts
similarity index 100%
rename from Tests/misc/point1.ts
rename to TS Tests/misc/point1.ts
diff --git a/Tests/misc/point2.js b/TS Tests/misc/point2.js
similarity index 100%
rename from Tests/misc/point2.js
rename to TS Tests/misc/point2.js
diff --git a/Tests/misc/point2.ts b/TS Tests/misc/point2.ts
similarity index 100%
rename from Tests/misc/point2.ts
rename to TS Tests/misc/point2.ts
diff --git a/Tests/misc/point3.js b/TS Tests/misc/point3.js
similarity index 100%
rename from Tests/misc/point3.js
rename to TS Tests/misc/point3.js
diff --git a/Tests/misc/point3.ts b/TS Tests/misc/point3.ts
similarity index 100%
rename from Tests/misc/point3.ts
rename to TS Tests/misc/point3.ts
diff --git a/Tests/misc/rectangle utils 1.js b/TS Tests/misc/rectangle utils 1.js
similarity index 100%
rename from Tests/misc/rectangle utils 1.js
rename to TS Tests/misc/rectangle utils 1.js
diff --git a/Tests/misc/rectangle utils 1.ts b/TS Tests/misc/rectangle utils 1.ts
similarity index 100%
rename from Tests/misc/rectangle utils 1.ts
rename to TS Tests/misc/rectangle utils 1.ts
diff --git a/Tests/misc/rectangle utils 2.js b/TS Tests/misc/rectangle utils 2.js
similarity index 100%
rename from Tests/misc/rectangle utils 2.js
rename to TS Tests/misc/rectangle utils 2.js
diff --git a/Tests/misc/rectangle utils 2.ts b/TS Tests/misc/rectangle utils 2.ts
similarity index 100%
rename from Tests/misc/rectangle utils 2.ts
rename to TS Tests/misc/rectangle utils 2.ts
diff --git a/Tests/mobile/fullscreen.html b/TS Tests/mobile/fullscreen.html
similarity index 100%
rename from Tests/mobile/fullscreen.html
rename to TS Tests/mobile/fullscreen.html
diff --git a/Tests/mobile/sprite test 1.js b/TS Tests/mobile/sprite test 1.js
similarity index 100%
rename from Tests/mobile/sprite test 1.js
rename to TS Tests/mobile/sprite test 1.js
diff --git a/Tests/mobile/sprite test 1.ts b/TS Tests/mobile/sprite test 1.ts
similarity index 100%
rename from Tests/mobile/sprite test 1.ts
rename to TS Tests/mobile/sprite test 1.ts
diff --git a/Tests/mobile/test1.html b/TS Tests/mobile/test1.html
similarity index 100%
rename from Tests/mobile/test1.html
rename to TS Tests/mobile/test1.html
diff --git a/Tests/particles/graphic emitter.js b/TS Tests/particles/graphic emitter.js
similarity index 100%
rename from Tests/particles/graphic emitter.js
rename to TS Tests/particles/graphic emitter.js
diff --git a/Tests/particles/graphic emitter.ts b/TS Tests/particles/graphic emitter.ts
similarity index 100%
rename from Tests/particles/graphic emitter.ts
rename to TS Tests/particles/graphic emitter.ts
diff --git a/Tests/particles/mousetrail.js b/TS Tests/particles/mousetrail.js
similarity index 100%
rename from Tests/particles/mousetrail.js
rename to TS Tests/particles/mousetrail.js
diff --git a/Tests/particles/mousetrail.ts b/TS Tests/particles/mousetrail.ts
similarity index 100%
rename from Tests/particles/mousetrail.ts
rename to TS Tests/particles/mousetrail.ts
diff --git a/Tests/particles/multiple streams.js b/TS Tests/particles/multiple streams.js
similarity index 100%
rename from Tests/particles/multiple streams.js
rename to TS Tests/particles/multiple streams.js
diff --git a/Tests/particles/multiple streams.ts b/TS Tests/particles/multiple streams.ts
similarity index 100%
rename from Tests/particles/multiple streams.ts
rename to TS Tests/particles/multiple streams.ts
diff --git a/Tests/particles/sprite emitter.js b/TS Tests/particles/sprite emitter.js
similarity index 100%
rename from Tests/particles/sprite emitter.js
rename to TS Tests/particles/sprite emitter.js
diff --git a/Tests/particles/sprite emitter.ts b/TS Tests/particles/sprite emitter.ts
similarity index 100%
rename from Tests/particles/sprite emitter.ts
rename to TS Tests/particles/sprite emitter.ts
diff --git a/Tests/particles/when particles collide.js b/TS Tests/particles/when particles collide.js
similarity index 100%
rename from Tests/particles/when particles collide.js
rename to TS Tests/particles/when particles collide.js
diff --git a/Tests/particles/when particles collide.ts b/TS Tests/particles/when particles collide.ts
similarity index 100%
rename from Tests/particles/when particles collide.ts
rename to TS Tests/particles/when particles collide.ts
diff --git a/Tests/phaser-debug.js b/TS Tests/phaser-debug.js
similarity index 97%
rename from Tests/phaser-debug.js
rename to TS Tests/phaser-debug.js
index 20b99c56..20fcef2e 100644
--- a/Tests/phaser-debug.js
+++ b/TS Tests/phaser-debug.js
@@ -1,14542 +1,14596 @@
-var Phaser;
-(function (Phaser) {
- var Types = (function () {
- function Types() { }
- Types.RENDERER_AUTO_DETECT = 0;
- Types.RENDERER_HEADLESS = 1;
- Types.RENDERER_CANVAS = 2;
- Types.RENDERER_WEBGL = 3;
- Types.CAMERA_TYPE_ORTHOGRAPHIC = 0;
- Types.CAMERA_TYPE_ISOMETRIC = 1;
- Types.CAMERA_FOLLOW_LOCKON = 0;
- Types.CAMERA_FOLLOW_PLATFORMER = 1;
- Types.CAMERA_FOLLOW_TOPDOWN = 2;
- Types.CAMERA_FOLLOW_TOPDOWN_TIGHT = 3;
- Types.GROUP = 0;
- Types.SPRITE = 1;
- Types.GEOMSPRITE = 2;
- Types.PARTICLE = 3;
- Types.EMITTER = 4;
- Types.TILEMAP = 5;
- Types.SCROLLZONE = 6;
- Types.BUTTON = 7;
- Types.DYNAMICTEXTURE = 8;
- Types.GEOM_POINT = 0;
- Types.GEOM_CIRCLE = 1;
- Types.GEOM_RECTANGLE = 2;
- Types.GEOM_LINE = 3;
- Types.GEOM_POLYGON = 4;
- Types.BODY_DISABLED = 0;
- Types.BODY_STATIC = 1;
- Types.BODY_KINETIC = 2;
- Types.BODY_DYNAMIC = 3;
- Types.OUT_OF_BOUNDS_KILL = 0;
- Types.OUT_OF_BOUNDS_DESTROY = 1;
- Types.OUT_OF_BOUNDS_PERSIST = 2;
- Types.SORT_ASCENDING = -1;
- Types.SORT_DESCENDING = 1;
- Types.LEFT = 0x0001;
- Types.RIGHT = 0x0010;
- Types.UP = 0x0100;
- Types.DOWN = 0x1000;
- Types.NONE = 0;
- Types.CEILING = 0x0100;
- Types.FLOOR = 0x1000;
- Types.WALL = 0x0001 | 0x0010;
- Types.ANY = 0x0001 | 0x0010 | 0x0100 | 0x1000;
- return Types;
- })();
- Phaser.Types = Types;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Point = (function () {
- function Point(x, y) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- this.x = x;
- this.y = y;
- }
- Point.prototype.copyFrom = function (source) {
- return this.setTo(source.x, source.y);
- };
- Point.prototype.invert = function () {
- return this.setTo(this.y, this.x);
- };
- Point.prototype.setTo = function (x, y) {
- this.x = x;
- this.y = y;
- return this;
- };
- Point.prototype.toString = function () {
- return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
- };
- return Point;
- })();
- Phaser.Point = Point;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Rectangle = (function () {
- function Rectangle(x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = 0; }
- if (typeof height === "undefined") { height = 0; }
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
- Object.defineProperty(Rectangle.prototype, "halfWidth", {
- get: function () {
- return Math.round(this.width / 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "halfHeight", {
- get: function () {
- return Math.round(this.height / 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottom", {
- get: function () {
- return this.y + this.height;
- },
- set: function (value) {
- if(value <= this.y) {
- this.height = 0;
- } else {
- this.height = (this.y - value);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottomRight", {
- set: function (value) {
- this.right = value.x;
- this.bottom = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "left", {
- get: function () {
- return this.x;
- },
- set: function (value) {
- if(value >= this.right) {
- this.width = 0;
- } else {
- this.width = this.right - value;
- }
- this.x = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "right", {
- get: function () {
- return this.x + this.width;
- },
- set: function (value) {
- if(value <= this.x) {
- this.width = 0;
- } else {
- this.width = this.x + value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "volume", {
- get: function () {
- return this.width * this.height;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "perimeter", {
- get: function () {
- return (this.width * 2) + (this.height * 2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "top", {
- get: function () {
- return this.y;
- },
- set: function (value) {
- if(value >= this.bottom) {
- this.height = 0;
- this.y = value;
- } else {
- this.height = (this.bottom - value);
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "topLeft", {
- set: function (value) {
- this.x = value.x;
- this.y = value.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "empty", {
- get: function () {
- return (!this.width || !this.height);
- },
- set: function (value) {
- this.setTo(0, 0, 0, 0);
- },
- enumerable: true,
- configurable: true
- });
- Rectangle.prototype.offset = function (dx, dy) {
- this.x += dx;
- this.y += dy;
- return this;
- };
- Rectangle.prototype.offsetPoint = function (point) {
- return this.offset(point.x, point.y);
- };
- Rectangle.prototype.setTo = function (x, y, width, height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- return this;
- };
- Rectangle.prototype.floor = function () {
- this.x = Math.floor(this.x);
- this.y = Math.floor(this.y);
- };
- Rectangle.prototype.copyFrom = function (source) {
- return this.setTo(source.x, source.y, source.width, source.height);
- };
- Rectangle.prototype.toString = function () {
- return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
- };
- return Rectangle;
- })();
- Phaser.Rectangle = Rectangle;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Circle = (function () {
- function Circle(x, y, diameter) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof diameter === "undefined") { diameter = 0; }
- this._diameter = 0;
- this._radius = 0;
- this.x = 0;
- this.y = 0;
- this.setTo(x, y, diameter);
- }
- Object.defineProperty(Circle.prototype, "diameter", {
- get: function () {
- return this._diameter;
- },
- set: function (value) {
- if(value > 0) {
- this._diameter = value;
- this._radius = value * 0.5;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Circle.prototype, "radius", {
- get: function () {
- return this._radius;
- },
- set: function (value) {
- if(value > 0) {
- this._radius = value;
- this._diameter = value * 2;
- }
- },
- enumerable: true,
- configurable: true
- });
- Circle.prototype.circumference = function () {
- return 2 * (Math.PI * this._radius);
- };
- Object.defineProperty(Circle.prototype, "bottom", {
- get: function () {
- return this.y + this._radius;
- },
- set: function (value) {
- if(value < this.y) {
- this._radius = 0;
- this._diameter = 0;
- } else {
- this.radius = value - this.y;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Circle.prototype, "left", {
- get: function () {
- return this.x - this._radius;
- },
- set: function (value) {
- if(value > this.x) {
- this._radius = 0;
- this._diameter = 0;
- } else {
- this.radius = this.x - value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Circle.prototype, "right", {
- get: function () {
- return this.x + this._radius;
- },
- set: function (value) {
- if(value < this.x) {
- this._radius = 0;
- this._diameter = 0;
- } else {
- this.radius = value - this.x;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Circle.prototype, "top", {
- get: function () {
- return this.y - this._radius;
- },
- set: function (value) {
- if(value > this.y) {
- this._radius = 0;
- this._diameter = 0;
- } else {
- this.radius = this.y - value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Circle.prototype, "area", {
- get: function () {
- if(this._radius > 0) {
- return Math.PI * this._radius * this._radius;
- } else {
- return 0;
- }
- },
- enumerable: true,
- configurable: true
- });
- Circle.prototype.setTo = function (x, y, diameter) {
- this.x = x;
- this.y = y;
- this._diameter = diameter;
- this._radius = diameter * 0.5;
- return this;
- };
- Circle.prototype.copyFrom = function (source) {
- return this.setTo(source.x, source.y, source.diameter);
- };
- Object.defineProperty(Circle.prototype, "empty", {
- get: function () {
- return (this._diameter == 0);
- },
- set: function (value) {
- this.setTo(0, 0, 0);
- },
- enumerable: true,
- configurable: true
- });
- Circle.prototype.offset = function (dx, dy) {
- this.x += dx;
- this.y += dy;
- return this;
- };
- Circle.prototype.offsetPoint = function (point) {
- return this.offset(point.x, point.y);
- };
- Circle.prototype.toString = function () {
- return "[{Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
- };
- return Circle;
- })();
- Phaser.Circle = Circle;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Line = (function () {
- function Line(x1, y1, x2, y2) {
- if (typeof x1 === "undefined") { x1 = 0; }
- if (typeof y1 === "undefined") { y1 = 0; }
- if (typeof x2 === "undefined") { x2 = 0; }
- if (typeof y2 === "undefined") { y2 = 0; }
- this.x1 = 0;
- this.y1 = 0;
- this.x2 = 0;
- this.y2 = 0;
- this.setTo(x1, y1, x2, y2);
- }
- Line.prototype.clone = function (output) {
- if (typeof output === "undefined") { output = new Line(); }
- return output.setTo(this.x1, this.y1, this.x2, this.y2);
- };
- Line.prototype.copyFrom = function (source) {
- return this.setTo(source.x1, source.y1, source.x2, source.y2);
- };
- Line.prototype.copyTo = function (target) {
- return target.copyFrom(this);
- };
- Line.prototype.setTo = function (x1, y1, x2, y2) {
- if (typeof x1 === "undefined") { x1 = 0; }
- if (typeof y1 === "undefined") { y1 = 0; }
- if (typeof x2 === "undefined") { x2 = 0; }
- if (typeof y2 === "undefined") { y2 = 0; }
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- return this;
- };
- Object.defineProperty(Line.prototype, "width", {
- get: function () {
- return Math.max(this.x1, this.x2) - Math.min(this.x1, this.x2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Line.prototype, "height", {
- get: function () {
- return Math.max(this.y1, this.y2) - Math.min(this.y1, this.y2);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Line.prototype, "length", {
- get: function () {
- return Math.sqrt((this.x2 - this.x1) * (this.x2 - this.x1) + (this.y2 - this.y1) * (this.y2 - this.y1));
- },
- enumerable: true,
- configurable: true
- });
- Line.prototype.getY = function (x) {
- return this.slope * x + this.yIntercept;
- };
- Object.defineProperty(Line.prototype, "angle", {
- get: function () {
- return Math.atan2(this.x2 - this.x1, this.y2 - this.y1);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Line.prototype, "slope", {
- get: function () {
- return (this.y2 - this.y1) / (this.x2 - this.x1);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Line.prototype, "perpSlope", {
- get: function () {
- return -((this.x2 - this.x1) / (this.y2 - this.y1));
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Line.prototype, "yIntercept", {
- get: function () {
- return (this.y1 - this.slope * this.x1);
- },
- enumerable: true,
- configurable: true
- });
- Line.prototype.isPointOnLine = function (x, y) {
- if((x - this.x1) * (this.y2 - this.y1) === (this.x2 - this.x1) * (y - this.y1)) {
- return true;
- } else {
- return false;
- }
- };
- Line.prototype.isPointOnLineSegment = function (x, y) {
- var xMin = Math.min(this.x1, this.x2);
- var xMax = Math.max(this.x1, this.x2);
- var yMin = Math.min(this.y1, this.y2);
- var yMax = Math.max(this.y1, this.y2);
- if(this.isPointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax)) {
- return true;
- } else {
- return false;
- }
- };
- Line.prototype.intersectLineLine = function (line) {
- };
- Line.prototype.toString = function () {
- return "[{Line (x1=" + this.x1 + " y1=" + this.y1 + " x2=" + this.x2 + " y2=" + this.y2 + ")}]";
- };
- return Line;
- })();
- Phaser.Line = Line;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var GameMath = (function () {
- function GameMath(game) {
- this.cosTable = [];
- this.sinTable = [];
- this.game = game;
- GameMath.sinA = [];
- GameMath.cosA = [];
- for(var i = 0; i < 360; i++) {
- GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
- GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
- }
- }
- GameMath.PI = 3.141592653589793;
- GameMath.PI_2 = 1.5707963267948965;
- GameMath.PI_4 = 0.7853981633974483;
- GameMath.PI_8 = 0.39269908169872413;
- GameMath.PI_16 = 0.19634954084936206;
- GameMath.TWO_PI = 6.283185307179586;
- GameMath.THREE_PI_2 = 4.7123889803846895;
- GameMath.E = 2.71828182845905;
- GameMath.LN10 = 2.302585092994046;
- GameMath.LN2 = 0.6931471805599453;
- GameMath.LOG10E = 0.4342944819032518;
- GameMath.LOG2E = 1.442695040888963387;
- GameMath.SQRT1_2 = 0.7071067811865476;
- GameMath.SQRT2 = 1.4142135623730951;
- GameMath.DEG_TO_RAD = 0.017453292519943294444444444444444;
- GameMath.RAD_TO_DEG = 57.295779513082325225835265587527;
- GameMath.B_16 = 65536;
- GameMath.B_31 = 2147483648;
- GameMath.B_32 = 4294967296;
- GameMath.B_48 = 281474976710656;
- GameMath.B_53 = 9007199254740992;
- GameMath.B_64 = 18446744073709551616;
- GameMath.ONE_THIRD = 0.333333333333333333333333333333333;
- GameMath.TWO_THIRDS = 0.666666666666666666666666666666666;
- GameMath.ONE_SIXTH = 0.166666666666666666666666666666666;
- GameMath.COS_PI_3 = 0.86602540378443864676372317075294;
- GameMath.SIN_2PI_3 = 0.03654595;
- GameMath.CIRCLE_ALPHA = 0.5522847498307933984022516322796;
- GameMath.ON = true;
- GameMath.OFF = false;
- GameMath.SHORT_EPSILON = 0.1;
- GameMath.PERC_EPSILON = 0.001;
- GameMath.EPSILON = 0.0001;
- GameMath.LONG_EPSILON = 0.00000001;
- GameMath.prototype.fuzzyEqual = function (a, b, epsilon) {
- if (typeof epsilon === "undefined") { epsilon = 0.0001; }
- return Math.abs(a - b) < epsilon;
- };
- GameMath.prototype.fuzzyLessThan = function (a, b, epsilon) {
- if (typeof epsilon === "undefined") { epsilon = 0.0001; }
- return a < b + epsilon;
- };
- GameMath.prototype.fuzzyGreaterThan = function (a, b, epsilon) {
- if (typeof epsilon === "undefined") { epsilon = 0.0001; }
- return a > b - epsilon;
- };
- GameMath.prototype.fuzzyCeil = function (val, epsilon) {
- if (typeof epsilon === "undefined") { epsilon = 0.0001; }
- return Math.ceil(val - epsilon);
- };
- GameMath.prototype.fuzzyFloor = function (val, epsilon) {
- if (typeof epsilon === "undefined") { epsilon = 0.0001; }
- return Math.floor(val + epsilon);
- };
- GameMath.prototype.average = function () {
- var args = [];
- for (var _i = 0; _i < (arguments.length - 0); _i++) {
- args[_i] = arguments[_i + 0];
- }
- var avg = 0;
- for(var i = 0; i < args.length; i++) {
- avg += args[i];
- }
- return avg / args.length;
- };
- GameMath.prototype.slam = function (value, target, epsilon) {
- if (typeof epsilon === "undefined") { epsilon = 0.0001; }
- return (Math.abs(value - target) < epsilon) ? target : value;
- };
- GameMath.prototype.percentageMinMax = function (val, max, min) {
- if (typeof min === "undefined") { min = 0; }
- val -= min;
- max -= min;
- if(!max) {
- return 0;
- } else {
- return val / max;
- }
- };
- GameMath.prototype.sign = function (n) {
- if(n) {
- return n / Math.abs(n);
- } else {
- return 0;
- }
- };
- GameMath.prototype.truncate = function (n) {
- return (n > 0) ? Math.floor(n) : Math.ceil(n);
- };
- GameMath.prototype.shear = function (n) {
- return n % 1;
- };
- GameMath.prototype.wrap = function (val, max, min) {
- if (typeof min === "undefined") { min = 0; }
- val -= min;
- max -= min;
- if(max == 0) {
- return min;
- }
- val %= max;
- val += min;
- while(val < min) {
- val += max;
- }
- return val;
- };
- GameMath.prototype.arithWrap = function (value, max, min) {
- if (typeof min === "undefined") { min = 0; }
- max -= min;
- if(max == 0) {
- return min;
- }
- return value - max * Math.floor((value - min) / max);
- };
- GameMath.prototype.clamp = function (input, max, min) {
- if (typeof min === "undefined") { min = 0; }
- return Math.max(min, Math.min(max, input));
- };
- GameMath.prototype.snapTo = function (input, gap, start) {
- if (typeof start === "undefined") { start = 0; }
- if(gap == 0) {
- return input;
- }
- input -= start;
- input = gap * Math.round(input / gap);
- return start + input;
- };
- GameMath.prototype.snapToFloor = function (input, gap, start) {
- if (typeof start === "undefined") { start = 0; }
- if(gap == 0) {
- return input;
- }
- input -= start;
- input = gap * Math.floor(input / gap);
- return start + input;
- };
- GameMath.prototype.snapToCeil = function (input, gap, start) {
- if (typeof start === "undefined") { start = 0; }
- if(gap == 0) {
- return input;
- }
- input -= start;
- input = gap * Math.ceil(input / gap);
- return start + input;
- };
- GameMath.prototype.snapToInArray = function (input, arr, sort) {
- if (typeof sort === "undefined") { sort = true; }
- if(sort) {
- arr.sort();
- }
- if(input < arr[0]) {
- return arr[0];
- }
- var i = 1;
- while(arr[i] < input) {
- i++;
- }
- var low = arr[i - 1];
- var high = (i < arr.length) ? arr[i] : Number.POSITIVE_INFINITY;
- return ((high - input) <= (input - low)) ? high : low;
- };
- GameMath.prototype.roundTo = function (value, place, base) {
- if (typeof place === "undefined") { place = 0; }
- if (typeof base === "undefined") { base = 10; }
- var p = Math.pow(base, -place);
- return Math.round(value * p) / p;
- };
- GameMath.prototype.floorTo = function (value, place, base) {
- if (typeof place === "undefined") { place = 0; }
- if (typeof base === "undefined") { base = 10; }
- var p = Math.pow(base, -place);
- return Math.floor(value * p) / p;
- };
- GameMath.prototype.ceilTo = function (value, place, base) {
- if (typeof place === "undefined") { place = 0; }
- if (typeof base === "undefined") { base = 10; }
- var p = Math.pow(base, -place);
- return Math.ceil(value * p) / p;
- };
- GameMath.prototype.interpolateFloat = function (a, b, weight) {
- return (b - a) * weight + a;
- };
- GameMath.prototype.radiansToDegrees = function (angle) {
- return angle * GameMath.RAD_TO_DEG;
- };
- GameMath.prototype.degreesToRadians = function (angle) {
- return angle * GameMath.DEG_TO_RAD;
- };
- GameMath.prototype.angleBetween = function (x1, y1, x2, y2) {
- return Math.atan2(y2 - y1, x2 - x1);
- };
- GameMath.prototype.normalizeAngle = function (angle, radians) {
- if (typeof radians === "undefined") { radians = true; }
- var rd = (radians) ? GameMath.PI : 180;
- return this.wrap(angle, rd, -rd);
- };
- GameMath.prototype.nearestAngleBetween = function (a1, a2, radians) {
- if (typeof radians === "undefined") { radians = true; }
- var rd = (radians) ? GameMath.PI : 180;
- a1 = this.normalizeAngle(a1, radians);
- a2 = this.normalizeAngle(a2, radians);
- if(a1 < -rd / 2 && a2 > rd / 2) {
- a1 += rd * 2;
- }
- if(a2 < -rd / 2 && a1 > rd / 2) {
- a2 += rd * 2;
- }
- return a2 - a1;
- };
- GameMath.prototype.normalizeAngleToAnother = function (dep, ind, radians) {
- if (typeof radians === "undefined") { radians = true; }
- return ind + this.nearestAngleBetween(ind, dep, radians);
- };
- GameMath.prototype.normalizeAngleAfterAnother = function (dep, ind, radians) {
- if (typeof radians === "undefined") { radians = true; }
- dep = this.normalizeAngle(dep - ind, radians);
- return ind + dep;
- };
- GameMath.prototype.normalizeAngleBeforeAnother = function (dep, ind, radians) {
- if (typeof radians === "undefined") { radians = true; }
- dep = this.normalizeAngle(ind - dep, radians);
- return ind - dep;
- };
- GameMath.prototype.interpolateAngles = function (a1, a2, weight, radians, ease) {
- if (typeof radians === "undefined") { radians = true; }
- if (typeof ease === "undefined") { ease = null; }
- a1 = this.normalizeAngle(a1, radians);
- a2 = this.normalizeAngleToAnother(a2, a1, radians);
- return (typeof ease === 'function') ? ease(weight, a1, a2 - a1, 1) : this.interpolateFloat(a1, a2, weight);
- };
- GameMath.prototype.logBaseOf = function (value, base) {
- return Math.log(value) / Math.log(base);
- };
- GameMath.prototype.GCD = function (m, n) {
- var r;
- m = Math.abs(m);
- n = Math.abs(n);
- if(m < n) {
- r = m;
- m = n;
- n = r;
- }
- while(true) {
- r = m % n;
- if(!r) {
- return n;
- }
- m = n;
- n = r;
- }
- return 1;
- };
- GameMath.prototype.LCM = function (m, n) {
- return (m * n) / this.GCD(m, n);
- };
- GameMath.prototype.factorial = function (value) {
- if(value == 0) {
- return 1;
- }
- var res = value;
- while(--value) {
- res *= value;
- }
- return res;
- };
- GameMath.prototype.gammaFunction = function (value) {
- return this.factorial(value - 1);
- };
- GameMath.prototype.fallingFactorial = function (base, exp) {
- return this.factorial(base) / this.factorial(base - exp);
- };
- GameMath.prototype.risingFactorial = function (base, exp) {
- return this.factorial(base + exp - 1) / this.factorial(base - 1);
- };
- GameMath.prototype.binCoef = function (n, k) {
- return this.fallingFactorial(n, k) / this.factorial(k);
- };
- GameMath.prototype.risingBinCoef = function (n, k) {
- return this.risingFactorial(n, k) / this.factorial(k);
- };
- GameMath.prototype.chanceRoll = function (chance) {
- if (typeof chance === "undefined") { chance = 50; }
- if(chance <= 0) {
- return false;
- } else if(chance >= 100) {
- return true;
- } else {
- if(Math.random() * 100 >= chance) {
- return false;
- } else {
- return true;
- }
- }
- };
- GameMath.prototype.maxAdd = function (value, amount, max) {
- value += amount;
- if(value > max) {
- value = max;
- }
- return value;
- };
- GameMath.prototype.minSub = function (value, amount, min) {
- value -= amount;
- if(value < min) {
- value = min;
- }
- return value;
- };
- GameMath.prototype.wrapValue = function (value, amount, max) {
- var diff;
- value = Math.abs(value);
- amount = Math.abs(amount);
- max = Math.abs(max);
- diff = (value + amount) % max;
- return diff;
- };
- GameMath.prototype.randomSign = function () {
- return (Math.random() > 0.5) ? 1 : -1;
- };
- GameMath.prototype.isOdd = function (n) {
- if(n & 1) {
- return true;
- } else {
- return false;
- }
- };
- GameMath.prototype.isEven = function (n) {
- if(n & 1) {
- return false;
- } else {
- return true;
- }
- };
- GameMath.prototype.wrapAngle = function (angle) {
- var result = angle;
- if(angle >= -180 && angle <= 180) {
- return angle;
- }
- result = (angle + 180) % 360;
- if(result < 0) {
- result += 360;
- }
- return result - 180;
- };
- GameMath.prototype.angleLimit = function (angle, min, max) {
- var result = angle;
- if(angle > max) {
- result = max;
- } else if(angle < min) {
- result = min;
- }
- return result;
- };
- GameMath.prototype.linearInterpolation = function (v, k) {
- var m = v.length - 1;
- var f = m * k;
- var i = Math.floor(f);
- if(k < 0) {
- return this.linear(v[0], v[1], f);
- }
- if(k > 1) {
- return this.linear(v[m], v[m - 1], m - f);
- }
- return this.linear(v[i], v[i + 1 > m ? m : i + 1], f - i);
- };
- GameMath.prototype.bezierInterpolation = function (v, k) {
- var b = 0;
- var n = v.length - 1;
- for(var i = 0; i <= n; i++) {
- b += Math.pow(1 - k, n - i) * Math.pow(k, i) * v[i] * this.bernstein(n, i);
- }
- return b;
- };
- GameMath.prototype.catmullRomInterpolation = function (v, k) {
- var m = v.length - 1;
- var f = m * k;
- var i = Math.floor(f);
- if(v[0] === v[m]) {
- if(k < 0) {
- i = Math.floor(f = m * (1 + k));
- }
- return this.catmullRom(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
- } else {
- if(k < 0) {
- return v[0] - (this.catmullRom(v[0], v[0], v[1], v[1], -f) - v[0]);
- }
- if(k > 1) {
- return v[m] - (this.catmullRom(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
- }
- return this.catmullRom(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
- }
- };
- GameMath.prototype.linear = function (p0, p1, t) {
- return (p1 - p0) * t + p0;
- };
- GameMath.prototype.bernstein = function (n, i) {
- return this.factorial(n) / this.factorial(i) / this.factorial(n - i);
- };
- GameMath.prototype.catmullRom = function (p0, p1, p2, p3, t) {
- var v0 = (p2 - p0) * 0.5, v1 = (p3 - p1) * 0.5, t2 = t * t, t3 = t * t2;
- return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
- };
- GameMath.prototype.difference = function (a, b) {
- return Math.abs(a - b);
- };
- GameMath.prototype.getRandom = function (objects, startIndex, length) {
- if (typeof startIndex === "undefined") { startIndex = 0; }
- if (typeof length === "undefined") { length = 0; }
- if(objects != null) {
- var l = length;
- if((l == 0) || (l > objects.length - startIndex)) {
- l = objects.length - startIndex;
- }
- if(l > 0) {
- return objects[startIndex + Math.floor(Math.random() * l)];
- }
- }
- return null;
- };
- GameMath.prototype.floor = function (value) {
- var n = value | 0;
- return (value > 0) ? (n) : ((n != value) ? (n - 1) : (n));
- };
- GameMath.prototype.ceil = function (value) {
- var n = value | 0;
- return (value > 0) ? ((n != value) ? (n + 1) : (n)) : (n);
- };
- GameMath.prototype.sinCosGenerator = function (length, sinAmplitude, cosAmplitude, frequency) {
- if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; }
- if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; }
- if (typeof frequency === "undefined") { frequency = 1.0; }
- var sin = sinAmplitude;
- var cos = cosAmplitude;
- var frq = frequency * Math.PI / length;
- this.cosTable = [];
- this.sinTable = [];
- for(var c = 0; c < length; c++) {
- cos -= sin * frq;
- sin += cos * frq;
- this.cosTable[c] = cos;
- this.sinTable[c] = sin;
- }
- return this.sinTable;
- };
- GameMath.prototype.shiftSinTable = function () {
- if(this.sinTable) {
- var s = this.sinTable.shift();
- this.sinTable.push(s);
- return s;
- }
- };
- GameMath.prototype.shiftCosTable = function () {
- if(this.cosTable) {
- var s = this.cosTable.shift();
- this.cosTable.push(s);
- return s;
- }
- };
- GameMath.prototype.shuffleArray = function (array) {
- for(var i = array.length - 1; i > 0; i--) {
- var j = Math.floor(Math.random() * (i + 1));
- var temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- return array;
- };
- GameMath.prototype.distanceBetween = function (x1, y1, x2, y2) {
- var dx = x1 - x2;
- var dy = y1 - y2;
- return Math.sqrt(dx * dx + dy * dy);
- };
- GameMath.prototype.vectorLength = function (dx, dy) {
- return Math.sqrt(dx * dx + dy * dy);
- };
- return GameMath;
- })();
- Phaser.GameMath = GameMath;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Vec2 = (function () {
- function Vec2(x, y) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- this.x = x;
- this.y = y;
- return this;
- }
- Vec2.prototype.copyFrom = function (source) {
- return this.setTo(source.x, source.y);
- };
- Vec2.prototype.setTo = function (x, y) {
- this.x = x;
- this.y = y;
- return this;
- };
- Vec2.prototype.add = function (a) {
- this.x += a.x;
- this.y += a.y;
- return this;
- };
- Vec2.prototype.subtract = function (v) {
- this.x -= v.x;
- this.y -= v.y;
- return this;
- };
- Vec2.prototype.multiply = function (v) {
- this.x *= v.x;
- this.y *= v.y;
- return this;
- };
- Vec2.prototype.divide = function (v) {
- this.x /= v.x;
- this.y /= v.y;
- return this;
- };
- Vec2.prototype.length = function () {
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
- };
- Vec2.prototype.lengthSq = function () {
- return (this.x * this.x) + (this.y * this.y);
- };
- Vec2.prototype.normalize = function () {
- var inv = (this.x != 0 || this.y != 0) ? 1 / Math.sqrt(this.x * this.x + this.y * this.y) : 0;
- this.x *= inv;
- this.y *= inv;
- return this;
- };
- Vec2.prototype.dot = function (a) {
- return ((this.x * a.x) + (this.y * a.y));
- };
- Vec2.prototype.cross = function (a) {
- return ((this.x * a.y) - (this.y * a.x));
- };
- Vec2.prototype.projectionLength = function (a) {
- var den = a.dot(a);
- if(den == 0) {
- return 0;
- } else {
- return Math.abs(this.dot(a) / den);
- }
- };
- Vec2.prototype.angle = function (a) {
- return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
- };
- Vec2.prototype.scale = function (x, y) {
- this.x *= x;
- this.y *= y || x;
- return this;
- };
- Vec2.prototype.multiplyByScalar = function (scalar) {
- this.x *= scalar;
- this.y *= scalar;
- return this;
- };
- Vec2.prototype.multiplyAddByScalar = function (a, scalar) {
- this.x += a.x * scalar;
- this.y += a.y * scalar;
- return this;
- };
- Vec2.prototype.divideByScalar = function (scalar) {
- this.x /= scalar;
- this.y /= scalar;
- return this;
- };
- Vec2.prototype.reverse = function () {
- this.x = -this.x;
- this.y = -this.y;
- return this;
- };
- Vec2.prototype.equals = function (value) {
- return (this.x == value && this.y == value);
- };
- Vec2.prototype.toString = function () {
- return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
- };
- return Vec2;
- })();
- Phaser.Vec2 = Vec2;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Vec2Utils = (function () {
- function Vec2Utils() { }
- Vec2Utils.add = function add(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.x + b.x, a.y + b.y);
- };
- Vec2Utils.subtract = function subtract(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.x - b.x, a.y - b.y);
- };
- Vec2Utils.multiply = function multiply(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.x * b.x, a.y * b.y);
- };
- Vec2Utils.divide = function divide(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.x / b.x, a.y / b.y);
- };
- Vec2Utils.scale = function scale(a, s, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.x * s, a.y * s);
- };
- Vec2Utils.multiplyAdd = function multiplyAdd(a, b, s, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.x + b.x * s, a.y + b.y * s);
- };
- Vec2Utils.negative = function negative(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(-a.x, -a.y);
- };
- Vec2Utils.perp = function perp(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(-a.y, a.x);
- };
- Vec2Utils.rperp = function rperp(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.y, -a.x);
- };
- Vec2Utils.equals = function equals(a, b) {
- return a.x == b.x && a.y == b.y;
- };
- Vec2Utils.epsilonEquals = function epsilonEquals(a, b, epsilon) {
- return Math.abs(a.x - b.x) <= epsilon && Math.abs(a.y - b.y) <= epsilon;
- };
- Vec2Utils.distance = function distance(a, b) {
- return Math.sqrt(Vec2Utils.distanceSq(a, b));
- };
- Vec2Utils.distanceSq = function distanceSq(a, b) {
- return ((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y));
- };
- Vec2Utils.project = function project(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- var amt = a.dot(b) / b.lengthSq();
- if(amt != 0) {
- out.setTo(amt * b.x, amt * b.y);
- }
- return out;
- };
- Vec2Utils.projectUnit = function projectUnit(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- var amt = a.dot(b);
- if(amt != 0) {
- out.setTo(amt * b.x, amt * b.y);
- }
- return out;
- };
- Vec2Utils.normalRightHand = function normalRightHand(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.y * -1, a.x);
- };
- Vec2Utils.normalize = function normalize(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- var m = a.length();
- if(m != 0) {
- out.setTo(a.x / m, a.y / m);
- }
- return out;
- };
- Vec2Utils.dot = function dot(a, b) {
- return ((a.x * b.x) + (a.y * b.y));
- };
- Vec2Utils.cross = function cross(a, b) {
- return ((a.x * b.y) - (a.y * b.x));
- };
- Vec2Utils.angle = function angle(a, b) {
- return Math.atan2(a.x * b.y - a.y * b.x, a.x * b.x + a.y * b.y);
- };
- Vec2Utils.angleSq = function angleSq(a, b) {
- return a.subtract(b).angle(b.subtract(a));
- };
- Vec2Utils.rotateAroundOrigin = function rotateAroundOrigin(a, b, theta, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- var x = a.x - b.x;
- var y = a.y - b.y;
- return out.setTo(x * Math.cos(theta) - y * Math.sin(theta) + b.x, x * Math.sin(theta) + y * Math.cos(theta) + b.y);
- };
- Vec2Utils.rotate = function rotate(a, theta, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- var c = Math.cos(theta);
- var s = Math.sin(theta);
- return out.setTo(a.x * c - a.y * s, a.x * s + a.y * c);
- };
- Vec2Utils.clone = function clone(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Vec2(); }
- return out.setTo(a.x, a.y);
- };
- return Vec2Utils;
- })();
- Phaser.Vec2Utils = Vec2Utils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Mat3 = (function () {
- function Mat3() {
- this.data = [
- 1,
- 0,
- 0,
- 0,
- 1,
- 0,
- 0,
- 0,
- 1
- ];
- }
- Object.defineProperty(Mat3.prototype, "a00", {
- get: function () {
- return this.data[0];
- },
- set: function (value) {
- this.data[0] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a01", {
- get: function () {
- return this.data[1];
- },
- set: function (value) {
- this.data[1] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a02", {
- get: function () {
- return this.data[2];
- },
- set: function (value) {
- this.data[2] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a10", {
- get: function () {
- return this.data[3];
- },
- set: function (value) {
- this.data[3] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a11", {
- get: function () {
- return this.data[4];
- },
- set: function (value) {
- this.data[4] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a12", {
- get: function () {
- return this.data[5];
- },
- set: function (value) {
- this.data[5] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a20", {
- get: function () {
- return this.data[6];
- },
- set: function (value) {
- this.data[6] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a21", {
- get: function () {
- return this.data[7];
- },
- set: function (value) {
- this.data[7] = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Mat3.prototype, "a22", {
- get: function () {
- return this.data[8];
- },
- set: function (value) {
- this.data[8] = value;
- },
- enumerable: true,
- configurable: true
- });
- Mat3.prototype.copyFromMat3 = function (source) {
- this.data[0] = source.data[0];
- this.data[1] = source.data[1];
- this.data[2] = source.data[2];
- this.data[3] = source.data[3];
- this.data[4] = source.data[4];
- this.data[5] = source.data[5];
- this.data[6] = source.data[6];
- this.data[7] = source.data[7];
- this.data[8] = source.data[8];
- return this;
- };
- Mat3.prototype.copyFromMat4 = function (source) {
- this.data[0] = source[0];
- this.data[1] = source[1];
- this.data[2] = source[2];
- this.data[3] = source[4];
- this.data[4] = source[5];
- this.data[5] = source[6];
- this.data[6] = source[8];
- this.data[7] = source[9];
- this.data[8] = source[10];
- return this;
- };
- Mat3.prototype.clone = function (out) {
- if (typeof out === "undefined") { out = new Phaser.Mat3(); }
- out[0] = this.data[0];
- out[1] = this.data[1];
- out[2] = this.data[2];
- out[3] = this.data[3];
- out[4] = this.data[4];
- out[5] = this.data[5];
- out[6] = this.data[6];
- out[7] = this.data[7];
- out[8] = this.data[8];
- return out;
- };
- Mat3.prototype.identity = function () {
- return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
- };
- Mat3.prototype.translate = function (v) {
- this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
- this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
- this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
- return this;
- };
- Mat3.prototype.setTemps = function () {
- this._a00 = this.data[0];
- this._a01 = this.data[1];
- this._a02 = this.data[2];
- this._a10 = this.data[3];
- this._a11 = this.data[4];
- this._a12 = this.data[5];
- this._a20 = this.data[6];
- this._a21 = this.data[7];
- this._a22 = this.data[8];
- };
- Mat3.prototype.rotate = function (rad) {
- this.setTemps();
- var s = Phaser.GameMath.sinA[rad];
- var c = Phaser.GameMath.cosA[rad];
- this.data[0] = c * this._a00 + s * this._a10;
- this.data[1] = c * this._a01 + s * this._a10;
- this.data[2] = c * this._a02 + s * this._a12;
- this.data[3] = c * this._a10 - s * this._a00;
- this.data[4] = c * this._a11 - s * this._a01;
- this.data[5] = c * this._a12 - s * this._a02;
- return this;
- };
- Mat3.prototype.scale = function (v) {
- this.data[0] = v.x * this.data[0];
- this.data[1] = v.x * this.data[1];
- this.data[2] = v.x * this.data[2];
- this.data[3] = v.y * this.data[3];
- this.data[4] = v.y * this.data[4];
- this.data[5] = v.y * this.data[5];
- return this;
- };
- Mat3.prototype.setTo = function (a00, a01, a02, a10, a11, a12, a20, a21, a22) {
- this.data[0] = a00;
- this.data[1] = a01;
- this.data[2] = a02;
- this.data[3] = a10;
- this.data[4] = a11;
- this.data[5] = a12;
- this.data[6] = a20;
- this.data[7] = a21;
- this.data[8] = a22;
- return this;
- };
- Mat3.prototype.toString = function () {
- return '';
- };
- return Mat3;
- })();
- Phaser.Mat3 = Mat3;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Mat3Utils = (function () {
- function Mat3Utils() { }
- Mat3Utils.transpose = function transpose(source, dest) {
- if (typeof dest === "undefined") { dest = null; }
- if(dest === null) {
- 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 = 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;
- 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 = 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 = 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 = 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 = {}));
-var __extends = this.__extends || function (d, b) {
- function __() { this.constructor = d; }
- __.prototype = b.prototype;
- d.prototype = new __();
-};
-var Phaser;
-(function (Phaser) {
- var QuadTree = (function (_super) {
- __extends(QuadTree, _super);
- function QuadTree(manager, x, y, width, height, parent) {
- if (typeof parent === "undefined") { parent = null; }
- _super.call(this, x, y, width, height);
- QuadTree.physics = manager;
- this._headA = this._tailA = new Phaser.LinkedList();
- this._headB = this._tailB = new Phaser.LinkedList();
- if(parent != null) {
- if(parent._headA.object != null) {
- this._iterator = parent._headA;
- while(this._iterator != null) {
- if(this._tailA.object != null) {
- this._ot = this._tailA;
- this._tailA = new Phaser.LinkedList();
- this._ot.next = this._tailA;
- }
- this._tailA.object = this._iterator.object;
- this._iterator = this._iterator.next;
- }
- }
- if(parent._headB.object != null) {
- this._iterator = parent._headB;
- while(this._iterator != null) {
- if(this._tailB.object != null) {
- this._ot = this._tailB;
- this._tailB = new Phaser.LinkedList();
- this._ot.next = this._tailB;
- }
- this._tailB.object = this._iterator.object;
- this._iterator = this._iterator.next;
- }
- }
- } else {
- QuadTree._min = (this.width + this.height) / (2 * QuadTree.divisions);
- }
- this._canSubdivide = (this.width > QuadTree._min) || (this.height > QuadTree._min);
- this._northWestTree = null;
- this._northEastTree = null;
- this._southEastTree = null;
- this._southWestTree = null;
- this._leftEdge = this.x;
- this._rightEdge = this.x + this.width;
- this._halfWidth = this.width / 2;
- this._midpointX = this._leftEdge + this._halfWidth;
- this._topEdge = this.y;
- this._bottomEdge = this.y + this.height;
- this._halfHeight = this.height / 2;
- this._midpointY = this._topEdge + this._halfHeight;
- }
- QuadTree.A_LIST = 0;
- QuadTree.B_LIST = 1;
- QuadTree.prototype.destroy = function () {
- this._tailA.destroy();
- this._tailB.destroy();
- this._headA.destroy();
- this._headB.destroy();
- this._tailA = null;
- this._tailB = null;
- this._headA = null;
- this._headB = null;
- if(this._northWestTree != null) {
- this._northWestTree.destroy();
- }
- if(this._northEastTree != null) {
- this._northEastTree.destroy();
- }
- if(this._southEastTree != null) {
- this._southEastTree.destroy();
- }
- if(this._southWestTree != null) {
- this._southWestTree.destroy();
- }
- this._northWestTree = null;
- this._northEastTree = null;
- this._southEastTree = null;
- this._southWestTree = null;
- QuadTree._object = null;
- QuadTree._processingCallback = null;
- QuadTree._notifyCallback = null;
- };
- QuadTree.prototype.load = function (objectOrGroup1, objectOrGroup2, notifyCallback, processCallback, context) {
- if (typeof objectOrGroup2 === "undefined") { objectOrGroup2 = null; }
- if (typeof notifyCallback === "undefined") { notifyCallback = null; }
- if (typeof processCallback === "undefined") { processCallback = null; }
- if (typeof context === "undefined") { context = null; }
- this.add(objectOrGroup1, QuadTree.A_LIST);
- if(objectOrGroup2 != null) {
- this.add(objectOrGroup2, QuadTree.B_LIST);
- QuadTree._useBothLists = true;
- } else {
- QuadTree._useBothLists = false;
- }
- QuadTree._notifyCallback = notifyCallback;
- QuadTree._processingCallback = processCallback;
- QuadTree._callbackContext = context;
- };
- QuadTree.prototype.add = function (objectOrGroup, list) {
- QuadTree._list = list;
- if(objectOrGroup.type == Phaser.Types.GROUP) {
- this._i = 0;
- this._members = objectOrGroup['members'];
- this._l = objectOrGroup['length'];
- while(this._i < this._l) {
- this._basic = this._members[this._i++];
- if(this._basic != null && this._basic.exists) {
- if(this._basic.type == Phaser.Types.GROUP) {
- this.add(this._basic, list);
- } else {
- QuadTree._object = this._basic;
- if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
- this.addObject();
- }
- }
- }
- }
- } else {
- QuadTree._object = objectOrGroup;
- if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
- this.addObject();
- }
- }
- };
- QuadTree.prototype.addObject = function () {
- if(!this._canSubdivide || ((this._leftEdge >= QuadTree._object.body.bounds.x) && (this._rightEdge <= QuadTree._object.body.bounds.right) && (this._topEdge >= QuadTree._object.body.bounds.y) && (this._bottomEdge <= QuadTree._object.body.bounds.bottom))) {
- this.addToList();
- return;
- }
- if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) {
- if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
- if(this._northWestTree == null) {
- this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northWestTree.addObject();
- return;
- }
- if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
- if(this._southWestTree == null) {
- this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southWestTree.addObject();
- return;
- }
- }
- if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) {
- if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
- if(this._northEastTree == null) {
- this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northEastTree.addObject();
- return;
- }
- if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
- if(this._southEastTree == null) {
- this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southEastTree.addObject();
- return;
- }
- }
- if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
- if(this._northWestTree == null) {
- this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northWestTree.addObject();
- }
- if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
- if(this._northEastTree == null) {
- this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
- }
- this._northEastTree.addObject();
- }
- if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
- if(this._southEastTree == null) {
- this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southEastTree.addObject();
- }
- if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
- if(this._southWestTree == null) {
- this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
- }
- this._southWestTree.addObject();
- }
- };
- QuadTree.prototype.addToList = function () {
- if(QuadTree._list == QuadTree.A_LIST) {
- if(this._tailA.object != null) {
- this._ot = this._tailA;
- this._tailA = new Phaser.LinkedList();
- this._ot.next = this._tailA;
- }
- this._tailA.object = QuadTree._object;
- } else {
- if(this._tailB.object != null) {
- this._ot = this._tailB;
- this._tailB = new Phaser.LinkedList();
- this._ot.next = this._tailB;
- }
- this._tailB.object = QuadTree._object;
- }
- if(!this._canSubdivide) {
- return;
- }
- if(this._northWestTree != null) {
- this._northWestTree.addToList();
- }
- if(this._northEastTree != null) {
- this._northEastTree.addToList();
- }
- if(this._southEastTree != null) {
- this._southEastTree.addToList();
- }
- if(this._southWestTree != null) {
- this._southWestTree.addToList();
- }
- };
- QuadTree.prototype.execute = function () {
- this._overlapProcessed = false;
- if(this._headA.object != null) {
- this._iterator = this._headA;
- while(this._iterator != null) {
- QuadTree._object = this._iterator.object;
- if(QuadTree._useBothLists) {
- QuadTree._iterator = this._headB;
- } else {
- QuadTree._iterator = this._iterator.next;
- }
- if(QuadTree._object.exists && (QuadTree._object.body.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
- this._overlapProcessed = true;
- }
- this._iterator = this._iterator.next;
- }
- }
- if((this._northWestTree != null) && this._northWestTree.execute()) {
- this._overlapProcessed = true;
- }
- if((this._northEastTree != null) && this._northEastTree.execute()) {
- this._overlapProcessed = true;
- }
- if((this._southEastTree != null) && this._southEastTree.execute()) {
- this._overlapProcessed = true;
- }
- if((this._southWestTree != null) && this._southWestTree.execute()) {
- this._overlapProcessed = true;
- }
- return this._overlapProcessed;
- };
- QuadTree.prototype.overlapNode = function () {
- this._overlapProcessed = false;
- while(QuadTree._iterator != null) {
- if(!QuadTree._object.exists || (QuadTree._object.body.allowCollisions <= 0)) {
- break;
- }
- this._checkObject = QuadTree._iterator.object;
- if((QuadTree._object === this._checkObject) || !this._checkObject.exists || (this._checkObject.body.allowCollisions <= 0)) {
- QuadTree._iterator = QuadTree._iterator.next;
- continue;
- }
- QuadTree._iterator = QuadTree._iterator.next;
- }
- return this._overlapProcessed;
- };
- return QuadTree;
- })(Phaser.Rectangle);
- Phaser.QuadTree = QuadTree;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var LinkedList = (function () {
- function LinkedList() {
- this.object = null;
- this.next = null;
- }
- LinkedList.prototype.destroy = function () {
- this.object = null;
- if(this.next != null) {
- this.next.destroy();
- }
- this.next = null;
- };
- return LinkedList;
- })();
- Phaser.LinkedList = LinkedList;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var RandomDataGenerator = (function () {
- function RandomDataGenerator(seeds) {
- if (typeof seeds === "undefined") { seeds = []; }
- this.c = 1;
- this.sow(seeds);
- }
- RandomDataGenerator.prototype.uint32 = function () {
- return this.rnd.apply(this) * 0x100000000;
- };
- RandomDataGenerator.prototype.fract32 = function () {
- return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;
- };
- RandomDataGenerator.prototype.rnd = function () {
- var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10;
- this.c = t | 0;
- this.s0 = this.s1;
- this.s1 = this.s2;
- this.s2 = t - this.c;
- return this.s2;
- };
- RandomDataGenerator.prototype.hash = function (data) {
- var h, i, n;
- n = 0xefc8249d;
- data = data.toString();
- for(i = 0; i < data.length; i++) {
- n += data.charCodeAt(i);
- h = 0.02519603282416938 * n;
- n = h >>> 0;
- h -= n;
- h *= n;
- n = h >>> 0;
- h -= n;
- n += h * 0x100000000;
- }
- return (n >>> 0) * 2.3283064365386963e-10;
- };
- RandomDataGenerator.prototype.sow = function (seeds) {
- if (typeof seeds === "undefined") { seeds = []; }
- this.s0 = this.hash(' ');
- this.s1 = this.hash(this.s0);
- this.s2 = this.hash(this.s1);
- var seed;
- for(var i = 0; seed = seeds[i++]; ) {
- this.s0 -= this.hash(seed);
- this.s0 += ~~(this.s0 < 0);
- this.s1 -= this.hash(seed);
- this.s1 += ~~(this.s1 < 0);
- this.s2 -= this.hash(seed);
- this.s2 += ~~(this.s2 < 0);
- }
- };
- Object.defineProperty(RandomDataGenerator.prototype, "integer", {
- get: function () {
- return this.uint32();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RandomDataGenerator.prototype, "frac", {
- get: function () {
- return this.fract32();
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RandomDataGenerator.prototype, "real", {
- get: function () {
- return this.uint32() + this.fract32();
- },
- enumerable: true,
- configurable: true
- });
- RandomDataGenerator.prototype.integerInRange = function (min, max) {
- return Math.floor(this.realInRange(min, max));
- };
- RandomDataGenerator.prototype.realInRange = function (min, max) {
- min = min || 0;
- max = max || 0;
- return this.frac * (max - min) + min;
- };
- Object.defineProperty(RandomDataGenerator.prototype, "normal", {
- get: function () {
- return 1 - 2 * this.frac;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(RandomDataGenerator.prototype, "uuid", {
- get: function () {
- var a, b;
- for(b = a = ''; a++ < 36; b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-') {
- ;
- }
- return b;
- },
- enumerable: true,
- configurable: true
- });
- RandomDataGenerator.prototype.pick = function (array) {
- return array[this.integerInRange(0, array.length)];
- };
- RandomDataGenerator.prototype.weightedPick = function (array) {
- return array[~~(Math.pow(this.frac, 2) * array.length)];
- };
- RandomDataGenerator.prototype.timestamp = function (min, max) {
- if (typeof min === "undefined") { min = 946684800000; }
- if (typeof max === "undefined") { max = 1577862000000; }
- return this.realInRange(min, max);
- };
- Object.defineProperty(RandomDataGenerator.prototype, "angle", {
- get: function () {
- return this.integerInRange(-180, 180);
- },
- enumerable: true,
- configurable: true
- });
- return RandomDataGenerator;
- })();
- Phaser.RandomDataGenerator = RandomDataGenerator;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Plugin = (function () {
- function Plugin(game, parent) {
- this.game = game;
- this.parent = parent;
- this.active = false;
- this.visible = false;
- this.hasPreUpdate = false;
- this.hasUpdate = false;
- this.hasPostUpdate = false;
- this.hasPreRender = false;
- this.hasRender = false;
- this.hasPostRender = false;
- }
- Plugin.prototype.preUpdate = function () {
- };
- Plugin.prototype.update = function () {
- };
- Plugin.prototype.postUpdate = function () {
- };
- Plugin.prototype.preRender = function () {
- };
- Plugin.prototype.render = function () {
- };
- Plugin.prototype.postRender = function () {
- };
- Plugin.prototype.destroy = function () {
- this.game = null;
- this.parent = null;
- this.active = false;
- this.visible = false;
- };
- return Plugin;
- })();
- Phaser.Plugin = Plugin;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var PluginManager = (function () {
- function PluginManager(game, parent) {
- this.game = game;
- this._parent = parent;
- this.plugins = [];
- }
- PluginManager.prototype.add = function (plugin) {
- var result = false;
- if(typeof plugin === 'function') {
- plugin = new plugin(this.game, this._parent);
- } else {
- plugin.game = this.game;
- plugin.parent = this._parent;
- }
- if(typeof plugin['preUpdate'] === 'function') {
- plugin.hasPreUpdate = true;
- result = true;
- }
- if(typeof plugin['update'] === 'function') {
- plugin.hasUpdate = true;
- result = true;
- }
- if(typeof plugin['postUpdate'] === 'function') {
- plugin.hasPostUpdate = true;
- result = true;
- }
- if(typeof plugin['preRender'] === 'function') {
- plugin.hasPreRender = true;
- result = true;
- }
- if(typeof plugin['render'] === 'function') {
- plugin.hasRender = true;
- result = true;
- }
- if(typeof plugin['postRender'] === 'function') {
- plugin.hasPostRender = true;
- result = true;
- }
- if(result == true) {
- if(plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) {
- plugin.active = true;
- }
- if(plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender) {
- plugin.visible = true;
- }
- this._pluginsLength = this.plugins.push(plugin);
- return plugin;
- } else {
- return null;
- }
- };
- PluginManager.prototype.remove = function (plugin) {
- this._pluginsLength--;
- };
- PluginManager.prototype.preUpdate = function () {
- for(this._p = 0; this._p < this._pluginsLength; this._p++) {
- if(this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) {
- this.plugins[this._p].preUpdate();
- }
- }
- };
- PluginManager.prototype.update = function () {
- for(this._p = 0; this._p < this._pluginsLength; this._p++) {
- if(this.plugins[this._p].active && this.plugins[this._p].hasUpdate) {
- this.plugins[this._p].update();
- }
- }
- };
- PluginManager.prototype.postUpdate = function () {
- for(this._p = 0; this._p < this._pluginsLength; this._p++) {
- if(this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) {
- this.plugins[this._p].postUpdate();
- }
- }
- };
- PluginManager.prototype.preRender = function () {
- for(this._p = 0; this._p < this._pluginsLength; this._p++) {
- if(this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) {
- this.plugins[this._p].preRender();
- }
- }
- };
- PluginManager.prototype.render = function () {
- for(this._p = 0; this._p < this._pluginsLength; this._p++) {
- if(this.plugins[this._p].visible && this.plugins[this._p].hasRender) {
- this.plugins[this._p].render();
- }
- }
- };
- PluginManager.prototype.postRender = function () {
- for(this._p = 0; this._p < this._pluginsLength; this._p++) {
- if(this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) {
- this.plugins[this._p].postRender();
- }
- }
- };
- PluginManager.prototype.destroy = function () {
- this.plugins.length = 0;
- this._pluginsLength = 0;
- this.game = null;
- this._parent = null;
- };
- return PluginManager;
- })();
- Phaser.PluginManager = PluginManager;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Signal = (function () {
- function Signal() {
- this._bindings = [];
- this._prevParams = null;
- this.memorize = false;
- this._shouldPropagate = true;
- this.active = true;
- }
- Signal.VERSION = '1.0.0';
- Signal.prototype.validateListener = function (listener, fnName) {
- if(typeof listener !== 'function') {
- throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName));
- }
- };
- Signal.prototype._registerListener = function (listener, isOnce, listenerContext, priority) {
- var prevIndex = this._indexOfListener(listener, listenerContext);
- var binding;
- if(prevIndex !== -1) {
- binding = this._bindings[prevIndex];
- if(binding.isOnce() !== isOnce) {
- throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.');
- }
- } else {
- binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
- this._addBinding(binding);
- }
- if(this.memorize && this._prevParams) {
- binding.execute(this._prevParams);
- }
- return binding;
- };
- Signal.prototype._addBinding = function (binding) {
- var n = this._bindings.length;
- do {
- --n;
- }while(this._bindings[n] && binding.priority <= this._bindings[n].priority);
- this._bindings.splice(n + 1, 0, binding);
- };
- Signal.prototype._indexOfListener = function (listener, context) {
- var n = this._bindings.length;
- var cur;
- while(n--) {
- cur = this._bindings[n];
- if(cur.getListener() === listener && cur.context === context) {
- return n;
- }
- }
- return -1;
- };
- Signal.prototype.has = function (listener, context) {
- if (typeof context === "undefined") { context = null; }
- return this._indexOfListener(listener, context) !== -1;
- };
- Signal.prototype.add = function (listener, listenerContext, priority) {
- if (typeof listenerContext === "undefined") { listenerContext = null; }
- if (typeof priority === "undefined") { priority = 0; }
- this.validateListener(listener, 'add');
- return this._registerListener(listener, false, listenerContext, priority);
- };
- Signal.prototype.addOnce = function (listener, listenerContext, priority) {
- if (typeof listenerContext === "undefined") { listenerContext = null; }
- if (typeof priority === "undefined") { priority = 0; }
- this.validateListener(listener, 'addOnce');
- return this._registerListener(listener, true, listenerContext, priority);
- };
- Signal.prototype.remove = function (listener, context) {
- if (typeof context === "undefined") { context = null; }
- this.validateListener(listener, 'remove');
- var i = this._indexOfListener(listener, context);
- if(i !== -1) {
- this._bindings[i]._destroy();
- this._bindings.splice(i, 1);
- }
- return listener;
- };
- Signal.prototype.removeAll = function () {
- if(this._bindings) {
- var n = this._bindings.length;
- while(n--) {
- this._bindings[n]._destroy();
- }
- this._bindings.length = 0;
- }
- };
- Signal.prototype.getNumListeners = function () {
- return this._bindings.length;
- };
- Signal.prototype.halt = function () {
- this._shouldPropagate = false;
- };
- Signal.prototype.dispatch = function () {
- var paramsArr = [];
- for (var _i = 0; _i < (arguments.length - 0); _i++) {
- paramsArr[_i] = arguments[_i + 0];
- }
- if(!this.active) {
- return;
- }
- var n = this._bindings.length;
- var bindings;
- if(this.memorize) {
- this._prevParams = paramsArr;
- }
- if(!n) {
- return;
- }
- bindings = this._bindings.slice(0);
- this._shouldPropagate = true;
- do {
- n--;
- }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
- };
- Signal.prototype.forget = function () {
- this._prevParams = null;
- };
- Signal.prototype.dispose = function () {
- this.removeAll();
- delete this._bindings;
- delete this._prevParams;
- };
- Signal.prototype.toString = function () {
- return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']';
- };
- return Signal;
- })();
- Phaser.Signal = Signal;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var SignalBinding = (function () {
- function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
- if (typeof priority === "undefined") { priority = 0; }
- this.active = true;
- this.params = null;
- this._listener = listener;
- this._isOnce = isOnce;
- this.context = listenerContext;
- this._signal = signal;
- this.priority = priority || 0;
- }
- SignalBinding.prototype.execute = function (paramsArr) {
- var handlerReturn;
- var params;
- if(this.active && !!this._listener) {
- params = this.params ? this.params.concat(paramsArr) : paramsArr;
- handlerReturn = this._listener.apply(this.context, params);
- if(this._isOnce) {
- this.detach();
- }
- }
- return handlerReturn;
- };
- SignalBinding.prototype.detach = function () {
- return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
- };
- SignalBinding.prototype.isBound = function () {
- return (!!this._signal && !!this._listener);
- };
- SignalBinding.prototype.isOnce = function () {
- return this._isOnce;
- };
- SignalBinding.prototype.getListener = function () {
- return this._listener;
- };
- SignalBinding.prototype.getSignal = function () {
- return this._signal;
- };
- SignalBinding.prototype._destroy = function () {
- delete this._signal;
- delete this._listener;
- delete this.context;
- };
- SignalBinding.prototype.toString = function () {
- return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']';
- };
- return SignalBinding;
- })();
- Phaser.SignalBinding = SignalBinding;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Group = (function () {
- function Group(game, maxSize) {
- if (typeof maxSize === "undefined") { maxSize = 0; }
- this._sortIndex = '';
- this._zCounter = 0;
- this.ID = -1;
- this.z = -1;
- this.group = null;
- this.modified = false;
- this.game = game;
- this.type = Phaser.Types.GROUP;
- this.active = true;
- this.exists = true;
- this.visible = true;
- this.members = [];
- this.length = 0;
- this._maxSize = maxSize;
- this._marker = 0;
- this._sortIndex = null;
- this.ID = this.game.world.getNextGroupID();
- this.transform = new Phaser.Components.TransformManager(this);
- this.texture = new Phaser.Display.Texture(this);
- this.texture.opaque = false;
- }
- Group.prototype.getNextZIndex = function () {
- return this._zCounter++;
- };
- Group.prototype.destroy = function () {
- if(this.members != null) {
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null) {
- this._member.destroy();
- }
- }
- this.members.length = 0;
- }
- this._sortIndex = null;
- };
- Group.prototype.update = function () {
- if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
- this.modified = true;
- }
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null && this._member.exists && this._member.active) {
- if(this._member.type != Phaser.Types.GROUP) {
- this._member.preUpdate();
- }
- this._member.update();
- }
- }
- };
- Group.prototype.postUpdate = function () {
- if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
- this.modified = false;
- }
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null && this._member.exists && this._member.active) {
- this._member.postUpdate();
- }
- }
- };
- Group.prototype.render = function (camera) {
- if(camera.isHidden(this) == true) {
- return;
- }
- this.game.renderer.groupRenderer.preRender(camera, this);
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) {
- if(this._member.type == Phaser.Types.GROUP) {
- this._member.render(camera);
- } else {
- this.game.renderer.renderGameObject(camera, this._member);
- }
- }
- }
- this.game.renderer.groupRenderer.postRender(camera, this);
- };
- Group.prototype.directRender = function (camera) {
- this.game.renderer.groupRenderer.preRender(camera, this);
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null && this._member.exists) {
- if(this._member.type == Phaser.Types.GROUP) {
- this._member.directRender(camera);
- } else {
- this.game.renderer.renderGameObject(this._member);
- }
- }
- }
- this.game.renderer.groupRenderer.postRender(camera, this);
- };
- Object.defineProperty(Group.prototype, "maxSize", {
- get: function () {
- return this._maxSize;
- },
- set: function (size) {
- this._maxSize = size;
- if(this._marker >= this._maxSize) {
- this._marker = 0;
- }
- if(this._maxSize == 0 || this.members == null || (this._maxSize >= this.members.length)) {
- return;
- }
- this._i = this._maxSize;
- this._length = this.members.length;
- while(this._i < this._length) {
- this._member = this.members[this._i++];
- if(this._member != null) {
- this._member.destroy();
- }
- }
- this.length = this.members.length = this._maxSize;
- },
- enumerable: true,
- configurable: true
- });
- Group.prototype.add = function (object) {
- if(object.group && (object.group.ID == this.ID || (object.type == Phaser.Types.GROUP && object.ID == this.ID))) {
- return object;
- }
- this._i = 0;
- this._length = this.members.length;
- while(this._i < this._length) {
- if(this.members[this._i] == null) {
- this.members[this._i] = object;
- this.setObjectIDs(object);
- if(this._i >= this.length) {
- this.length = this._i + 1;
- }
- return object;
- }
- this._i++;
- }
- if(this._maxSize > 0) {
- if(this.members.length >= this._maxSize) {
- return object;
- } else if(this.members.length * 2 <= this._maxSize) {
- this.members.length *= 2;
- } else {
- this.members.length = this._maxSize;
- }
- } else {
- this.members.length *= 2;
- }
- this.members[this._i] = object;
- this.length = this._i + 1;
- this.setObjectIDs(object);
- return object;
- };
- Group.prototype.addNewSprite = function (x, y, key, frame) {
- if (typeof key === "undefined") { key = ''; }
- if (typeof frame === "undefined") { frame = null; }
- return this.add(new Phaser.Sprite(this.game, x, y, key, frame));
- };
- Group.prototype.setObjectIDs = function (object, zIndex) {
- if (typeof zIndex === "undefined") { zIndex = -1; }
- if(object.group !== null) {
- object.group.remove(object);
- }
- object.group = this;
- if(zIndex == -1) {
- zIndex = this.getNextZIndex();
- }
- object.z = zIndex;
- if(object['events']) {
- object['events'].onAddedToGroup.dispatch(object, this, object.z);
- }
- };
- Group.prototype.recycle = function (objectClass) {
- if (typeof objectClass === "undefined") { objectClass = null; }
- if(this._maxSize > 0) {
- if(this.length < this._maxSize) {
- if(objectClass == null) {
- return null;
- }
- return this.add(new objectClass(this.game));
- } else {
- this._member = this.members[this._marker++];
- if(this._marker >= this._maxSize) {
- this._marker = 0;
- }
- return this._member;
- }
- } else {
- this._member = this.getFirstAvailable(objectClass);
- if(this._member != null) {
- return this._member;
- }
- if(objectClass == null) {
- return null;
- }
- return this.add(new objectClass(this.game));
- }
- };
- Group.prototype.remove = function (object, splice) {
- if (typeof splice === "undefined") { splice = false; }
- this._i = this.members.indexOf(object);
- if(this._i < 0 || (this._i >= this.members.length)) {
- return null;
- }
- if(splice) {
- this.members.splice(this._i, 1);
- this.length--;
- } else {
- this.members[this._i] = null;
- }
- if(object['events']) {
- object['events'].onRemovedFromGroup.dispatch(object, this);
- }
- object.group = null;
- object.z = -1;
- return object;
- };
- Group.prototype.replace = function (oldObject, newObject) {
- this._i = this.members.indexOf(oldObject);
- if(this._i < 0 || (this._i >= this.members.length)) {
- return null;
- }
- this.setObjectIDs(newObject, this.members[this._i].z);
- this.remove(this.members[this._i]);
- this.members[this._i] = newObject;
- return newObject;
- };
- Group.prototype.swap = function (child1, child2, sort) {
- if (typeof sort === "undefined") { sort = true; }
- if(child1.group.ID != this.ID || child2.group.ID != this.ID || child1 === child2) {
- return false;
- }
- var tempZ = child1.z;
- child1.z = child2.z;
- child2.z = tempZ;
- if(sort) {
- this.sort();
- }
- return true;
- };
- Group.prototype.bringToTop = function (child) {
- var oldZ = child.z;
- if(!child || child.group == null || child.group.ID != this.ID) {
- return false;
- }
- 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;
- }
- }
- if(child.z == topZ) {
- return false;
- }
- child.z = topZ + 1;
- this.sort();
- for(var i = 0; i < this.length; i++) {
- if(this.members[i]) {
- this.members[i].z = i;
- }
- }
- return true;
- };
- Group.prototype.sort = function (index, order) {
- if (typeof index === "undefined") { index = 'z'; }
- if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
- var _this = this;
- this._sortIndex = index;
- this._sortOrder = order;
- this.members.sort(function (a, b) {
- return _this.sortHandler(a, b);
- });
- };
- Group.prototype.sortHandler = function (obj1, obj2) {
- if(!obj1 || !obj2) {
- return 0;
- }
- if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
- return this._sortOrder;
- } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
- return -this._sortOrder;
- }
- return 0;
- };
- Group.prototype.setAll = function (variableName, value, recurse) {
- if (typeof recurse === "undefined") { recurse = true; }
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null) {
- if(recurse && this._member.type == Phaser.Types.GROUP) {
- this._member.setAll(variableName, value, recurse);
- } else {
- this._member[variableName] = value;
- }
- }
- }
- };
- Group.prototype.callAll = function (functionName, recurse) {
- if (typeof recurse === "undefined") { recurse = true; }
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null) {
- if(recurse && this._member.type == Phaser.Types.GROUP) {
- this._member.callAll(functionName, recurse);
- } else {
- this._member[functionName]();
- }
- }
- }
- };
- Group.prototype.forEach = function (callback, recursive) {
- if (typeof recursive === "undefined") { recursive = false; }
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null) {
- if(recursive && this._member.type == Phaser.Types.GROUP) {
- this._member.forEach(callback, true);
- } else {
- callback.call(this, this._member);
- }
- }
- }
- };
- Group.prototype.forEachAlive = function (context, callback, recursive) {
- if (typeof recursive === "undefined") { recursive = false; }
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null && this._member.alive) {
- if(recursive && this._member.type == Phaser.Types.GROUP) {
- this._member.forEachAlive(context, callback, true);
- } else {
- callback.call(context, this._member);
- }
- }
- }
- };
- Group.prototype.getFirstAvailable = function (objectClass) {
- if (typeof objectClass === "undefined") { objectClass = null; }
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if((this._member != null) && !this._member.exists && ((objectClass == null) || (typeof this._member === objectClass))) {
- return this._member;
- }
- }
- return null;
- };
- Group.prototype.getFirstNull = function () {
- this._i = 0;
- while(this._i < this.length) {
- if(this.members[this._i] == null) {
- return this._i;
- } else {
- this._i++;
- }
- }
- return -1;
- };
- Group.prototype.getFirstExtant = function () {
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null && this._member.exists) {
- return this._member;
- }
- }
- return null;
- };
- Group.prototype.getFirstAlive = function () {
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if((this._member != null) && this._member.exists && this._member.alive) {
- return this._member;
- }
- }
- return null;
- };
- Group.prototype.getFirstDead = function () {
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if((this._member != null) && !this._member.alive) {
- return this._member;
- }
- }
- return null;
- };
- Group.prototype.countLiving = function () {
- this._count = -1;
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null) {
- if(this._count < 0) {
- this._count = 0;
- }
- if(this._member.exists && this._member.alive) {
- this._count++;
- }
- }
- }
- return this._count;
- };
- Group.prototype.countDead = function () {
- this._count = -1;
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if(this._member != null) {
- if(this._count < 0) {
- this._count = 0;
- }
- if(!this._member.alive) {
- this._count++;
- }
- }
- }
- return this._count;
- };
- Group.prototype.getRandom = function (startIndex, length) {
- if (typeof startIndex === "undefined") { startIndex = 0; }
- if (typeof length === "undefined") { length = 0; }
- if(length == 0) {
- length = this.length;
- }
- return this.game.math.getRandom(this.members, startIndex, length);
- };
- Group.prototype.clear = function () {
- this.length = this.members.length = 0;
- };
- Group.prototype.kill = function () {
- this._i = 0;
- while(this._i < this.length) {
- this._member = this.members[this._i++];
- if((this._member != null) && this._member.exists) {
- this._member.kill();
- }
- }
- };
- return Group;
- })();
- Phaser.Group = Group;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Camera = (function () {
- function Camera(game, id, x, y, width, height) {
- this._target = null;
- this.worldBounds = null;
- this.modified = false;
- this.deadzone = null;
- this.visible = true;
- this.z = -1;
- this.game = game;
- this.ID = id;
- this.z = id;
- width = this.game.math.clamp(width, this.game.stage.width, 1);
- height = this.game.math.clamp(height, this.game.stage.height, 1);
- this.worldView = new Phaser.Rectangle(0, 0, width, height);
- this.screenView = new Phaser.Rectangle(x, y, width, height);
- this.plugins = new Phaser.PluginManager(this.game, this);
- this.transform = new Phaser.Components.TransformManager(this);
- this.texture = new Phaser.Display.Texture(this);
- this._canvas = document.createElement('canvas');
- this._canvas.width = width;
- this._canvas.height = height;
- this._renderLocal = true;
- this.texture.canvas = this._canvas;
- this.texture.context = this.texture.canvas.getContext('2d');
- this.texture.backgroundColor = this.game.stage.backgroundColor;
- this.scale = this.transform.scale;
- this.alpha = this.texture.alpha;
- this.origin = this.transform.origin;
- this.crop = this.texture.crop;
- }
- Object.defineProperty(Camera.prototype, "alpha", {
- get: function () {
- return this.texture.alpha;
- },
- set: function (value) {
- this.texture.alpha = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "directToStage", {
- set: function (value) {
- if(value) {
- this._renderLocal = false;
- this.texture.canvas = this.game.stage.canvas;
- Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
- } else {
- this._renderLocal = true;
- this.texture.canvas = this._canvas;
- Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
- }
- this.texture.context = this.texture.canvas.getContext('2d');
- },
- enumerable: true,
- configurable: true
- });
- Camera.prototype.hide = function (object) {
- object.texture.hideFromCamera(this);
- };
- Camera.prototype.isHidden = function (object) {
- return object.texture.isHidden(this);
- };
- Camera.prototype.show = function (object) {
- object.texture.showToCamera(this);
- };
- Camera.prototype.follow = function (target, style) {
- if (typeof style === "undefined") { style = Phaser.Types.CAMERA_FOLLOW_LOCKON; }
- this._target = target;
- var helper;
- switch(style) {
- case Phaser.Types.CAMERA_FOLLOW_PLATFORMER:
- var w = this.width / 8;
- var h = this.height / 3;
- this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
- break;
- case Phaser.Types.CAMERA_FOLLOW_TOPDOWN:
- helper = Math.max(this.width, this.height) / 4;
- this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
- break;
- case Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT:
- helper = Math.max(this.width, this.height) / 8;
- this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
- break;
- case Phaser.Types.CAMERA_FOLLOW_LOCKON:
- default:
- this.deadzone = null;
- break;
- }
- };
- Camera.prototype.focusOnXY = function (x, y) {
- x += (x > 0) ? 0.0000001 : -0.0000001;
- y += (y > 0) ? 0.0000001 : -0.0000001;
- this.worldView.x = Math.round(x - this.worldView.halfWidth);
- this.worldView.y = Math.round(y - this.worldView.halfHeight);
- };
- Camera.prototype.focusOn = function (point) {
- point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
- point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
- this.worldView.x = Math.round(point.x - this.worldView.halfWidth);
- this.worldView.y = Math.round(point.y - this.worldView.halfHeight);
- };
- Camera.prototype.setBounds = function (x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = 0; }
- if (typeof height === "undefined") { height = 0; }
- if(this.worldBounds == null) {
- this.worldBounds = new Phaser.Rectangle();
- }
- this.worldBounds.setTo(x, y, width, height);
- this.worldView.x = x;
- this.worldView.y = y;
- this.update();
- };
- Camera.prototype.update = function () {
- if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
- this.modified = true;
- }
- this.plugins.preUpdate();
- if(this._target !== null) {
- if(this.deadzone == null) {
- this.focusOnXY(this._target.x, this._target.y);
- } else {
- var edge;
- var targetX = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
- var targetY = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
- edge = targetX - this.deadzone.x;
- if(this.worldView.x > edge) {
- this.worldView.x = edge;
- }
- edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
- if(this.worldView.x < edge) {
- this.worldView.x = edge;
- }
- edge = targetY - this.deadzone.y;
- if(this.worldView.y > edge) {
- this.worldView.y = edge;
- }
- edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
- if(this.worldView.y < edge) {
- this.worldView.y = edge;
- }
- }
- }
- if(this.worldBounds !== null) {
- if(this.worldView.x < this.worldBounds.left) {
- this.worldView.x = this.worldBounds.left;
- }
- if(this.worldView.x > this.worldBounds.right - this.width) {
- this.worldView.x = (this.worldBounds.right - this.width) + 1;
- }
- if(this.worldView.y < this.worldBounds.top) {
- this.worldView.y = this.worldBounds.top;
- }
- if(this.worldView.y > this.worldBounds.bottom - this.height) {
- this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
- }
- }
- this.worldView.floor();
- this.plugins.update();
- };
- Camera.prototype.postUpdate = function () {
- if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
- this.modified = false;
- }
- if(this.worldBounds !== null) {
- if(this.worldView.x < this.worldBounds.left) {
- this.worldView.x = this.worldBounds.left;
- }
- if(this.worldView.x > this.worldBounds.right - this.width) {
- this.worldView.x = this.worldBounds.right - this.width;
- }
- if(this.worldView.y < this.worldBounds.top) {
- this.worldView.y = this.worldBounds.top;
- }
- if(this.worldView.y > this.worldBounds.bottom - this.height) {
- this.worldView.y = this.worldBounds.bottom - this.height;
- }
- }
- this.worldView.floor();
- this.plugins.postUpdate();
- };
- Camera.prototype.destroy = function () {
- this.game.world.cameras.removeCamera(this.ID);
- this.plugins.destroy();
- };
- Object.defineProperty(Camera.prototype, "x", {
- get: function () {
- return this.worldView.x;
- },
- set: function (value) {
- this.worldView.x = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "y", {
- get: function () {
- return this.worldView.y;
- },
- set: function (value) {
- this.worldView.y = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "width", {
- get: function () {
- return this.screenView.width;
- },
- set: function (value) {
- this.screenView.width = value;
- this.worldView.width = value;
- if(value !== this.texture.canvas.width) {
- this.texture.canvas.width = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Camera.prototype, "height", {
- get: function () {
- return this.screenView.height;
- },
- set: function (value) {
- this.screenView.height = value;
- this.worldView.height = value;
- if(value !== this.texture.canvas.height) {
- this.texture.canvas.height = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Camera.prototype.setPosition = function (x, y) {
- this.screenView.x = x;
- this.screenView.y = y;
- };
- Camera.prototype.setSize = function (width, height) {
- this.screenView.width = width * this.transform.scale.x;
- this.screenView.height = height * this.transform.scale.y;
- this.worldView.width = width;
- this.worldView.height = height;
- if(width !== this.texture.canvas.width) {
- this.texture.canvas.width = width;
- }
- if(height !== this.texture.canvas.height) {
- this.texture.canvas.height = height;
- }
- };
- Object.defineProperty(Camera.prototype, "rotation", {
- get: function () {
- return this.transform.rotation;
- },
- set: function (value) {
- this.transform.rotation = this.game.math.wrap(value, 360, 0);
- },
- enumerable: true,
- configurable: true
- });
- return Camera;
- })();
- Phaser.Camera = Camera;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var CameraManager = (function () {
- function CameraManager(game, x, y, width, height) {
- this._sortIndex = '';
- this.game = game;
- this._cameras = [];
- this._cameraLength = 0;
- this.defaultCamera = this.addCamera(x, y, width, height);
- this.defaultCamera.directToStage = true;
- this.current = this.defaultCamera;
- }
- CameraManager.prototype.getAll = function () {
- return this._cameras;
- };
- CameraManager.prototype.update = function () {
- for(var i = 0; i < this._cameras.length; i++) {
- this._cameras[i].update();
- }
- };
- CameraManager.prototype.postUpdate = function () {
- for(var i = 0; i < this._cameras.length; i++) {
- this._cameras[i].postUpdate();
- }
- };
- CameraManager.prototype.addCamera = function (x, y, width, height) {
- var newCam = new Phaser.Camera(this.game, this._cameraLength, x, y, width, height);
- this._cameraLength = this._cameras.push(newCam);
- return newCam;
- };
- CameraManager.prototype.removeCamera = function (id) {
- for(var c = 0; c < this._cameras.length; c++) {
- if(this._cameras[c].ID == id) {
- if(this.current.ID === this._cameras[c].ID) {
- this.current = null;
- }
- this._cameras.splice(c, 1);
- return true;
- }
- }
- return false;
- };
- CameraManager.prototype.swap = function (camera1, camera2, sort) {
- if (typeof sort === "undefined") { sort = true; }
- if(camera1.ID == camera2.ID) {
- return false;
- }
- var tempZ = camera1.z;
- camera1.z = camera2.z;
- camera2.z = tempZ;
- if(sort) {
- this.sort();
- }
- return true;
- };
- CameraManager.prototype.getCameraUnderPoint = function (x, y) {
- for(var c = this._cameraLength - 1; c >= 0; c--) {
- if(this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) {
- return this._cameras[c];
- }
- }
- return null;
- };
- CameraManager.prototype.sort = function (index, order) {
- if (typeof index === "undefined") { index = 'z'; }
- if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
- var _this = this;
- this._sortIndex = index;
- this._sortOrder = order;
- this._cameras.sort(function (a, b) {
- return _this.sortHandler(a, b);
- });
- };
- CameraManager.prototype.sortHandler = function (obj1, obj2) {
- if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
- return this._sortOrder;
- } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
- return -this._sortOrder;
- }
- return 0;
- };
- CameraManager.prototype.destroy = function () {
- this._cameras.length = 0;
- this.current = this.addCamera(0, 0, this.game.stage.width, this.game.stage.height);
- };
- return CameraManager;
- })();
- Phaser.CameraManager = CameraManager;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Display) {
- var CSS3Filters = (function () {
- function CSS3Filters(parent) {
- this._blur = 0;
- this._grayscale = 0;
- this._sepia = 0;
- this._brightness = 0;
- this._contrast = 0;
- this._hueRotate = 0;
- this._invert = 0;
- this._opacity = 0;
- this._saturate = 0;
- this.parent = parent;
- }
- CSS3Filters.prototype.setFilter = function (local, prefix, value, unit) {
- this[local] = value;
- if(this.parent) {
- this.parent.style['-webkit-filter'] = prefix + '(' + value + unit + ')';
- }
- };
- Object.defineProperty(CSS3Filters.prototype, "blur", {
- get: function () {
- return this._blur;
- },
- set: function (radius) {
- this.setFilter('_blur', 'blur', radius, 'px');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "grayscale", {
- get: function () {
- return this._grayscale;
- },
- set: function (amount) {
- this.setFilter('_grayscale', 'grayscale', amount, '%');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "sepia", {
- get: function () {
- return this._sepia;
- },
- set: function (amount) {
- this.setFilter('_sepia', 'sepia', amount, '%');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "brightness", {
- get: function () {
- return this._brightness;
- },
- set: function (amount) {
- this.setFilter('_brightness', 'brightness', amount, '%');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "contrast", {
- get: function () {
- return this._contrast;
- },
- set: function (amount) {
- this.setFilter('_contrast', 'contrast', amount, '%');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "hueRotate", {
- get: function () {
- return this._hueRotate;
- },
- set: function (angle) {
- this.setFilter('_hueRotate', 'hue-rotate', angle, 'deg');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "invert", {
- get: function () {
- return this._invert;
- },
- set: function (value) {
- this.setFilter('_invert', 'invert', value, '%');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "opacity", {
- get: function () {
- return this._opacity;
- },
- set: function (value) {
- this.setFilter('_opacity', 'opacity', value, '%');
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(CSS3Filters.prototype, "saturate", {
- get: function () {
- return this._saturate;
- },
- set: function (value) {
- this.setFilter('_saturate', 'saturate', value, '%');
- },
- enumerable: true,
- configurable: true
- });
- return CSS3Filters;
- })();
- Display.CSS3Filters = CSS3Filters;
- })(Phaser.Display || (Phaser.Display = {}));
- var Display = Phaser.Display;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Display) {
- var DynamicTexture = (function () {
- function DynamicTexture(game, width, height) {
- this._sx = 0;
- this._sy = 0;
- this._sw = 0;
- this._sh = 0;
- this._dx = 0;
- this._dy = 0;
- this._dw = 0;
- this._dh = 0;
- this.globalCompositeOperation = null;
- this.game = game;
- this.type = Phaser.Types.DYNAMICTEXTURE;
- this.canvas = document.createElement('canvas');
- this.canvas.width = width;
- this.canvas.height = height;
- this.context = this.canvas.getContext('2d');
- this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
- this.bounds = new Phaser.Rectangle(0, 0, width, height);
- }
- DynamicTexture.prototype.getPixel = function (x, y) {
- var imageData = this.context.getImageData(x, y, 1, 1);
- return Phaser.ColorUtils.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
- };
- DynamicTexture.prototype.getPixel32 = function (x, y) {
- var imageData = this.context.getImageData(x, y, 1, 1);
- return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
- };
- DynamicTexture.prototype.getPixels = function (rect) {
- return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
- };
- DynamicTexture.prototype.setPixel = function (x, y, color) {
- this.context.fillStyle = color;
- this.context.fillRect(x, y, 1, 1);
- };
- DynamicTexture.prototype.setPixel32 = function (x, y, color) {
- this.context.fillStyle = color;
- this.context.fillRect(x, y, 1, 1);
- };
- DynamicTexture.prototype.setPixels = function (rect, input) {
- this.context.putImageData(input, rect.x, rect.y);
- };
- DynamicTexture.prototype.fillRect = function (rect, color) {
- this.context.fillStyle = color;
- this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
- };
- DynamicTexture.prototype.pasteImage = function (key, frame, destX, destY, destWidth, destHeight) {
- if (typeof frame === "undefined") { frame = -1; }
- if (typeof destX === "undefined") { destX = 0; }
- if (typeof destY === "undefined") { destY = 0; }
- if (typeof destWidth === "undefined") { destWidth = null; }
- if (typeof destHeight === "undefined") { destHeight = null; }
- var texture = null;
- var frameData;
- this._sx = 0;
- this._sy = 0;
- this._dx = destX;
- this._dy = destY;
- if(frame > -1) {
- } else {
- texture = this.game.cache.getImage(key);
- this._sw = texture.width;
- this._sh = texture.height;
- this._dw = texture.width;
- this._dh = texture.height;
- }
- if(destWidth !== null) {
- this._dw = destWidth;
- }
- if(destHeight !== null) {
- this._dh = destHeight;
- }
- if(texture != null) {
- this.context.drawImage(texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
- }
- };
- DynamicTexture.prototype.copyPixels = function (sourceTexture, sourceRect, destPoint) {
- if(Phaser.RectangleUtils.equals(sourceRect, this.bounds) == true) {
- this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
- } else {
- this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
- }
- };
- DynamicTexture.prototype.add = function (sprite) {
- sprite.texture.canvas = this.canvas;
- sprite.texture.context = this.context;
- };
- DynamicTexture.prototype.assignCanvasToGameObjects = function (objects) {
- for(var i = 0; i < objects.length; i++) {
- if(objects[i].texture) {
- objects[i].texture.canvas = this.canvas;
- objects[i].texture.context = this.context;
- }
- }
- };
- DynamicTexture.prototype.clear = function () {
- this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
- };
- DynamicTexture.prototype.render = function (x, y) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if(this.globalCompositeOperation) {
- this.game.stage.context.save();
- this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
- }
- this.game.stage.context.drawImage(this.canvas, x, y);
- if(this.globalCompositeOperation) {
- this.game.stage.context.restore();
- }
- };
- Object.defineProperty(DynamicTexture.prototype, "width", {
- get: function () {
- return this.bounds.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(DynamicTexture.prototype, "height", {
- get: function () {
- return this.bounds.height;
- },
- enumerable: true,
- configurable: true
- });
- return DynamicTexture;
- })();
- Display.DynamicTexture = DynamicTexture;
- })(Phaser.Display || (Phaser.Display = {}));
- var Display = Phaser.Display;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Display) {
- var Texture = (function () {
- function Texture(parent) {
- this.imageTexture = null;
- this.dynamicTexture = null;
- this.loaded = false;
- this.opaque = false;
- this.backgroundColor = 'rgb(255,255,255)';
- this.globalCompositeOperation = null;
- this.renderRotation = true;
- this.flippedX = false;
- this.flippedY = false;
- this.isDynamic = false;
- this.game = parent.game;
- this.parent = parent;
- this.canvas = parent.game.stage.canvas;
- this.context = parent.game.stage.context;
- this.alpha = 1;
- this.flippedX = false;
- this.flippedY = false;
- this._width = 16;
- this._height = 16;
- this.cameraBlacklist = [];
- this._blacklist = 0;
- }
- Texture.prototype.hideFromCamera = function (camera) {
- if(this.isHidden(camera) == false) {
- this.cameraBlacklist.push(camera.ID);
- this._blacklist++;
- }
- };
- Texture.prototype.isHidden = function (camera) {
- if(this._blacklist && this.cameraBlacklist.indexOf(camera.ID) !== -1) {
- return true;
- }
- return false;
- };
- Texture.prototype.showToCamera = function (camera) {
- if(this.isHidden(camera)) {
- this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
- this._blacklist--;
- }
- };
- Texture.prototype.setTo = function (image, dynamic) {
- if (typeof image === "undefined") { image = null; }
- if (typeof dynamic === "undefined") { dynamic = null; }
- if(dynamic) {
- this.isDynamic = true;
- this.dynamicTexture = dynamic;
- this.texture = this.dynamicTexture.canvas;
- } else {
- this.isDynamic = false;
- this.imageTexture = image;
- this.texture = this.imageTexture;
- this._width = image.width;
- this._height = image.height;
- }
- this.loaded = true;
- return this.parent;
- };
- Texture.prototype.loadImage = function (key, clearAnimations, updateBody) {
- if (typeof clearAnimations === "undefined") { clearAnimations = true; }
- if (typeof updateBody === "undefined") { updateBody = true; }
- if(clearAnimations && this.parent['animations'] && this.parent['animations'].frameData !== null) {
- this.parent.animations.destroy();
- }
- if(this.game.cache.getImage(key) !== null) {
- this.setTo(this.game.cache.getImage(key), null);
- this.cacheKey = key;
- if(this.game.cache.isSpriteSheet(key) && this.parent['animations']) {
- this.parent.animations.loadFrameData(this.parent.game.cache.getFrameData(key));
- } else {
- if(updateBody && this.parent['body']) {
- this.parent.body.bounds.width = this.width;
- this.parent.body.bounds.height = this.height;
- }
- }
- }
- };
- Texture.prototype.loadDynamicTexture = function (texture) {
- if(this.parent.animations.frameData !== null) {
- this.parent.animations.destroy();
- }
- this.setTo(null, texture);
- this.parent.texture.width = this.width;
- this.parent.texture.height = this.height;
- };
- Object.defineProperty(Texture.prototype, "width", {
- get: function () {
- if(this.isDynamic) {
- return this.dynamicTexture.width;
- } else {
- return this._width;
- }
- },
- set: function (value) {
- this._width = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Texture.prototype, "height", {
- get: function () {
- if(this.isDynamic) {
- return this.dynamicTexture.height;
- } else {
- return this._height;
- }
- },
- set: function (value) {
- this._height = value;
- },
- enumerable: true,
- configurable: true
- });
- return Texture;
- })();
- Display.Texture = Texture;
- })(Phaser.Display || (Phaser.Display = {}));
- var Display = Phaser.Display;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Back = (function () {
- function Back() { }
- Back.In = function In(k) {
- var s = 1.70158;
- return k * k * ((s + 1) * k - s);
- };
- Back.Out = function Out(k) {
- var s = 1.70158;
- return --k * k * ((s + 1) * k + s) + 1;
- };
- Back.InOut = function InOut(k) {
- var s = 1.70158 * 1.525;
- if((k *= 2) < 1) {
- return 0.5 * (k * k * ((s + 1) * k - s));
- }
- return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
- };
- return Back;
- })();
- Easing.Back = Back;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Bounce = (function () {
- function Bounce() { }
- Bounce.In = function In(k) {
- return 1 - Phaser.Easing.Bounce.Out(1 - k);
- };
- Bounce.Out = function Out(k) {
- if(k < (1 / 2.75)) {
- return 7.5625 * k * k;
- } else if(k < (2 / 2.75)) {
- return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
- } else if(k < (2.5 / 2.75)) {
- return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
- } else {
- return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
- }
- };
- Bounce.InOut = function InOut(k) {
- if(k < 0.5) {
- return Phaser.Easing.Bounce.In(k * 2) * 0.5;
- }
- return Phaser.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
- };
- return Bounce;
- })();
- Easing.Bounce = Bounce;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Circular = (function () {
- function Circular() { }
- Circular.In = function In(k) {
- return 1 - Math.sqrt(1 - k * k);
- };
- Circular.Out = function Out(k) {
- return Math.sqrt(1 - (--k * k));
- };
- Circular.InOut = function InOut(k) {
- if((k *= 2) < 1) {
- return -0.5 * (Math.sqrt(1 - k * k) - 1);
- }
- return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
- };
- return Circular;
- })();
- Easing.Circular = Circular;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Cubic = (function () {
- function Cubic() { }
- Cubic.In = function In(k) {
- return k * k * k;
- };
- Cubic.Out = function Out(k) {
- return --k * k * k + 1;
- };
- Cubic.InOut = function InOut(k) {
- if((k *= 2) < 1) {
- return 0.5 * k * k * k;
- }
- return 0.5 * ((k -= 2) * k * k + 2);
- };
- return Cubic;
- })();
- Easing.Cubic = Cubic;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Elastic = (function () {
- function Elastic() { }
- Elastic.In = function In(k) {
- var s, a = 0.1, p = 0.4;
- if(k === 0) {
- return 0;
- }
- if(k === 1) {
- return 1;
- }
- if(!a || a < 1) {
- a = 1;
- s = p / 4;
- } else {
- s = p * Math.asin(1 / a) / (2 * Math.PI);
- }
- return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
- };
- Elastic.Out = function Out(k) {
- var s, a = 0.1, p = 0.4;
- if(k === 0) {
- return 0;
- }
- if(k === 1) {
- return 1;
- }
- if(!a || a < 1) {
- a = 1;
- s = p / 4;
- } else {
- s = p * Math.asin(1 / a) / (2 * Math.PI);
- }
- return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
- };
- Elastic.InOut = function InOut(k) {
- var s, a = 0.1, p = 0.4;
- if(k === 0) {
- return 0;
- }
- if(k === 1) {
- return 1;
- }
- if(!a || a < 1) {
- a = 1;
- s = p / 4;
- } else {
- s = p * Math.asin(1 / a) / (2 * Math.PI);
- }
- if((k *= 2) < 1) {
- return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
- }
- return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
- };
- return Elastic;
- })();
- Easing.Elastic = Elastic;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Exponential = (function () {
- function Exponential() { }
- Exponential.In = function In(k) {
- return k === 0 ? 0 : Math.pow(1024, k - 1);
- };
- Exponential.Out = function Out(k) {
- return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
- };
- Exponential.InOut = function InOut(k) {
- if(k === 0) {
- return 0;
- }
- if(k === 1) {
- return 1;
- }
- if((k *= 2) < 1) {
- return 0.5 * Math.pow(1024, k - 1);
- }
- return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
- };
- return Exponential;
- })();
- Easing.Exponential = Exponential;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Linear = (function () {
- function Linear() { }
- Linear.None = function None(k) {
- return k;
- };
- return Linear;
- })();
- Easing.Linear = Linear;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Quadratic = (function () {
- function Quadratic() { }
- Quadratic.In = function In(k) {
- return k * k;
- };
- Quadratic.Out = function Out(k) {
- return k * (2 - k);
- };
- Quadratic.InOut = function InOut(k) {
- if((k *= 2) < 1) {
- return 0.5 * k * k;
- }
- return -0.5 * (--k * (k - 2) - 1);
- };
- return Quadratic;
- })();
- Easing.Quadratic = Quadratic;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Quartic = (function () {
- function Quartic() { }
- Quartic.In = function In(k) {
- return k * k * k * k;
- };
- Quartic.Out = function Out(k) {
- return 1 - (--k * k * k * k);
- };
- Quartic.InOut = function InOut(k) {
- if((k *= 2) < 1) {
- return 0.5 * k * k * k * k;
- }
- return -0.5 * ((k -= 2) * k * k * k - 2);
- };
- return Quartic;
- })();
- Easing.Quartic = Quartic;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Quintic = (function () {
- function Quintic() { }
- Quintic.In = function In(k) {
- return k * k * k * k * k;
- };
- Quintic.Out = function Out(k) {
- return --k * k * k * k * k + 1;
- };
- Quintic.InOut = function InOut(k) {
- if((k *= 2) < 1) {
- return 0.5 * k * k * k * k * k;
- }
- return 0.5 * ((k -= 2) * k * k * k * k + 2);
- };
- return Quintic;
- })();
- Easing.Quintic = Quintic;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Easing) {
- var Sinusoidal = (function () {
- function Sinusoidal() { }
- Sinusoidal.In = function In(k) {
- return 1 - Math.cos(k * Math.PI / 2);
- };
- Sinusoidal.Out = function Out(k) {
- return Math.sin(k * Math.PI / 2);
- };
- Sinusoidal.InOut = function InOut(k) {
- return 0.5 * (1 - Math.cos(Math.PI * k));
- };
- return Sinusoidal;
- })();
- Easing.Sinusoidal = Sinusoidal;
- })(Phaser.Easing || (Phaser.Easing = {}));
- var Easing = Phaser.Easing;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Tween = (function () {
- function Tween(object, game) {
- this._object = null;
- this._pausedTime = 0;
- this._valuesStart = {
- };
- this._valuesEnd = {
- };
- this._duration = 1000;
- this._delayTime = 0;
- this._startTime = null;
- this._loop = false;
- this._yoyo = false;
- this._yoyoCount = 0;
- this._chainedTweens = [];
- this.isRunning = false;
- this._object = object;
- this.game = game;
- this._manager = this.game.tweens;
- this._interpolationFunction = this.game.math.linearInterpolation;
- this._easingFunction = Phaser.Easing.Linear.None;
- this._chainedTweens = [];
- this.onStart = new Phaser.Signal();
- this.onUpdate = new Phaser.Signal();
- this.onComplete = new Phaser.Signal();
- }
- Tween.prototype.to = function (properties, duration, ease, autoStart, delay, loop, yoyo) {
- if (typeof duration === "undefined") { duration = 1000; }
- if (typeof ease === "undefined") { ease = null; }
- if (typeof autoStart === "undefined") { autoStart = false; }
- if (typeof delay === "undefined") { delay = 0; }
- if (typeof loop === "undefined") { loop = false; }
- if (typeof yoyo === "undefined") { yoyo = false; }
- this._duration = duration;
- this._valuesEnd = properties;
- if(ease !== null) {
- this._easingFunction = ease;
- }
- if(delay > 0) {
- this._delayTime = delay;
- }
- this._loop = loop;
- this._yoyo = yoyo;
- this._yoyoCount = 0;
- if(autoStart === true) {
- return this.start();
- } else {
- return this;
- }
- };
- Tween.prototype.loop = function (value) {
- this._loop = value;
- return this;
- };
- Tween.prototype.yoyo = function (value) {
- this._yoyo = value;
- this._yoyoCount = 0;
- return this;
- };
- Tween.prototype.start = function (looped) {
- if (typeof looped === "undefined") { looped = false; }
- if(this.game === null || this._object === null) {
- return;
- }
- if(looped == false) {
- this._manager.add(this);
- this.onStart.dispatch(this._object);
- }
- this._startTime = this.game.time.now + this._delayTime;
- this.isRunning = true;
- for(var property in this._valuesEnd) {
- if(this._object[property] === null || !(property in this._object)) {
- throw Error('Phaser.Tween interpolation of null value of non-existing property');
- continue;
- }
- if(this._valuesEnd[property] instanceof Array) {
- if(this._valuesEnd[property].length === 0) {
- continue;
- }
- this._valuesEnd[property] = [
- this._object[property]
- ].concat(this._valuesEnd[property]);
- }
- if(looped == false) {
- this._valuesStart[property] = this._object[property];
- }
- }
- return this;
- };
- Tween.prototype.reverse = function () {
- var tempObj = {
- };
- for(var property in this._valuesStart) {
- tempObj[property] = this._valuesStart[property];
- this._valuesStart[property] = this._valuesEnd[property];
- this._valuesEnd[property] = tempObj[property];
- }
- this._yoyoCount++;
- return this.start(true);
- };
- Tween.prototype.reset = function () {
- for(var property in this._valuesStart) {
- this._object[property] = this._valuesStart[property];
- }
- return this.start(true);
- };
- Tween.prototype.clear = function () {
- this._chainedTweens = [];
- this.onStart.removeAll();
- this.onUpdate.removeAll();
- this.onComplete.removeAll();
- return this;
- };
- Tween.prototype.stop = function () {
- if(this._manager !== null) {
- this._manager.remove(this);
- }
- this.isRunning = false;
- this.onComplete.dispose();
- return this;
- };
- Object.defineProperty(Tween.prototype, "parent", {
- set: function (value) {
- this.game = value;
- this._manager = this.game.tweens;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Tween.prototype, "delay", {
- get: function () {
- return this._delayTime;
- },
- set: function (amount) {
- this._delayTime = amount;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Tween.prototype, "easing", {
- get: function () {
- return this._easingFunction;
- },
- set: function (easing) {
- this._easingFunction = easing;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Tween.prototype, "interpolation", {
- get: function () {
- return this._interpolationFunction;
- },
- set: function (interpolation) {
- this._interpolationFunction = interpolation;
- },
- enumerable: true,
- configurable: true
- });
- Tween.prototype.chain = function (tween) {
- this._chainedTweens.push(tween);
- return this;
- };
- Tween.prototype.pause = function () {
- this._paused = true;
- };
- Tween.prototype.resume = function () {
- this._paused = false;
- this._startTime += this.game.time.pauseDuration;
- };
- Tween.prototype.update = function (time) {
- if(this._paused || time < this._startTime) {
- return true;
- }
- this._tempElapsed = (time - this._startTime) / this._duration;
- this._tempElapsed = this._tempElapsed > 1 ? 1 : this._tempElapsed;
- this._tempValue = this._easingFunction(this._tempElapsed);
- for(var property in this._valuesStart) {
- if(this._valuesEnd[property] instanceof Array) {
- this._object[property] = this._interpolationFunction(this._valuesEnd[property], this._tempValue);
- } else {
- this._object[property] = this._valuesStart[property] + (this._valuesEnd[property] - this._valuesStart[property]) * this._tempValue;
- }
- }
- this.onUpdate.dispatch(this._object, this._tempValue);
- if(this._tempElapsed == 1) {
- if(this._yoyo) {
- if(this._yoyoCount == 0) {
- this.reverse();
- return true;
- } else {
- if(this._loop == false) {
- this.onComplete.dispatch(this._object);
- for(var i = 0; i < this._chainedTweens.length; i++) {
- this._chainedTweens[i].start();
- }
- return false;
- } else {
- this._yoyoCount = 0;
- this.reverse();
- return true;
- }
- }
- }
- if(this._loop) {
- this._yoyoCount = 0;
- this.reset();
- return true;
- } else {
- this.onComplete.dispatch(this._object);
- for(var i = 0; i < this._chainedTweens.length; i++) {
- this._chainedTweens[i].start();
- }
- if(this._chainedTweens.length == 0) {
- this.isRunning = false;
- }
- return false;
- }
- }
- return true;
- };
- return Tween;
- })();
- Phaser.Tween = Tween;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var TweenManager = (function () {
- function TweenManager(game) {
- this.game = game;
- this._tweens = [];
- this.game.onPause.add(this.pauseAll, this);
- this.game.onResume.add(this.resumeAll, this);
- }
- TweenManager.prototype.getAll = function () {
- return this._tweens;
- };
- TweenManager.prototype.removeAll = function () {
- this._tweens.length = 0;
- };
- TweenManager.prototype.create = function (object, localReference) {
- if (typeof localReference === "undefined") { localReference = false; }
- if(localReference) {
- object['tween'] = new Phaser.Tween(object, this.game);
- return object['tween'];
- } else {
- return new Phaser.Tween(object, this.game);
- }
- };
- TweenManager.prototype.add = function (tween) {
- tween.parent = this.game;
- this._tweens.push(tween);
- return tween;
- };
- TweenManager.prototype.remove = function (tween) {
- var i = this._tweens.indexOf(tween);
- if(i !== -1) {
- this._tweens.splice(i, 1);
- }
- };
- TweenManager.prototype.update = function () {
- if(this._tweens.length === 0) {
- return false;
- }
- var i = 0;
- var numTweens = this._tweens.length;
- while(i < numTweens) {
- if(this._tweens[i].update(this.game.time.now)) {
- i++;
- } else {
- this._tweens.splice(i, 1);
- numTweens--;
- }
- }
- return true;
- };
- TweenManager.prototype.pauseAll = function () {
- if(this._tweens.length === 0) {
- return false;
- }
- var i = 0;
- var numTweens = this._tweens.length;
- while(i < numTweens) {
- this._tweens[i].pause();
- i++;
- }
- };
- TweenManager.prototype.resumeAll = function () {
- if(this._tweens.length === 0) {
- return false;
- }
- var i = 0;
- var numTweens = this._tweens.length;
- while(i < numTweens) {
- this._tweens[i].resume();
- i++;
- }
- };
- return TweenManager;
- })();
- Phaser.TweenManager = TweenManager;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var TimeManager = (function () {
- function TimeManager(game) {
- this.physicsElapsed = 0;
- this.time = 0;
- this.pausedTime = 0;
- this.now = 0;
- this.delta = 0;
- this.fps = 0;
- this.fpsMin = 1000;
- this.fpsMax = 0;
- this.msMin = 1000;
- this.msMax = 0;
- this.frames = 0;
- this._timeLastSecond = 0;
- this.pauseDuration = 0;
- this._pauseStarted = 0;
- this.game = game;
- this._started = 0;
- this._timeLastSecond = this._started;
- this.time = this._started;
- this.game.onPause.add(this.gamePaused, this);
- this.game.onResume.add(this.gameResumed, this);
- }
- Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", {
- get: function () {
- return (this.now - this._started) * 0.001;
- },
- enumerable: true,
- configurable: true
- });
- TimeManager.prototype.update = function (raf) {
- this.now = raf;
- this.delta = this.now - this.time;
- this.msMin = Math.min(this.msMin, this.delta);
- this.msMax = Math.max(this.msMax, this.delta);
- this.frames++;
- if(this.now > this._timeLastSecond + 1000) {
- this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
- this.fpsMin = Math.min(this.fpsMin, this.fps);
- this.fpsMax = Math.max(this.fpsMax, this.fps);
- this._timeLastSecond = this.now;
- this.frames = 0;
- }
- this.time = this.now;
- this.physicsElapsed = 1.0 * (this.delta / 1000);
- if(this.game.paused) {
- this.pausedTime = this.now - this._pauseStarted;
- }
- };
- TimeManager.prototype.gamePaused = function () {
- this._pauseStarted = this.now;
- };
- TimeManager.prototype.gameResumed = function () {
- this.delta = 0;
- this.physicsElapsed = 0;
- this.time = Date.now();
- this.pauseDuration = this.pausedTime;
- };
- TimeManager.prototype.elapsedSince = function (since) {
- return this.now - since;
- };
- TimeManager.prototype.elapsedSecondsSince = function (since) {
- return (this.now - since) * 0.001;
- };
- TimeManager.prototype.reset = function () {
- this._started = this.now;
- };
- return TimeManager;
- })();
- Phaser.TimeManager = TimeManager;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Net = (function () {
- function Net(game) {
- this.game = game;
- }
- Net.prototype.checkDomainName = function (domain) {
- return window.location.hostname.indexOf(domain) !== -1;
- };
- Net.prototype.updateQueryString = function (key, value, redirect, url) {
- if (typeof redirect === "undefined") { redirect = false; }
- if (typeof url === "undefined") { url = ''; }
- if(url == '') {
- url = window.location.href;
- }
- var output = '';
- var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
- if(re.test(url)) {
- if(typeof value !== 'undefined' && value !== null) {
- output = url.replace(re, '$1' + key + "=" + value + '$2$3');
- } else {
- output = url.replace(re, '$1$3').replace(/(&|\?)$/, '');
- }
- } else {
- if(typeof value !== 'undefined' && value !== null) {
- var separator = url.indexOf('?') !== -1 ? '&' : '?';
- var hash = url.split('#');
- url = hash[0] + separator + key + '=' + value;
- if(hash[1]) {
- url += '#' + hash[1];
- }
- output = url;
- } else {
- output = url;
- }
- }
- if(redirect) {
- window.location.href = output;
- } else {
- return output;
- }
- };
- Net.prototype.getQueryString = function (parameter) {
- if (typeof parameter === "undefined") { parameter = ''; }
- var output = {
- };
- var keyValues = location.search.substring(1).split('&');
- for(var i in keyValues) {
- var key = keyValues[i].split('=');
- if(key.length > 1) {
- if(parameter && parameter == this.decodeURI(key[0])) {
- return this.decodeURI(key[1]);
- } else {
- output[this.decodeURI(key[0])] = this.decodeURI(key[1]);
- }
- }
- }
- return output;
- };
- Net.prototype.decodeURI = function (value) {
- return decodeURIComponent(value.replace(/\+/g, " "));
- };
- return Net;
- })();
- Phaser.Net = Net;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Keyboard = (function () {
- function Keyboard(game) {
- this._keys = {
- };
- this._capture = {
- };
- this.disabled = false;
- this.game = game;
- }
- Keyboard.prototype.start = function () {
- var _this = this;
- this._onKeyDown = function (event) {
- return _this.onKeyDown(event);
- };
- this._onKeyUp = function (event) {
- return _this.onKeyUp(event);
- };
- document.body.addEventListener('keydown', this._onKeyDown, false);
- document.body.addEventListener('keyup', this._onKeyUp, false);
- };
- Keyboard.prototype.stop = function () {
- document.body.removeEventListener('keydown', this._onKeyDown);
- document.body.removeEventListener('keyup', this._onKeyUp);
- };
- Keyboard.prototype.addKeyCapture = function (keycode) {
- if(typeof keycode === 'object') {
- for(var i = 0; i < keycode.length; i++) {
- this._capture[keycode[i]] = true;
- }
- } else {
- this._capture[keycode] = true;
- }
- };
- Keyboard.prototype.removeKeyCapture = function (keycode) {
- delete this._capture[keycode];
- };
- Keyboard.prototype.clearCaptures = function () {
- this._capture = {
- };
- };
- Keyboard.prototype.onKeyDown = function (event) {
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- if(this._capture[event.keyCode]) {
- event.preventDefault();
- }
- if(!this._keys[event.keyCode]) {
- this._keys[event.keyCode] = {
- isDown: true,
- timeDown: this.game.time.now,
- timeUp: 0
- };
- } else {
- this._keys[event.keyCode].isDown = true;
- this._keys[event.keyCode].timeDown = this.game.time.now;
- }
- };
- Keyboard.prototype.onKeyUp = function (event) {
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- if(this._capture[event.keyCode]) {
- event.preventDefault();
- }
- if(!this._keys[event.keyCode]) {
- this._keys[event.keyCode] = {
- isDown: false,
- timeDown: 0,
- timeUp: this.game.time.now
- };
- } else {
- this._keys[event.keyCode].isDown = false;
- this._keys[event.keyCode].timeUp = this.game.time.now;
- }
- };
- Keyboard.prototype.reset = function () {
- for(var key in this._keys) {
- this._keys[key].isDown = false;
- }
- };
- Keyboard.prototype.justPressed = function (keycode, duration) {
- if (typeof duration === "undefined") { duration = 250; }
- if(this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration)) {
- return true;
- } else {
- return false;
- }
- };
- Keyboard.prototype.justReleased = function (keycode, duration) {
- if (typeof duration === "undefined") { duration = 250; }
- if(this._keys[keycode] && this._keys[keycode].isDown === false && (this.game.time.now - this._keys[keycode].timeUp < duration)) {
- return true;
- } else {
- return false;
- }
- };
- Keyboard.prototype.isDown = function (keycode) {
- if(this._keys[keycode]) {
- return this._keys[keycode].isDown;
- } else {
- return false;
- }
- };
- Keyboard.A = "A".charCodeAt(0);
- Keyboard.B = "B".charCodeAt(0);
- Keyboard.C = "C".charCodeAt(0);
- Keyboard.D = "D".charCodeAt(0);
- Keyboard.E = "E".charCodeAt(0);
- Keyboard.F = "F".charCodeAt(0);
- Keyboard.G = "G".charCodeAt(0);
- Keyboard.H = "H".charCodeAt(0);
- Keyboard.I = "I".charCodeAt(0);
- Keyboard.J = "J".charCodeAt(0);
- Keyboard.K = "K".charCodeAt(0);
- Keyboard.L = "L".charCodeAt(0);
- Keyboard.M = "M".charCodeAt(0);
- Keyboard.N = "N".charCodeAt(0);
- Keyboard.O = "O".charCodeAt(0);
- Keyboard.P = "P".charCodeAt(0);
- Keyboard.Q = "Q".charCodeAt(0);
- Keyboard.R = "R".charCodeAt(0);
- Keyboard.S = "S".charCodeAt(0);
- Keyboard.T = "T".charCodeAt(0);
- Keyboard.U = "U".charCodeAt(0);
- Keyboard.V = "V".charCodeAt(0);
- Keyboard.W = "W".charCodeAt(0);
- Keyboard.X = "X".charCodeAt(0);
- Keyboard.Y = "Y".charCodeAt(0);
- Keyboard.Z = "Z".charCodeAt(0);
- Keyboard.ZERO = "0".charCodeAt(0);
- Keyboard.ONE = "1".charCodeAt(0);
- Keyboard.TWO = "2".charCodeAt(0);
- Keyboard.THREE = "3".charCodeAt(0);
- Keyboard.FOUR = "4".charCodeAt(0);
- Keyboard.FIVE = "5".charCodeAt(0);
- Keyboard.SIX = "6".charCodeAt(0);
- Keyboard.SEVEN = "7".charCodeAt(0);
- Keyboard.EIGHT = "8".charCodeAt(0);
- Keyboard.NINE = "9".charCodeAt(0);
- Keyboard.NUMPAD_0 = 96;
- Keyboard.NUMPAD_1 = 97;
- Keyboard.NUMPAD_2 = 98;
- Keyboard.NUMPAD_3 = 99;
- Keyboard.NUMPAD_4 = 100;
- Keyboard.NUMPAD_5 = 101;
- Keyboard.NUMPAD_6 = 102;
- Keyboard.NUMPAD_7 = 103;
- Keyboard.NUMPAD_8 = 104;
- Keyboard.NUMPAD_9 = 105;
- Keyboard.NUMPAD_MULTIPLY = 106;
- Keyboard.NUMPAD_ADD = 107;
- Keyboard.NUMPAD_ENTER = 108;
- Keyboard.NUMPAD_SUBTRACT = 109;
- Keyboard.NUMPAD_DECIMAL = 110;
- Keyboard.NUMPAD_DIVIDE = 111;
- Keyboard.F1 = 112;
- Keyboard.F2 = 113;
- Keyboard.F3 = 114;
- Keyboard.F4 = 115;
- Keyboard.F5 = 116;
- Keyboard.F6 = 117;
- Keyboard.F7 = 118;
- Keyboard.F8 = 119;
- Keyboard.F9 = 120;
- Keyboard.F10 = 121;
- Keyboard.F11 = 122;
- Keyboard.F12 = 123;
- Keyboard.F13 = 124;
- Keyboard.F14 = 125;
- Keyboard.F15 = 126;
- Keyboard.COLON = 186;
- Keyboard.EQUALS = 187;
- Keyboard.UNDERSCORE = 189;
- Keyboard.QUESTION_MARK = 191;
- Keyboard.TILDE = 192;
- Keyboard.OPEN_BRACKET = 219;
- Keyboard.BACKWARD_SLASH = 220;
- Keyboard.CLOSED_BRACKET = 221;
- Keyboard.QUOTES = 222;
- Keyboard.BACKSPACE = 8;
- Keyboard.TAB = 9;
- Keyboard.CLEAR = 12;
- Keyboard.ENTER = 13;
- Keyboard.SHIFT = 16;
- Keyboard.CONTROL = 17;
- Keyboard.ALT = 18;
- Keyboard.CAPS_LOCK = 20;
- Keyboard.ESC = 27;
- Keyboard.SPACEBAR = 32;
- Keyboard.PAGE_UP = 33;
- Keyboard.PAGE_DOWN = 34;
- Keyboard.END = 35;
- Keyboard.HOME = 36;
- Keyboard.LEFT = 37;
- Keyboard.UP = 38;
- Keyboard.RIGHT = 39;
- Keyboard.DOWN = 40;
- Keyboard.INSERT = 45;
- Keyboard.DELETE = 46;
- Keyboard.HELP = 47;
- Keyboard.NUM_LOCK = 144;
- return Keyboard;
- })();
- Phaser.Keyboard = Keyboard;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Mouse = (function () {
- function Mouse(game) {
- this.disabled = false;
- this.mouseDownCallback = null;
- this.mouseMoveCallback = null;
- this.mouseUpCallback = null;
- this.game = game;
- this.callbackContext = this.game;
- }
- Mouse.LEFT_BUTTON = 0;
- Mouse.MIDDLE_BUTTON = 1;
- Mouse.RIGHT_BUTTON = 2;
- Mouse.prototype.start = function () {
- var _this = this;
- if(this.game.device.android && this.game.device.chrome == false) {
- return;
- }
- this._onMouseDown = function (event) {
- return _this.onMouseDown(event);
- };
- this._onMouseMove = function (event) {
- return _this.onMouseMove(event);
- };
- this._onMouseUp = function (event) {
- return _this.onMouseUp(event);
- };
- this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
- this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
- this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
- };
- Mouse.prototype.onMouseDown = function (event) {
- if(this.mouseDownCallback) {
- this.mouseDownCallback.call(this.callbackContext, event);
- }
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event['identifier'] = 0;
- this.game.input.mousePointer.start(event);
- };
- Mouse.prototype.onMouseMove = function (event) {
- if(this.mouseMoveCallback) {
- this.mouseMoveCallback.call(this.callbackContext, event);
- }
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event['identifier'] = 0;
- this.game.input.mousePointer.move(event);
- };
- Mouse.prototype.onMouseUp = function (event) {
- if(this.mouseUpCallback) {
- this.mouseUpCallback.call(this.callbackContext, event);
- }
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event['identifier'] = 0;
- this.game.input.mousePointer.stop(event);
- };
- Mouse.prototype.stop = function () {
- this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown);
- this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove);
- this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp);
- };
- return Mouse;
- })();
- Phaser.Mouse = Mouse;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var MSPointer = (function () {
- function MSPointer(game) {
- this.disabled = false;
- this.game = game;
- }
- MSPointer.prototype.start = function () {
- var _this = this;
- if(this.game.device.mspointer == true) {
- this._onMSPointerDown = function (event) {
- return _this.onPointerDown(event);
- };
- this._onMSPointerMove = function (event) {
- return _this.onPointerMove(event);
- };
- this._onMSPointerUp = function (event) {
- return _this.onPointerUp(event);
- };
- this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
- this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
- this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
- }
- };
- MSPointer.prototype.onPointerDown = function (event) {
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event.preventDefault();
- event.identifier = event.pointerId;
- this.game.input.startPointer(event);
- };
- MSPointer.prototype.onPointerMove = function (event) {
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event.preventDefault();
- event.identifier = event.pointerId;
- this.game.input.updatePointer(event);
- };
- MSPointer.prototype.onPointerUp = function (event) {
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event.preventDefault();
- event.identifier = event.pointerId;
- this.game.input.stopPointer(event);
- };
- MSPointer.prototype.stop = function () {
- if(this.game.device.mspointer == true) {
- this.game.stage.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
- this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
- this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
- }
- };
- return MSPointer;
- })();
- Phaser.MSPointer = MSPointer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Touch = (function () {
- function Touch(game) {
- this.disabled = false;
- this.touchStartCallback = null;
- this.touchMoveCallback = null;
- this.touchEndCallback = null;
- this.touchEnterCallback = null;
- this.touchLeaveCallback = null;
- this.touchCancelCallback = null;
- this.game = game;
- this.callbackContext = this.game;
- }
- Touch.prototype.start = function () {
- var _this = this;
- if(this.game.device.touch) {
- this._onTouchStart = function (event) {
- return _this.onTouchStart(event);
- };
- this._onTouchMove = function (event) {
- return _this.onTouchMove(event);
- };
- this._onTouchEnd = function (event) {
- return _this.onTouchEnd(event);
- };
- this._onTouchEnter = function (event) {
- return _this.onTouchEnter(event);
- };
- this._onTouchLeave = function (event) {
- return _this.onTouchLeave(event);
- };
- this._onTouchCancel = function (event) {
- return _this.onTouchCancel(event);
- };
- this._documentTouchMove = function (event) {
- return _this.consumeTouchMove(event);
- };
- this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false);
- this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false);
- this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false);
- this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false);
- this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false);
- this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
- document.addEventListener('touchmove', this._documentTouchMove, false);
- }
- };
- Touch.prototype.consumeTouchMove = function (event) {
- event.preventDefault();
- };
- Touch.prototype.onTouchStart = function (event) {
- if(this.touchStartCallback) {
- this.touchStartCallback.call(this.callbackContext, event);
- }
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event.preventDefault();
- for(var i = 0; i < event.changedTouches.length; i++) {
- this.game.input.startPointer(event.changedTouches[i]);
- }
- };
- Touch.prototype.onTouchCancel = function (event) {
- if(this.touchCancelCallback) {
- this.touchCancelCallback.call(this.callbackContext, event);
- }
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event.preventDefault();
- for(var i = 0; i < event.changedTouches.length; i++) {
- this.game.input.stopPointer(event.changedTouches[i]);
- }
- };
- Touch.prototype.onTouchEnter = function (event) {
- if(this.touchEnterCallback) {
- this.touchEnterCallback.call(this.callbackContext, event);
- }
- if(this.game.input.disabled || this.disabled) {
- return;
- }
- event.preventDefault();
- for(var i = 0; i < event.changedTouches.length; i++) {
- }
- };
- Touch.prototype.onTouchLeave = function (event) {
- if(this.touchLeaveCallback) {
- this.touchLeaveCallback.call(this.callbackContext, event);
- }
- event.preventDefault();
- for(var i = 0; i < event.changedTouches.length; i++) {
- }
- };
- Touch.prototype.onTouchMove = function (event) {
- if(this.touchMoveCallback) {
- this.touchMoveCallback.call(this.callbackContext, event);
- }
- event.preventDefault();
- for(var i = 0; i < event.changedTouches.length; i++) {
- this.game.input.updatePointer(event.changedTouches[i]);
- }
- };
- Touch.prototype.onTouchEnd = function (event) {
- if(this.touchEndCallback) {
- this.touchEndCallback.call(this.callbackContext, event);
- }
- event.preventDefault();
- for(var i = 0; i < event.changedTouches.length; i++) {
- this.game.input.stopPointer(event.changedTouches[i]);
- }
- };
- Touch.prototype.stop = function () {
- if(this.game.device.touch) {
- this.game.stage.canvas.removeEventListener('touchstart', this._onTouchStart);
- this.game.stage.canvas.removeEventListener('touchmove', this._onTouchMove);
- this.game.stage.canvas.removeEventListener('touchend', this._onTouchEnd);
- this.game.stage.canvas.removeEventListener('touchenter', this._onTouchEnter);
- this.game.stage.canvas.removeEventListener('touchleave', this._onTouchLeave);
- this.game.stage.canvas.removeEventListener('touchcancel', this._onTouchCancel);
- document.removeEventListener('touchmove', this._documentTouchMove);
- }
- };
- return Touch;
- })();
- Phaser.Touch = Touch;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Pointer = (function () {
- function Pointer(game, id) {
- this._holdSent = false;
- this._history = [];
- this._nextDrop = 0;
- this._stateReset = false;
- this.positionDown = null;
- this.position = null;
- this.circle = null;
- this.withinGame = false;
- this.clientX = -1;
- this.clientY = -1;
- this.pageX = -1;
- this.pageY = -1;
- this.screenX = -1;
- this.screenY = -1;
- this.x = -1;
- this.y = -1;
- this.isMouse = false;
- this.isDown = false;
- this.isUp = true;
- this.timeDown = 0;
- this.timeUp = 0;
- this.previousTapTime = 0;
- this.totalTouches = 0;
- this.msSinceLastClick = Number.MAX_VALUE;
- this.targetObject = null;
- this.camera = null;
- this.game = game;
- this.id = id;
- this.active = false;
- this.position = new Phaser.Vec2();
- this.positionDown = new Phaser.Vec2();
- this.circle = new Phaser.Circle(0, 0, 44);
- if(id == 0) {
- this.isMouse = true;
- }
- }
- Object.defineProperty(Pointer.prototype, "duration", {
- get: function () {
- if(this.isUp) {
- return -1;
- }
- return this.game.time.now - this.timeDown;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Pointer.prototype, "worldX", {
- get: function () {
- if(this.camera) {
- return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
- }
- return null;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Pointer.prototype, "worldY", {
- get: function () {
- if(this.camera) {
- return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
- }
- return null;
- },
- enumerable: true,
- configurable: true
- });
- Pointer.prototype.start = function (event) {
- this.identifier = event.identifier;
- this.target = event.target;
- if(event.button) {
- this.button = event.button;
- }
- if(this.game.paused == true && this.game.stage.scale.incorrectOrientation == false) {
- this.game.stage.resumeGame();
- return this;
- }
- this._history.length = 0;
- this.active = true;
- this.withinGame = true;
- this.isDown = true;
- this.isUp = false;
- this.msSinceLastClick = this.game.time.now - this.timeDown;
- this.timeDown = this.game.time.now;
- this._holdSent = false;
- this.move(event);
- this.positionDown.setTo(this.x, this.y);
- if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
- this.game.input.x = this.x;
- this.game.input.y = this.y;
- this.game.input.position.setTo(this.x, this.y);
- this.game.input.onDown.dispatch(this);
- this.game.input.resetSpeed(this.x, this.y);
- }
- this._stateReset = false;
- this.totalTouches++;
- if(this.isMouse == false) {
- this.game.input.currentPointers++;
- }
- if(this.targetObject !== null) {
- this.targetObject.input._touchedHandler(this);
- }
- return this;
- };
- Pointer.prototype.update = function () {
- if(this.active) {
- if(this._holdSent == false && this.duration >= this.game.input.holdRate) {
- if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
- this.game.input.onHold.dispatch(this);
- }
- this._holdSent = true;
- }
- if(this.game.input.recordPointerHistory && this.game.time.now >= this._nextDrop) {
- this._nextDrop = this.game.time.now + this.game.input.recordRate;
- this._history.push({
- x: this.position.x,
- y: this.position.y
- });
- if(this._history.length > this.game.input.recordLimit) {
- this._history.shift();
- }
- }
- this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y);
- }
- };
- Pointer.prototype.move = function (event) {
- if(this.game.input.pollLocked) {
- return;
- }
- if(event.button) {
- this.button = event.button;
- }
- this.clientX = event.clientX;
- this.clientY = event.clientY;
- this.pageX = event.pageX;
- this.pageY = event.pageY;
- this.screenX = event.screenX;
- this.screenY = event.screenY;
- this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
- this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
- this.position.setTo(this.x, this.y);
- this.circle.x = this.x;
- this.circle.y = this.y;
- if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
- this.game.input.activePointer = this;
- this.game.input.x = this.x;
- this.game.input.y = this.y;
- this.game.input.position.setTo(this.game.input.x, this.game.input.y);
- this.game.input.circle.x = this.game.input.x;
- this.game.input.circle.y = this.game.input.y;
- }
- if(this.game.paused) {
- return this;
- }
- if(this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true) {
- if(this.targetObject.input.update(this) == false) {
- this.targetObject = null;
- }
- return this;
- }
- this._highestRenderOrderID = -1;
- this._highestRenderObject = -1;
- this._highestInputPriorityID = -1;
- for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
- if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) {
- if(this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID)) {
- this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID;
- this._highestRenderObject = i;
- this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID;
- }
- }
- }
- if(this._highestRenderObject == -1) {
- if(this.targetObject !== null) {
- this.targetObject.input._pointerOutHandler(this);
- this.targetObject = null;
- }
- } else {
- if(this.targetObject == null) {
- this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
- this.targetObject.input._pointerOverHandler(this);
- } else {
- if(this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) {
- if(this.targetObject.input.update(this) == false) {
- this.targetObject = null;
- }
- } else {
- this.targetObject.input._pointerOutHandler(this);
- this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
- this.targetObject.input._pointerOverHandler(this);
- }
- }
- }
- return this;
- };
- Pointer.prototype.leave = function (event) {
- this.withinGame = false;
- this.move(event);
- };
- Pointer.prototype.stop = function (event) {
- if(this._stateReset) {
- event.preventDefault();
- return;
- }
- this.timeUp = this.game.time.now;
- if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
- this.game.input.onUp.dispatch(this);
- if(this.duration >= 0 && this.duration <= this.game.input.tapRate) {
- if(this.timeUp - this.previousTapTime < this.game.input.doubleTapRate) {
- this.game.input.onTap.dispatch(this, true);
- } else {
- this.game.input.onTap.dispatch(this, false);
- }
- this.previousTapTime = this.timeUp;
- }
- }
- if(this.id > 0) {
- this.active = false;
- }
- this.withinGame = false;
- this.isDown = false;
- this.isUp = true;
- if(this.isMouse == false) {
- this.game.input.currentPointers--;
- }
- for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
- if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) {
- this.game.input.inputObjects[i].input._releasedHandler(this);
- }
- }
- if(this.targetObject) {
- this.targetObject.input._releasedHandler(this);
- }
- this.targetObject = null;
- return this;
- };
- Pointer.prototype.justPressed = function (duration) {
- if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; }
- if(this.isDown === true && (this.timeDown + duration) > this.game.time.now) {
- return true;
- } else {
- return false;
- }
- };
- Pointer.prototype.justReleased = function (duration) {
- if (typeof duration === "undefined") { duration = this.game.input.justReleasedRate; }
- if(this.isUp === true && (this.timeUp + duration) > this.game.time.now) {
- return true;
- } else {
- return false;
- }
- };
- Pointer.prototype.reset = function () {
- if(this.isMouse == false) {
- this.active = false;
- }
- this.identifier = null;
- this.isDown = false;
- this.isUp = true;
- this.totalTouches = 0;
- this._holdSent = false;
- this._history.length = 0;
- this._stateReset = true;
- if(this.targetObject && this.targetObject.input) {
- this.targetObject.input._releasedHandler(this);
- }
- this.targetObject = null;
- };
- Pointer.prototype.toString = function () {
- return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
- };
- return Pointer;
- })();
- Phaser.Pointer = Pointer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Components) {
- var InputHandler = (function () {
- function InputHandler(parent) {
- this.priorityID = 0;
- this.indexID = 0;
- this.isDragged = false;
- this.dragPixelPerfect = false;
- this.allowHorizontalDrag = true;
- this.allowVerticalDrag = true;
- this.bringToTop = false;
- this.snapOnDrag = false;
- this.snapOnRelease = false;
- this.snapX = 0;
- this.snapY = 0;
- this.draggable = false;
- this.boundsRect = null;
- this.boundsSprite = null;
- this.consumePointerEvent = false;
- this.game = parent.game;
- this._parent = parent;
- this.enabled = false;
- }
- InputHandler.prototype.pointerX = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].x;
- };
- InputHandler.prototype.pointerY = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].y;
- };
- InputHandler.prototype.pointerDown = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].isDown;
- };
- InputHandler.prototype.pointerUp = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].isUp;
- };
- InputHandler.prototype.pointerTimeDown = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].timeDown;
- };
- InputHandler.prototype.pointerTimeUp = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].timeUp;
- };
- InputHandler.prototype.pointerOver = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].isOver;
- };
- InputHandler.prototype.pointerOut = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].isOut;
- };
- InputHandler.prototype.pointerTimeOver = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].timeOver;
- };
- InputHandler.prototype.pointerTimeOut = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].timeOut;
- };
- InputHandler.prototype.pointerDragged = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- return this._pointerData[pointer].isDragged;
- };
- InputHandler.prototype.start = function (priority, checkBody, useHandCursor) {
- if (typeof priority === "undefined") { priority = 0; }
- if (typeof checkBody === "undefined") { checkBody = false; }
- if (typeof useHandCursor === "undefined") { useHandCursor = false; }
- if(this.enabled == false) {
- this.checkBody = checkBody;
- this.useHandCursor = useHandCursor;
- this.priorityID = priority;
- this._pointerData = [];
- for(var i = 0; i < 10; i++) {
- this._pointerData.push({
- id: i,
- x: 0,
- y: 0,
- isDown: false,
- isUp: false,
- isOver: false,
- isOut: false,
- timeOver: 0,
- timeOut: 0,
- timeDown: 0,
- timeUp: 0,
- downDuration: 0,
- isDragged: false
- });
- }
- this.snapOffset = new Phaser.Point();
- this.enabled = true;
- this.game.input.addGameObject(this._parent);
- if(this._parent.events.onInputOver == null) {
- this._parent.events.onInputOver = new Phaser.Signal();
- this._parent.events.onInputOut = new Phaser.Signal();
- this._parent.events.onInputDown = new Phaser.Signal();
- this._parent.events.onInputUp = new Phaser.Signal();
- this._parent.events.onDragStart = new Phaser.Signal();
- this._parent.events.onDragStop = new Phaser.Signal();
- }
- }
- return this._parent;
- };
- InputHandler.prototype.reset = function () {
- this.enabled = false;
- for(var i = 0; i < 10; i++) {
- this._pointerData[i] = {
- id: i,
- x: 0,
- y: 0,
- isDown: false,
- isUp: false,
- isOver: false,
- isOut: false,
- timeOver: 0,
- timeOut: 0,
- timeDown: 0,
- timeUp: 0,
- downDuration: 0,
- isDragged: false
- };
- }
- };
- InputHandler.prototype.stop = function () {
- if(this.enabled == false) {
- return;
- } else {
- this.enabled = false;
- this.game.input.removeGameObject(this.indexID);
- }
- };
- InputHandler.prototype.destroy = function () {
- if(this.enabled) {
- this.enabled = false;
- this.game.input.removeGameObject(this.indexID);
- }
- };
- InputHandler.prototype.checkPointerOver = function (pointer) {
- if(this.enabled == false || this._parent.visible == false) {
- return false;
- } else {
- return Phaser.SpriteUtils.overlapsPointer(this._parent, pointer);
- }
- };
- InputHandler.prototype.update = function (pointer) {
- if(this.enabled == false || this._parent.visible == false) {
- this._pointerOutHandler(pointer);
- return false;
- }
- if(this.draggable && this._draggedPointerID == pointer.id) {
- return this.updateDrag(pointer);
- } else if(this._pointerData[pointer.id].isOver == true) {
- if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
- this._pointerData[pointer.id].x = pointer.x - this._parent.x;
- this._pointerData[pointer.id].y = pointer.y - this._parent.y;
- return true;
- } else {
- this._pointerOutHandler(pointer);
- return false;
- }
- }
- };
- InputHandler.prototype._pointerOverHandler = function (pointer) {
- if(this._pointerData[pointer.id].isOver == false) {
- this._pointerData[pointer.id].isOver = true;
- this._pointerData[pointer.id].isOut = false;
- this._pointerData[pointer.id].timeOver = this.game.time.now;
- this._pointerData[pointer.id].x = pointer.x - this._parent.x;
- this._pointerData[pointer.id].y = pointer.y - this._parent.y;
- if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
- this.game.stage.canvas.style.cursor = "pointer";
- }
- this._parent.events.onInputOver.dispatch(this._parent, pointer);
- }
- };
- InputHandler.prototype._pointerOutHandler = function (pointer) {
- this._pointerData[pointer.id].isOver = false;
- this._pointerData[pointer.id].isOut = true;
- this._pointerData[pointer.id].timeOut = this.game.time.now;
- if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
- this.game.stage.canvas.style.cursor = "default";
- }
- this._parent.events.onInputOut.dispatch(this._parent, pointer);
- };
- InputHandler.prototype._touchedHandler = function (pointer) {
- if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) {
- this._pointerData[pointer.id].isDown = true;
- this._pointerData[pointer.id].isUp = false;
- this._pointerData[pointer.id].timeDown = this.game.time.now;
- this._parent.events.onInputDown.dispatch(this._parent, pointer);
- if(this.draggable && this.isDragged == false) {
- this.startDrag(pointer);
- }
- if(this.bringToTop) {
- this._parent.bringToTop();
- }
- }
- return this.consumePointerEvent;
- };
- InputHandler.prototype._releasedHandler = function (pointer) {
- if(this._pointerData[pointer.id].isDown && pointer.isUp) {
- this._pointerData[pointer.id].isDown = false;
- this._pointerData[pointer.id].isUp = true;
- this._pointerData[pointer.id].timeUp = this.game.time.now;
- this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
- if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
- this._parent.events.onInputUp.dispatch(this._parent, pointer);
- } else {
- if(this.useHandCursor) {
- this.game.stage.canvas.style.cursor = "default";
- }
- }
- if(this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
- this.stopDrag(pointer);
- }
- }
- };
- InputHandler.prototype.updateDrag = function (pointer) {
- if(pointer.isUp) {
- this.stopDrag(pointer);
- return false;
- }
- if(this.allowHorizontalDrag) {
- this._parent.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
- }
- if(this.allowVerticalDrag) {
- this._parent.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
- }
- if(this.boundsRect) {
- this.checkBoundsRect();
- }
- if(this.boundsSprite) {
- this.checkBoundsSprite();
- }
- if(this.snapOnDrag) {
- this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
- this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
- }
- return true;
- };
- InputHandler.prototype.justOver = function (pointer, delay) {
- if (typeof pointer === "undefined") { pointer = 0; }
- if (typeof delay === "undefined") { delay = 500; }
- return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay);
- };
- InputHandler.prototype.justOut = function (pointer, delay) {
- if (typeof pointer === "undefined") { pointer = 0; }
- if (typeof delay === "undefined") { delay = 500; }
- return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay));
- };
- InputHandler.prototype.justPressed = function (pointer, delay) {
- if (typeof pointer === "undefined") { pointer = 0; }
- if (typeof delay === "undefined") { delay = 500; }
- return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay);
- };
- InputHandler.prototype.justReleased = function (pointer, delay) {
- if (typeof pointer === "undefined") { pointer = 0; }
- if (typeof delay === "undefined") { delay = 500; }
- return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay));
- };
- InputHandler.prototype.overDuration = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- if(this._pointerData[pointer].isOver) {
- return this.game.time.now - this._pointerData[pointer].timeOver;
- }
- return -1;
- };
- InputHandler.prototype.downDuration = function (pointer) {
- if (typeof pointer === "undefined") { pointer = 0; }
- if(this._pointerData[pointer].isDown) {
- return this.game.time.now - this._pointerData[pointer].timeDown;
- }
- return -1;
- };
- InputHandler.prototype.enableDrag = function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
- if (typeof lockCenter === "undefined") { lockCenter = false; }
- if (typeof bringToTop === "undefined") { bringToTop = false; }
- if (typeof pixelPerfect === "undefined") { pixelPerfect = false; }
- if (typeof alphaThreshold === "undefined") { alphaThreshold = 255; }
- if (typeof boundsRect === "undefined") { boundsRect = null; }
- if (typeof boundsSprite === "undefined") { boundsSprite = null; }
- this._dragPoint = new Phaser.Point();
- this.draggable = true;
- this.bringToTop = bringToTop;
- this.dragOffset = new Phaser.Point();
- this.dragFromCenter = lockCenter;
- this.dragPixelPerfect = pixelPerfect;
- this.dragPixelPerfectAlpha = alphaThreshold;
- if(boundsRect) {
- this.boundsRect = boundsRect;
- }
- if(boundsSprite) {
- this.boundsSprite = boundsSprite;
- }
- };
- InputHandler.prototype.disableDrag = function () {
- if(this._pointerData) {
- for(var i = 0; i < 10; i++) {
- this._pointerData[i].isDragged = false;
- }
- }
- this.draggable = false;
- this.isDragged = false;
- this._draggedPointerID = -1;
- };
- InputHandler.prototype.startDrag = function (pointer) {
- this.isDragged = true;
- this._draggedPointerID = pointer.id;
- this._pointerData[pointer.id].isDragged = true;
- if(this.dragFromCenter) {
- this._parent.transform.centerOn(pointer.worldX, pointer.worldY);
- this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
- } else {
- this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
- }
- this.updateDrag(pointer);
- if(this.bringToTop) {
- this._parent.bringToTop();
- }
- this._parent.events.onDragStart.dispatch(this._parent, pointer);
- };
- InputHandler.prototype.stopDrag = function (pointer) {
- this.isDragged = false;
- this._draggedPointerID = -1;
- this._pointerData[pointer.id].isDragged = false;
- if(this.snapOnRelease) {
- this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
- this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
- }
- this._parent.events.onDragStop.dispatch(this._parent, pointer);
- this._parent.events.onInputUp.dispatch(this._parent, pointer);
- };
- InputHandler.prototype.setDragLock = function (allowHorizontal, allowVertical) {
- if (typeof allowHorizontal === "undefined") { allowHorizontal = true; }
- if (typeof allowVertical === "undefined") { allowVertical = true; }
- this.allowHorizontalDrag = allowHorizontal;
- this.allowVerticalDrag = allowVertical;
- };
- InputHandler.prototype.enableSnap = function (snapX, snapY, onDrag, onRelease) {
- if (typeof onDrag === "undefined") { onDrag = true; }
- if (typeof onRelease === "undefined") { onRelease = false; }
- this.snapOnDrag = onDrag;
- this.snapOnRelease = onRelease;
- this.snapX = snapX;
- this.snapY = snapY;
- };
- InputHandler.prototype.disableSnap = function () {
- this.snapOnDrag = false;
- this.snapOnRelease = false;
- };
- InputHandler.prototype.checkBoundsRect = function () {
- if(this._parent.x < this.boundsRect.left) {
- this._parent.x = this.boundsRect.x;
- } else if((this._parent.x + this._parent.width) > this.boundsRect.right) {
- this._parent.x = this.boundsRect.right - this._parent.width;
- }
- if(this._parent.y < this.boundsRect.top) {
- this._parent.y = this.boundsRect.top;
- } else if((this._parent.y + this._parent.height) > this.boundsRect.bottom) {
- this._parent.y = this.boundsRect.bottom - this._parent.height;
- }
- };
- InputHandler.prototype.checkBoundsSprite = function () {
- if(this._parent.x < this.boundsSprite.x) {
- this._parent.x = this.boundsSprite.x;
- } else if((this._parent.x + this._parent.width) > (this.boundsSprite.x + this.boundsSprite.width)) {
- this._parent.x = (this.boundsSprite.x + this.boundsSprite.width) - this._parent.width;
- }
- if(this._parent.y < this.boundsSprite.y) {
- this._parent.y = this.boundsSprite.y;
- } else if((this._parent.y + this._parent.height) > (this.boundsSprite.y + this.boundsSprite.height)) {
- this._parent.y = (this.boundsSprite.y + this.boundsSprite.height) - this._parent.height;
- }
- };
- return InputHandler;
- })();
- Components.InputHandler = InputHandler;
- })(Phaser.Components || (Phaser.Components = {}));
- var Components = Phaser.Components;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var InputManager = (function () {
- function InputManager(game) {
- this.pollRate = 0;
- this._pollCounter = 0;
- this._oldPosition = null;
- this._x = 0;
- this._y = 0;
- this.disabled = false;
- this.multiInputOverride = InputManager.MOUSE_TOUCH_COMBINE;
- this.position = null;
- this.speed = null;
- this.circle = null;
- this.scale = null;
- this.maxPointers = 10;
- this.currentPointers = 0;
- this.tapRate = 200;
- this.doubleTapRate = 300;
- this.holdRate = 2000;
- this.justPressedRate = 200;
- this.justReleasedRate = 200;
- this.recordPointerHistory = false;
- this.recordRate = 100;
- this.recordLimit = 100;
- this.pointer3 = null;
- this.pointer4 = null;
- this.pointer5 = null;
- this.pointer6 = null;
- this.pointer7 = null;
- this.pointer8 = null;
- this.pointer9 = null;
- this.pointer10 = null;
- this.activePointer = null;
- this.inputObjects = [];
- this.totalTrackedObjects = 0;
- this.game = game;
- this.mousePointer = new Phaser.Pointer(this.game, 0);
- this.pointer1 = new Phaser.Pointer(this.game, 1);
- this.pointer2 = new Phaser.Pointer(this.game, 2);
- this.mouse = new Phaser.Mouse(this.game);
- this.keyboard = new Phaser.Keyboard(this.game);
- this.touch = new Phaser.Touch(this.game);
- this.mspointer = new Phaser.MSPointer(this.game);
- this.onDown = new Phaser.Signal();
- this.onUp = new Phaser.Signal();
- this.onTap = new Phaser.Signal();
- this.onHold = new Phaser.Signal();
- this.scale = new Phaser.Vec2(1, 1);
- this.speed = new Phaser.Vec2();
- this.position = new Phaser.Vec2();
- this._oldPosition = new Phaser.Vec2();
- this.circle = new Phaser.Circle(0, 0, 44);
- this.activePointer = this.mousePointer;
- this.currentPointers = 0;
- this.hitCanvas = document.createElement('canvas');
- this.hitCanvas.width = 1;
- this.hitCanvas.height = 1;
- this.hitContext = this.hitCanvas.getContext('2d');
- }
- InputManager.MOUSE_OVERRIDES_TOUCH = 0;
- InputManager.TOUCH_OVERRIDES_MOUSE = 1;
- InputManager.MOUSE_TOUCH_COMBINE = 2;
- Object.defineProperty(InputManager.prototype, "camera", {
- get: function () {
- return this.activePointer.camera;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(InputManager.prototype, "x", {
- get: function () {
- return this._x;
- },
- set: function (value) {
- this._x = Math.floor(value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(InputManager.prototype, "y", {
- get: function () {
- return this._y;
- },
- set: function (value) {
- this._y = Math.floor(value);
- },
- enumerable: true,
- configurable: true
- });
- InputManager.prototype.addPointer = function () {
- var next = 0;
- for(var i = 10; i > 0; i--) {
- if(this['pointer' + i] === null) {
- next = i;
- }
- }
- if(next == 0) {
- throw new Error("You can only have 10 Pointer objects");
- return null;
- } else {
- this['pointer' + next] = new Phaser.Pointer(this.game, next);
- return this['pointer' + next];
- }
- };
- InputManager.prototype.boot = function () {
- this.mouse.start();
- this.keyboard.start();
- this.touch.start();
- this.mspointer.start();
- this.mousePointer.active = true;
- };
- InputManager.prototype.addGameObject = function (object) {
- for(var i = 0; i < this.inputObjects.length; i++) {
- if(this.inputObjects[i] == null) {
- this.inputObjects[i] = object;
- object.input.indexID = i;
- this.totalTrackedObjects++;
- return;
- }
- }
- object.input.indexID = this.inputObjects.length;
- this.inputObjects.push(object);
- this.totalTrackedObjects++;
- };
- InputManager.prototype.removeGameObject = function (index) {
- if(this.inputObjects[index]) {
- this.inputObjects[index] = null;
- }
- };
- Object.defineProperty(InputManager.prototype, "pollLocked", {
- get: function () {
- return (this.pollRate > 0 && this._pollCounter < this.pollRate);
- },
- enumerable: true,
- configurable: true
- });
- InputManager.prototype.update = function () {
- if(this.pollRate > 0 && this._pollCounter < this.pollRate) {
- this._pollCounter++;
- return;
- }
- this.speed.x = this.position.x - this._oldPosition.x;
- this.speed.y = this.position.y - this._oldPosition.y;
- this._oldPosition.copyFrom(this.position);
- this.mousePointer.update();
- this.pointer1.update();
- this.pointer2.update();
- if(this.pointer3) {
- this.pointer3.update();
- }
- if(this.pointer4) {
- this.pointer4.update();
- }
- if(this.pointer5) {
- this.pointer5.update();
- }
- if(this.pointer6) {
- this.pointer6.update();
- }
- if(this.pointer7) {
- this.pointer7.update();
- }
- if(this.pointer8) {
- this.pointer8.update();
- }
- if(this.pointer9) {
- this.pointer9.update();
- }
- if(this.pointer10) {
- this.pointer10.update();
- }
- this._pollCounter = 0;
- };
- InputManager.prototype.reset = function (hard) {
- if (typeof hard === "undefined") { hard = false; }
- this.keyboard.reset();
- this.mousePointer.reset();
- for(var i = 1; i <= 10; i++) {
- if(this['pointer' + i]) {
- this['pointer' + i].reset();
- }
- }
- this.currentPointers = 0;
- this.game.stage.canvas.style.cursor = "default";
- if(hard == true) {
- this.onDown.dispose();
- this.onUp.dispose();
- this.onTap.dispose();
- this.onHold.dispose();
- this.onDown = new Phaser.Signal();
- this.onUp = new Phaser.Signal();
- this.onTap = new Phaser.Signal();
- this.onHold = new Phaser.Signal();
- for(var i = 0; i < this.totalTrackedObjects; i++) {
- if(this.inputObjects[i] && this.inputObjects[i].input) {
- this.inputObjects[i].input.reset();
- }
- }
- this.inputObjects.length = 0;
- this.totalTrackedObjects = 0;
- }
- this._pollCounter = 0;
- };
- InputManager.prototype.resetSpeed = function (x, y) {
- this._oldPosition.setTo(x, y);
- this.speed.setTo(0, 0);
- };
- Object.defineProperty(InputManager.prototype, "totalInactivePointers", {
- get: function () {
- return 10 - this.currentPointers;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(InputManager.prototype, "totalActivePointers", {
- get: function () {
- this.currentPointers = 0;
- for(var i = 1; i <= 10; i++) {
- if(this['pointer' + i] && this['pointer' + i].active) {
- this.currentPointers++;
- }
- }
- return this.currentPointers;
- },
- enumerable: true,
- configurable: true
- });
- InputManager.prototype.startPointer = function (event) {
- if(this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) {
- return null;
- }
- if(this.pointer1.active == false) {
- return this.pointer1.start(event);
- } else if(this.pointer2.active == false) {
- return this.pointer2.start(event);
- } else {
- for(var i = 3; i <= 10; i++) {
- if(this['pointer' + i] && this['pointer' + i].active == false) {
- return this['pointer' + i].start(event);
- }
- }
- }
- return null;
- };
- InputManager.prototype.updatePointer = function (event) {
- if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
- return this.pointer1.move(event);
- } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
- return this.pointer2.move(event);
- } else {
- for(var i = 3; i <= 10; i++) {
- if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
- return this['pointer' + i].move(event);
- }
- }
- }
- return null;
- };
- InputManager.prototype.stopPointer = function (event) {
- if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
- return this.pointer1.stop(event);
- } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
- return this.pointer2.stop(event);
- } else {
- for(var i = 3; i <= 10; i++) {
- if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
- return this['pointer' + i].stop(event);
- }
- }
- }
- return null;
- };
- InputManager.prototype.getPointer = function (state) {
- if (typeof state === "undefined") { state = false; }
- if(this.pointer1.active == state) {
- return this.pointer1;
- } else if(this.pointer2.active == state) {
- return this.pointer2;
- } else {
- for(var i = 3; i <= 10; i++) {
- if(this['pointer' + i] && this['pointer' + i].active == state) {
- return this['pointer' + i];
- }
- }
- }
- return null;
- };
- InputManager.prototype.getPointerFromIdentifier = function (identifier) {
- if(this.pointer1.identifier == identifier) {
- return this.pointer1;
- } else if(this.pointer2.identifier == identifier) {
- return this.pointer2;
- } else {
- for(var i = 3; i <= 10; i++) {
- if(this['pointer' + i] && this['pointer' + i].identifier == identifier) {
- return this['pointer' + i];
- }
- }
- }
- return null;
- };
- Object.defineProperty(InputManager.prototype, "worldX", {
- get: function () {
- if(this.camera) {
- return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
- }
- return null;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(InputManager.prototype, "worldY", {
- get: function () {
- if(this.camera) {
- return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
- }
- return null;
- },
- enumerable: true,
- configurable: true
- });
- InputManager.prototype.getDistance = function (pointer1, pointer2) {
- return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position);
- };
- InputManager.prototype.getAngle = function (pointer1, pointer2) {
- return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
- };
- InputManager.prototype.pixelPerfectCheck = function (sprite, pointer, alpha) {
- if (typeof alpha === "undefined") { alpha = 255; }
- this.hitContext.clearRect(0, 0, 1, 1);
- return true;
- };
- return InputManager;
- })();
- Phaser.InputManager = InputManager;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Device = (function () {
- function Device() {
- this.patchAndroidClearRectBug = false;
- this.desktop = false;
- this.iOS = false;
- this.android = false;
- this.chromeOS = false;
- this.linux = false;
- this.macOS = false;
- this.windows = false;
- this.canvas = false;
- this.file = false;
- this.fileSystem = false;
- this.localStorage = false;
- this.webGL = false;
- this.worker = false;
- this.touch = false;
- this.mspointer = false;
- this.css3D = false;
- this.arora = false;
- this.chrome = false;
- this.epiphany = false;
- this.firefox = false;
- this.ie = false;
- this.ieVersion = 0;
- this.mobileSafari = false;
- this.midori = false;
- this.opera = false;
- this.safari = false;
- this.webApp = false;
- this.audioData = false;
- this.webAudio = false;
- this.ogg = false;
- this.opus = false;
- this.mp3 = false;
- this.wav = false;
- this.m4a = false;
- this.webm = false;
- this.iPhone = false;
- this.iPhone4 = false;
- this.iPad = false;
- this.pixelRatio = 0;
- this._checkAudio();
- this._checkBrowser();
- this._checkCSS3D();
- this._checkDevice();
- this._checkFeatures();
- this._checkOS();
- }
- Device.prototype._checkOS = function () {
- var ua = navigator.userAgent;
- if(/Android/.test(ua)) {
- this.android = true;
- } else if(/CrOS/.test(ua)) {
- this.chromeOS = true;
- } else if(/iP[ao]d|iPhone/i.test(ua)) {
- this.iOS = true;
- } else if(/Linux/.test(ua)) {
- this.linux = true;
- } else if(/Mac OS/.test(ua)) {
- this.macOS = true;
- } else if(/Windows/.test(ua)) {
- this.windows = true;
- }
- if(this.windows || this.macOS || this.linux) {
- this.desktop = true;
- }
- };
- Device.prototype._checkFeatures = function () {
- this.canvas = !!window['CanvasRenderingContext2D'];
- try {
- this.localStorage = !!localStorage.getItem;
- } catch (error) {
- this.localStorage = false;
- }
- this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
- this.fileSystem = !!window['requestFileSystem'];
- this.webGL = !!window['WebGLRenderingContext'];
- this.worker = !!window['Worker'];
- if('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
- this.touch = true;
- }
- if(window.navigator.msPointerEnabled) {
- this.mspointer = true;
- }
- };
- Device.prototype._checkBrowser = function () {
- var ua = navigator.userAgent;
- if(/Arora/.test(ua)) {
- this.arora = true;
- } else if(/Chrome/.test(ua)) {
- this.chrome = true;
- } else if(/Epiphany/.test(ua)) {
- this.epiphany = true;
- } else if(/Firefox/.test(ua)) {
- this.firefox = true;
- } else if(/Mobile Safari/.test(ua)) {
- this.mobileSafari = true;
- } else if(/MSIE (\d+\.\d+);/.test(ua)) {
- this.ie = true;
- this.ieVersion = parseInt(RegExp.$1);
- } else if(/Midori/.test(ua)) {
- this.midori = true;
- } else if(/Opera/.test(ua)) {
- this.opera = true;
- } else if(/Safari/.test(ua)) {
- this.safari = true;
- }
- if(navigator['standalone']) {
- this.webApp = true;
- }
- };
- Device.prototype.canPlayAudio = function (type) {
- if(type == 'mp3' && this.mp3) {
- return true;
- } else if(type == 'ogg' && (this.ogg || this.opus)) {
- return true;
- } else if(type == 'm4a' && this.m4a) {
- return true;
- } else if(type == 'wav' && this.wav) {
- return true;
- } else if(type == 'webm' && this.webm) {
- return true;
- }
- return false;
- };
- Device.prototype._checkAudio = function () {
- this.audioData = !!(window['Audio']);
- this.webAudio = !!(window['webkitAudioContext'] || window['AudioContext']);
- var audioElement = document.createElement('audio');
- var result = false;
- try {
- if(result = !!audioElement.canPlayType) {
- if(audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
- this.ogg = true;
- }
- if(audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '')) {
- this.opus = true;
- }
- if(audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
- this.mp3 = true;
- }
- if(audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
- this.wav = true;
- }
- if(audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
- this.m4a = true;
- }
- if(audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
- this.webm = true;
- }
- }
- } catch (e) {
- }
- };
- Device.prototype._checkDevice = function () {
- this.pixelRatio = window['devicePixelRatio'] || 1;
- this.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
- this.iPhone4 = (this.pixelRatio == 2 && this.iPhone);
- this.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
- };
- Device.prototype._checkCSS3D = function () {
- var el = document.createElement('p');
- var has3d;
- var transforms = {
- 'webkitTransform': '-webkit-transform',
- 'OTransform': '-o-transform',
- 'msTransform': '-ms-transform',
- 'MozTransform': '-moz-transform',
- 'transform': 'transform'
- };
- document.body.insertBefore(el, null);
- for(var t in transforms) {
- if(el.style[t] !== undefined) {
- el.style[t] = "translate3d(1px,1px,1px)";
- has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
- }
- }
- document.body.removeChild(el);
- this.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
- };
- Device.prototype.isConsoleOpen = function () {
- if(window.console && window.console['firebug']) {
- return true;
- }
- if(window.console) {
- console.profile();
- console.profileEnd();
- if(console.clear) {
- console.clear();
- }
- return console['profiles'].length > 0;
- }
- return false;
- };
- return Device;
- })();
- Phaser.Device = Device;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var RequestAnimationFrame = (function () {
- function RequestAnimationFrame(game, callback) {
- this._isSetTimeOut = false;
- this.isRunning = false;
- this.game = game;
- this.callback = callback;
- var vendors = [
- 'ms',
- 'moz',
- 'webkit',
- 'o'
- ];
- for(var x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
- window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
- window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
- }
- this.start();
- }
- RequestAnimationFrame.prototype.isUsingSetTimeOut = function () {
- return this._isSetTimeOut;
- };
- RequestAnimationFrame.prototype.isUsingRAF = function () {
- return this._isSetTimeOut === true;
- };
- RequestAnimationFrame.prototype.start = function (callback) {
- if (typeof callback === "undefined") { callback = null; }
- var _this = this;
- if(callback) {
- this.callback = callback;
- }
- if(!window.requestAnimationFrame) {
- this._isSetTimeOut = true;
- this._onLoop = function () {
- return _this.SetTimeoutUpdate();
- };
- this._timeOutID = window.setTimeout(this._onLoop, 0);
- } else {
- this._isSetTimeOut = false;
- this._onLoop = function () {
- return _this.RAFUpdate(0);
- };
- window.requestAnimationFrame(this._onLoop);
- }
- this.isRunning = true;
- };
- RequestAnimationFrame.prototype.stop = function () {
- if(this._isSetTimeOut) {
- clearTimeout(this._timeOutID);
- } else {
- window.cancelAnimationFrame;
- }
- this.isRunning = false;
- };
- RequestAnimationFrame.prototype.RAFUpdate = function (time) {
- var _this = this;
- this.game.time.update(time);
- if(this.callback) {
- this.callback.call(this.game);
- }
- this._onLoop = function (time) {
- return _this.RAFUpdate(time);
- };
- window.requestAnimationFrame(this._onLoop);
- };
- RequestAnimationFrame.prototype.SetTimeoutUpdate = function () {
- var _this = this;
- this.game.time.update(Date.now());
- this._onLoop = function () {
- return _this.SetTimeoutUpdate();
- };
- this._timeOutID = window.setTimeout(this._onLoop, 16);
- if(this.callback) {
- this.callback.call(this.game);
- }
- };
- return RequestAnimationFrame;
- })();
- Phaser.RequestAnimationFrame = RequestAnimationFrame;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var StageScaleMode = (function () {
- function StageScaleMode(game, width, height) {
- var _this = this;
- this._startHeight = 0;
- this.forceLandscape = false;
- this.forcePortrait = false;
- this.incorrectOrientation = false;
- this.pageAlignHorizontally = false;
- this.pageAlignVeritcally = false;
- this.minWidth = null;
- this.maxWidth = null;
- this.minHeight = null;
- this.maxHeight = null;
- this.width = 0;
- this.height = 0;
- this.maxIterations = 5;
- this.game = game;
- this.enterLandscape = new Phaser.Signal();
- this.enterPortrait = new Phaser.Signal();
- if(window['orientation']) {
- this.orientation = window['orientation'];
- } else {
- if(window.outerWidth > window.outerHeight) {
- this.orientation = 90;
- } else {
- this.orientation = 0;
- }
- }
- this.scaleFactor = new Phaser.Vec2(1, 1);
- this.aspectRatio = 0;
- this.minWidth = width;
- this.minHeight = height;
- this.maxWidth = width;
- this.maxHeight = height;
- window.addEventListener('orientationchange', function (event) {
- return _this.checkOrientation(event);
- }, false);
- window.addEventListener('resize', function (event) {
- return _this.checkResize(event);
- }, false);
- }
- StageScaleMode.EXACT_FIT = 0;
- StageScaleMode.NO_SCALE = 1;
- StageScaleMode.SHOW_ALL = 2;
- Object.defineProperty(StageScaleMode.prototype, "isFullScreen", {
- get: function () {
- if(document['fullscreenElement'] === null || document['mozFullScreenElement'] === null || document['webkitFullscreenElement'] === null) {
- return false;
- }
- return true;
- },
- enumerable: true,
- configurable: true
- });
- StageScaleMode.prototype.startFullScreen = function () {
- if(this.isFullScreen) {
- return;
- }
- var element = this.game.stage.canvas;
- if(element['requestFullScreen']) {
- element['requestFullScreen']();
- } else if(element['mozRequestFullScreen']) {
- element['mozRequestFullScreen']();
- } else if(element['webkitRequestFullScreen']) {
- element['webkitRequestFullScreen']();
- }
- };
- StageScaleMode.prototype.stopFullScreen = function () {
- if(document['cancelFullScreen']) {
- document['cancelFullScreen']();
- } else if(document['mozCancelFullScreen']) {
- document['mozCancelFullScreen']();
- } else if(document['webkitCancelFullScreen']) {
- document['webkitCancelFullScreen']();
- }
- };
- StageScaleMode.prototype.update = function () {
- if(this.forceLandscape || this.forcePortrait) {
- this.checkOrientationState();
- }
- };
- StageScaleMode.prototype.checkOrientationState = function () {
- if(this.incorrectOrientation) {
- if((this.forceLandscape && window.innerWidth > window.innerHeight) || (this.forcePortrait && window.innerHeight > window.innerWidth)) {
- this.game.paused = false;
- this.incorrectOrientation = false;
- this.refresh();
- }
- } else {
- if((this.forceLandscape && window.innerWidth < window.innerHeight) || (this.forcePortrait && window.innerHeight < window.innerWidth)) {
- this.game.paused = true;
- this.incorrectOrientation = true;
- this.refresh();
- }
- }
- };
- Object.defineProperty(StageScaleMode.prototype, "isPortrait", {
- get: function () {
- return this.orientation == 0 || this.orientation == 180;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(StageScaleMode.prototype, "isLandscape", {
- get: function () {
- return this.orientation === 90 || this.orientation === -90;
- },
- enumerable: true,
- configurable: true
- });
- StageScaleMode.prototype.checkOrientation = function (event) {
- this.orientation = window['orientation'];
- if(this.isLandscape) {
- this.enterLandscape.dispatch(this.orientation, true, false);
- } else {
- this.enterPortrait.dispatch(this.orientation, false, true);
- }
- if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
- this.refresh();
- }
- };
- StageScaleMode.prototype.checkResize = function (event) {
- if(window.outerWidth > window.outerHeight) {
- this.orientation = 90;
- } else {
- this.orientation = 0;
- }
- if(this.isLandscape) {
- this.enterLandscape.dispatch(this.orientation, true, false);
- } else {
- this.enterPortrait.dispatch(this.orientation, false, true);
- }
- if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
- this.refresh();
- }
- };
- StageScaleMode.prototype.refresh = function () {
- var _this = this;
- if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
- document.documentElement['style'].minHeight = '2000px';
- this._startHeight = window.innerHeight;
- if(this.game.device.android && this.game.device.chrome == false) {
- window.scrollTo(0, 1);
- } else {
- window.scrollTo(0, 0);
- }
- }
- if(this._check == null && this.maxIterations > 0) {
- this._iterations = this.maxIterations;
- this._check = window.setInterval(function () {
- return _this.setScreenSize();
- }, 10);
- this.setScreenSize();
- }
- };
- StageScaleMode.prototype.setScreenSize = function (force) {
- if (typeof force === "undefined") { force = false; }
- if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
- if(this.game.device.android && this.game.device.chrome == false) {
- window.scrollTo(0, 1);
- } else {
- window.scrollTo(0, 0);
- }
- }
- this._iterations--;
- if(force || window.innerHeight > this._startHeight || this._iterations < 0) {
- document.documentElement['style'].minHeight = window.innerHeight + 'px';
- if(this.incorrectOrientation == true) {
- this.setMaximum();
- } else if(this.game.stage.scaleMode == StageScaleMode.EXACT_FIT) {
- this.setExactFit();
- } else if(this.game.stage.scaleMode == StageScaleMode.SHOW_ALL) {
- this.setShowAll();
- }
- this.setSize();
- clearInterval(this._check);
- this._check = null;
- }
- };
- StageScaleMode.prototype.setSize = function () {
- if(this.incorrectOrientation == false) {
- if(this.maxWidth && this.width > this.maxWidth) {
- this.width = this.maxWidth;
- }
- if(this.maxHeight && this.height > this.maxHeight) {
- this.height = this.maxHeight;
- }
- if(this.minWidth && this.width < this.minWidth) {
- this.width = this.minWidth;
- }
- if(this.minHeight && this.height < this.minHeight) {
- this.height = this.minHeight;
- }
- }
- this.game.stage.canvas.style.width = this.width + 'px';
- this.game.stage.canvas.style.height = this.height + 'px';
- this.game.input.scale.setTo(this.game.stage.width / this.width, this.game.stage.height / this.height);
- if(this.pageAlignHorizontally) {
- if(this.width < window.innerWidth && this.incorrectOrientation == false) {
- this.game.stage.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px';
- } else {
- this.game.stage.canvas.style.marginLeft = '0px';
- }
- }
- if(this.pageAlignVeritcally) {
- if(this.height < window.innerHeight && this.incorrectOrientation == false) {
- this.game.stage.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px';
- } else {
- this.game.stage.canvas.style.marginTop = '0px';
- }
- }
- this.game.stage.getOffset(this.game.stage.canvas);
- this.aspectRatio = this.width / this.height;
- this.scaleFactor.x = this.game.stage.width / this.width;
- this.scaleFactor.y = this.game.stage.height / this.height;
- };
- StageScaleMode.prototype.setMaximum = function () {
- this.width = window.innerWidth;
- this.height = window.innerHeight;
- };
- StageScaleMode.prototype.setShowAll = function () {
- var multiplier = Math.min((window.innerHeight / this.game.stage.height), (window.innerWidth / this.game.stage.width));
- this.width = Math.round(this.game.stage.width * multiplier);
- this.height = Math.round(this.game.stage.height * multiplier);
- };
- StageScaleMode.prototype.setExactFit = function () {
- if(this.maxWidth && window.innerWidth > this.maxWidth) {
- this.width = this.maxWidth;
- } else {
- this.width = window.innerWidth;
- }
- if(this.maxHeight && window.innerHeight > this.maxHeight) {
- this.height = this.maxHeight;
- } else {
- this.height = window.innerHeight;
- }
- };
- return StageScaleMode;
- })();
- Phaser.StageScaleMode = StageScaleMode;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var BootScreen = (function () {
- function BootScreen(game) {
- this._logoData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAAZCAYAAADdYmvFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAstJREFUeNrsWlFuwjAMbavdZGcAcRm4AXzvCPuGG8BlEJxhZ+l4TJ48z3actGGthqUI1MaO/V6cmIT2/fW10eTt46NvKshtvDZlG31yfOL9a/ldU6x4IZ0GQs0gS217enMkJYr5ixXkYrFoVqtV1kDn8/n+KfXw/Hq9Nin7h8MhScB2u3Xtav2ivsNWrh7XLcWMYqA4eUZ1kj0MAifHJEeKFojWzyIH+rL/0Cwif2AX9nN1oQOgrTg8XcTFx+ScdEOJ4WBxXQ1EjRyrn0cOzzQLzFyQSQcgw/5Qkkr0JVEQpNIdhL4vm4DL5fLulNTHcy6Uxl4/6iMLiePx2KzX6/v30+n0aynUlrnSeNq2/VN9bgM4dFPdNPmsJnIg/PuQbJmLdFN3UNu0SzbyJ0GOWJVWZE/QMkY+owrqXxGEdZA37BVyX6lJTipT6J1lf7fbqc+xh8nYeIvikatP+PGW0nEJ4jOydHYOIcfKnmgWoZDQSIIeio4Sf1IthYWskCO4vqQ6lFYjl8tl9L1H67PZbMz3VO3t93uVXHofmUjReLyMwHi5eCb3ICwJj5ZU9nCg+SzUgPYyif+2epTk4pkkyDp+eXTlZu2BkUybEkklePZfK9lPuTnc07vbmt1bYulHBeNQgx18SsH4ni/cV2rSLtqNDNUH2JQ2SsXS57Y9PHlfumkwCdICt5rnkNdPjpMiIEWgRlAJSdF4SvCQMWj+VyfI0h8D/EgWSYKiJKXi8VrOhJUxaFiFCOKKUJAtR78k9eX4USLHXqLGXOIiWUT4Vj9JiP4W0io3VDz8AJXblNWQrOimLjIGy/9uLICH6mrVmFbxEFHauzmc0fGJJmPg/v+6D0oB7N2bj0FsNHtSWTQniWTR931QlHXvasDTHXLjqY0/1/8hSDxACD+lAGH8dKQbQk5N3TFtzDmLWutvV0+pL5FVoHvCNG35FGAAayS4KUoKC9QAAAAASUVORK5CYII=";
- this._color1 = {
- r: 20,
- g: 20,
- b: 20
- };
- this._color2 = {
- r: 200,
- g: 200,
- b: 200
- };
- this._fade = null;
- this.game = game;
- this._logo = new Image();
- this._logo.src = this._logoData;
- }
- BootScreen.prototype.update = function () {
- if(this._fade == null) {
- this.colorCycle();
- }
- this._color1.r = Math.round(this._color1.r);
- this._color1.g = Math.round(this._color1.g);
- this._color1.b = Math.round(this._color1.b);
- this._color2.r = Math.round(this._color2.r);
- this._color2.g = Math.round(this._color2.g);
- this._color2.b = Math.round(this._color2.b);
- };
- BootScreen.prototype.render = function () {
- var grd = this.game.stage.context.createLinearGradient(0, 0, 0, this.game.stage.height);
- grd.addColorStop(0, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
- grd.addColorStop(0.5, 'rgb(' + this._color2.r + ', ' + this._color2.g + ', ' + this._color2.b + ')');
- grd.addColorStop(1, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
- this.game.stage.context.fillStyle = grd;
- this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
- this.game.stage.context.shadowOffsetX = 0;
- this.game.stage.context.shadowOffsetY = 0;
- if(this._logo) {
- this.game.stage.context.drawImage(this._logo, 32, 32);
- }
- this.game.stage.context.shadowColor = 'rgb(0,0,0)';
- this.game.stage.context.shadowOffsetX = 1;
- this.game.stage.context.shadowOffsetY = 1;
- this.game.stage.context.shadowBlur = 0;
- this.game.stage.context.fillStyle = 'rgb(255,255,255)';
- this.game.stage.context.font = 'bold 18px Arial';
- this.game.stage.context.textBaseline = 'top';
- this.game.stage.context.fillText(Phaser.VERSION, 32, 64 + 32);
- this.game.stage.context.fillText('Game Size: ' + this.game.stage.width + ' x ' + this.game.stage.height, 32, 64 + 64);
- this.game.stage.context.fillText('www.photonstorm.com', 32, 64 + 96);
- this.game.stage.context.font = '16px Arial';
- this.game.stage.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 64 + 160);
- this.game.stage.context.fillText('functions in the Game constructor or use Game.switchState()', 32, 64 + 184);
- };
- BootScreen.prototype.colorCycle = function () {
- this._fade = this.game.add.tween(this._color2);
- this._fade.to({
- r: Math.random() * 250,
- g: Math.random() * 250,
- b: Math.random() * 250
- }, 3000, Phaser.Easing.Linear.None);
- this._fade.onComplete.add(this.colorCycle, this);
- this._fade.start();
- };
- return BootScreen;
- })();
- Phaser.BootScreen = BootScreen;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var OrientationScreen = (function () {
- function OrientationScreen(game) {
- this._enabled = false;
- this.game = game;
- }
- OrientationScreen.prototype.enable = function (imageKey) {
- this._enabled = true;
- this.image = this.game.cache.getImage(imageKey);
- };
- OrientationScreen.prototype.update = function () {
- };
- OrientationScreen.prototype.render = function () {
- if(this._enabled) {
- this.game.stage.context.drawImage(this.image, 0, 0, this.image.width, this.image.height, 0, 0, this.game.stage.width, this.game.stage.height);
- }
- };
- return OrientationScreen;
- })();
- Phaser.OrientationScreen = OrientationScreen;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var PauseScreen = (function () {
- function PauseScreen(game, width, height) {
- this.game = game;
- this._canvas = document.createElement('canvas');
- this._canvas.width = width;
- this._canvas.height = height;
- this._context = this._canvas.getContext('2d');
- }
- PauseScreen.prototype.onPaused = function () {
- this._context.clearRect(0, 0, this._canvas.width, this._canvas.height);
- this._context.drawImage(this.game.stage.canvas, 0, 0);
- this._color = {
- r: 255,
- g: 255,
- b: 255
- };
- this.fadeOut();
- };
- PauseScreen.prototype.onResume = function () {
- this._fade.stop();
- this.game.tweens.remove(this._fade);
- };
- PauseScreen.prototype.update = function () {
- this._color.r = Math.round(this._color.r);
- this._color.g = Math.round(this._color.g);
- this._color.b = Math.round(this._color.b);
- };
- PauseScreen.prototype.render = function () {
- this.game.stage.context.drawImage(this._canvas, 0, 0);
- this.game.stage.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
- this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
- var arrowWidth = Math.round(this.game.stage.width / 2);
- var arrowHeight = Math.round(this.game.stage.height / 2);
- var sx = this.game.stage.centerX - arrowWidth / 2;
- var sy = this.game.stage.centerY - arrowHeight / 2;
- this.game.stage.context.beginPath();
- this.game.stage.context.moveTo(sx, sy);
- this.game.stage.context.lineTo(sx, sy + arrowHeight);
- this.game.stage.context.lineTo(sx + arrowWidth, this.game.stage.centerY);
- this.game.stage.context.fillStyle = 'rgba(' + this._color.r + ', ' + this._color.g + ', ' + this._color.b + ', 0.8)';
- this.game.stage.context.fill();
- this.game.stage.context.closePath();
- };
- PauseScreen.prototype.fadeOut = function () {
- this._fade = this.game.add.tween(this._color);
- this._fade.to({
- r: 50,
- g: 50,
- b: 50
- }, 1000, Phaser.Easing.Linear.None);
- this._fade.onComplete.add(this.fadeIn, this);
- this._fade.start();
- };
- PauseScreen.prototype.fadeIn = function () {
- this._fade = this.game.add.tween(this._color);
- this._fade.to({
- r: 255,
- g: 255,
- b: 255
- }, 1000, Phaser.Easing.Linear.None);
- this._fade.onComplete.add(this.fadeOut, this);
- this._fade.start();
- };
- return PauseScreen;
- })();
- Phaser.PauseScreen = PauseScreen;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var SoundManager = (function () {
- function SoundManager(game) {
- this.usingWebAudio = false;
- this.usingAudioTag = false;
- this.noAudio = false;
- this.context = null;
- this._muted = false;
- this.touchLocked = false;
- this._unlockSource = null;
- this.onSoundDecode = new Phaser.Signal();
- this.game = game;
- this._volume = 1;
- this._muted = false;
- this._sounds = [];
- if(this.game.device.iOS && this.game.device.webAudio == false) {
- this.channels = 1;
- }
- if(this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) {
- this.game.input.touch.callbackContext = this;
- this.game.input.touch.touchStartCallback = this.unlock;
- this.game.input.mouse.callbackContext = this;
- this.game.input.mouse.mouseDownCallback = this.unlock;
- this.touchLocked = true;
- } else {
- this.touchLocked = false;
- }
- if(window['PhaserGlobal']) {
- if(window['PhaserGlobal'].disableAudio == true) {
- this.usingWebAudio = false;
- this.noAudio = true;
- return;
- }
- if(window['PhaserGlobal'].disableWebAudio == true) {
- this.usingWebAudio = false;
- this.usingAudioTag = true;
- this.noAudio = false;
- return;
- }
- }
- this.usingWebAudio = true;
- this.noAudio = false;
- if(!!window['AudioContext']) {
- this.context = new window['AudioContext']();
- } else if(!!window['webkitAudioContext']) {
- this.context = new window['webkitAudioContext']();
- } else if(!!window['Audio']) {
- this.usingWebAudio = false;
- this.usingAudioTag = true;
- } else {
- this.usingWebAudio = false;
- this.noAudio = true;
- }
- if(this.context !== null) {
- if(typeof this.context.createGain === 'undefined') {
- this.masterGain = this.context.createGainNode();
- } else {
- this.masterGain = this.context.createGain();
- }
- this.masterGain.gain.value = 1;
- this.masterGain.connect(this.context.destination);
- }
- }
- SoundManager.prototype.unlock = function () {
- if(this.touchLocked == false) {
- return;
- }
- if(this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false)) {
- var buffer = this.context.createBuffer(1, 1, 22050);
- this._unlockSource = this.context.createBufferSource();
- this._unlockSource.buffer = buffer;
- this._unlockSource.connect(this.context.destination);
- this._unlockSource.noteOn(0);
- } else {
- this.touchLocked = false;
- this._unlockSource = null;
- this.game.input.touch.callbackContext = null;
- this.game.input.touch.touchStartCallback = null;
- this.game.input.mouse.callbackContext = null;
- this.game.input.mouse.mouseDownCallback = null;
- }
- };
- Object.defineProperty(SoundManager.prototype, "mute", {
- get: function () {
- return this._muted;
- },
- set: function (value) {
- if(value) {
- if(this._muted) {
- return;
- }
- this._muted = true;
- if(this.usingWebAudio) {
- this._muteVolume = this.masterGain.gain.value;
- this.masterGain.gain.value = 0;
- }
- for(var i = 0; i < this._sounds.length; i++) {
- if(this._sounds[i].usingAudioTag) {
- this._sounds[i].mute = true;
- }
- }
- } else {
- if(this._muted == false) {
- return;
- }
- this._muted = false;
- if(this.usingWebAudio) {
- this.masterGain.gain.value = this._muteVolume;
- }
- for(var i = 0; i < this._sounds.length; i++) {
- if(this._sounds[i].usingAudioTag) {
- this._sounds[i].mute = false;
- }
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SoundManager.prototype, "volume", {
- get: function () {
- if(this.usingWebAudio) {
- return this.masterGain.gain.value;
- } else {
- return this._volume;
- }
- },
- set: function (value) {
- value = this.game.math.clamp(value, 1, 0);
- this._volume = value;
- if(this.usingWebAudio) {
- this.masterGain.gain.value = value;
- }
- for(var i = 0; i < this._sounds.length; i++) {
- if(this._sounds[i].usingAudioTag) {
- this._sounds[i].volume = this._sounds[i].volume * value;
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- SoundManager.prototype.stopAll = function () {
- for(var i = 0; i < this._sounds.length; i++) {
- if(this._sounds[i]) {
- this._sounds[i].stop();
- }
- }
- };
- SoundManager.prototype.pauseAll = function () {
- for(var i = 0; i < this._sounds.length; i++) {
- if(this._sounds[i]) {
- this._sounds[i].pause();
- }
- }
- };
- SoundManager.prototype.resumeAll = function () {
- for(var i = 0; i < this._sounds.length; i++) {
- if(this._sounds[i]) {
- this._sounds[i].resume();
- }
- }
- };
- SoundManager.prototype.decode = function (key, sound) {
- if (typeof sound === "undefined") { sound = null; }
- var soundData = this.game.cache.getSoundData(key);
- if(soundData) {
- if(this.game.cache.isSoundDecoded(key) === false) {
- this.game.cache.updateSound(key, 'isDecoding', true);
- var that = this;
- this.context.decodeAudioData(soundData, function (buffer) {
- that.game.cache.decodedSound(key, buffer);
- if(sound) {
- that.onSoundDecode.dispatch(sound);
- }
- });
- }
- }
- };
- SoundManager.prototype.update = function () {
- if(this.touchLocked) {
- if(this.game.device.webAudio && this._unlockSource !== null) {
- if((this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
- this.touchLocked = false;
- this._unlockSource = null;
- this.game.input.touch.callbackContext = null;
- this.game.input.touch.touchStartCallback = null;
- }
- }
- }
- for(var i = 0; i < this._sounds.length; i++) {
- this._sounds[i].update();
- }
- };
- SoundManager.prototype.add = function (key, volume, loop) {
- if (typeof volume === "undefined") { volume = 1; }
- if (typeof loop === "undefined") { loop = false; }
- var sound = new Phaser.Sound(this.game, key, volume, loop);
- this._sounds.push(sound);
- return sound;
- };
- return SoundManager;
- })();
- Phaser.SoundManager = SoundManager;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Sound = (function () {
- function Sound(game, key, volume, loop) {
- if (typeof volume === "undefined") { volume = 1; }
- if (typeof loop === "undefined") { loop = false; }
- this.context = null;
- this._buffer = null;
- this._muted = false;
- this.usingWebAudio = false;
- this.usingAudioTag = false;
- this.name = '';
- this.autoplay = false;
- this.totalDuration = 0;
- this.startTime = 0;
- this.currentTime = 0;
- this.duration = 0;
- this.stopTime = 0;
- this.paused = false;
- this.loop = false;
- this.isPlaying = false;
- this.currentMarker = '';
- this.pendingPlayback = false;
- this.override = false;
- this.game = game;
- this.usingWebAudio = this.game.sound.usingWebAudio;
- this.usingAudioTag = this.game.sound.usingAudioTag;
- this.key = key;
- if(this.usingWebAudio) {
- this.context = this.game.sound.context;
- this.masterGainNode = this.game.sound.masterGain;
- if(typeof this.context.createGain === 'undefined') {
- this.gainNode = this.context.createGainNode();
- } else {
- this.gainNode = this.context.createGain();
- }
- this.gainNode.gain.value = volume * this.game.sound.volume;
- this.gainNode.connect(this.masterGainNode);
- } else {
- if(this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false) {
- this._sound = this.game.cache.getSoundData(key);
- this.totalDuration = this._sound.duration;
- } else {
- this.game.cache.onSoundUnlock.add(this.soundHasUnlocked, this);
- }
- }
- this._volume = volume;
- this.loop = loop;
- this.markers = {
- };
- this.onDecoded = new Phaser.Signal();
- this.onPlay = new Phaser.Signal();
- this.onPause = new Phaser.Signal();
- this.onResume = new Phaser.Signal();
- this.onLoop = new Phaser.Signal();
- this.onStop = new Phaser.Signal();
- this.onMute = new Phaser.Signal();
- this.onMarkerComplete = new Phaser.Signal();
- }
- Sound.prototype.soundHasUnlocked = function (key) {
- if(key == this.key) {
- this._sound = this.game.cache.getSoundData(this.key);
- this.totalDuration = this._sound.duration;
- }
- };
- Object.defineProperty(Sound.prototype, "isDecoding", {
- get: function () {
- return this.game.cache.getSound(this.key).isDecoding;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Sound.prototype, "isDecoded", {
- get: function () {
- return this.game.cache.isSoundDecoded(this.key);
- },
- enumerable: true,
- configurable: true
- });
- Sound.prototype.addMarker = function (name, start, stop, volume, loop) {
- if (typeof volume === "undefined") { volume = 1; }
- if (typeof loop === "undefined") { loop = false; }
- this.markers[name] = {
- name: name,
- start: start,
- stop: stop,
- volume: volume,
- duration: stop - start,
- loop: loop
- };
- };
- Sound.prototype.removeMarker = function (name) {
- delete this.markers[name];
- };
- Sound.prototype.update = function () {
- if(this.pendingPlayback && this.game.cache.isSoundReady(this.key)) {
- this.pendingPlayback = false;
- this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
- }
- if(this.isPlaying) {
- this.currentTime = this.game.time.now - this.startTime;
- if(this.currentTime >= this.duration) {
- if(this.usingWebAudio) {
- if(this.loop) {
- this.onLoop.dispatch(this);
- if(this.currentMarker == '') {
- this.currentTime = 0;
- this.startTime = this.game.time.now;
- } else {
- this.play(this.currentMarker, 0, this.volume, true, true);
- }
- } else {
- this.stop();
- }
- } else {
- if(this.loop) {
- this.onLoop.dispatch(this);
- this.play(this.currentMarker, 0, this.volume, true, true);
- } else {
- this.stop();
- }
- }
- }
- }
- };
- Sound.prototype.play = function (marker, position, volume, loop, forceRestart) {
- if (typeof marker === "undefined") { marker = ''; }
- if (typeof position === "undefined") { position = 0; }
- if (typeof volume === "undefined") { volume = 1; }
- if (typeof loop === "undefined") { loop = false; }
- if (typeof forceRestart === "undefined") { forceRestart = false; }
- if(this.isPlaying == true && forceRestart == false && this.override == false) {
- return;
- }
- if(this.isPlaying && this.override) {
- if(this.usingWebAudio) {
- if(typeof this._sound.stop === 'undefined') {
- this._sound.noteOff(0);
- } else {
- this._sound.stop(0);
- }
- } else if(this.usingAudioTag) {
- this._sound.pause();
- this._sound.currentTime = 0;
- }
- }
- this.currentMarker = marker;
- if(marker !== '' && this.markers[marker]) {
- this.position = this.markers[marker].start;
- this.volume = this.markers[marker].volume;
- this.loop = this.markers[marker].loop;
- this.duration = this.markers[marker].duration * 1000;
- this._tempMarker = marker;
- this._tempPosition = this.position;
- this._tempVolume = this.volume;
- this._tempLoop = this.loop;
- } else {
- this.position = position;
- this.volume = volume;
- this.loop = loop;
- this.duration = 0;
- this._tempMarker = marker;
- this._tempPosition = position;
- this._tempVolume = volume;
- this._tempLoop = loop;
- }
- if(this.usingWebAudio) {
- if(this.game.cache.isSoundDecoded(this.key)) {
- if(this._buffer == null) {
- this._buffer = this.game.cache.getSoundData(this.key);
- }
- this._sound = this.context.createBufferSource();
- this._sound.buffer = this._buffer;
- this._sound.connect(this.gainNode);
- this.totalDuration = this._sound.buffer.duration;
- if(this.duration == 0) {
- this.duration = this.totalDuration * 1000;
- }
- if(this.loop && marker == '') {
- this._sound.loop = true;
- }
- if(typeof this._sound.start === 'undefined') {
- this._sound.noteGrainOn(0, this.position, this.duration / 1000);
- } else {
- this._sound.start(0, this.position, this.duration / 1000);
- }
- this.isPlaying = true;
- this.startTime = this.game.time.now;
- this.currentTime = 0;
- this.stopTime = this.startTime + this.duration;
- this.onPlay.dispatch(this);
- } else {
- this.pendingPlayback = true;
- if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false) {
- this.game.sound.decode(this.key, this);
- }
- }
- } else {
- if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).locked) {
- this.game.cache.reloadSound(this.key);
- this.pendingPlayback = true;
- } else {
- if(this._sound && this._sound.readyState == 4) {
- if(this.duration == 0) {
- this.duration = this.totalDuration * 1000;
- }
- this._sound.currentTime = this.position;
- this._sound.muted = this._muted;
- if(this._muted) {
- this._sound.volume = 0;
- } else {
- this._sound.volume = this._volume;
- }
- this._sound.play();
- this.isPlaying = true;
- this.startTime = this.game.time.now;
- this.currentTime = 0;
- this.stopTime = this.startTime + this.duration;
- this.onPlay.dispatch(this);
- } else {
- this.pendingPlayback = true;
- }
- }
- }
- };
- Sound.prototype.restart = function (marker, position, volume, loop) {
- if (typeof marker === "undefined") { marker = ''; }
- if (typeof position === "undefined") { position = 0; }
- if (typeof volume === "undefined") { volume = 1; }
- if (typeof loop === "undefined") { loop = false; }
- this.play(marker, position, volume, loop, true);
- };
- Sound.prototype.pause = function () {
- if(this.isPlaying && this._sound) {
- this.stop();
- this.isPlaying = false;
- this.paused = true;
- this.onPause.dispatch(this);
- }
- };
- Sound.prototype.resume = function () {
- if(this.paused && this._sound) {
- if(this.usingWebAudio) {
- if(typeof this._sound.start === 'undefined') {
- this._sound.noteGrainOn(0, this.position, this.duration);
- } else {
- this._sound.start(0, this.position, this.duration);
- }
- } else {
- this._sound.play();
- }
- this.isPlaying = true;
- this.paused = false;
- this.onResume.dispatch(this);
- }
- };
- Sound.prototype.stop = function () {
- if(this.isPlaying && this._sound) {
- if(this.usingWebAudio) {
- if(typeof this._sound.stop === 'undefined') {
- this._sound.noteOff(0);
- } else {
- this._sound.stop(0);
- }
- } else if(this.usingAudioTag) {
- this._sound.pause();
- this._sound.currentTime = 0;
- }
- }
- this.isPlaying = false;
- var prevMarker = this.currentMarker;
- this.currentMarker = '';
- this.onStop.dispatch(this, prevMarker);
- };
- Object.defineProperty(Sound.prototype, "mute", {
- get: function () {
- return this._muted;
- },
- set: function (value) {
- if(value) {
- this._muted = true;
- if(this.usingWebAudio) {
- this._muteVolume = this.gainNode.gain.value;
- this.gainNode.gain.value = 0;
- } else if(this.usingAudioTag && this._sound) {
- this._muteVolume = this._sound.volume;
- this._sound.volume = 0;
- }
- } else {
- this._muted = false;
- if(this.usingWebAudio) {
- this.gainNode.gain.value = this._muteVolume;
- } else if(this.usingAudioTag && this._sound) {
- this._sound.volume = this._muteVolume;
- }
- }
- this.onMute.dispatch(this);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Sound.prototype, "volume", {
- get: function () {
- return this._volume;
- },
- set: function (value) {
- this._volume = value;
- if(this.usingWebAudio) {
- this.gainNode.gain.value = value;
- } else if(this.usingAudioTag && this._sound) {
- this._sound.volume = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- return Sound;
- })();
- Phaser.Sound = Sound;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Animation = (function () {
- function Animation(game, parent, frameData, name, frames, delay, looped) {
- this.game = game;
- this._parent = parent;
- this._frames = frames;
- this._frameData = frameData;
- this.name = name;
- this.delay = 1000 / delay;
- this.looped = looped;
- this.isFinished = false;
- this.isPlaying = false;
- this._frameIndex = 0;
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
- }
- Object.defineProperty(Animation.prototype, "frameTotal", {
- get: function () {
- return this._frames.length;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Animation.prototype, "frame", {
- get: function () {
- if(this.currentFrame !== null) {
- return this.currentFrame.index;
- } else {
- return this._frameIndex;
- }
- },
- set: function (value) {
- this.currentFrame = this._frameData.getFrame(value);
- if(this.currentFrame !== null) {
- this._parent.texture.width = this.currentFrame.width;
- this._parent.texture.height = this.currentFrame.height;
- this._frameIndex = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Animation.prototype.play = function (frameRate, loop) {
- if (typeof frameRate === "undefined") { frameRate = null; }
- if (typeof loop === "undefined") { loop = null; }
- if(frameRate !== null) {
- this.delay = 1000 / frameRate;
- }
- if(loop !== null) {
- this.looped = loop;
- }
- this.isPlaying = true;
- this.isFinished = false;
- this._timeLastFrame = this.game.time.now;
- this._timeNextFrame = this.game.time.now + this.delay;
- this._frameIndex = 0;
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
- this._parent.events.onAnimationStart.dispatch(this._parent, this);
- return this;
- };
- Animation.prototype.restart = function () {
- this.isPlaying = true;
- this.isFinished = false;
- this._timeLastFrame = this.game.time.now;
- this._timeNextFrame = this.game.time.now + this.delay;
- this._frameIndex = 0;
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
- };
- Animation.prototype.stop = function () {
- this.isPlaying = false;
- this.isFinished = true;
- };
- Animation.prototype.update = function () {
- if(this.isPlaying == true && this.game.time.now >= this._timeNextFrame) {
- this._frameIndex++;
- if(this._frameIndex == this._frames.length) {
- if(this.looped) {
- this._frameIndex = 0;
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
- this._parent.events.onAnimationLoop.dispatch(this._parent, this);
- } else {
- this.onComplete();
- }
- } else {
- this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
- }
- this._timeLastFrame = this.game.time.now;
- this._timeNextFrame = this.game.time.now + this.delay;
- return true;
- }
- return false;
- };
- Animation.prototype.destroy = function () {
- this.game = null;
- this._parent = null;
- this._frames = null;
- this._frameData = null;
- this.currentFrame = null;
- this.isPlaying = false;
- };
- Animation.prototype.onComplete = function () {
- this.isPlaying = false;
- this.isFinished = true;
- this._parent.events.onAnimationComplete.dispatch(this._parent, this);
- };
- return Animation;
- })();
- Phaser.Animation = Animation;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Components) {
- var AnimationManager = (function () {
- function AnimationManager(parent) {
- this._frameData = null;
- this.autoUpdateBounds = true;
- this.currentFrame = null;
- this._parent = parent;
- this.game = parent.game;
- this._anims = {
- };
- }
- AnimationManager.prototype.loadFrameData = function (frameData) {
- this._frameData = frameData;
- this.frame = 0;
- };
- AnimationManager.prototype.add = function (name, frames, frameRate, loop, useNumericIndex) {
- if (typeof frames === "undefined") { frames = null; }
- if (typeof frameRate === "undefined") { frameRate = 60; }
- if (typeof loop === "undefined") { loop = false; }
- if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
- if(this._frameData == null) {
- return;
- }
- if(this._parent.events.onAnimationStart == null) {
- this._parent.events.onAnimationStart = new Phaser.Signal();
- this._parent.events.onAnimationComplete = new Phaser.Signal();
- this._parent.events.onAnimationLoop = new Phaser.Signal();
- }
- if(frames == null) {
- frames = this._frameData.getFrameIndexes();
- } else {
- if(this.validateFrames(frames, useNumericIndex) == false) {
- throw Error('Invalid frames given to Animation ' + name);
- return;
- }
- }
- if(useNumericIndex == false) {
- frames = this._frameData.getFrameIndexesByName(frames);
- }
- this._anims[name] = new Phaser.Animation(this.game, this._parent, this._frameData, name, frames, frameRate, loop);
- this.currentAnim = this._anims[name];
- this.currentFrame = this.currentAnim.currentFrame;
- return this._anims[name];
- };
- AnimationManager.prototype.validateFrames = function (frames, useNumericIndex) {
- for(var i = 0; i < frames.length; i++) {
- if(useNumericIndex == true) {
- if(frames[i] > this._frameData.total) {
- return false;
- }
- } else {
- if(this._frameData.checkFrameName(frames[i]) == false) {
- return false;
- }
- }
- }
- return true;
- };
- AnimationManager.prototype.play = function (name, frameRate, loop) {
- if (typeof frameRate === "undefined") { frameRate = null; }
- if (typeof loop === "undefined") { loop = null; }
- if(this._anims[name]) {
- if(this.currentAnim == this._anims[name]) {
- if(this.currentAnim.isPlaying == false) {
- return this.currentAnim.play(frameRate, loop);
- }
- } else {
- this.currentAnim = this._anims[name];
- return this.currentAnim.play(frameRate, loop);
- }
- }
- };
- AnimationManager.prototype.stop = function (name) {
- if(this._anims[name]) {
- this.currentAnim = this._anims[name];
- this.currentAnim.stop();
- }
- };
- AnimationManager.prototype.update = function () {
- if(this.currentAnim && this.currentAnim.update() == true) {
- this.currentFrame = this.currentAnim.currentFrame;
- this._parent.texture.width = this.currentFrame.width;
- this._parent.texture.height = this.currentFrame.height;
- }
- };
- Object.defineProperty(AnimationManager.prototype, "frameData", {
- get: function () {
- return this._frameData;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(AnimationManager.prototype, "frameTotal", {
- get: function () {
- if(this._frameData) {
- return this._frameData.total;
- } else {
- return -1;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(AnimationManager.prototype, "frame", {
- get: function () {
- return this._frameIndex;
- },
- set: function (value) {
- if(this._frameData && this._frameData.getFrame(value) !== null) {
- this.currentFrame = this._frameData.getFrame(value);
- this._parent.texture.width = this.currentFrame.width;
- this._parent.texture.height = this.currentFrame.height;
- if(this.autoUpdateBounds && this._parent['body']) {
- this._parent.body.bounds.width = this.currentFrame.width;
- this._parent.body.bounds.height = this.currentFrame.height;
- }
- this._frameIndex = value;
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(AnimationManager.prototype, "frameName", {
- get: function () {
- return this.currentFrame.name;
- },
- set: function (value) {
- if(this._frameData && this._frameData.getFrameByName(value)) {
- this.currentFrame = this._frameData.getFrameByName(value);
- this._parent.texture.width = this.currentFrame.width;
- this._parent.texture.height = this.currentFrame.height;
- this._frameIndex = this.currentFrame.index;
- } else {
- throw new Error("Cannot set frameName: " + value);
- }
- },
- enumerable: true,
- configurable: true
- });
- AnimationManager.prototype.destroy = function () {
- this._anims = {
- };
- this._frameData = null;
- this._frameIndex = 0;
- this.currentAnim = null;
- this.currentFrame = null;
- };
- return AnimationManager;
- })();
- Components.AnimationManager = AnimationManager;
- })(Phaser.Components || (Phaser.Components = {}));
- var Components = Phaser.Components;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Frame = (function () {
- function Frame(x, y, width, height, name) {
- this.name = '';
- this.rotated = false;
- this.rotationDirection = 'cw';
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- this.name = name;
- this.rotated = false;
- this.trimmed = false;
- }
- Frame.prototype.setRotation = function (rotated, rotationDirection) {
- };
- Frame.prototype.setTrim = function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
- this.trimmed = trimmed;
- if(trimmed) {
- this.width = actualWidth;
- this.height = actualHeight;
- this.sourceSizeW = actualWidth;
- this.sourceSizeH = actualHeight;
- this.spriteSourceSizeX = destX;
- this.spriteSourceSizeY = destY;
- this.spriteSourceSizeW = destWidth;
- this.spriteSourceSizeH = destHeight;
- }
- };
- return Frame;
- })();
- Phaser.Frame = Frame;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var FrameData = (function () {
- function FrameData() {
- this._frames = [];
- this._frameNames = [];
- }
- Object.defineProperty(FrameData.prototype, "total", {
- get: function () {
- return this._frames.length;
- },
- enumerable: true,
- configurable: true
- });
- FrameData.prototype.addFrame = function (frame) {
- frame.index = this._frames.length;
- this._frames.push(frame);
- if(frame.name !== '') {
- this._frameNames[frame.name] = frame.index;
- }
- return frame;
- };
- FrameData.prototype.getFrame = function (index) {
- if(this._frames[index]) {
- return this._frames[index];
- }
- return null;
- };
- FrameData.prototype.getFrameByName = function (name) {
- if(this._frameNames[name] !== '') {
- return this._frames[this._frameNames[name]];
- }
- return null;
- };
- FrameData.prototype.checkFrameName = function (name) {
- if(this._frameNames[name] == null) {
- return false;
- }
- return true;
- };
- FrameData.prototype.getFrameRange = function (start, end, output) {
- if (typeof output === "undefined") { output = []; }
- for(var i = start; i <= end; i++) {
- output.push(this._frames[i]);
- }
- return output;
- };
- FrameData.prototype.getFrameIndexes = function (output) {
- if (typeof output === "undefined") { output = []; }
- output.length = 0;
- for(var i = 0; i < this._frames.length; i++) {
- output.push(i);
- }
- return output;
- };
- FrameData.prototype.getFrameIndexesByName = function (input) {
- var output = [];
- for(var i = 0; i < input.length; i++) {
- if(this.getFrameByName(input[i])) {
- output.push(this.getFrameByName(input[i]).index);
- }
- }
- return output;
- };
- FrameData.prototype.getAllFrames = function () {
- return this._frames;
- };
- FrameData.prototype.getFrames = function (range) {
- var output = [];
- for(var i = 0; i < range.length; i++) {
- output.push(this._frames[i]);
- }
- return output;
- };
- return FrameData;
- })();
- Phaser.FrameData = FrameData;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Cache = (function () {
- function Cache(game) {
- this.onSoundUnlock = new Phaser.Signal();
- this.game = game;
- this._canvases = {
- };
- this._images = {
- };
- this._sounds = {
- };
- this._text = {
- };
- }
- Cache.prototype.addCanvas = function (key, canvas, context) {
- this._canvases[key] = {
- canvas: canvas,
- context: context
- };
- };
- Cache.prototype.addSpriteSheet = function (key, url, data, frameWidth, frameHeight, frameMax) {
- this._images[key] = {
- url: url,
- data: data,
- spriteSheet: true,
- frameWidth: frameWidth,
- frameHeight: frameHeight
- };
- this._images[key].frameData = Phaser.AnimationLoader.parseSpriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
- };
- Cache.prototype.addTextureAtlas = function (key, url, data, atlasData, format) {
- this._images[key] = {
- url: url,
- data: data,
- spriteSheet: true
- };
- if(format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY) {
- this._images[key].frameData = Phaser.AnimationLoader.parseJSONData(this.game, atlasData);
- } else if(format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING) {
- this._images[key].frameData = Phaser.AnimationLoader.parseXMLData(this.game, atlasData, format);
- }
- };
- Cache.prototype.addImage = function (key, url, data) {
- this._images[key] = {
- url: url,
- data: data,
- spriteSheet: false
- };
- };
- Cache.prototype.addSound = function (key, url, data, webAudio, audioTag) {
- if (typeof webAudio === "undefined") { webAudio = true; }
- if (typeof audioTag === "undefined") { audioTag = false; }
- var locked = this.game.sound.touchLocked;
- var decoded = false;
- if(audioTag) {
- decoded = true;
- }
- this._sounds[key] = {
- url: url,
- data: data,
- locked: locked,
- isDecoding: false,
- decoded: decoded,
- webAudio: webAudio,
- audioTag: audioTag
- };
- };
- Cache.prototype.reloadSound = function (key) {
- var _this = this;
- if(this._sounds[key]) {
- this._sounds[key].data.src = this._sounds[key].url;
- this._sounds[key].data.addEventListener('canplaythrough', function () {
- return _this.reloadSoundComplete(key);
- }, false);
- this._sounds[key].data.load();
- }
- };
- Cache.prototype.reloadSoundComplete = function (key) {
- if(this._sounds[key]) {
- this._sounds[key].locked = false;
- this.onSoundUnlock.dispatch(key);
- }
- };
- Cache.prototype.updateSound = function (key, property, value) {
- if(this._sounds[key]) {
- this._sounds[key][property] = value;
- }
- };
- Cache.prototype.decodedSound = function (key, data) {
- this._sounds[key].data = data;
- this._sounds[key].decoded = true;
- this._sounds[key].isDecoding = false;
- };
- Cache.prototype.addText = function (key, url, data) {
- this._text[key] = {
- url: url,
- data: data
- };
- };
- Cache.prototype.getCanvas = function (key) {
- if(this._canvases[key]) {
- return this._canvases[key].canvas;
- }
- return null;
- };
- Cache.prototype.getImage = function (key) {
- if(this._images[key]) {
- return this._images[key].data;
- }
- return null;
- };
- Cache.prototype.getFrameData = function (key) {
- if(this._images[key] && this._images[key].spriteSheet == true) {
- return this._images[key].frameData;
- }
- return null;
- };
- Cache.prototype.getSound = function (key) {
- if(this._sounds[key]) {
- return this._sounds[key];
- }
- return null;
- };
- Cache.prototype.getSoundData = function (key) {
- if(this._sounds[key]) {
- return this._sounds[key].data;
- }
- return null;
- };
- Cache.prototype.isSoundDecoded = function (key) {
- if(this._sounds[key]) {
- return this._sounds[key].decoded;
- }
- };
- Cache.prototype.isSoundReady = function (key) {
- if(this._sounds[key] && this._sounds[key].decoded == true && this._sounds[key].locked == false) {
- return true;
- }
- return false;
- };
- Cache.prototype.isSpriteSheet = function (key) {
- if(this._images[key]) {
- return this._images[key].spriteSheet;
- }
- };
- Cache.prototype.getText = function (key) {
- if(this._text[key]) {
- return this._text[key].data;
- }
- return null;
- };
- Cache.prototype.getImageKeys = function () {
- var output = [];
- for(var item in this._images) {
- output.push(item);
- }
- return output;
- };
- Cache.prototype.getSoundKeys = function () {
- var output = [];
- for(var item in this._sounds) {
- output.push(item);
- }
- return output;
- };
- Cache.prototype.getTextKeys = function () {
- var output = [];
- for(var item in this._text) {
- output.push(item);
- }
- return output;
- };
- Cache.prototype.removeCanvas = function (key) {
- delete this._canvases[key];
- };
- Cache.prototype.removeImage = function (key) {
- delete this._images[key];
- };
- Cache.prototype.removeSound = function (key) {
- delete this._sounds[key];
- };
- Cache.prototype.removeText = function (key) {
- delete this._text[key];
- };
- Cache.prototype.destroy = function () {
- for(var item in this._canvases) {
- delete this._canvases[item['key']];
- }
- for(var item in this._images) {
- delete this._images[item['key']];
- }
- for(var item in this._sounds) {
- delete this._sounds[item['key']];
- }
- for(var item in this._text) {
- delete this._text[item['key']];
- }
- };
- return Cache;
- })();
- Phaser.Cache = Cache;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Loader = (function () {
- function Loader(game) {
- this.crossOrigin = '';
- this.baseURL = '';
- this.game = game;
- this._keys = [];
- this._fileList = {
- };
- this._xhr = new XMLHttpRequest();
- this._queueSize = 0;
- this.isLoading = false;
- this.onFileComplete = new Phaser.Signal();
- this.onFileError = new Phaser.Signal();
- this.onLoadStart = new Phaser.Signal();
- this.onLoadComplete = new Phaser.Signal();
- }
- Loader.TEXTURE_ATLAS_JSON_ARRAY = 0;
- Loader.TEXTURE_ATLAS_JSON_HASH = 1;
- Loader.TEXTURE_ATLAS_XML_STARLING = 2;
- Loader.prototype.reset = function () {
- this._queueSize = 0;
- this.isLoading = false;
- };
- Object.defineProperty(Loader.prototype, "queueSize", {
- get: function () {
- return this._queueSize;
- },
- enumerable: true,
- configurable: true
- });
- Loader.prototype.image = function (key, url, overwrite) {
- if (typeof overwrite === "undefined") { overwrite = false; }
- if(overwrite == true || this.checkKeyExists(key) == false) {
- this._queueSize++;
- this._fileList[key] = {
- type: 'image',
- key: key,
- url: url,
- data: null,
- error: false,
- loaded: false
- };
- this._keys.push(key);
- }
- };
- Loader.prototype.spritesheet = function (key, url, frameWidth, frameHeight, frameMax) {
- if (typeof frameMax === "undefined") { frameMax = -1; }
- if(this.checkKeyExists(key) === false) {
- this._queueSize++;
- this._fileList[key] = {
- type: 'spritesheet',
- key: key,
- url: url,
- data: null,
- frameWidth: frameWidth,
- frameHeight: frameHeight,
- frameMax: frameMax,
- error: false,
- loaded: false
- };
- this._keys.push(key);
- }
- };
- Loader.prototype.atlas = function (key, textureURL, atlasURL, atlasData, format) {
- if (typeof atlasURL === "undefined") { atlasURL = null; }
- if (typeof atlasData === "undefined") { atlasData = null; }
- if (typeof format === "undefined") { format = Loader.TEXTURE_ATLAS_JSON_ARRAY; }
- if(this.checkKeyExists(key) === false) {
- if(atlasURL !== null) {
- this._queueSize++;
- this._fileList[key] = {
- type: 'textureatlas',
- key: key,
- url: textureURL,
- atlasURL: atlasURL,
- data: null,
- format: format,
- error: false,
- loaded: false
- };
- this._keys.push(key);
- } else {
- if(format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
- if(typeof atlasData === 'string') {
- atlasData = JSON.parse(atlasData);
- }
- this._queueSize++;
- this._fileList[key] = {
- type: 'textureatlas',
- key: key,
- url: textureURL,
- data: null,
- atlasURL: null,
- atlasData: atlasData,
- format: format,
- error: false,
- loaded: false
- };
- this._keys.push(key);
- } else if(format == Loader.TEXTURE_ATLAS_XML_STARLING) {
- if(typeof atlasData === 'string') {
- var xml;
- try {
- if(window['DOMParser']) {
- var domparser = new DOMParser();
- xml = domparser.parseFromString(atlasData, "text/xml");
- } else {
- xml = new ActiveXObject("Microsoft.XMLDOM");
- xml.async = 'false';
- xml.loadXML(atlasData);
- }
- } catch (e) {
- xml = undefined;
- }
- if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
- throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
- } else {
- atlasData = xml;
- }
- }
- this._queueSize++;
- this._fileList[key] = {
- type: 'textureatlas',
- key: key,
- url: textureURL,
- data: null,
- atlasURL: null,
- atlasData: atlasData,
- format: format,
- error: false,
- loaded: false
- };
- this._keys.push(key);
- }
- }
- }
- };
- Loader.prototype.audio = function (key, urls, autoDecode) {
- if (typeof autoDecode === "undefined") { autoDecode = true; }
- if(this.checkKeyExists(key) === false) {
- this._queueSize++;
- this._fileList[key] = {
- type: 'audio',
- key: key,
- url: urls,
- data: null,
- buffer: null,
- error: false,
- loaded: false,
- autoDecode: autoDecode
- };
- this._keys.push(key);
- }
- };
- Loader.prototype.text = function (key, url) {
- if(this.checkKeyExists(key) === false) {
- this._queueSize++;
- this._fileList[key] = {
- type: 'text',
- key: key,
- url: url,
- data: null,
- error: false,
- loaded: false
- };
- this._keys.push(key);
- }
- };
- Loader.prototype.removeFile = function (key) {
- delete this._fileList[key];
- };
- Loader.prototype.removeAll = function () {
- this._fileList = {
- };
- };
- Loader.prototype.start = function () {
- if(this.isLoading) {
- return;
- }
- this.progress = 0;
- this.hasLoaded = false;
- this.isLoading = true;
- this.onLoadStart.dispatch(this.queueSize);
- if(this._keys.length > 0) {
- this._progressChunk = 100 / this._keys.length;
- this.loadFile();
- } else {
- this.progress = 100;
- this.hasLoaded = true;
- this.onLoadComplete.dispatch();
- }
- };
- Loader.prototype.loadFile = function () {
- var _this = this;
- var file = this._fileList[this._keys.pop()];
- switch(file.type) {
- case 'image':
- case 'spritesheet':
- case 'textureatlas':
- file.data = new Image();
- file.data.name = file.key;
- file.data.onload = function () {
- return _this.fileComplete(file.key);
- };
- file.data.onerror = function () {
- return _this.fileError(file.key);
- };
- file.data.crossOrigin = this.crossOrigin;
- file.data.src = this.baseURL + file.url;
- break;
- case 'audio':
- file.url = this.getAudioURL(file.url);
- if(file.url !== null) {
- if(this.game.sound.usingWebAudio) {
- this._xhr.open("GET", this.baseURL + file.url, true);
- this._xhr.responseType = "arraybuffer";
- this._xhr.onload = function () {
- return _this.fileComplete(file.key);
- };
- this._xhr.onerror = function () {
- return _this.fileError(file.key);
- };
- this._xhr.send();
- } else if(this.game.sound.usingAudioTag) {
- if(this.game.sound.touchLocked) {
- file.data = new Audio();
- file.data.name = file.key;
- file.data.preload = 'auto';
- file.data.src = this.baseURL + file.url;
- this.fileComplete(file.key);
- } else {
- file.data = new Audio();
- file.data.name = file.key;
- file.data.onerror = function () {
- return _this.fileError(file.key);
- };
- file.data.preload = 'auto';
- file.data.src = this.baseURL + file.url;
- file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
- file.data.load();
- }
- }
- }
- break;
- case 'text':
- this._xhr.open("GET", this.baseURL + file.url, true);
- this._xhr.responseType = "text";
- this._xhr.onload = function () {
- return _this.fileComplete(file.key);
- };
- this._xhr.onerror = function () {
- return _this.fileError(file.key);
- };
- this._xhr.send();
- break;
- }
- };
- Loader.prototype.getAudioURL = function (urls) {
- var extension;
- for(var i = 0; i < urls.length; i++) {
- extension = urls[i].toLowerCase();
- extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
- if(this.game.device.canPlayAudio(extension)) {
- return urls[i];
- }
- }
- return null;
- };
- Loader.prototype.fileError = function (key) {
- this._fileList[key].loaded = true;
- this._fileList[key].error = true;
- this.onFileError.dispatch(key);
- throw new Error("Phaser.Loader error loading file: " + key);
- this.nextFile(key, false);
- };
- Loader.prototype.fileComplete = function (key) {
- var _this = this;
- if(!this._fileList[key]) {
- throw new Error('Phaser.Loader fileComplete invalid key ' + key);
- return;
- }
- this._fileList[key].loaded = true;
- var file = this._fileList[key];
- var loadNext = true;
- switch(file.type) {
- case 'image':
- this.game.cache.addImage(file.key, file.url, file.data);
- break;
- case 'spritesheet':
- this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax);
- break;
- case 'textureatlas':
- if(file.atlasURL == null) {
- this.game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
- } else {
- loadNext = false;
- this._xhr.open("GET", this.baseURL + file.atlasURL, true);
- this._xhr.responseType = "text";
- if(file.format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
- this._xhr.onload = function () {
- return _this.jsonLoadComplete(file.key);
- };
- } else if(file.format == Loader.TEXTURE_ATLAS_XML_STARLING) {
- this._xhr.onload = function () {
- return _this.xmlLoadComplete(file.key);
- };
- }
- this._xhr.onerror = function () {
- return _this.dataLoadError(file.key);
- };
- this._xhr.send();
- }
- break;
- case 'audio':
- if(this.game.sound.usingWebAudio) {
- file.data = this._xhr.response;
- this.game.cache.addSound(file.key, file.url, file.data, true, false);
- if(file.autoDecode) {
- this.game.cache.updateSound(key, 'isDecoding', true);
- var that = this;
- var key = file.key;
- this.game.sound.context.decodeAudioData(file.data, function (buffer) {
- if(buffer) {
- that.game.cache.decodedSound(key, buffer);
- }
- });
- }
- } else {
- file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete);
- this.game.cache.addSound(file.key, file.url, file.data, false, true);
- }
- break;
- case 'text':
- file.data = this._xhr.response;
- this.game.cache.addText(file.key, file.url, file.data);
- break;
- }
- if(loadNext) {
- this.nextFile(key, true);
- }
- };
- Loader.prototype.jsonLoadComplete = function (key) {
- var data = JSON.parse(this._xhr.response);
- var file = this._fileList[key];
- this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
- this.nextFile(key, true);
- };
- Loader.prototype.dataLoadError = function (key) {
- var file = this._fileList[key];
- file.error = true;
- throw new Error("Phaser.Loader dataLoadError: " + key);
- this.nextFile(key, true);
- };
- Loader.prototype.xmlLoadComplete = function (key) {
- var atlasData = this._xhr.response;
- var xml;
- try {
- if(window['DOMParser']) {
- var domparser = new DOMParser();
- xml = domparser.parseFromString(atlasData, "text/xml");
- } else {
- xml = new ActiveXObject("Microsoft.XMLDOM");
- xml.async = 'false';
- xml.loadXML(atlasData);
- }
- } catch (e) {
- xml = undefined;
- }
- if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
- throw new Error("Phaser.Loader. Invalid XML given");
- }
- var file = this._fileList[key];
- this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
- this.nextFile(key, true);
- };
- Loader.prototype.nextFile = function (previousKey, success) {
- this.progress = Math.round(this.progress + this._progressChunk);
- if(this.progress > 100) {
- this.progress = 100;
- }
- this.onFileComplete.dispatch(this.progress, previousKey, success, this._queueSize - this._keys.length, this._queueSize);
- if(this._keys.length > 0) {
- this.loadFile();
- } else {
- this.hasLoaded = true;
- this.isLoading = false;
- this.removeAll();
- this.onLoadComplete.dispatch();
- }
- };
- Loader.prototype.checkKeyExists = function (key) {
- if(this._fileList[key]) {
- return true;
- } else {
- return false;
- }
- };
- return Loader;
- })();
- Phaser.Loader = Loader;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var AnimationLoader = (function () {
- function AnimationLoader() { }
- AnimationLoader.parseSpriteSheet = function parseSpriteSheet(game, key, frameWidth, frameHeight, frameMax) {
- var img = game.cache.getImage(key);
- if(img == null) {
- return null;
- }
- var width = img.width;
- var height = img.height;
- var row = Math.round(width / frameWidth);
- var column = Math.round(height / frameHeight);
- var total = row * column;
- if(frameMax !== -1) {
- total = frameMax;
- }
- if(width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
- throw new Error("AnimationLoader.parseSpriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
- return null;
- }
- var data = new Phaser.FrameData();
- var x = 0;
- var y = 0;
- for(var i = 0; i < total; i++) {
- data.addFrame(new Phaser.Frame(x, y, frameWidth, frameHeight, ''));
- x += frameWidth;
- if(x === width) {
- x = 0;
- y += frameHeight;
- }
- }
- return data;
- };
- AnimationLoader.parseJSONData = function parseJSONData(game, json) {
- if(!json['frames']) {
- console.log(json);
- throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
- }
- var data = new Phaser.FrameData();
- var frames = json['frames'];
- var newFrame;
- for(var i = 0; i < frames.length; i++) {
- newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
- newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
- }
- return data;
- };
- AnimationLoader.parseXMLData = function parseXMLData(game, xml, format) {
- if(!xml.getElementsByTagName('TextureAtlas')) {
- throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing tag");
- }
- var data = new Phaser.FrameData();
- var frames = xml.getElementsByTagName('SubTexture');
- var newFrame;
- for(var i = 0; i < frames.length; i++) {
- var frame = frames[i].attributes;
- newFrame = data.addFrame(new Phaser.Frame(frame.x.nodeValue, frame.y.nodeValue, frame.width.nodeValue, frame.height.nodeValue, frame.name.nodeValue));
- if(frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0') {
- newFrame.setTrim(true, frame.width.nodeValue, frame.height.nodeValue, Math.abs(frame.frameX.nodeValue), Math.abs(frame.frameY.nodeValue), frame.frameWidth.nodeValue, frame.frameHeight.nodeValue);
- }
- }
- return data;
- };
- return AnimationLoader;
- })();
- Phaser.AnimationLoader = AnimationLoader;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Tile = (function () {
- function Tile(game, tilemap, index, width, height) {
- this.mass = 1.0;
- this.collideLeft = false;
- this.collideRight = false;
- this.collideUp = false;
- this.collideDown = false;
- this.separateX = true;
- this.separateY = true;
- this.game = game;
- this.tilemap = tilemap;
- this.index = index;
- this.width = width;
- this.height = height;
- this.allowCollisions = Phaser.Types.NONE;
- }
- Tile.prototype.destroy = function () {
- this.tilemap = null;
- };
- Tile.prototype.setCollision = function (collision, resetCollisions, separateX, separateY) {
- if(resetCollisions) {
- this.resetCollision();
- }
- this.separateX = separateX;
- this.separateY = separateY;
- this.allowCollisions = collision;
- if(collision & Phaser.Types.ANY) {
- this.collideLeft = true;
- this.collideRight = true;
- this.collideUp = true;
- this.collideDown = true;
- return;
- }
- if(collision & Phaser.Types.LEFT || collision & Phaser.Types.WALL) {
- this.collideLeft = true;
- }
- if(collision & Phaser.Types.RIGHT || collision & Phaser.Types.WALL) {
- this.collideRight = true;
- }
- if(collision & Phaser.Types.UP || collision & Phaser.Types.CEILING) {
- this.collideUp = true;
- }
- if(collision & Phaser.Types.DOWN || collision & Phaser.Types.CEILING) {
- this.collideDown = true;
- }
- };
- Tile.prototype.resetCollision = function () {
- this.allowCollisions = Phaser.Types.NONE;
- this.collideLeft = false;
- this.collideRight = false;
- this.collideUp = false;
- this.collideDown = false;
- };
- Tile.prototype.toString = function () {
- return "[{Tile (index=" + this.index + " collisions=" + this.allowCollisions + " width=" + this.width + " height=" + this.height + ")}]";
- };
- return Tile;
- })();
- Phaser.Tile = Tile;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Tilemap = (function () {
- function Tilemap(game, key, mapData, format, resizeWorld, tileWidth, tileHeight) {
- if (typeof resizeWorld === "undefined") { resizeWorld = true; }
- if (typeof tileWidth === "undefined") { tileWidth = 0; }
- if (typeof tileHeight === "undefined") { tileHeight = 0; }
- this.z = -1;
- this.renderOrderID = 0;
- this.collisionCallback = null;
- this.game = game;
- this.type = Phaser.Types.TILEMAP;
- this.exists = true;
- this.active = true;
- this.visible = true;
- this.alive = true;
- this.z = -1;
- this.group = null;
- this.name = '';
- this.texture = new Phaser.Display.Texture(this);
- this.transform = new Phaser.Components.TransformManager(this);
- this.tiles = [];
- this.layers = [];
- this.mapFormat = format;
- switch(format) {
- case Tilemap.FORMAT_CSV:
- this.parseCSV(game.cache.getText(mapData), key, tileWidth, tileHeight);
- break;
- case Tilemap.FORMAT_TILED_JSON:
- this.parseTiledJSON(game.cache.getText(mapData), key);
- break;
- }
- if(this.currentLayer && resizeWorld) {
- this.game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
- }
- }
- Tilemap.FORMAT_CSV = 0;
- Tilemap.FORMAT_TILED_JSON = 1;
- Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) {
- var layer = new Phaser.TilemapLayer(this, 0, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
- data = data.trim();
- var rows = data.split("\n");
- for(var i = 0; i < rows.length; i++) {
- var column = rows[i].split(",");
- if(column.length > 0) {
- layer.addColumn(column);
- }
- }
- layer.updateBounds();
- var tileQuantity = layer.parseTileOffsets();
- this.currentLayer = layer;
- this.collisionLayer = layer;
- this.layers.push(layer);
- this.generateTiles(tileQuantity);
- };
- Tilemap.prototype.parseTiledJSON = function (data, key) {
- data = data.trim();
- var json = JSON.parse(data);
- for(var i = 0; i < json.layers.length; i++) {
- var layer = new Phaser.TilemapLayer(this, i, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
- if(!json.layers[i].data) {
- continue;
- }
- layer.alpha = json.layers[i].opacity;
- layer.visible = json.layers[i].visible;
- layer.tileMargin = json.tilesets[0].margin;
- layer.tileSpacing = json.tilesets[0].spacing;
- var c = 0;
- var row;
- for(var t = 0; t < json.layers[i].data.length; t++) {
- if(c == 0) {
- row = [];
- }
- row.push(json.layers[i].data[t]);
- c++;
- if(c == json.layers[i].width) {
- layer.addColumn(row);
- c = 0;
- }
- }
- layer.updateBounds();
- var tileQuantity = layer.parseTileOffsets();
- this.currentLayer = layer;
- this.collisionLayer = layer;
- this.layers.push(layer);
- }
- this.generateTiles(tileQuantity);
- };
- Tilemap.prototype.generateTiles = function (qty) {
- for(var i = 0; i < qty; i++) {
- this.tiles.push(new Phaser.Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
- }
- };
- Object.defineProperty(Tilemap.prototype, "widthInPixels", {
- get: function () {
- return this.currentLayer.widthInPixels;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Tilemap.prototype, "heightInPixels", {
- get: function () {
- return this.currentLayer.heightInPixels;
- },
- enumerable: true,
- configurable: true
- });
- Tilemap.prototype.setCollisionCallback = function (context, callback) {
- this.collisionCallbackContext = context;
- this.collisionCallback = callback;
- };
- Tilemap.prototype.setCollisionRange = function (start, end, collision, resetCollisions, separateX, separateY) {
- if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
- if (typeof resetCollisions === "undefined") { resetCollisions = false; }
- if (typeof separateX === "undefined") { separateX = true; }
- if (typeof separateY === "undefined") { separateY = true; }
- for(var i = start; i < end; i++) {
- this.tiles[i].setCollision(collision, resetCollisions, separateX, separateY);
- }
- };
- Tilemap.prototype.setCollisionByIndex = function (values, collision, resetCollisions, separateX, separateY) {
- if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
- if (typeof resetCollisions === "undefined") { resetCollisions = false; }
- if (typeof separateX === "undefined") { separateX = true; }
- if (typeof separateY === "undefined") { separateY = true; }
- for(var i = 0; i < values.length; i++) {
- this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
- }
- };
- Tilemap.prototype.getTileByIndex = function (value) {
- if(this.tiles[value]) {
- return this.tiles[value];
- }
- return null;
- };
- Tilemap.prototype.getTile = function (x, y, layer) {
- if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
- return this.tiles[this.layers[layer].getTileIndex(x, y)];
- };
- Tilemap.prototype.getTileFromWorldXY = function (x, y, layer) {
- if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
- return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
- };
- Tilemap.prototype.getTileFromInputXY = function (layer) {
- if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
- return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.worldX, this.game.input.worldY)];
- };
- Tilemap.prototype.getTileOverlaps = function (object) {
- return this.currentLayer.getTileOverlaps(object);
- };
- Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
- if (typeof objectOrGroup === "undefined") { objectOrGroup = null; }
- if (typeof callback === "undefined") { callback = null; }
- if (typeof context === "undefined") { context = null; }
- if(callback !== null && context !== null) {
- this.collisionCallback = callback;
- this.collisionCallbackContext = context;
- }
- if(objectOrGroup == null) {
- objectOrGroup = this.game.world.group;
- }
- if(objectOrGroup.isGroup == false) {
- this.collideGameObject(objectOrGroup);
- } else {
- objectOrGroup.forEachAlive(this, this.collideGameObject, true);
- }
- };
- Tilemap.prototype.collideGameObject = function (object) {
- if(object.body.type == Phaser.Types.BODY_DYNAMIC && object.exists == true && object.body.allowCollisions != Phaser.Types.NONE) {
- this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
- if(this.collisionCallback !== null && this._tempCollisionData.length > 0) {
- this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData);
- }
- return true;
- } else {
- return false;
- }
- };
- Tilemap.prototype.putTile = function (x, y, index, layer) {
- if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
- this.layers[layer].putTile(x, y, index);
- };
- Tilemap.prototype.preUpdate = function () {
- };
- Tilemap.prototype.update = function () {
- };
- Tilemap.prototype.postUpdate = function () {
- };
- Tilemap.prototype.destroy = function () {
- this.texture = null;
- this.transform = null;
- this.tiles.length = 0;
- this.layers.length = 0;
- };
- return Tilemap;
- })();
- Phaser.Tilemap = Tilemap;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var TilemapLayer = (function () {
- function TilemapLayer(parent, id, key, mapFormat, name, tileWidth, tileHeight) {
- this.exists = true;
- this.visible = true;
- this.widthInTiles = 0;
- this.heightInTiles = 0;
- this.widthInPixels = 0;
- this.heightInPixels = 0;
- this.tileMargin = 0;
- this.tileSpacing = 0;
- this.parent = parent;
- this.game = parent.game;
- this.ID = id;
- this.name = name;
- this.mapFormat = mapFormat;
- this.tileWidth = tileWidth;
- this.tileHeight = tileHeight;
- this.boundsInTiles = new Phaser.Rectangle();
- this.texture = new Phaser.Display.Texture(this);
- this.transform = new Phaser.Components.TransformManager(this);
- if(key !== null) {
- this.texture.loadImage(key, false);
- } else {
- this.texture.opaque = true;
- }
- this.alpha = this.texture.alpha;
- this.mapData = [];
- this._tempTileBlock = [];
- }
- TilemapLayer.prototype.putTileWorldXY = function (x, y, index) {
- 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;
- }
- }
- };
- TilemapLayer.prototype.putTile = function (x, y, index) {
- if(y >= 0 && y < this.mapData.length) {
- if(x >= 0 && x < this.mapData[y].length) {
- this.mapData[y][x] = index;
- }
- }
- };
- TilemapLayer.prototype.swapTile = function (tileA, tileB, x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = this.widthInTiles; }
- if (typeof height === "undefined") { height = this.heightInTiles; }
- this.getTempBlock(x, y, width, height);
- for(var r = 0; r < this._tempTileBlock.length; r++) {
- if(this._tempTileBlock[r].tile.index == tileA) {
- this._tempTileBlock[r].newIndex = true;
- }
- if(this._tempTileBlock[r].tile.index == tileB) {
- this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileA;
- }
- }
- for(var r = 0; r < this._tempTileBlock.length; r++) {
- if(this._tempTileBlock[r].newIndex == true) {
- this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
- }
- }
- };
- TilemapLayer.prototype.fillTile = function (index, x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = this.widthInTiles; }
- 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] = index;
- }
- };
- TilemapLayer.prototype.randomiseTiles = function (tiles, x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = this.widthInTiles; }
- 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);
- }
- };
- TilemapLayer.prototype.replaceTile = function (tileA, tileB, x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = this.widthInTiles; }
- if (typeof height === "undefined") { height = this.heightInTiles; }
- this.getTempBlock(x, y, width, height);
- for(var r = 0; r < this._tempTileBlock.length; r++) {
- if(this._tempTileBlock[r].tile.index == tileA) {
- this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
- }
- }
- };
- TilemapLayer.prototype.getTileBlock = function (x, y, width, height) {
- var output = [];
- this.getTempBlock(x, y, width, height);
- for(var r = 0; r < this._tempTileBlock.length; r++) {
- output.push({
- x: this._tempTileBlock[r].x,
- y: this._tempTileBlock[r].y,
- tile: this._tempTileBlock[r].tile
- });
- }
- return output;
- };
- TilemapLayer.prototype.getTileFromWorldXY = function (x, y) {
- 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 = function (object) {
- if(object.body.bounds.x < 0 || object.body.bounds.x > this.widthInPixels || object.body.bounds.y < 0 || object.body.bounds.bottom > this.heightInPixels) {
- return;
- }
- 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._tempBlockResults = [];
- this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
- return this._tempBlockResults;
- };
- TilemapLayer.prototype.getTempBlock = function (x, y, width, height, collisionOnly) {
- if (typeof collisionOnly === "undefined") { collisionOnly = false; }
- if(x < 0) {
- x = 0;
- }
- if(y < 0) {
- y = 0;
- }
- if(width > this.widthInTiles) {
- width = this.widthInTiles;
- }
- if(height > this.heightInTiles) {
- height = this.heightInTiles;
- }
- this._tempTileBlock = [];
- for(var ty = y; ty < y + height; ty++) {
- for(var tx = x; tx < x + width; tx++) {
- if(collisionOnly) {
- 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]]
- });
- }
- } else {
- if(this.mapData[ty] && this.mapData[ty][tx]) {
- this._tempTileBlock.push({
- x: tx,
- y: ty,
- tile: this.parent.tiles[this.mapData[ty][tx]]
- });
- }
- }
- }
- }
- };
- TilemapLayer.prototype.getTileIndex = function (x, y) {
- if(y >= 0 && y < this.mapData.length) {
- if(x >= 0 && x < this.mapData[y].length) {
- return this.mapData[y][x];
- }
- }
- return null;
- };
- TilemapLayer.prototype.addColumn = function (column) {
- var data = [];
- for(var c = 0; c < column.length; c++) {
- data[c] = parseInt(column[c]);
- }
- if(this.widthInTiles == 0) {
- this.widthInTiles = data.length;
- this.widthInPixels = this.widthInTiles * this.tileWidth;
- }
- this.mapData.push(data);
- this.heightInTiles++;
- this.heightInPixels += this.tileHeight;
- };
- TilemapLayer.prototype.updateBounds = function () {
- this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
- };
- TilemapLayer.prototype.parseTileOffsets = function () {
- this.tileOffsets = [];
- var i = 0;
- if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) {
- 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] = {
- x: tx,
- y: ty
- };
- i++;
- }
- }
- return this.tileOffsets.length;
- };
- return TilemapLayer;
- })();
- Phaser.TilemapLayer = TilemapLayer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- var PhysicsManager = (function () {
- function PhysicsManager(game) {
- this._length = 0;
- this.grav = 0.2;
- this.drag = 1;
- this.bounce = 0.3;
- this.friction = 0.05;
- this.min_f = 0;
- this.max_f = 1;
- this.min_b = 0;
- this.max_b = 1;
- this.min_g = 0;
- this.max_g = 1;
- this.xmin = 0;
- this.xmax = 800;
- this.ymin = 0;
- this.ymax = 600;
- this.objrad = 24;
- this.tilerad = 24 * 2;
- this.objspeed = 0.2;
- this.maxspeed = 20;
- this.game = game;
- }
- PhysicsManager.prototype.update = function () {
- };
- PhysicsManager.prototype.updateMotion = function (body) {
- this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
- body.angularVelocity += this._velocityDelta;
- body.sprite.transform.rotation += body.angularVelocity * this.game.time.physicsElapsed;
- body.angularVelocity += this._velocityDelta;
- this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
- body.velocity.x += this._velocityDelta;
- this._delta = body.velocity.x * this.game.time.physicsElapsed;
- body.aabb.pos.x += this._delta;
- body.deltaX = this._delta;
- this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
- body.velocity.y += this._velocityDelta;
- this._delta = body.velocity.y * this.game.time.physicsElapsed;
- body.aabb.pos.y += this._delta;
- body.deltaY = this._delta;
- };
- PhysicsManager.prototype.computeVelocity = function (velocity, gravity, acceleration, drag, max) {
- if (typeof gravity === "undefined") { gravity = 0; }
- if (typeof acceleration === "undefined") { acceleration = 0; }
- if (typeof drag === "undefined") { drag = 0; }
- if (typeof max === "undefined") { max = 10000; }
- if(acceleration !== 0) {
- velocity += (acceleration + gravity) * this.game.time.physicsElapsed;
- } else if(drag !== 0) {
- this._drag = drag * this.game.time.physicsElapsed;
- if(velocity - this._drag > 0) {
- velocity = velocity - this._drag;
- } else if(velocity + this._drag < 0) {
- velocity += this._drag;
- } else {
- velocity = 0;
- }
- }
- velocity += gravity;
- if(velocity != 0) {
- if(velocity > max) {
- velocity = max;
- } else if(velocity < -max) {
- velocity = -max;
- }
- }
- return velocity;
- };
- return PhysicsManager;
- })();
- Physics.PhysicsManager = PhysicsManager;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- var Body = (function () {
- function Body(sprite, type) {
- this.angularVelocity = 0;
- this.angularAcceleration = 0;
- this.angularDrag = 0;
- this.maxAngular = 10000;
- this.deltaX = 0;
- this.deltaY = 0;
- this.sprite = sprite;
- this.game = sprite.game;
- this.type = type;
- this.aabb = new Phaser.Physics.AABB(sprite.game, sprite.x, sprite.y, sprite.width, sprite.height);
- this.velocity = new Phaser.Vec2();
- this.acceleration = new Phaser.Vec2();
- this.drag = new Phaser.Vec2();
- this.gravity = new Phaser.Vec2();
- this.maxVelocity = new Phaser.Vec2(10000, 10000);
- this.angularVelocity = 0;
- this.angularAcceleration = 0;
- this.angularDrag = 0;
- this.maxAngular = 10000;
- this.allowCollisions = Phaser.Types.ANY;
- }
- return Body;
- })();
- Physics.Body = Body;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- var AABB = (function () {
- function AABB(game, x, y, width, height) {
- this.type = 0;
- this._vx = 0;
- this._vy = 0;
- this._deltaX = 0;
- this._deltaY = 0;
- this.game = game;
- this.pos = new Phaser.Vec2(x, y);
- this.oldpos = new Phaser.Vec2(x, y);
- this.width = Math.abs(width);
- this.height = Math.abs(height);
- this.velocity = new Phaser.Vec2();
- this.acceleration = new Phaser.Vec2();
- this.bounce = new Phaser.Vec2(0, 0);
- this.drag = new Phaser.Vec2(0, 0);
- this.gravity = new Phaser.Vec2(0, 2);
- this.maxVelocity = new Phaser.Vec2(1000, 1000);
- this.aabbTileProjections = {
- };
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.AABB22Deg.CollideS;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.AABB22Deg.CollideB;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.AABB45Deg.Collide;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.AABB67Deg.CollideS;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.AABB67Deg.CollideB;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.AABBConcave.Collide;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.AABBConvex.Collide;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.AABBFull.Collide;
- this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.AABBHalf.Collide;
- }
- AABB.COL_NONE = 0;
- AABB.COL_AXIS = 1;
- AABB.COL_OTHER = 2;
- AABB.prototype.update = function () {
- this.oldpos.x = this.pos.x;
- this.oldpos.y = this.pos.y;
- this._vx = (this.game.physics.computeVelocity(this.velocity.x, this.gravity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
- this.velocity.x += this._vx;
- this._deltaX = this.velocity.x * this.game.time.physicsElapsed;
- this._vy = (this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
- this.velocity.y += this._vy;
- this._deltaY = this.velocity.y * this.game.time.physicsElapsed;
- this.pos.x += this._deltaX;
- this.pos.y += this._deltaY;
- };
- AABB.prototype.FFupdate = function () {
- this.oldpos.x = this.pos.x;
- this.oldpos.y = this.pos.y;
- if(this.acceleration.x != 0) {
- this.velocity.x += (this.acceleration.x / 1000 * this.game.time.delta);
- }
- if(this.acceleration.y != 0) {
- this.velocity.y += (this.acceleration.y / 1000 * this.game.time.delta);
- }
- this._vx = ((this.velocity.x / 1000) * this.game.time.delta);
- this._vy = ((this.velocity.y / 1000) * this.game.time.delta);
- if(this._vx != 0) {
- if(this.drag.x != 0) {
- this._vx * this.drag.x;
- }
- if(this.gravity.x != 0) {
- this._vx * this.gravity.x;
- }
- if(this.velocity.x > this.maxVelocity.x) {
- this.velocity.x = this.maxVelocity.x;
- } else if(this.velocity.x < -this.maxVelocity.x) {
- this.velocity.x = -this.maxVelocity.x;
- }
- }
- if(this._vy != 0) {
- if(this.drag.y != 0) {
- this._vy * this.drag.y;
- }
- if(this.gravity.y != 0) {
- this._vy * this.gravity.y;
- }
- if(this.velocity.y > this.maxVelocity.y) {
- this.velocity.y = this.maxVelocity.y;
- } else if(this.velocity.y < -this.maxVelocity.y) {
- this.velocity.y = -this.maxVelocity.y;
- }
- }
- this.pos.x += this._vx;
- this.pos.y += this._vy;
- };
- AABB.prototype.integrateVerlet = function () {
- var px = this.pos.x;
- var py = this.pos.y;
- var ox = this.oldpos.x;
- var oy = this.oldpos.y;
- this.oldpos.x = this.pos.x;
- this.oldpos.y = this.pos.y;
- this.pos.x += (this.drag.x * px) - (this.drag.x * ox) + this.gravity.x;
- this.pos.y += (this.drag.y * py) - (this.drag.y * oy) + this.gravity.y;
- };
- AABB.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
- if (typeof obj === "undefined") { obj = null; }
- var dp = (this._vx * dx + this._vy * dy);
- var nx = dp * dx;
- var ny = dp * dy;
- var tx = this._vx - nx;
- var ty = this._vy - ny;
- this.pos.x += px;
- this.pos.y += py;
- if(dp < 0) {
- this.velocity.x += nx;
- this.velocity.y += ny;
- if(dx !== 0) {
- }
- if(dy !== 0) {
- }
- }
- };
- AABB.prototype.collideAABBVsTile = function (tile) {
- var pos = this.pos;
- var c = tile;
- var tx = c.pos.x;
- var ty = c.pos.y;
- var txw = c.xw;
- var tyw = c.yw;
- var dx = pos.x - tx;
- var px = (txw + this.width) - Math.abs(dx);
- if(0 < px) {
- var dy = pos.y - ty;
- var py = (tyw + this.height) - Math.abs(dy);
- if(0 < py) {
- if(px < py) {
- if(dx < 0) {
- px *= -1;
- py = 0;
- } else {
- py = 0;
- }
- } else {
- if(dy < 0) {
- px = 0;
- py *= -1;
- } else {
- px = 0;
- }
- }
- this.resolveBoxTile(px, py, this, c);
- }
- }
- };
- AABB.prototype.collideAABBVsWorldBounds = function () {
- var p = this.pos;
- var xw = this.width;
- var yw = this.height;
- var XMIN = 0;
- var XMAX = 800;
- var YMIN = 0;
- var YMAX = 600;
- var dx = XMIN - (p.x - xw);
- if(0 < dx) {
- this.reportCollisionVsWorld(dx, 0, 1, 0, null);
- } else {
- dx = (p.x + xw) - XMAX;
- if(0 < dx) {
- this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
- }
- }
- var dy = YMIN - (p.y - yw);
- if(0 < dy) {
- this.reportCollisionVsWorld(0, dy, 0, 1, null);
- } else {
- dy = (p.y + yw) - YMAX;
- if(0 < dy) {
- this.reportCollisionVsWorld(0, -dy, 0, -1, null);
- }
- }
- };
- AABB.prototype.resolveBoxTile = function (x, y, box, t) {
- if(0 < t.ID) {
- return this.aabbTileProjections[t.CTYPE](x, y, box, t);
- } else {
- return false;
- }
- };
- AABB.prototype.render = function (context) {
- context.beginPath();
- context.strokeStyle = 'rgb(0,255,0)';
- context.strokeRect(this.pos.x - this.width, this.pos.y - this.height, this.width * 2, this.height * 2);
- context.stroke();
- context.closePath();
- context.fillStyle = 'rgb(0,255,0)';
- context.fillRect(this.pos.x, this.pos.y, 2, 2);
- };
- return AABB;
- })();
- Physics.AABB = AABB;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- var Circle = (function () {
- function Circle(game, x, y, radius) {
- this.type = 1;
- this.game = game;
- this.pos = new Phaser.Vec2(x, y);
- this.oldpos = new Phaser.Vec2(x, y);
- this.radius = radius;
- this.circleTileProjections = {
- };
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.Circle22Deg.CollideS;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.Circle22Deg.CollideB;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.Circle45Deg.Collide;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.Circle67Deg.CollideS;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.Circle67Deg.CollideB;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.CircleConcave.Collide;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.CircleConvex.Collide;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.CircleFull.Collide;
- this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.CircleHalf.Collide;
- }
- Circle.COL_NONE = 0;
- Circle.COL_AXIS = 1;
- Circle.COL_OTHER = 2;
- Circle.prototype.integrateVerlet = function () {
- var d = 1;
- var g = 0.2;
- var p = this.pos;
- var o = this.oldpos;
- var px;
- var py;
- var ox = o.x;
- var oy = o.y;
- o.x = px = p.x;
- o.y = py = p.y;
- p.x += (d * px) - (d * ox);
- p.y += (d * py) - (d * oy) + g;
- };
- Circle.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
- if (typeof obj === "undefined") { obj = null; }
- var p = this.pos;
- var o = this.oldpos;
- var vx = p.x - o.x;
- var vy = p.y - o.y;
- var dp = (vx * dx + vy * dy);
- var nx = dp * dx;
- var ny = dp * dy;
- var tx = vx - nx;
- var ty = vy - ny;
- var b, bx, by, f, fx, fy;
- if(dp < 0) {
- f = 0.05;
- fx = tx * f;
- fy = ty * f;
- b = 1 + 0.3;
- bx = (nx * b);
- by = (ny * b);
- } else {
- bx = by = fx = fy = 0;
- }
- p.x += px;
- p.y += py;
- o.x += px + bx + fx;
- o.y += py + by + fy;
- };
- Circle.prototype.collideCircleVsWorldBounds = function () {
- var p = this.pos;
- var r = this.radius;
- var XMIN = 0;
- var XMAX = 800;
- var YMIN = 0;
- var YMAX = 600;
- var dx = XMIN - (p.x - r);
- if(0 < dx) {
- this.reportCollisionVsWorld(dx, 0, 1, 0, null);
- } else {
- dx = (p.x + r) - XMAX;
- if(0 < dx) {
- this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
- }
- }
- var dy = YMIN - (p.y - r);
- if(0 < dy) {
- this.reportCollisionVsWorld(0, dy, 0, 1, null);
- } else {
- dy = (p.y + r) - YMAX;
- if(0 < dy) {
- this.reportCollisionVsWorld(0, -dy, 0, -1, null);
- }
- }
- };
- Circle.prototype.render = function (context) {
- context.beginPath();
- context.strokeStyle = 'rgb(0,255,0)';
- context.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2);
- context.stroke();
- context.closePath();
- if(this.oH == 1) {
- context.beginPath();
- context.strokeStyle = 'rgb(255,0,0)';
- context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
- context.lineTo(this.pos.x - this.radius, this.pos.y + this.radius);
- context.stroke();
- context.closePath();
- } else if(this.oH == -1) {
- context.beginPath();
- context.strokeStyle = 'rgb(255,0,0)';
- context.moveTo(this.pos.x + this.radius, this.pos.y - this.radius);
- context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
- context.stroke();
- context.closePath();
- }
- if(this.oV == 1) {
- context.beginPath();
- context.strokeStyle = 'rgb(255,0,0)';
- context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
- context.lineTo(this.pos.x + this.radius, this.pos.y - this.radius);
- context.stroke();
- context.closePath();
- } else if(this.oV == -1) {
- context.beginPath();
- context.strokeStyle = 'rgb(255,0,0)';
- context.moveTo(this.pos.x - this.radius, this.pos.y + this.radius);
- context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
- context.stroke();
- context.closePath();
- }
- };
- Circle.prototype.collideCircleVsTile = function (tile) {
- var pos = this.pos;
- var r = this.radius;
- var c = tile;
- var tx = c.pos.x;
- var ty = c.pos.y;
- var txw = c.xw;
- var tyw = c.yw;
- var dx = pos.x - tx;
- var px = (txw + r) - Math.abs(dx);
- if(0 < px) {
- var dy = pos.y - ty;
- var py = (tyw + r) - Math.abs(dy);
- if(0 < py) {
- this.oH = 0;
- this.oV = 0;
- if(dx < -txw) {
- this.oH = -1;
- } else if(txw < dx) {
- this.oH = 1;
- }
- if(dy < -tyw) {
- this.oV = -1;
- } else if(tyw < dy) {
- this.oV = 1;
- }
- this.resolveCircleTile(px, py, this.oH, this.oV, this, c);
- }
- }
- };
- Circle.prototype.resolveCircleTile = function (x, y, oH, oV, obj, t) {
- if(0 < t.ID) {
- return this.circleTileProjections[t.CTYPE](x, y, oH, oV, obj, t);
- } else {
- console.log("resolveCircleTile() was called with an empty (or unknown) tile!: ID=" + t.ID + " (" + t.i + "," + t.j + ")");
- return false;
- }
- };
- return Circle;
- })();
- Physics.Circle = Circle;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- var TileMapCell = (function () {
- function TileMapCell(game, x, y, xw, yw) {
- this.game = game;
- this.ID = TileMapCell.TID_EMPTY;
- this.CTYPE = TileMapCell.CTYPE_EMPTY;
- this.pos = new Phaser.Vec2(x, y);
- this.xw = xw;
- this.yw = yw;
- this.minx = this.pos.x - this.xw;
- this.maxx = this.pos.x + this.xw;
- this.miny = this.pos.y - this.yw;
- this.maxy = this.pos.y + this.yw;
- this.signx = 0;
- this.signy = 0;
- this.sx = 0;
- this.sy = 0;
- }
- TileMapCell.TID_EMPTY = 0;
- TileMapCell.TID_FULL = 1;
- TileMapCell.TID_45DEGpn = 2;
- TileMapCell.TID_45DEGnn = 3;
- TileMapCell.TID_45DEGnp = 4;
- TileMapCell.TID_45DEGpp = 5;
- TileMapCell.TID_CONCAVEpn = 6;
- TileMapCell.TID_CONCAVEnn = 7;
- TileMapCell.TID_CONCAVEnp = 8;
- TileMapCell.TID_CONCAVEpp = 9;
- TileMapCell.TID_CONVEXpn = 10;
- TileMapCell.TID_CONVEXnn = 11;
- TileMapCell.TID_CONVEXnp = 12;
- TileMapCell.TID_CONVEXpp = 13;
- TileMapCell.TID_22DEGpnS = 14;
- TileMapCell.TID_22DEGnnS = 15;
- TileMapCell.TID_22DEGnpS = 16;
- TileMapCell.TID_22DEGppS = 17;
- TileMapCell.TID_22DEGpnB = 18;
- TileMapCell.TID_22DEGnnB = 19;
- TileMapCell.TID_22DEGnpB = 20;
- TileMapCell.TID_22DEGppB = 21;
- TileMapCell.TID_67DEGpnS = 22;
- TileMapCell.TID_67DEGnnS = 23;
- TileMapCell.TID_67DEGnpS = 24;
- TileMapCell.TID_67DEGppS = 25;
- TileMapCell.TID_67DEGpnB = 26;
- TileMapCell.TID_67DEGnnB = 27;
- TileMapCell.TID_67DEGnpB = 28;
- TileMapCell.TID_67DEGppB = 29;
- TileMapCell.TID_HALFd = 30;
- TileMapCell.TID_HALFr = 31;
- TileMapCell.TID_HALFu = 32;
- TileMapCell.TID_HALFl = 33;
- TileMapCell.CTYPE_EMPTY = 0;
- TileMapCell.CTYPE_FULL = 1;
- TileMapCell.CTYPE_45DEG = 2;
- TileMapCell.CTYPE_CONCAVE = 6;
- TileMapCell.CTYPE_CONVEX = 10;
- TileMapCell.CTYPE_22DEGs = 14;
- TileMapCell.CTYPE_22DEGb = 18;
- TileMapCell.CTYPE_67DEGs = 22;
- TileMapCell.CTYPE_67DEGb = 26;
- TileMapCell.CTYPE_HALF = 30;
- TileMapCell.prototype.SetState = function (ID) {
- if(ID == TileMapCell.TID_EMPTY) {
- this.Clear();
- } else {
- this.ID = ID;
- this.UpdateType();
- }
- return this;
- };
- TileMapCell.prototype.Clear = function () {
- this.ID = TileMapCell.TID_EMPTY;
- this.UpdateType();
- };
- TileMapCell.prototype.render = function (context) {
- context.beginPath();
- context.strokeStyle = 'rgb(255,255,0)';
- context.strokeRect(this.minx, this.miny, this.xw * 2, this.yw * 2);
- context.strokeRect(this.pos.x, this.pos.y, 2, 2);
- context.closePath();
- };
- TileMapCell.prototype.UpdateType = function () {
- if(0 < this.ID) {
- if(this.ID < TileMapCell.CTYPE_45DEG) {
- this.CTYPE = TileMapCell.CTYPE_FULL;
- this.signx = 0;
- this.signy = 0;
- this.sx = 0;
- this.sy = 0;
- } else if(this.ID < TileMapCell.CTYPE_CONCAVE) {
- this.CTYPE = TileMapCell.CTYPE_45DEG;
- if(this.ID == TileMapCell.TID_45DEGpn) {
- console.log('set tile as 45deg pn');
- this.signx = 1;
- this.signy = -1;
- this.sx = this.signx / Math.SQRT2;
- this.sy = this.signy / Math.SQRT2;
- } else if(this.ID == TileMapCell.TID_45DEGnn) {
- this.signx = -1;
- this.signy = -1;
- this.sx = this.signx / Math.SQRT2;
- this.sy = this.signy / Math.SQRT2;
- } else if(this.ID == TileMapCell.TID_45DEGnp) {
- this.signx = -1;
- this.signy = 1;
- this.sx = this.signx / Math.SQRT2;
- this.sy = this.signy / Math.SQRT2;
- } else if(this.ID == TileMapCell.TID_45DEGpp) {
- this.signx = 1;
- this.signy = 1;
- this.sx = this.signx / Math.SQRT2;
- this.sy = this.signy / Math.SQRT2;
- } else {
- return false;
- }
- } else if(this.ID < TileMapCell.CTYPE_CONVEX) {
- this.CTYPE = TileMapCell.CTYPE_CONCAVE;
- if(this.ID == TileMapCell.TID_CONCAVEpn) {
- this.signx = 1;
- this.signy = -1;
- this.sx = 0;
- this.sy = 0;
- } else if(this.ID == TileMapCell.TID_CONCAVEnn) {
- this.signx = -1;
- this.signy = -1;
- this.sx = 0;
- this.sy = 0;
- } else if(this.ID == TileMapCell.TID_CONCAVEnp) {
- this.signx = -1;
- this.signy = 1;
- this.sx = 0;
- this.sy = 0;
- } else if(this.ID == TileMapCell.TID_CONCAVEpp) {
- this.signx = 1;
- this.signy = 1;
- this.sx = 0;
- this.sy = 0;
- } else {
- return false;
- }
- } else if(this.ID < TileMapCell.CTYPE_22DEGs) {
- this.CTYPE = TileMapCell.CTYPE_CONVEX;
- if(this.ID == TileMapCell.TID_CONVEXpn) {
- this.signx = 1;
- this.signy = -1;
- this.sx = 0;
- this.sy = 0;
- } else if(this.ID == TileMapCell.TID_CONVEXnn) {
- this.signx = -1;
- this.signy = -1;
- this.sx = 0;
- this.sy = 0;
- } else if(this.ID == TileMapCell.TID_CONVEXnp) {
- this.signx = -1;
- this.signy = 1;
- this.sx = 0;
- this.sy = 0;
- } else if(this.ID == TileMapCell.TID_CONVEXpp) {
- this.signx = 1;
- this.signy = 1;
- this.sx = 0;
- this.sy = 0;
- } else {
- return false;
- }
- } else if(this.ID < TileMapCell.CTYPE_22DEGb) {
- this.CTYPE = TileMapCell.CTYPE_22DEGs;
- if(this.ID == TileMapCell.TID_22DEGpnS) {
- this.signx = 1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else if(this.ID == TileMapCell.TID_22DEGnnS) {
- this.signx = -1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else if(this.ID == TileMapCell.TID_22DEGnpS) {
- this.signx = -1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else if(this.ID == TileMapCell.TID_22DEGppS) {
- this.signx = 1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else {
- return false;
- }
- } else if(this.ID < TileMapCell.CTYPE_67DEGs) {
- this.CTYPE = TileMapCell.CTYPE_22DEGb;
- if(this.ID == TileMapCell.TID_22DEGpnB) {
- this.signx = 1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else if(this.ID == TileMapCell.TID_22DEGnnB) {
- this.signx = -1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else if(this.ID == TileMapCell.TID_22DEGnpB) {
- this.signx = -1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else if(this.ID == TileMapCell.TID_22DEGppB) {
- this.signx = 1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 1) / slen;
- this.sy = (this.signy * 2) / slen;
- } else {
- return false;
- }
- } else if(this.ID < TileMapCell.CTYPE_67DEGb) {
- this.CTYPE = TileMapCell.CTYPE_67DEGs;
- if(this.ID == TileMapCell.TID_67DEGpnS) {
- this.signx = 1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else if(this.ID == TileMapCell.TID_67DEGnnS) {
- this.signx = -1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else if(this.ID == TileMapCell.TID_67DEGnpS) {
- this.signx = -1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else if(this.ID == TileMapCell.TID_67DEGppS) {
- this.signx = 1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else {
- return false;
- }
- } else if(this.ID < TileMapCell.CTYPE_HALF) {
- this.CTYPE = TileMapCell.CTYPE_67DEGb;
- if(this.ID == TileMapCell.TID_67DEGpnB) {
- this.signx = 1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else if(this.ID == TileMapCell.TID_67DEGnnB) {
- this.signx = -1;
- this.signy = -1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else if(this.ID == TileMapCell.TID_67DEGnpB) {
- this.signx = -1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else if(this.ID == TileMapCell.TID_67DEGppB) {
- this.signx = 1;
- this.signy = 1;
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- this.sx = (this.signx * 2) / slen;
- this.sy = (this.signy * 1) / slen;
- } else {
- return false;
- }
- } else {
- this.CTYPE = TileMapCell.CTYPE_HALF;
- if(this.ID == TileMapCell.TID_HALFd) {
- this.signx = 0;
- this.signy = -1;
- this.sx = this.signx;
- this.sy = this.signy;
- } else if(this.ID == TileMapCell.TID_HALFu) {
- this.signx = 0;
- this.signy = 1;
- this.sx = this.signx;
- this.sy = this.signy;
- } else if(this.ID == TileMapCell.TID_HALFl) {
- this.signx = 1;
- this.signy = 0;
- this.sx = this.signx;
- this.sy = this.signy;
- } else if(this.ID == TileMapCell.TID_HALFr) {
- this.signx = -1;
- this.signy = 0;
- this.sx = this.signx;
- this.sy = this.signy;
- } else {
- return false;
- }
- }
- } else {
- this.CTYPE = TileMapCell.CTYPE_EMPTY;
- this.signx = 0;
- this.signy = 0;
- this.sx = 0;
- this.sy = 0;
- }
- };
- return TileMapCell;
- })();
- Physics.TileMapCell = TileMapCell;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var AABB22Deg = (function () {
- function AABB22Deg() { }
- AABB22Deg.CollideS = function CollideS(x, y, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var py = obj.pos.y - (signy * obj.height);
- var penY = t.pos.y - py;
- if(0 < (penY * signy)) {
- var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));
- var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
- var sx = t.sx;
- var sy = t.sy;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP = Math.sqrt(x * x + y * y);
- var aY = Math.abs(penY);
- if(lenP < lenN) {
- if(aY < lenP) {
- obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
- return Phaser.Physics.AABB.COL_OTHER;
- } else {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- }
- } else {
- if(aY < lenN) {
- obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
- return Phaser.Physics.AABB.COL_OTHER;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- }
- }
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- AABB22Deg.CollideB = function CollideB(x, y, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
- var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));
- var sx = t.sx;
- var sy = t.sy;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP = Math.sqrt(x * x + y * y);
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- return AABB22Deg;
- })();
- Projection.AABB22Deg = AABB22Deg;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var AABB45Deg = (function () {
- function AABB45Deg() { }
- AABB45Deg.Collide = function Collide(x, y, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var ox = (obj.pos.x - (signx * obj.width)) - t.pos.x;
- var oy = (obj.pos.y - (signy * obj.height)) - t.pos.y;
- var sx = t.sx;
- var sy = t.sy;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP = Math.sqrt(x * x + y * y);
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- return AABB45Deg;
- })();
- Projection.AABB45Deg = AABB45Deg;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var AABB67Deg = (function () {
- function AABB67Deg() { }
- AABB67Deg.CollideS = function CollideS(x, y, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var px = obj.pos.x - (signx * obj.width);
- var penX = t.pos.x - px;
- if(0 < (penX * signx)) {
- var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
- var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));
- var sx = t.sx;
- var sy = t.sy;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP = Math.sqrt(x * x + y * y);
- var aX = Math.abs(penX);
- if(lenP < lenN) {
- if(aX < lenP) {
- obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
- return Phaser.Physics.AABB.COL_OTHER;
- } else {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- }
- } else {
- if(aX < lenN) {
- obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
- return Phaser.Physics.AABB.COL_OTHER;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- }
- }
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- AABB67Deg.CollideB = function CollideB(x, y, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));
- var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
- var sx = t.sx;
- var sy = t.sy;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP = Math.sqrt(x * x + y * y);
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- return AABB67Deg;
- })();
- Projection.AABB67Deg = AABB67Deg;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var AABBConcave = (function () {
- function AABBConcave() { }
- AABBConcave.Collide = function Collide(x, y, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var ox = (t.pos.x + (signx * t.xw)) - (obj.pos.x - (signx * obj.width));
- var oy = (t.pos.y + (signy * t.yw)) - (obj.pos.y - (signy * obj.height));
- var twid = t.xw * 2;
- var rad = Math.sqrt(twid * twid + 0);
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = len - rad;
- if(0 < pen) {
- var lenP = Math.sqrt(x * x + y * y);
- if(lenP < pen) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- } else {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- return AABBConcave;
- })();
- Projection.AABBConcave = AABBConcave;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var AABBConvex = (function () {
- function AABBConvex() { }
- AABBConvex.Collide = function Collide(x, y, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
- var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
- var len = Math.sqrt(ox * ox + oy * oy);
- var twid = t.xw * 2;
- var rad = Math.sqrt(twid * twid + 0);
- var pen = rad - len;
- if(((signx * ox) < 0) || ((signy * oy) < 0)) {
- var lenP = Math.sqrt(x * x + y * y);
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- } else if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- return AABBConvex;
- })();
- Projection.AABBConvex = AABBConvex;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var AABBFull = (function () {
- function AABBFull() { }
- AABBFull.Collide = function Collide(x, y, obj, t) {
- var l = Math.sqrt(x * x + y * y);
- obj.reportCollisionVsWorld(x, y, x / l, y / l, t);
- return Phaser.Physics.AABB.COL_AXIS;
- };
- return AABBFull;
- })();
- Projection.AABBFull = AABBFull;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var AABBHalf = (function () {
- function AABBHalf() { }
- AABBHalf.Collide = function Collide(x, y, obj, t) {
- var sx = t.signx;
- var sy = t.signy;
- var ox = (obj.pos.x - (sx * obj.width)) - t.pos.x;
- var oy = (obj.pos.y - (sy * obj.height)) - t.pos.y;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP = Math.sqrt(x * x + y * y);
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.AABB.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy, t);
- return Phaser.Physics.AABB.COL_OTHER;
- }
- }
- return Phaser.Physics.AABB.COL_NONE;
- };
- return AABBHalf;
- })();
- Projection.AABBHalf = AABBHalf;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var Circle22Deg = (function () {
- function Circle22Deg() { }
- Circle22Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- if(0 < (signy * oV)) {
- return Phaser.Physics.Circle.COL_NONE;
- } else if(oH == 0) {
- if(oV == 0) {
- var sx = t.sx;
- var sy = t.sy;
- var r = obj.radius;
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - t.pos.y;
- var perp = (ox * -sy) + (oy * sx);
- if(0 < (perp * signx * signy)) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = r - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- ox -= r * sx;
- oy -= r * sy;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP;
- if(x < y) {
- lenP = x;
- y = 0;
- if((obj.pos.x - t.pos.x) < 0) {
- x *= -1;
- }
- } else {
- lenP = y;
- x = 0;
- if((obj.pos.y - t.pos.y) < 0) {
- y *= -1;
- }
- }
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- } else {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- }
- } else if(oV == 0) {
- if((signx * oH) < 0) {
- var vx = t.pos.x - (signx * t.xw);
- var vy = t.pos.y;
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- if((dy * signy) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- var sx = t.sx;
- var sy = t.sy;
- var ox = obj.pos.x - (t.pos.x + (oH * t.xw));
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var perp = (ox * -sy) + (oy * sx);
- if((perp * signx * signy) < 0) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- Circle22Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var sx;
- var sy;
- if(oH == 0) {
- if(oV == 0) {
- sx = t.sx;
- sy = t.sy;
- var r = obj.radius;
- var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));
- var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP;
- if(x < y) {
- lenP = x;
- y = 0;
- if((obj.pos.x - t.pos.x) < 0) {
- x *= -1;
- }
- } else {
- lenP = y;
- x = 0;
- if((obj.pos.y - t.pos.y) < 0) {
- y *= -1;
- }
- }
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- if((signy * oV) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- sx = t.sx;
- sy = t.sy;
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y + (signy * t.yw));
- var perp = (ox * -sy) + (oy * sx);
- if(0 < (perp * signx * signy)) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- }
- } else if(oV == 0) {
- if((signx * oH) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var ox = obj.pos.x - (t.pos.x + (signx * t.xw));
- var oy = obj.pos.y - t.pos.y;
- if((oy * signy) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- sx = t.sx;
- sy = t.sy;
- var perp = (ox * -sy) + (oy * sx);
- if((perp * signx * signy) < 0) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- }
- } else {
- if(0 < ((signx * oH) + (signy * oV))) {
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- sx = (signx * 1) / slen;
- sy = (signy * 2) / slen;
- var r = obj.radius;
- var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));
- var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- return Phaser.Physics.Circle.COL_NONE;
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- return Circle22Deg;
- })();
- Projection.Circle22Deg = Circle22Deg;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var Circle45Deg = (function () {
- function Circle45Deg() { }
- Circle45Deg.Collide = function Collide(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var lenP;
- if(oH == 0) {
- if(oV == 0) {
- var sx = t.sx;
- var sy = t.sy;
- var ox = (obj.pos.x - (sx * obj.radius)) - t.pos.x;
- var oy = (obj.pos.y - (sy * obj.radius)) - t.pos.y;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- if(x < y) {
- lenP = x;
- y = 0;
- if((obj.pos.x - t.pos.x) < 0) {
- x *= -1;
- }
- } else {
- lenP = y;
- x = 0;
- if((obj.pos.y - t.pos.y) < 0) {
- y *= -1;
- }
- }
- var lenN = Math.sqrt(sx * sx + sy * sy);
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- if((signy * oV) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var sx = t.sx;
- var sy = t.sy;
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y + (oV * t.yw));
- var perp = (ox * -sy) + (oy * sx);
- if(0 < (perp * signx * signy)) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- }
- } else if(oV == 0) {
- if((signx * oH) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var sx = t.sx;
- var sy = t.sy;
- var ox = obj.pos.x - (t.pos.x + (oH * t.xw));
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var perp = (ox * -sy) + (oy * sx);
- if((perp * signx * signy) < 0) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- } else {
- if(0 < ((signx * oH) + (signy * oV))) {
- return Phaser.Physics.Circle.COL_NONE;
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- return Circle45Deg;
- })();
- Projection.Circle45Deg = Circle45Deg;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var Circle67Deg = (function () {
- function Circle67Deg() { }
- Circle67Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var sx;
- var sy;
- if(0 < (signx * oH)) {
- return Phaser.Physics.Circle.COL_NONE;
- } else if(oH == 0) {
- if(oV == 0) {
- sx = t.sx;
- sy = t.sy;
- var r = obj.radius;
- var ox = obj.pos.x - t.pos.x;
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var perp = (ox * -sy) + (oy * sx);
- if((perp * signx * signy) < 0) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = r - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- ox -= r * sx;
- oy -= r * sy;
- var dp = (ox * sx) + (oy * sy);
- var lenP;
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- if(x < y) {
- lenP = x;
- y = 0;
- if((obj.pos.x - t.pos.x) < 0) {
- x *= -1;
- }
- } else {
- lenP = y;
- x = 0;
- if((obj.pos.y - t.pos.y) < 0) {
- y *= -1;
- }
- }
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- } else {
- if((signy * oV) < 0) {
- var vx = t.pos.x;
- var vy = t.pos.y - (signy * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- if((dx * signx) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- sx = t.sx;
- sy = t.sy;
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y + (oV * t.yw));
- var perp = (ox * -sy) + (oy * sx);
- if(0 < (perp * signx * signy)) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- }
- } else if(oV == 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- Circle67Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var sx;
- var sy;
- if(oH == 0) {
- if(oV == 0) {
- sx = t.sx;
- sy = t.sy;
- var r = obj.radius;
- var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));
- var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));
- var dp = (ox * sx) + (oy * sy);
- var lenP;
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- if(x < y) {
- lenP = x;
- y = 0;
- if((obj.pos.x - t.pos.x) < 0) {
- x *= -1;
- }
- } else {
- lenP = y;
- x = 0;
- if((obj.pos.y - t.pos.y) < 0) {
- y *= -1;
- }
- }
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- if((signy * oV) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var ox = obj.pos.x - t.pos.x;
- var oy = obj.pos.y - (t.pos.y + (signy * t.yw));
- if((ox * signx) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- sx = t.sx;
- sy = t.sy;
- var perp = (ox * -sy) + (oy * sx);
- if(0 < (perp * signx * signy)) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- }
- }
- } else if(oV == 0) {
- if((signx * oH) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var slen = Math.sqrt(2 * 2 + 1 * 1);
- var sx = (signx * 2) / slen;
- var sy = (signy * 1) / slen;
- var ox = obj.pos.x - (t.pos.x + (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var perp = (ox * -sy) + (oy * sx);
- if((perp * signx * signy) < 0) {
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = obj.radius - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var dp = (ox * sx) + (oy * sy);
- var pen = obj.radius - Math.abs(dp);
- if(0 < pen) {
- obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- } else {
- if(0 < ((signx * oH) + (signy * oV))) {
- sx = t.sx;
- sy = t.sy;
- var r = obj.radius;
- var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));
- var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- return Phaser.Physics.Circle.COL_NONE;
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- return Circle67Deg;
- })();
- Projection.Circle67Deg = Circle67Deg;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var CircleConcave = (function () {
- function CircleConcave() { }
- CircleConcave.Collide = function Collide(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var lenP;
- if(oH == 0) {
- if(oV == 0) {
- var ox = (t.pos.x + (signx * t.xw)) - obj.pos.x;
- var oy = (t.pos.y + (signy * t.yw)) - obj.pos.y;
- var twid = t.xw * 2;
- var trad = Math.sqrt(twid * twid + 0);
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = (len + obj.radius) - trad;
- if(0 < pen) {
- if(x < y) {
- lenP = x;
- y = 0;
- if((obj.pos.x - t.pos.x) < 0) {
- x *= -1;
- }
- } else {
- lenP = y;
- x = 0;
- if((obj.pos.y - t.pos.y) < 0) {
- y *= -1;
- }
- }
- if(lenP < pen) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- return Phaser.Physics.Circle.COL_NONE;
- }
- } else {
- if((signy * oV) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var vx = t.pos.x - (signx * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = 0;
- dy = oV;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- } else if(oV == 0) {
- if((signx * oH) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y - (signy * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH;
- dy = 0;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- if(0 < ((signx * oH) + (signy * oV))) {
- return Phaser.Physics.Circle.COL_NONE;
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- return CircleConcave;
- })();
- Projection.CircleConcave = CircleConcave;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var CircleConvex = (function () {
- function CircleConvex() { }
- CircleConvex.Collide = function Collide(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var lenP;
- if(oH == 0) {
- if(oV == 0) {
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var twid = t.xw * 2;
- var trad = Math.sqrt(twid * twid + 0);
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = (trad + obj.radius) - len;
- if(0 < pen) {
- if(x < y) {
- lenP = x;
- y = 0;
- if((obj.pos.x - t.pos.x) < 0) {
- x *= -1;
- }
- } else {
- lenP = y;
- x = 0;
- if((obj.pos.y - t.pos.y) < 0) {
- y *= -1;
- }
- }
- if(lenP < pen) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- if((signy * oV) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var twid = t.xw * 2;
- var trad = Math.sqrt(twid * twid + 0);
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = (trad + obj.radius) - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- } else if(oV == 0) {
- if((signx * oH) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var twid = t.xw * 2;
- var trad = Math.sqrt(twid * twid + 0);
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = (trad + obj.radius) - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- if(0 < ((signx * oH) + (signy * oV))) {
- var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
- var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
- var twid = t.xw * 2;
- var trad = Math.sqrt(twid * twid + 0);
- var len = Math.sqrt(ox * ox + oy * oy);
- var pen = (trad + obj.radius) - len;
- if(0 < pen) {
- ox /= len;
- oy /= len;
- obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- return CircleConvex;
- })();
- Projection.CircleConvex = CircleConvex;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var CircleFull = (function () {
- function CircleFull() { }
- CircleFull.Collide = function Collide(x, y, oH, oV, obj, t) {
- if(oH == 0) {
- if(oV == 0) {
- if(x < y) {
- var dx = obj.pos.x - t.pos.x;
- if(dx < 0) {
- obj.reportCollisionVsWorld(-x, 0, -1, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(x, 0, 1, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- }
- } else {
- var dy = obj.pos.y - t.pos.y;
- if(dy < 0) {
- obj.reportCollisionVsWorld(0, -y, 0, -1, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(0, y, 0, 1, t);
- return Phaser.Physics.Circle.COL_AXIS;
- }
- }
- } else {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- }
- } else if(oV == 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- return CircleFull;
- })();
- Projection.CircleFull = CircleFull;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Physics) {
- (function (Projection) {
- var CircleHalf = (function () {
- function CircleHalf() { }
- CircleHalf.Collide = function Collide(x, y, oH, oV, obj, t) {
- var signx = t.signx;
- var signy = t.signy;
- var celldp = (oH * signx + oV * signy);
- if(0 < celldp) {
- return Phaser.Physics.Circle.COL_NONE;
- } else if(oH == 0) {
- if(oV == 0) {
- var r = obj.radius;
- var ox = (obj.pos.x - (signx * r)) - t.pos.x;
- var oy = (obj.pos.y - (signy * r)) - t.pos.y;
- var sx = signx;
- var sy = signy;
- var dp = (ox * sx) + (oy * sy);
- if(dp < 0) {
- sx *= -dp;
- sy *= -dp;
- var lenN = Math.sqrt(sx * sx + sy * sy);
- var lenP = Math.sqrt(x * x + y * y);
- if(lenP < lenN) {
- obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- if(celldp == 0) {
- var r = obj.radius;
- var dx = obj.pos.x - t.pos.x;
- if((dx * signx) < 0) {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var dy = obj.pos.y - (t.pos.y + oV * t.yw);
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = signx / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
- return Phaser.Physics.Circle.COL_AXIS;
- }
- }
- } else if(oV == 0) {
- if(celldp == 0) {
- var r = obj.radius;
- var dy = obj.pos.y - t.pos.y;
- if((dy * signy) < 0) {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- } else {
- var dx = obj.pos.x - (t.pos.x + oH * t.xw);
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = signx / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- } else {
- obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
- return Phaser.Physics.Circle.COL_AXIS;
- }
- } else {
- var vx = t.pos.x + (oH * t.xw);
- var vy = t.pos.y + (oV * t.yw);
- var dx = obj.pos.x - vx;
- var dy = obj.pos.y - vy;
- var len = Math.sqrt(dx * dx + dy * dy);
- var pen = obj.radius - len;
- if(0 < pen) {
- if(len == 0) {
- dx = oH / Math.SQRT2;
- dy = oV / Math.SQRT2;
- } else {
- dx /= len;
- dy /= len;
- }
- obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
- return Phaser.Physics.Circle.COL_OTHER;
- }
- }
- return Phaser.Physics.Circle.COL_NONE;
- };
- return CircleHalf;
- })();
- Projection.CircleHalf = CircleHalf;
- })(Physics.Projection || (Physics.Projection = {}));
- var Projection = Physics.Projection;
- })(Phaser.Physics || (Phaser.Physics = {}));
- var Physics = Phaser.Physics;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Components) {
- var Events = (function () {
- function Events(parent) {
- this.game = parent.game;
- this._parent = parent;
- this.onAddedToGroup = new Phaser.Signal();
- this.onRemovedFromGroup = new Phaser.Signal();
- this.onKilled = new Phaser.Signal();
- this.onRevived = new Phaser.Signal();
- this.onOutOfBounds = new Phaser.Signal();
- }
- return Events;
- })();
- Components.Events = Events;
- })(Phaser.Components || (Phaser.Components = {}));
- var Components = Phaser.Components;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Sprite = (function () {
- function Sprite(game, x, y, key, frame) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof key === "undefined") { key = null; }
- if (typeof frame === "undefined") { frame = null; }
- this.modified = false;
- this.x = 0;
- this.y = 0;
- this.z = -1;
- this.renderOrderID = 0;
- this.game = game;
- this.type = Phaser.Types.SPRITE;
- this.exists = true;
- this.active = true;
- this.visible = true;
- this.alive = true;
- this.x = x;
- this.y = y;
- this.z = -1;
- this.group = null;
- this.name = '';
- this.events = new Phaser.Components.Events(this);
- this.animations = new Phaser.Components.AnimationManager(this);
- this.input = new Phaser.Components.InputHandler(this);
- this.texture = new Phaser.Display.Texture(this);
- this.transform = new Phaser.Components.TransformManager(this);
- if(key !== null) {
- this.texture.loadImage(key, false);
- } else {
- this.texture.opaque = true;
- }
- if(frame !== null) {
- if(typeof frame == 'string') {
- this.frameName = frame;
- } else {
- this.frame = frame;
- }
- }
- this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
- this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
- this.transform.setCache();
- this.outOfBounds = false;
- this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
- this.scale = this.transform.scale;
- this.alpha = this.texture.alpha;
- this.origin = this.transform.origin;
- this.crop = this.texture.crop;
- }
- Object.defineProperty(Sprite.prototype, "rotation", {
- get: function () {
- return this.transform.rotation;
- },
- set: function (value) {
- this.transform.rotation = this.game.math.wrap(value, 360, 0);
- if(this.body) {
- }
- },
- enumerable: true,
- configurable: true
- });
- Sprite.prototype.bringToTop = function () {
- if(this.group) {
- this.group.bringToTop(this);
- }
- };
- Object.defineProperty(Sprite.prototype, "alpha", {
- get: function () {
- return this.texture.alpha;
- },
- set: function (value) {
- this.texture.alpha = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Sprite.prototype, "frame", {
- get: function () {
- return this.animations.frame;
- },
- set: function (value) {
- this.animations.frame = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Sprite.prototype, "frameName", {
- get: function () {
- return this.animations.frameName;
- },
- set: function (value) {
- this.animations.frameName = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Sprite.prototype, "width", {
- get: function () {
- return this.texture.width * this.transform.scale.x;
- },
- set: function (value) {
- this.transform.scale.x = value / this.texture.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Sprite.prototype, "height", {
- get: function () {
- return this.texture.height * this.transform.scale.y;
- },
- set: function (value) {
- this.transform.scale.y = value / this.texture.height;
- },
- enumerable: true,
- configurable: true
- });
- Sprite.prototype.preUpdate = function () {
- this.transform.update();
- if(this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0) {
- this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
- } else {
- this.worldView.x = this.x - (this.width * this.transform.origin.x);
- }
- if(this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0) {
- this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
- } else {
- this.worldView.y = this.y - (this.height * this.transform.origin.y);
- }
- this.worldView.width = this.width;
- this.worldView.height = this.height;
- if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
- this.modified = true;
- }
- };
- Sprite.prototype.update = function () {
- };
- Sprite.prototype.postUpdate = function () {
- this.animations.update();
- this.checkBounds();
- if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
- this.modified = false;
- }
- };
- Sprite.prototype.checkBounds = function () {
- if(Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds)) {
- this.outOfBounds = false;
- } else {
- if(this.outOfBounds == false) {
- this.events.onOutOfBounds.dispatch(this);
- }
- this.outOfBounds = true;
- if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL) {
- this.kill();
- } else if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY) {
- this.destroy();
- }
- }
- };
- Sprite.prototype.destroy = function () {
- this.input.destroy();
- };
- Sprite.prototype.kill = function (removeFromGroup) {
- if (typeof removeFromGroup === "undefined") { removeFromGroup = false; }
- this.alive = false;
- this.exists = false;
- if(removeFromGroup && this.group) {
- }
- this.events.onKilled.dispatch(this);
- };
- Sprite.prototype.revive = function () {
- this.alive = true;
- this.exists = true;
- this.events.onRevived.dispatch(this);
- };
- return Sprite;
- })();
- Phaser.Sprite = Sprite;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Components) {
- var TransformManager = (function () {
- function TransformManager(parent) {
- this._dirty = false;
- this.rotationOffset = 0;
- this.rotation = 0;
- this.game = parent.game;
- this.parent = parent;
- this.local = new Phaser.Mat3();
- this.scrollFactor = new Phaser.Vec2(1, 1);
- this.origin = new Phaser.Vec2();
- this.scale = new Phaser.Vec2(1, 1);
- this.skew = new Phaser.Vec2();
- this.center = new Phaser.Point();
- this.upperLeft = new Phaser.Point();
- this.upperRight = new Phaser.Point();
- this.bottomLeft = new Phaser.Point();
- this.bottomRight = new Phaser.Point();
- this._pos = new Phaser.Point();
- this._scale = new Phaser.Point();
- this._size = new Phaser.Point();
- this._halfSize = new Phaser.Point();
- this._offset = new Phaser.Point();
- this._origin = new Phaser.Point();
- this._sc = new Phaser.Point();
- this._scA = new Phaser.Point();
- }
- Object.defineProperty(TransformManager.prototype, "distance", {
- get: function () {
- return this._distance;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TransformManager.prototype, "angleToCenter", {
- get: function () {
- return this._angle;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TransformManager.prototype, "offsetX", {
- get: function () {
- return this._offset.x;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TransformManager.prototype, "offsetY", {
- get: function () {
- return this._offset.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TransformManager.prototype, "halfWidth", {
- get: function () {
- return this._halfSize.x;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TransformManager.prototype, "halfHeight", {
- get: function () {
- return this._halfSize.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TransformManager.prototype, "sin", {
- get: function () {
- return this._sc.x;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(TransformManager.prototype, "cos", {
- get: function () {
- return this._sc.y;
- },
- enumerable: true,
- configurable: true
- });
- TransformManager.prototype.centerOn = function (x, y) {
- this.parent.x = x + (this.parent.x - this.center.x);
- this.parent.y = y + (this.parent.y - this.center.y);
- };
- TransformManager.prototype.setCache = function () {
- this._pos.x = this.parent.x;
- this._pos.y = this.parent.y;
- this._halfSize.x = this.parent.width / 2;
- this._halfSize.y = this.parent.height / 2;
- this._offset.x = this.origin.x * this.parent.width;
- this._offset.y = this.origin.y * this.parent.height;
- this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
- this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
- this._size.x = this.parent.width;
- this._size.y = this.parent.height;
- this._origin.x = this.origin.x;
- this._origin.y = this.origin.y;
- this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
- this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
- this._prevRotation = this.rotation;
- if(this.parent.texture && this.parent.texture.renderRotation) {
- this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
- this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
- } else {
- this._sc.x = 0;
- this._sc.y = 1;
- }
- this.center.x = this.parent.x + this._distance * this._scA.y;
- this.center.y = this.parent.y + this._distance * this._scA.x;
- this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
- this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
- this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
- this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
- this._pos.x = this.parent.x;
- this._pos.y = this.parent.y;
- this._flippedX = this.parent.texture.flippedX;
- this._flippedY = this.parent.texture.flippedY;
- };
- TransformManager.prototype.update = function () {
- this._dirty = false;
- if(this.parent.width !== this._size.x || this.parent.height !== this._size.y || this.origin.x !== this._origin.x || this.origin.y !== this._origin.y) {
- this._halfSize.x = this.parent.width / 2;
- this._halfSize.y = this.parent.height / 2;
- this._offset.x = this.origin.x * this.parent.width;
- this._offset.y = this.origin.y * this.parent.height;
- this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
- this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
- this._size.x = this.parent.width;
- this._size.y = this.parent.height;
- this._origin.x = this.origin.x;
- this._origin.y = this.origin.y;
- this._dirty = true;
- }
- if(this.rotation != this._prevRotation || this._dirty) {
- this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
- this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
- if(this.parent.texture.renderRotation) {
- this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
- this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
- } else {
- this._sc.x = 0;
- this._sc.y = 1;
- }
- this._prevRotation = this.rotation;
- this._dirty = true;
- }
- if(this._dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y) {
- this.center.x = this.parent.x + this._distance * this._scA.y;
- this.center.y = this.parent.y + this._distance * this._scA.x;
- this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
- this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
- this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
- this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
- this._pos.x = this.parent.x;
- this._pos.y = this.parent.y;
- this.local.data[2] = this.parent.x;
- this.local.data[5] = this.parent.y;
- }
- if(this._dirty || this._flippedX != this.parent.texture.flippedX) {
- this._flippedX = this.parent.texture.flippedX;
- if(this._flippedX) {
- this.local.data[0] = this._sc.y * -this.scale.x;
- this.local.data[3] = (this._sc.x * -this.scale.x) + this.skew.x;
- } else {
- this.local.data[0] = this._sc.y * this.scale.x;
- this.local.data[3] = (this._sc.x * this.scale.x) + this.skew.x;
- }
- }
- if(this._dirty || this._flippedY != this.parent.texture.flippedY) {
- this._flippedY = this.parent.texture.flippedY;
- if(this._flippedY) {
- this.local.data[4] = this._sc.y * -this.scale.y;
- this.local.data[1] = -(this._sc.x * -this.scale.y) + this.skew.y;
- } else {
- this.local.data[4] = this._sc.y * this.scale.y;
- this.local.data[1] = -(this._sc.x * this.scale.y) + this.skew.y;
- }
- }
- };
- return TransformManager;
- })();
- Components.TransformManager = TransformManager;
- })(Phaser.Components || (Phaser.Components = {}));
- var Components = Phaser.Components;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var ScrollRegion = (function () {
- function ScrollRegion(x, y, width, height, speedX, speedY) {
- this._anchorWidth = 0;
- this._anchorHeight = 0;
- this._inverseWidth = 0;
- this._inverseHeight = 0;
- this.visible = true;
- this._A = new Phaser.Rectangle(x, y, width, height);
- this._B = new Phaser.Rectangle(x, y, width, height);
- this._C = new Phaser.Rectangle(x, y, width, height);
- this._D = new Phaser.Rectangle(x, y, width, height);
- this._scroll = new Phaser.Vec2();
- this._bounds = new Phaser.Rectangle(x, y, width, height);
- this.scrollSpeed = new Phaser.Vec2(speedX, speedY);
- }
- ScrollRegion.prototype.update = function (delta) {
- this._scroll.x += this.scrollSpeed.x;
- this._scroll.y += this.scrollSpeed.y;
- if(this._scroll.x > this._bounds.right) {
- this._scroll.x = this._bounds.x;
- }
- if(this._scroll.x < this._bounds.x) {
- this._scroll.x = this._bounds.right;
- }
- if(this._scroll.y > this._bounds.bottom) {
- this._scroll.y = this._bounds.y;
- }
- if(this._scroll.y < this._bounds.y) {
- this._scroll.y = this._bounds.bottom;
- }
- this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
- this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
- if(this._anchorWidth > this._bounds.width) {
- this._anchorWidth = this._bounds.width;
- }
- if(this._anchorHeight > this._bounds.height) {
- this._anchorHeight = this._bounds.height;
- }
- this._inverseWidth = this._bounds.width - this._anchorWidth;
- this._inverseHeight = this._bounds.height - this._anchorHeight;
- this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
- this._B.y = this._scroll.y;
- this._B.width = this._inverseWidth;
- this._B.height = this._anchorHeight;
- this._C.x = this._scroll.x;
- this._C.width = this._anchorWidth;
- this._C.height = this._inverseHeight;
- this._D.width = this._inverseWidth;
- this._D.height = this._inverseHeight;
- };
- ScrollRegion.prototype.render = function (context, texture, dx, dy, dw, dh) {
- if(this.visible == false) {
- return;
- }
- this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
- this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
- this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
- this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
- };
- ScrollRegion.prototype.crop = function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
- offsetX += destX;
- offsetY += destY;
- if(srcW > (destX + destW) - offsetX) {
- srcW = (destX + destW) - offsetX;
- }
- if(srcH > (destY + destH) - offsetY) {
- srcH = (destY + destH) - offsetY;
- }
- srcX = Math.floor(srcX);
- srcY = Math.floor(srcY);
- srcW = Math.floor(srcW);
- srcH = Math.floor(srcH);
- offsetX = Math.floor(offsetX + this._bounds.x);
- offsetY = Math.floor(offsetY + this._bounds.y);
- if(srcW > 0 && srcH > 0) {
- context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
- }
- };
- return ScrollRegion;
- })();
- Phaser.ScrollRegion = ScrollRegion;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var ScrollZone = (function (_super) {
- __extends(ScrollZone, _super);
- function ScrollZone(game, key, x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = 0; }
- if (typeof height === "undefined") { height = 0; }
- _super.call(this, game, x, y, key);
- this.type = Phaser.Types.SCROLLZONE;
- this.regions = [];
- if(this.texture.loaded) {
- if(width > this.width || height > this.height) {
- this.createRepeatingTexture(width, height);
- this.width = width;
- this.height = height;
- }
- this.addRegion(0, 0, this.width, this.height);
- if((width < this.width || height < this.height) && width !== 0 && height !== 0) {
- this.width = width;
- this.height = height;
- }
- }
- }
- ScrollZone.prototype.addRegion = function (x, y, width, height, speedX, speedY) {
- if (typeof speedX === "undefined") { speedX = 0; }
- if (typeof speedY === "undefined") { speedY = 0; }
- if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
- throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
- return null;
- }
- this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
- this.regions.push(this.currentRegion);
- return this.currentRegion;
- };
- ScrollZone.prototype.setSpeed = function (x, y) {
- if(this.currentRegion) {
- this.currentRegion.scrollSpeed.setTo(x, y);
- }
- return this;
- };
- ScrollZone.prototype.update = function () {
- for(var i = 0; i < this.regions.length; i++) {
- this.regions[i].update(this.game.time.delta);
- }
- };
- ScrollZone.prototype.createRepeatingTexture = function (regionWidth, regionHeight) {
- var tileWidth = Math.ceil(this.width / regionWidth) * regionWidth;
- var tileHeight = Math.ceil(this.height / regionHeight) * regionHeight;
- var dt = new Phaser.Display.DynamicTexture(this.game, tileWidth, tileHeight);
- dt.context.rect(0, 0, tileWidth, tileHeight);
- dt.context.fillStyle = dt.context.createPattern(this.texture.imageTexture, "repeat");
- dt.context.fill();
- this.texture.loadDynamicTexture(dt);
- };
- return ScrollZone;
- })(Phaser.Sprite);
- Phaser.ScrollZone = ScrollZone;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var GameObjectFactory = (function () {
- function GameObjectFactory(game) {
- this.game = game;
- this._world = this.game.world;
- }
- GameObjectFactory.prototype.camera = function (x, y, width, height) {
- return this._world.cameras.addCamera(x, y, width, height);
- };
- GameObjectFactory.prototype.button = function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof key === "undefined") { key = null; }
- if (typeof callback === "undefined") { callback = null; }
- if (typeof callbackContext === "undefined") { callbackContext = null; }
- if (typeof overFrame === "undefined") { overFrame = null; }
- if (typeof outFrame === "undefined") { outFrame = null; }
- if (typeof downFrame === "undefined") { downFrame = null; }
- return this._world.group.add(new Phaser.UI.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
- };
- GameObjectFactory.prototype.sprite = function (x, y, key, frame) {
- if (typeof key === "undefined") { key = ''; }
- if (typeof frame === "undefined") { frame = null; }
- return this._world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
- };
- GameObjectFactory.prototype.audio = function (key, volume, loop) {
- if (typeof volume === "undefined") { volume = 1; }
- if (typeof loop === "undefined") { loop = false; }
- return this.game.sound.add(key, volume, loop);
- };
- GameObjectFactory.prototype.circle = function (x, y, radius) {
- return new Phaser.Physics.Circle(this.game, x, y, radius);
- };
- GameObjectFactory.prototype.aabb = function (x, y, width, height) {
- return new Phaser.Physics.AABB(this.game, x, y, Math.floor(width / 2), Math.floor(height / 2));
- };
- GameObjectFactory.prototype.cell = function (x, y, width, height, state) {
- if (typeof state === "undefined") { state = Phaser.Physics.TileMapCell.TID_FULL; }
- return new Phaser.Physics.TileMapCell(this.game, x, y, width, height).SetState(state);
- };
- GameObjectFactory.prototype.dynamicTexture = function (width, height) {
- return new Phaser.Display.DynamicTexture(this.game, width, height);
- };
- GameObjectFactory.prototype.group = function (maxSize) {
- if (typeof maxSize === "undefined") { maxSize = 0; }
- return this._world.group.add(new Phaser.Group(this.game, maxSize));
- };
- GameObjectFactory.prototype.scrollZone = function (key, x, y, width, height) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof width === "undefined") { width = 0; }
- if (typeof height === "undefined") { height = 0; }
- return this._world.group.add(new Phaser.ScrollZone(this.game, key, x, y, width, height));
- };
- GameObjectFactory.prototype.tilemap = function (key, mapData, format, resizeWorld, tileWidth, tileHeight) {
- if (typeof resizeWorld === "undefined") { resizeWorld = true; }
- if (typeof tileWidth === "undefined") { tileWidth = 0; }
- if (typeof tileHeight === "undefined") { tileHeight = 0; }
- return this._world.group.add(new Phaser.Tilemap(this.game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
- };
- GameObjectFactory.prototype.tween = function (obj, localReference) {
- if (typeof localReference === "undefined") { localReference = false; }
- return this.game.tweens.create(obj, localReference);
- };
- GameObjectFactory.prototype.existingSprite = function (sprite) {
- return this._world.group.add(sprite);
- };
- GameObjectFactory.prototype.existingGroup = function (group) {
- return this._world.group.add(group);
- };
- GameObjectFactory.prototype.existingButton = function (button) {
- return this._world.group.add(button);
- };
- GameObjectFactory.prototype.existingScrollZone = function (scrollZone) {
- return this._world.group.add(scrollZone);
- };
- GameObjectFactory.prototype.existingTilemap = function (tilemap) {
- return this._world.group.add(tilemap);
- };
- GameObjectFactory.prototype.existingTween = function (tween) {
- return this.game.tweens.add(tween);
- };
- return GameObjectFactory;
- })();
- Phaser.GameObjectFactory = GameObjectFactory;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (UI) {
- var Button = (function (_super) {
- __extends(Button, _super);
- function Button(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- if (typeof key === "undefined") { key = null; }
- if (typeof callback === "undefined") { callback = null; }
- if (typeof callbackContext === "undefined") { callbackContext = null; }
- if (typeof overFrame === "undefined") { overFrame = null; }
- if (typeof outFrame === "undefined") { outFrame = null; }
- if (typeof downFrame === "undefined") { downFrame = null; }
- _super.call(this, game, x, y, key, outFrame);
- this._onOverFrameName = null;
- this._onOutFrameName = null;
- this._onDownFrameName = null;
- this._onUpFrameName = null;
- this._onOverFrameID = null;
- this._onOutFrameID = null;
- this._onDownFrameID = null;
- this._onUpFrameID = null;
- this.type = Phaser.Types.BUTTON;
- if(typeof overFrame == 'string') {
- this._onOverFrameName = overFrame;
- } else {
- this._onOverFrameID = overFrame;
- }
- if(typeof outFrame == 'string') {
- this._onOutFrameName = outFrame;
- this._onUpFrameName = outFrame;
- } else {
- this._onOutFrameID = outFrame;
- this._onUpFrameID = outFrame;
- }
- if(typeof downFrame == 'string') {
- this._onDownFrameName = downFrame;
- } else {
- this._onDownFrameID = downFrame;
- }
- this.onInputOver = new Phaser.Signal();
- this.onInputOut = new Phaser.Signal();
- this.onInputDown = new Phaser.Signal();
- this.onInputUp = new Phaser.Signal();
- if(callback) {
- this.onInputUp.add(callback, callbackContext);
- }
- this.input.start(0, false, true);
- this.events.onInputOver.add(this.onInputOverHandler, this);
- this.events.onInputOut.add(this.onInputOutHandler, this);
- this.events.onInputDown.add(this.onInputDownHandler, this);
- this.events.onInputUp.add(this.onInputUpHandler, this);
- }
- Button.prototype.onInputOverHandler = function (pointer) {
- if(this._onOverFrameName != null) {
- this.frameName = this._onOverFrameName;
- } else if(this._onOverFrameID != null) {
- this.frame = this._onOverFrameID;
- }
- if(this.onInputOver) {
- this.onInputOver.dispatch(this, pointer);
- }
- };
- Button.prototype.onInputOutHandler = function (pointer) {
- if(this._onOutFrameName != null) {
- this.frameName = this._onOutFrameName;
- } else if(this._onOutFrameID != null) {
- this.frame = this._onOutFrameID;
- }
- if(this.onInputOut) {
- this.onInputOut.dispatch(this, pointer);
- }
- };
- Button.prototype.onInputDownHandler = function (pointer) {
- if(this._onDownFrameName != null) {
- this.frameName = this._onDownFrameName;
- } else if(this._onDownFrameID != null) {
- this.frame = this._onDownFrameID;
- }
- if(this.onInputDown) {
- this.onInputDown.dispatch(this, pointer);
- }
- };
- Button.prototype.onInputUpHandler = function (pointer) {
- if(this._onUpFrameName != null) {
- this.frameName = this._onUpFrameName;
- } else if(this._onUpFrameID != null) {
- this.frame = this._onUpFrameID;
- }
- if(this.onInputUp) {
- this.onInputUp.dispatch(this, pointer);
- }
- };
- Object.defineProperty(Button.prototype, "priorityID", {
- get: function () {
- return this.input.priorityID;
- },
- set: function (value) {
- this.input.priorityID = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Button.prototype, "useHandCursor", {
- get: function () {
- return this.input.useHandCursor;
- },
- set: function (value) {
- this.input.useHandCursor = value;
- },
- enumerable: true,
- configurable: true
- });
- return Button;
- })(Phaser.Sprite);
- UI.Button = Button;
- })(Phaser.UI || (Phaser.UI = {}));
- var UI = Phaser.UI;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var CanvasUtils = (function () {
- function CanvasUtils() { }
- CanvasUtils.getAspectRatio = function getAspectRatio(canvas) {
- return canvas.width / canvas.height;
- };
- CanvasUtils.setBackgroundColor = function setBackgroundColor(canvas, color) {
- if (typeof color === "undefined") { color = 'rgb(0,0,0)'; }
- canvas.style.backgroundColor = color;
- return canvas;
- };
- CanvasUtils.setTouchAction = function setTouchAction(canvas, value) {
- if (typeof value === "undefined") { value = 'none'; }
- canvas.style.msTouchAction = value;
- canvas.style['ms-touch-action'] = value;
- canvas.style['touch-action'] = value;
- return canvas;
- };
- CanvasUtils.addToDOM = function addToDOM(canvas, parent, overflowHidden) {
- if (typeof parent === "undefined") { parent = ''; }
- if (typeof overflowHidden === "undefined") { overflowHidden = true; }
- if((parent !== '' || parent !== null) && document.getElementById(parent)) {
- document.getElementById(parent).appendChild(canvas);
- if(overflowHidden) {
- document.getElementById(parent).style.overflow = 'hidden';
- }
- } else {
- document.body.appendChild(canvas);
- }
- return canvas;
- };
- CanvasUtils.setTransform = function setTransform(context, translateX, translateY, scaleX, scaleY, skewX, skewY) {
- context.setTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
- return context;
- };
- CanvasUtils.setSmoothingEnabled = function setSmoothingEnabled(context, value) {
- context['imageSmoothingEnabled'] = value;
- context['mozImageSmoothingEnabled'] = value;
- context['oImageSmoothingEnabled'] = value;
- context['webkitImageSmoothingEnabled'] = value;
- context['msImageSmoothingEnabled'] = value;
- return context;
- };
- CanvasUtils.setImageRenderingCrisp = function setImageRenderingCrisp(canvas) {
- canvas.style['image-rendering'] = 'crisp-edges';
- canvas.style['image-rendering'] = '-moz-crisp-edges';
- canvas.style['image-rendering'] = '-webkit-optimize-contrast';
- canvas.style.msInterpolationMode = 'nearest-neighbor';
- return canvas;
- };
- CanvasUtils.setImageRenderingBicubic = function setImageRenderingBicubic(canvas) {
- canvas.style['image-rendering'] = 'auto';
- canvas.style.msInterpolationMode = 'bicubic';
- return canvas;
- };
- return CanvasUtils;
- })();
- Phaser.CanvasUtils = CanvasUtils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var CircleUtils = (function () {
- function CircleUtils() { }
- CircleUtils.clone = function clone(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Circle(); }
- return out.setTo(a.x, a.y, a.diameter);
- };
- CircleUtils.contains = function contains(a, x, y) {
- if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
- var dx = (a.x - x) * (a.x - x);
- var dy = (a.y - y) * (a.y - y);
- return (dx + dy) <= (a.radius * a.radius);
- }
- return false;
- };
- CircleUtils.containsPoint = function containsPoint(a, point) {
- return CircleUtils.contains(a, point.x, point.y);
- };
- CircleUtils.containsCircle = function containsCircle(a, b) {
- return true;
- };
- CircleUtils.distanceBetween = function distanceBetween(a, target, round) {
- if (typeof round === "undefined") { round = false; }
- var dx = a.x - target.x;
- var dy = a.y - target.y;
- if(round === true) {
- return Math.round(Math.sqrt(dx * dx + dy * dy));
- } else {
- return Math.sqrt(dx * dx + dy * dy);
- }
- };
- CircleUtils.equals = function equals(a, b) {
- return (a.x == b.x && a.y == b.y && a.diameter == b.diameter);
- };
- CircleUtils.intersects = function intersects(a, b) {
- return (Phaser.CircleUtils.distanceBetween(a, b) <= (a.radius + b.radius));
- };
- CircleUtils.circumferencePoint = function circumferencePoint(a, angle, asDegrees, out) {
- if (typeof asDegrees === "undefined") { asDegrees = false; }
- if (typeof out === "undefined") { out = new Phaser.Point(); }
- if(asDegrees === true) {
- angle = angle * Phaser.GameMath.DEG_TO_RAD;
- }
- return out.setTo(a.x + a.radius * Math.cos(angle), a.y + a.radius * Math.sin(angle));
- };
- CircleUtils.intersectsRectangle = function intersectsRectangle(c, r) {
- var cx = Math.abs(c.x - r.x - r.halfWidth);
- var xDist = r.halfWidth + c.radius;
- if(cx > xDist) {
- return false;
- }
- var cy = Math.abs(c.y - r.y - r.halfHeight);
- var yDist = r.halfHeight + c.radius;
- if(cy > yDist) {
- return false;
- }
- if(cx <= r.halfWidth || cy <= r.halfHeight) {
- return true;
- }
- var xCornerDist = cx - r.halfWidth;
- var yCornerDist = cy - r.halfHeight;
- var xCornerDistSq = xCornerDist * xCornerDist;
- var yCornerDistSq = yCornerDist * yCornerDist;
- var maxCornerDistSq = c.radius * c.radius;
- return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
- };
- return CircleUtils;
- })();
- Phaser.CircleUtils = CircleUtils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var ColorUtils = (function () {
- function ColorUtils() { }
- ColorUtils.getColor32 = function getColor32(alpha, red, green, blue) {
- return alpha << 24 | red << 16 | green << 8 | blue;
- };
- ColorUtils.getColor = function getColor(red, green, blue) {
- return red << 16 | green << 8 | blue;
- };
- ColorUtils.getHSVColorWheel = function getHSVColorWheel(alpha) {
- if (typeof alpha === "undefined") { alpha = 255; }
- var colors = [];
- for(var c = 0; c <= 359; c++) {
- colors[c] = Phaser.ColorUtils.getWebRGB(Phaser.ColorUtils.HSVtoRGB(c, 1.0, 1.0, alpha));
- }
- return colors;
- };
- ColorUtils.hexToRGB = function hexToRGB(h) {
- var hex16 = (h.charAt(0) == "#") ? h.substring(1, 7) : h;
- var r = parseInt(hex16.substring(0, 2), 16);
- var g = parseInt(hex16.substring(2, 4), 16);
- var b = parseInt(hex16.substring(4, 6), 16);
- return {
- r: r,
- g: g,
- b: b
- };
- };
- ColorUtils.getComplementHarmony = function getComplementHarmony(color) {
- var hsv = Phaser.ColorUtils.RGBtoHSV(color);
- var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
- return Phaser.ColorUtils.HSVtoRGB(opposite, 1.0, 1.0);
- };
- ColorUtils.getAnalogousHarmony = function getAnalogousHarmony(color, threshold) {
- if (typeof threshold === "undefined") { threshold = 30; }
- var hsv = Phaser.ColorUtils.RGBtoHSV(color);
- if(threshold > 359 || threshold < 0) {
- throw Error("Color Warning: Invalid threshold given to getAnalogousHarmony()");
- }
- var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 359 - threshold, 359);
- var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, threshold, 359);
- return {
- color1: color,
- color2: Phaser.ColorUtils.HSVtoRGB(warmer, 1.0, 1.0),
- color3: Phaser.ColorUtils.HSVtoRGB(colder, 1.0, 1.0),
- hue1: hsv.hue,
- hue2: warmer,
- hue3: colder
- };
- };
- ColorUtils.getSplitComplementHarmony = function getSplitComplementHarmony(color, threshold) {
- if (typeof threshold === "undefined") { threshold = 30; }
- var hsv = Phaser.ColorUtils.RGBtoHSV(color);
- if(threshold >= 359 || threshold <= 0) {
- throw Error("Phaser.ColorUtils Warning: Invalid threshold given to getSplitComplementHarmony()");
- }
- var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
- var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite - threshold, 359);
- var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite + threshold, 359);
- return {
- color1: color,
- color2: Phaser.ColorUtils.HSVtoRGB(warmer, hsv.saturation, hsv.value),
- color3: Phaser.ColorUtils.HSVtoRGB(colder, hsv.saturation, hsv.value),
- hue1: hsv.hue,
- hue2: warmer,
- hue3: colder
- };
- };
- ColorUtils.getTriadicHarmony = function getTriadicHarmony(color) {
- var hsv = Phaser.ColorUtils.RGBtoHSV(color);
- var triadic1 = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 120, 359);
- var triadic2 = Phaser.ColorUtils.game.math.wrapValue(triadic1, 120, 359);
- return {
- color1: color,
- color2: Phaser.ColorUtils.HSVtoRGB(triadic1, 1.0, 1.0),
- color3: Phaser.ColorUtils.HSVtoRGB(triadic2, 1.0, 1.0)
- };
- };
- ColorUtils.getColorInfo = function getColorInfo(color) {
- var argb = Phaser.ColorUtils.getRGB(color);
- var hsl = Phaser.ColorUtils.RGBtoHSV(color);
- var result = Phaser.ColorUtils.RGBtoHexstring(color) + "\n";
- result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n";
- result = result.concat("Hue: " + hsl.hue + " Saturation: " + hsl.saturation + " Lightnes: " + hsl.lightness);
- return result;
- };
- ColorUtils.RGBtoHexstring = function RGBtoHexstring(color) {
- var argb = Phaser.ColorUtils.getRGB(color);
- return "0x" + Phaser.ColorUtils.colorToHexstring(argb.alpha) + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
- };
- ColorUtils.RGBtoWebstring = function RGBtoWebstring(color) {
- var argb = Phaser.ColorUtils.getRGB(color);
- return "#" + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
- };
- ColorUtils.colorToHexstring = function colorToHexstring(color) {
- var digits = "0123456789ABCDEF";
- var lsd = color % 16;
- var msd = (color - lsd) / 16;
- var hexified = digits.charAt(msd) + digits.charAt(lsd);
- return hexified;
- };
- ColorUtils.HSVtoRGB = function HSVtoRGB(h, s, v, alpha) {
- if (typeof alpha === "undefined") { alpha = 255; }
- var result;
- if(s == 0.0) {
- result = Phaser.ColorUtils.getColor32(alpha, v * 255, v * 255, v * 255);
- } else {
- h = h / 60.0;
- var f = h - Math.floor(h);
- var p = v * (1.0 - s);
- var q = v * (1.0 - s * f);
- var t = v * (1.0 - s * (1.0 - f));
- switch(Math.floor(h)) {
- case 0:
- result = Phaser.ColorUtils.getColor32(alpha, v * 255, t * 255, p * 255);
- break;
- case 1:
- result = Phaser.ColorUtils.getColor32(alpha, q * 255, v * 255, p * 255);
- break;
- case 2:
- result = Phaser.ColorUtils.getColor32(alpha, p * 255, v * 255, t * 255);
- break;
- case 3:
- result = Phaser.ColorUtils.getColor32(alpha, p * 255, q * 255, v * 255);
- break;
- case 4:
- result = Phaser.ColorUtils.getColor32(alpha, t * 255, p * 255, v * 255);
- break;
- case 5:
- result = Phaser.ColorUtils.getColor32(alpha, v * 255, p * 255, q * 255);
- break;
- default:
- throw new Error("Phaser.ColorUtils.HSVtoRGB : Unknown color");
- }
- }
- return result;
- };
- ColorUtils.RGBtoHSV = function RGBtoHSV(color) {
- var rgb = Phaser.ColorUtils.getRGB(color);
- var red = rgb.red / 255;
- var green = rgb.green / 255;
- var blue = rgb.blue / 255;
- var min = Math.min(red, green, blue);
- var max = Math.max(red, green, blue);
- var delta = max - min;
- var lightness = (max + min) / 2;
- var hue;
- var saturation;
- if(delta == 0) {
- hue = 0;
- saturation = 0;
- } else {
- if(lightness < 0.5) {
- saturation = delta / (max + min);
- } else {
- saturation = delta / (2 - max - min);
- }
- var delta_r = (((max - red) / 6) + (delta / 2)) / delta;
- var delta_g = (((max - green) / 6) + (delta / 2)) / delta;
- var delta_b = (((max - blue) / 6) + (delta / 2)) / delta;
- if(red == max) {
- hue = delta_b - delta_g;
- } else if(green == max) {
- hue = (1 / 3) + delta_r - delta_b;
- } else if(blue == max) {
- hue = (2 / 3) + delta_g - delta_r;
- }
- if(hue < 0) {
- hue += 1;
- }
- if(hue > 1) {
- hue -= 1;
- }
- }
- hue *= 360;
- hue = Math.round(hue);
- return {
- hue: hue,
- saturation: saturation,
- lightness: lightness,
- value: lightness
- };
- };
- ColorUtils.interpolateColor = function interpolateColor(color1, color2, steps, currentStep, alpha) {
- if (typeof alpha === "undefined") { alpha = 255; }
- var src1 = Phaser.ColorUtils.getRGB(color1);
- var src2 = Phaser.ColorUtils.getRGB(color2);
- var r = (((src2.red - src1.red) * currentStep) / steps) + src1.red;
- var g = (((src2.green - src1.green) * currentStep) / steps) + src1.green;
- var b = (((src2.blue - src1.blue) * currentStep) / steps) + src1.blue;
- return Phaser.ColorUtils.getColor32(alpha, r, g, b);
- };
- ColorUtils.interpolateColorWithRGB = function interpolateColorWithRGB(color, r, g, b, steps, currentStep) {
- var src = Phaser.ColorUtils.getRGB(color);
- var or = (((r - src.red) * currentStep) / steps) + src.red;
- var og = (((g - src.green) * currentStep) / steps) + src.green;
- var ob = (((b - src.blue) * currentStep) / steps) + src.blue;
- return Phaser.ColorUtils.getColor(or, og, ob);
- };
- ColorUtils.interpolateRGB = function interpolateRGB(r1, g1, b1, r2, g2, b2, steps, currentStep) {
- var r = (((r2 - r1) * currentStep) / steps) + r1;
- var g = (((g2 - g1) * currentStep) / steps) + g1;
- var b = (((b2 - b1) * currentStep) / steps) + b1;
- return Phaser.ColorUtils.getColor(r, g, b);
- };
- ColorUtils.getRandomColor = function getRandomColor(min, max, alpha) {
- if (typeof min === "undefined") { min = 0; }
- if (typeof max === "undefined") { max = 255; }
- if (typeof alpha === "undefined") { alpha = 255; }
- if(max > 255) {
- return Phaser.ColorUtils.getColor(255, 255, 255);
- }
- if(min > max) {
- return Phaser.ColorUtils.getColor(255, 255, 255);
- }
- var red = min + Math.round(Math.random() * (max - min));
- var green = min + Math.round(Math.random() * (max - min));
- var blue = min + Math.round(Math.random() * (max - min));
- return Phaser.ColorUtils.getColor32(alpha, red, green, blue);
- };
- ColorUtils.getRGB = function getRGB(color) {
- return {
- alpha: color >>> 24,
- red: color >> 16 & 0xFF,
- green: color >> 8 & 0xFF,
- blue: color & 0xFF
- };
- };
- ColorUtils.getWebRGB = function getWebRGB(color) {
- var alpha = (color >>> 24) / 255;
- var red = color >> 16 & 0xFF;
- var green = color >> 8 & 0xFF;
- var blue = color & 0xFF;
- return 'rgba(' + red.toString() + ',' + green.toString() + ',' + blue.toString() + ',' + alpha.toString() + ')';
- };
- ColorUtils.getAlpha = function getAlpha(color) {
- return color >>> 24;
- };
- ColorUtils.getAlphaFloat = function getAlphaFloat(color) {
- return (color >>> 24) / 255;
- };
- ColorUtils.getRed = function getRed(color) {
- return color >> 16 & 0xFF;
- };
- ColorUtils.getGreen = function getGreen(color) {
- return color >> 8 & 0xFF;
- };
- ColorUtils.getBlue = function getBlue(color) {
- return color & 0xFF;
- };
- return ColorUtils;
- })();
- Phaser.ColorUtils = ColorUtils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var PointUtils = (function () {
- function PointUtils() { }
- PointUtils.add = function add(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Point(); }
- return out.setTo(a.x + b.x, a.y + b.y);
- };
- PointUtils.subtract = function subtract(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Point(); }
- return out.setTo(a.x - b.x, a.y - b.y);
- };
- PointUtils.multiply = function multiply(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Point(); }
- return out.setTo(a.x * b.x, a.y * b.y);
- };
- PointUtils.divide = function divide(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Point(); }
- return out.setTo(a.x / b.x, a.y / b.y);
- };
- PointUtils.clamp = function clamp(a, min, max) {
- Phaser.PointUtils.clampX(a, min, max);
- Phaser.PointUtils.clampY(a, min, max);
- return a;
- };
- PointUtils.clampX = function clampX(a, min, max) {
- a.x = Math.max(Math.min(a.x, max), min);
- return a;
- };
- PointUtils.clampY = function clampY(a, min, max) {
- a.y = Math.max(Math.min(a.y, max), min);
- return a;
- };
- PointUtils.clone = function clone(a, output) {
- if (typeof output === "undefined") { output = new Phaser.Point(); }
- return output.setTo(a.x, a.y);
- };
- PointUtils.distanceBetween = function distanceBetween(a, b, round) {
- if (typeof round === "undefined") { round = false; }
- var dx = a.x - b.x;
- var dy = a.y - b.y;
- if(round === true) {
- return Math.round(Math.sqrt(dx * dx + dy * dy));
- } else {
- return Math.sqrt(dx * dx + dy * dy);
- }
- };
- PointUtils.equals = function equals(a, b) {
- return (a.x == b.x && a.y == b.y);
- };
- PointUtils.rotate = function rotate(a, x, y, angle, asDegrees, distance) {
- if (typeof asDegrees === "undefined") { asDegrees = false; }
- if (typeof distance === "undefined") { distance = null; }
- if(asDegrees) {
- angle = angle * Phaser.GameMath.DEG_TO_RAD;
- }
- if(distance === null) {
- distance = Math.sqrt(((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y)));
- }
- return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
- };
- PointUtils.rotateAroundPoint = function rotateAroundPoint(a, b, angle, asDegrees, distance) {
- if (typeof asDegrees === "undefined") { asDegrees = false; }
- if (typeof distance === "undefined") { distance = null; }
- return Phaser.PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
- };
- return PointUtils;
- })();
- Phaser.PointUtils = PointUtils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var RectangleUtils = (function () {
- function RectangleUtils() { }
- RectangleUtils.getTopLeftAsPoint = function getTopLeftAsPoint(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Point(); }
- return out.setTo(a.x, a.y);
- };
- RectangleUtils.getBottomRightAsPoint = function getBottomRightAsPoint(a, out) {
- if (typeof out === "undefined") { out = new Phaser.Point(); }
- return out.setTo(a.right, a.bottom);
- };
- RectangleUtils.inflate = function inflate(a, dx, dy) {
- a.x -= dx;
- a.width += 2 * dx;
- a.y -= dy;
- a.height += 2 * dy;
- return a;
- };
- RectangleUtils.inflatePoint = function inflatePoint(a, point) {
- return Phaser.RectangleUtils.inflate(a, point.x, point.y);
- };
- RectangleUtils.size = function size(a, output) {
- if (typeof output === "undefined") { output = new Phaser.Point(); }
- return output.setTo(a.width, a.height);
- };
- RectangleUtils.clone = function clone(a, output) {
- if (typeof output === "undefined") { output = new Phaser.Rectangle(); }
- return output.setTo(a.x, a.y, a.width, a.height);
- };
- RectangleUtils.contains = function contains(a, x, y) {
- return (x >= a.x && x <= a.right && y >= a.y && y <= a.bottom);
- };
- RectangleUtils.containsPoint = function containsPoint(a, point) {
- return Phaser.RectangleUtils.contains(a, point.x, point.y);
- };
- RectangleUtils.containsRect = function containsRect(a, b) {
- if(a.volume > b.volume) {
- return false;
- }
- return (a.x >= b.x && a.y >= b.y && a.right <= b.right && a.bottom <= b.bottom);
- };
- RectangleUtils.equals = function equals(a, b) {
- return (a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height);
- };
- RectangleUtils.intersection = function intersection(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
- if(Phaser.RectangleUtils.intersects(a, b)) {
- out.x = Math.max(a.x, b.x);
- out.y = Math.max(a.y, b.y);
- out.width = Math.min(a.right, b.right) - out.x;
- out.height = Math.min(a.bottom, b.bottom) - out.y;
- }
- return out;
- };
- RectangleUtils.intersects = function intersects(a, b, tolerance) {
- if (typeof tolerance === "undefined") { tolerance = 0; }
- return !(a.left > b.right + tolerance || a.right < b.left - tolerance || a.top > b.bottom + tolerance || a.bottom < b.top - tolerance);
- };
- RectangleUtils.intersectsRaw = function intersectsRaw(a, left, right, top, bottom, tolerance) {
- if (typeof tolerance === "undefined") { tolerance = 0; }
- return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
- };
- RectangleUtils.union = function union(a, b, out) {
- if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
- return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
- };
- return RectangleUtils;
- })();
- Phaser.RectangleUtils = RectangleUtils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var SpriteUtils = (function () {
- function SpriteUtils() { }
- SpriteUtils.updateCameraView = function updateCameraView(camera, sprite) {
- if(sprite.rotation == 0 || sprite.texture.renderRotation == false) {
- sprite.cameraView.x = Math.floor(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.width * sprite.transform.origin.x));
- sprite.cameraView.y = Math.floor(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.height * sprite.transform.origin.y));
- sprite.cameraView.width = sprite.width;
- sprite.cameraView.height = sprite.height;
- } else {
- if(sprite.transform.origin.x == 0.5 && sprite.transform.origin.y == 0.5) {
- Phaser.SpriteUtils._sin = sprite.transform.sin;
- Phaser.SpriteUtils._cos = sprite.transform.cos;
- if(Phaser.SpriteUtils._sin < 0) {
- Phaser.SpriteUtils._sin = -Phaser.SpriteUtils._sin;
- }
- if(Phaser.SpriteUtils._cos < 0) {
- Phaser.SpriteUtils._cos = -Phaser.SpriteUtils._cos;
- }
- sprite.cameraView.width = Math.round(sprite.height * Phaser.SpriteUtils._sin + sprite.width * Phaser.SpriteUtils._cos);
- sprite.cameraView.height = Math.round(sprite.height * Phaser.SpriteUtils._cos + sprite.width * Phaser.SpriteUtils._sin);
- sprite.cameraView.x = Math.round(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.cameraView.width * sprite.transform.origin.x));
- sprite.cameraView.y = Math.round(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.cameraView.height * sprite.transform.origin.y));
- } else {
- sprite.cameraView.x = Math.min(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x);
- sprite.cameraView.y = Math.min(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y);
- sprite.cameraView.width = Math.max(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x) - sprite.cameraView.x;
- sprite.cameraView.height = Math.max(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y) - sprite.cameraView.y;
- }
- }
- return sprite.cameraView;
- };
- SpriteUtils.getAsPoints = function getAsPoints(sprite) {
- var out = [];
- out.push(new Phaser.Point(sprite.x, sprite.y));
- out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y));
- out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y + sprite.height));
- out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
- return out;
- };
- SpriteUtils.overlapsPointer = function overlapsPointer(sprite, pointer) {
- if(sprite.transform.scrollFactor.equals(1)) {
- return Phaser.SpriteUtils.overlapsXY(sprite, pointer.worldX, pointer.worldY);
- } else if(sprite.transform.scrollFactor.equals(0)) {
- return Phaser.SpriteUtils.overlapsXY(sprite, pointer.x, pointer.y);
- } else {
- var px = pointer.worldX * sprite.transform.scrollFactor.x;
- var py = pointer.worldY * sprite.transform.scrollFactor.y;
- return Phaser.SpriteUtils.overlapsXY(sprite, px, py);
- }
- };
- SpriteUtils.overlapsXY = function overlapsXY(sprite, x, y) {
- if((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0) {
- return false;
- }
- if((x - sprite.transform.upperRight.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperRight.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) > 0) {
- return false;
- }
- if((x - sprite.transform.upperLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) < 0) {
- return false;
- }
- if((x - sprite.transform.bottomLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.bottomLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) > 0) {
- return false;
- }
- return true;
- };
- SpriteUtils.overlapsPoint = function overlapsPoint(sprite, point) {
- return Phaser.SpriteUtils.overlapsXY(sprite, point.x, point.y);
- };
- SpriteUtils.onScreen = function onScreen(sprite, camera) {
- if (typeof camera === "undefined") { camera = null; }
- if(camera == null) {
- camera = sprite.game.camera;
- }
- Phaser.SpriteUtils.getScreenXY(sprite, SpriteUtils._tempPoint, camera);
- return (Phaser.SpriteUtils._tempPoint.x + sprite.width > 0) && (Phaser.SpriteUtils._tempPoint.x < camera.width) && (Phaser.SpriteUtils._tempPoint.y + sprite.height > 0) && (Phaser.SpriteUtils._tempPoint.y < camera.height);
- };
- SpriteUtils.getScreenXY = function getScreenXY(sprite, point, camera) {
- if (typeof point === "undefined") { point = null; }
- if (typeof camera === "undefined") { camera = null; }
- if(point == null) {
- point = new Phaser.Point();
- }
- if(camera == null) {
- camera = sprite.game.camera;
- }
- point.x = sprite.x - camera.x * sprite.transform.scrollFactor.x;
- point.y = sprite.y - camera.y * sprite.transform.scrollFactor.y;
- point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
- point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
- return point;
- };
- SpriteUtils.reset = function reset(sprite, x, y) {
- sprite.revive();
- sprite.x = x;
- sprite.y = y;
- return sprite;
- };
- SpriteUtils.setBounds = function setBounds(x, y, width, height) {
- };
- return SpriteUtils;
- })();
- Phaser.SpriteUtils = SpriteUtils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var DebugUtils = (function () {
- function DebugUtils() { }
- DebugUtils.font = '14px Courier';
- DebugUtils.lineHeight = 16;
- DebugUtils.renderShadow = true;
- DebugUtils.start = function start(x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- Phaser.DebugUtils.currentX = x;
- Phaser.DebugUtils.currentY = y;
- Phaser.DebugUtils.currentColor = color;
- Phaser.DebugUtils.context.fillStyle = color;
- Phaser.DebugUtils.context.font = Phaser.DebugUtils.font;
- };
- DebugUtils.line = function line(text, x, y) {
- if (typeof x === "undefined") { x = null; }
- if (typeof y === "undefined") { y = null; }
- if(x !== null) {
- Phaser.DebugUtils.currentX = x;
- }
- if(y !== null) {
- Phaser.DebugUtils.currentY = y;
- }
- if(Phaser.DebugUtils.renderShadow) {
- Phaser.DebugUtils.context.fillStyle = 'rgb(0,0,0)';
- Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX + 1, Phaser.DebugUtils.currentY + 1);
- Phaser.DebugUtils.context.fillStyle = Phaser.DebugUtils.currentColor;
- }
- Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX, Phaser.DebugUtils.currentY);
- Phaser.DebugUtils.currentY += Phaser.DebugUtils.lineHeight;
- };
- DebugUtils.renderSpriteCorners = function renderSpriteCorners(sprite, color) {
- if (typeof color === "undefined") { color = 'rgb(255,0,255)'; }
- Phaser.DebugUtils.start(0, 0, color);
- Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperLeft.x) + ' y: ' + Math.floor(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
- Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperRight.x) + ' y: ' + Math.floor(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
- Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomLeft.x) + ' y: ' + Math.floor(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
- Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomRight.x) + ' y: ' + Math.floor(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
- };
- DebugUtils.renderSoundInfo = function renderSoundInfo(sound, x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- Phaser.DebugUtils.start(x, y, color);
- Phaser.DebugUtils.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback);
- Phaser.DebugUtils.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding);
- Phaser.DebugUtils.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying);
- Phaser.DebugUtils.line('Time: ' + sound.currentTime);
- Phaser.DebugUtils.line('Volume: ' + sound.volume + ' Muted: ' + sound.mute);
- Phaser.DebugUtils.line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag);
- if(sound.currentMarker !== '') {
- Phaser.DebugUtils.line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration);
- Phaser.DebugUtils.line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop);
- Phaser.DebugUtils.line('Position: ' + sound.position);
- }
- };
- DebugUtils.renderCameraInfo = function renderCameraInfo(camera, x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- Phaser.DebugUtils.start(x, y, color);
- Phaser.DebugUtils.line('Camera ID: ' + camera.ID + ' (' + camera.screenView.width + ' x ' + camera.screenView.height + ')');
- Phaser.DebugUtils.line('X: ' + camera.x + ' Y: ' + camera.y + ' Rotation: ' + camera.transform.rotation);
- Phaser.DebugUtils.line('WorldView X: ' + camera.worldView.x + ' Y: ' + camera.worldView.y + ' W: ' + camera.worldView.width + ' H: ' + camera.worldView.height);
- Phaser.DebugUtils.line('ScreenView X: ' + camera.screenView.x + ' Y: ' + camera.screenView.y + ' W: ' + camera.screenView.width + ' H: ' + camera.screenView.height);
- if(camera.worldBounds) {
- Phaser.DebugUtils.line('Bounds: ' + camera.worldBounds.width + ' x ' + camera.worldBounds.height);
- }
- };
- DebugUtils.renderPointer = function renderPointer(pointer, hideIfUp, downColor, upColor, color) {
- if (typeof hideIfUp === "undefined") { hideIfUp = false; }
- if (typeof downColor === "undefined") { downColor = 'rgba(0,255,0,0.5)'; }
- if (typeof upColor === "undefined") { upColor = 'rgba(255,0,0,0.5)'; }
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- if(hideIfUp == true && pointer.isUp == true) {
- return;
- }
- Phaser.DebugUtils.context.beginPath();
- Phaser.DebugUtils.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2);
- if(pointer.active) {
- Phaser.DebugUtils.context.fillStyle = downColor;
- } else {
- Phaser.DebugUtils.context.fillStyle = upColor;
- }
- Phaser.DebugUtils.context.fill();
- Phaser.DebugUtils.context.closePath();
- Phaser.DebugUtils.context.beginPath();
- Phaser.DebugUtils.context.moveTo(pointer.positionDown.x, pointer.positionDown.y);
- Phaser.DebugUtils.context.lineTo(pointer.position.x, pointer.position.y);
- Phaser.DebugUtils.context.lineWidth = 2;
- Phaser.DebugUtils.context.stroke();
- Phaser.DebugUtils.context.closePath();
- Phaser.DebugUtils.start(pointer.x, pointer.y - 100, color);
- Phaser.DebugUtils.line('ID: ' + pointer.id + " Active: " + pointer.active);
- Phaser.DebugUtils.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY);
- Phaser.DebugUtils.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y);
- Phaser.DebugUtils.line('Duration: ' + pointer.duration + " ms");
- };
- DebugUtils.renderSpriteInputInfo = function renderSpriteInputInfo(sprite, x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- Phaser.DebugUtils.start(x, y, color);
- Phaser.DebugUtils.line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')');
- Phaser.DebugUtils.line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1));
- Phaser.DebugUtils.line('over: ' + sprite.input.pointerOver() + ' duration: ' + sprite.input.overDuration().toFixed(0));
- Phaser.DebugUtils.line('down: ' + sprite.input.pointerDown() + ' duration: ' + sprite.input.downDuration().toFixed(0));
- Phaser.DebugUtils.line('just over: ' + sprite.input.justOver() + ' just out: ' + sprite.input.justOut());
- };
- DebugUtils.renderInputInfo = function renderInputInfo(x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- Phaser.DebugUtils.start(x, y, color);
- if(Phaser.DebugUtils.game.input.camera) {
- Phaser.DebugUtils.line('Input - Camera: ' + Phaser.DebugUtils.game.input.camera.ID);
- } else {
- Phaser.DebugUtils.line('Input - Camera: null');
- }
- Phaser.DebugUtils.line('X: ' + Phaser.DebugUtils.game.input.x + ' Y: ' + Phaser.DebugUtils.game.input.y);
- Phaser.DebugUtils.line('World X: ' + Phaser.DebugUtils.game.input.worldX + ' World Y: ' + Phaser.DebugUtils.game.input.worldY);
- Phaser.DebugUtils.line('Scale X: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1) + ' Scale Y: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1));
- Phaser.DebugUtils.line('Screen X: ' + Phaser.DebugUtils.game.input.activePointer.screenX + ' Screen Y: ' + Phaser.DebugUtils.game.input.activePointer.screenY);
- };
- DebugUtils.renderSpriteWorldView = function renderSpriteWorldView(sprite, x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- Phaser.DebugUtils.start(x, y, color);
- Phaser.DebugUtils.line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')');
- Phaser.DebugUtils.line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y);
- Phaser.DebugUtils.line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1));
- };
- DebugUtils.renderSpriteWorldViewBounds = function renderSpriteWorldViewBounds(sprite, color) {
- if (typeof color === "undefined") { color = 'rgba(0,255,0,0.3)'; }
- Phaser.DebugUtils.renderRectangle(sprite.worldView, color);
- };
- DebugUtils.renderSpriteInfo = function renderSpriteInfo(sprite, x, y, color) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- Phaser.DebugUtils.start(x, y, color);
- Phaser.DebugUtils.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y);
- Phaser.DebugUtils.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
- Phaser.DebugUtils.line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
- Phaser.DebugUtils.line('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1));
- Phaser.DebugUtils.line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
- Phaser.DebugUtils.line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
- Phaser.DebugUtils.line('cameraView x: ' + sprite.cameraView.x + ' y: ' + sprite.cameraView.y + ' width: ' + sprite.cameraView.width + ' height: ' + sprite.cameraView.height);
- Phaser.DebugUtils.line('inCamera: ' + Phaser.DebugUtils.game.renderer.spriteRenderer.inCamera(Phaser.DebugUtils.game.camera, sprite));
- };
- DebugUtils.renderSpriteBounds = function renderSpriteBounds(sprite, camera, color) {
- if (typeof camera === "undefined") { camera = null; }
- if (typeof color === "undefined") { color = 'rgba(0,255,0,0.2)'; }
- if(camera == null) {
- camera = Phaser.DebugUtils.game.camera;
- }
- var dx = sprite.worldView.x;
- var dy = sprite.worldView.y;
- Phaser.DebugUtils.context.fillStyle = color;
- Phaser.DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
- };
- DebugUtils.renderPixel = function renderPixel(x, y, fillStyle) {
- if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
- Phaser.DebugUtils.context.fillStyle = fillStyle;
- Phaser.DebugUtils.context.fillRect(x, y, 1, 1);
- };
- DebugUtils.renderPoint = function renderPoint(point, fillStyle) {
- if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
- Phaser.DebugUtils.context.fillStyle = fillStyle;
- Phaser.DebugUtils.context.fillRect(point.x, point.y, 1, 1);
- };
- DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) {
- if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
- Phaser.DebugUtils.context.fillStyle = fillStyle;
- Phaser.DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
- };
- DebugUtils.renderCircle = function renderCircle(circle, fillStyle) {
- if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
- Phaser.DebugUtils.context.fillStyle = fillStyle;
- Phaser.DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
- Phaser.DebugUtils.context.fill();
- };
- DebugUtils.renderText = function renderText(text, x, y, color, font) {
- if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
- if (typeof font === "undefined") { font = '16px Courier'; }
- Phaser.DebugUtils.context.font = font;
- Phaser.DebugUtils.context.fillStyle = color;
- Phaser.DebugUtils.context.fillText(text, x, y);
- };
- return DebugUtils;
- })();
- Phaser.DebugUtils = DebugUtils;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Headless) {
- var HeadlessRenderer = (function () {
- function HeadlessRenderer(game) {
- this.game = game;
- }
- HeadlessRenderer.prototype.render = function () {
- };
- HeadlessRenderer.prototype.renderGameObject = function (camera, object) {
- };
- return HeadlessRenderer;
- })();
- Headless.HeadlessRenderer = HeadlessRenderer;
- })(Renderer.Headless || (Renderer.Headless = {}));
- var Headless = Renderer.Headless;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Canvas) {
- var CameraRenderer = (function () {
- function CameraRenderer(game) {
- this._ga = 1;
- this._sx = 0;
- this._sy = 0;
- this._sw = 0;
- this._sh = 0;
- this._dx = 0;
- this._dy = 0;
- this._dw = 0;
- this._dh = 0;
- this._fx = 1;
- this._fy = 1;
- this._tx = 0;
- this._ty = 0;
- this._gac = 1;
- this._sin = 0;
- this._cos = 1;
- this.game = game;
- }
- CameraRenderer.prototype.preRender = function (camera) {
- if(camera.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
- return false;
- }
- if(this.game.device.patchAndroidClearRectBug) {
- camera.texture.context.fillStyle = 'rgb(0,0,0)';
- camera.texture.context.fillRect(0, 0, camera.width, camera.height);
- } else {
- camera.texture.context.clearRect(0, 0, camera.width, camera.height);
- }
- if(camera.texture.alpha !== 1 && camera.texture.context.globalAlpha != camera.texture.alpha) {
- this._ga = camera.texture.context.globalAlpha;
- camera.texture.context.globalAlpha = camera.texture.alpha;
- }
- if(camera.texture.opaque) {
- camera.texture.context.fillStyle = camera.texture.backgroundColor;
- camera.texture.context.fillRect(0, 0, camera.width, camera.height);
- }
- if(camera.texture.globalCompositeOperation) {
- camera.texture.context.globalCompositeOperation = camera.texture.globalCompositeOperation;
- }
- camera.plugins.preRender();
- };
- CameraRenderer.prototype.postRender = function (camera) {
- if(this._ga > -1) {
- camera.texture.context.globalAlpha = this._ga;
- }
- camera.plugins.postRender();
- this._ga = -1;
- this._sx = 0;
- this._sy = 0;
- this._sw = camera.width;
- this._sh = camera.height;
- this._fx = camera.transform.scale.x;
- this._fy = camera.transform.scale.y;
- this._sin = 0;
- this._cos = 1;
- this._dx = camera.screenView.x;
- this._dy = camera.screenView.y;
- this._dw = camera.width;
- this._dh = camera.height;
- this.game.stage.context.save();
- if(camera.texture.flippedX) {
- this._fx = -camera.transform.scale.x;
- }
- if(camera.texture.flippedY) {
- this._fy = -camera.transform.scale.y;
- }
- if(camera.modified) {
- if(camera.transform.rotation !== 0 || camera.transform.rotationOffset !== 0) {
- this._sin = Math.sin(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
- this._cos = Math.cos(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
- }
- this.game.stage.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + camera.transform.skew.x, -(this._sin * this._fy) + camera.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
- this._dx = camera.transform.origin.x * -this._dw;
- this._dy = camera.transform.origin.y * -this._dh;
- } else {
- this._dx -= (this._dw * camera.transform.origin.x);
- this._dy -= (this._dh * camera.transform.origin.y);
- }
- this._sx = Math.floor(this._sx);
- this._sy = Math.floor(this._sy);
- this._sw = Math.floor(this._sw);
- this._sh = Math.floor(this._sh);
- this._dx = Math.floor(this._dx);
- this._dy = Math.floor(this._dy);
- this._dw = Math.floor(this._dw);
- this._dh = Math.floor(this._dh);
- if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
- this.game.stage.context.restore();
- return false;
- }
- this.game.stage.context.drawImage(camera.texture.canvas, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
- this.game.stage.context.restore();
- };
- return CameraRenderer;
- })();
- Canvas.CameraRenderer = CameraRenderer;
- })(Renderer.Canvas || (Renderer.Canvas = {}));
- var Canvas = Renderer.Canvas;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Canvas) {
- var GeometryRenderer = (function () {
- function GeometryRenderer(game) {
- this._ga = 1;
- this._sx = 0;
- this._sy = 0;
- this._sw = 0;
- this._sh = 0;
- this._dx = 0;
- this._dy = 0;
- this._dw = 0;
- this._dh = 0;
- this._fx = 1;
- this._fy = 1;
- this._sin = 0;
- this._cos = 1;
- this.game = game;
- }
- GeometryRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) {
- if (typeof outline === "undefined") { outline = false; }
- if (typeof fill === "undefined") { fill = true; }
- if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; }
- if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; }
- if (typeof lineWidth === "undefined") { lineWidth = 1; }
- this._sx = 0;
- this._sy = 0;
- this._sw = circle.diameter;
- this._sh = circle.diameter;
- this._fx = 1;
- this._fy = 1;
- this._sin = 0;
- this._cos = 1;
- this._dx = camera.screenView.x + circle.x - camera.worldView.x;
- this._dy = camera.screenView.y + circle.y - camera.worldView.y;
- this._dw = circle.diameter;
- this._dh = circle.diameter;
- this._sx = Math.floor(this._sx);
- this._sy = Math.floor(this._sy);
- this._sw = Math.floor(this._sw);
- this._sh = Math.floor(this._sh);
- this._dx = Math.floor(this._dx);
- this._dy = Math.floor(this._dy);
- this._dw = Math.floor(this._dw);
- this._dh = Math.floor(this._dh);
- this.game.stage.saveCanvasValues();
- context.save();
- context.lineWidth = lineWidth;
- context.strokeStyle = lineColor;
- context.fillStyle = fillColor;
- context.beginPath();
- context.arc(this._dx, this._dy, circle.radius, 0, Math.PI * 2);
- context.closePath();
- if(outline) {
- }
- if(fill) {
- context.fill();
- }
- context.restore();
- this.game.stage.restoreCanvasValues();
- return true;
- };
- return GeometryRenderer;
- })();
- Canvas.GeometryRenderer = GeometryRenderer;
- })(Renderer.Canvas || (Renderer.Canvas = {}));
- var Canvas = Renderer.Canvas;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Canvas) {
- var GroupRenderer = (function () {
- function GroupRenderer(game) {
- this._ga = 1;
- this._sx = 0;
- this._sy = 0;
- this._sw = 0;
- this._sh = 0;
- this._dx = 0;
- this._dy = 0;
- this._dw = 0;
- this._dh = 0;
- this._fx = 1;
- this._fy = 1;
- this._sin = 0;
- this._cos = 1;
- this.game = game;
- }
- GroupRenderer.prototype.preRender = function (camera, group) {
- if(group.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
- return false;
- }
- this._ga = -1;
- this._sx = 0;
- this._sy = 0;
- this._sw = group.texture.width;
- this._sh = group.texture.height;
- this._fx = group.transform.scale.x;
- this._fy = group.transform.scale.y;
- this._sin = 0;
- this._cos = 1;
- this._dx = 0;
- this._dy = 0;
- this._dw = group.texture.width;
- this._dh = group.texture.height;
- if(group.texture.globalCompositeOperation) {
- group.texture.context.save();
- group.texture.context.globalCompositeOperation = group.texture.globalCompositeOperation;
- }
- if(group.texture.alpha !== 1 && group.texture.context.globalAlpha !== group.texture.alpha) {
- this._ga = group.texture.context.globalAlpha;
- group.texture.context.globalAlpha = group.texture.alpha;
- }
- if(group.texture.flippedX) {
- this._fx = -group.transform.scale.x;
- }
- if(group.texture.flippedY) {
- this._fy = -group.transform.scale.y;
- }
- if(group.modified) {
- if(group.transform.rotation !== 0 || group.transform.rotationOffset !== 0) {
- this._sin = Math.sin(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
- this._cos = Math.cos(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
- }
- group.texture.context.save();
- group.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + group.transform.skew.x, -(this._sin * this._fy) + group.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
- this._dx = -group.transform.origin.x;
- this._dy = -group.transform.origin.y;
- } else {
- if(!group.transform.origin.equals(0)) {
- this._dx -= group.transform.origin.x;
- this._dy -= group.transform.origin.y;
- }
- }
- this._sx = Math.floor(this._sx);
- this._sy = Math.floor(this._sy);
- this._sw = Math.floor(this._sw);
- this._sh = Math.floor(this._sh);
- this._dx = Math.floor(this._dx);
- this._dy = Math.floor(this._dy);
- this._dw = Math.floor(this._dw);
- this._dh = Math.floor(this._dh);
- if(group.texture.opaque) {
- group.texture.context.fillStyle = group.texture.backgroundColor;
- group.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
- }
- if(group.texture.loaded) {
- group.texture.context.drawImage(group.texture.texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
- }
- return true;
- };
- GroupRenderer.prototype.postRender = function (camera, group) {
- if(group.modified || group.texture.globalCompositeOperation) {
- group.texture.context.restore();
- }
- if(this._ga > -1) {
- group.texture.context.globalAlpha = this._ga;
- }
- };
- return GroupRenderer;
- })();
- Canvas.GroupRenderer = GroupRenderer;
- })(Renderer.Canvas || (Renderer.Canvas = {}));
- var Canvas = Renderer.Canvas;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Canvas) {
- var ScrollZoneRenderer = (function () {
- function ScrollZoneRenderer(game) {
- this._ga = 1;
- this._sx = 0;
- this._sy = 0;
- this._sw = 0;
- this._sh = 0;
- this._dx = 0;
- this._dy = 0;
- this._dw = 0;
- this._dh = 0;
- this._fx = 1;
- this._fy = 1;
- this._sin = 0;
- this._cos = 1;
- this.game = game;
- }
- ScrollZoneRenderer.prototype.inCamera = function (camera, scrollZone) {
- if(scrollZone.transform.scrollFactor.equals(0)) {
- return true;
- }
- return true;
- };
- ScrollZoneRenderer.prototype.render = function (camera, scrollZone) {
- if(scrollZone.transform.scale.x == 0 || scrollZone.transform.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false) {
- return false;
- }
- this._ga = -1;
- this._sx = 0;
- this._sy = 0;
- this._sw = scrollZone.width;
- this._sh = scrollZone.height;
- this._fx = scrollZone.transform.scale.x;
- this._fy = scrollZone.transform.scale.y;
- this._sin = 0;
- this._cos = 1;
- this._dx = (camera.screenView.x * scrollZone.transform.scrollFactor.x) + scrollZone.x - (camera.worldView.x * scrollZone.transform.scrollFactor.x);
- this._dy = (camera.screenView.y * scrollZone.transform.scrollFactor.y) + scrollZone.y - (camera.worldView.y * scrollZone.transform.scrollFactor.y);
- this._dw = scrollZone.width;
- this._dh = scrollZone.height;
- if(scrollZone.texture.alpha !== 1) {
- this._ga = scrollZone.texture.context.globalAlpha;
- scrollZone.texture.context.globalAlpha = scrollZone.texture.alpha;
- }
- if(scrollZone.texture.flippedX) {
- this._fx = -scrollZone.transform.scale.x;
- }
- if(scrollZone.texture.flippedY) {
- this._fy = -scrollZone.transform.scale.y;
- }
- if(scrollZone.modified) {
- if(scrollZone.texture.renderRotation == true && (scrollZone.rotation !== 0 || scrollZone.transform.rotationOffset !== 0)) {
- this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
- this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
- }
- scrollZone.texture.context.save();
- scrollZone.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + scrollZone.transform.skew.x, -(this._sin * this._fy) + scrollZone.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
- this._dx = -scrollZone.transform.origin.x;
- this._dy = -scrollZone.transform.origin.y;
- } else {
- if(!scrollZone.transform.origin.equals(0)) {
- this._dx -= scrollZone.transform.origin.x;
- this._dy -= scrollZone.transform.origin.y;
- }
- }
- this._sx = Math.floor(this._sx);
- this._sy = Math.floor(this._sy);
- this._sw = Math.floor(this._sw);
- this._sh = Math.floor(this._sh);
- this._dx = Math.floor(this._dx);
- this._dy = Math.floor(this._dy);
- this._dw = Math.floor(this._dw);
- this._dh = Math.floor(this._dh);
- for(var i = 0; i < scrollZone.regions.length; i++) {
- if(scrollZone.texture.isDynamic) {
- scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
- } else {
- scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
- }
- }
- if(scrollZone.modified) {
- scrollZone.texture.context.restore();
- }
- if(this._ga > -1) {
- scrollZone.texture.context.globalAlpha = this._ga;
- }
- this.game.renderer.renderCount++;
- return true;
- };
- return ScrollZoneRenderer;
- })();
- Canvas.ScrollZoneRenderer = ScrollZoneRenderer;
- })(Renderer.Canvas || (Renderer.Canvas = {}));
- var Canvas = Renderer.Canvas;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Canvas) {
- var SpriteRenderer = (function () {
- function SpriteRenderer(game) {
- this._ga = 1;
- this._sx = 0;
- this._sy = 0;
- this._sw = 0;
- this._sh = 0;
- this._dx = 0;
- this._dy = 0;
- this._dw = 0;
- this._dh = 0;
- this.game = game;
- }
- SpriteRenderer.prototype.inCamera = function (camera, sprite) {
- if(sprite.transform.scrollFactor.equals(0)) {
- return true;
- }
- return Phaser.RectangleUtils.intersects(sprite.cameraView, camera.screenView);
- };
- SpriteRenderer.prototype.render = function (camera, sprite) {
- Phaser.SpriteUtils.updateCameraView(camera, sprite);
- if(sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
- return false;
- }
- this._ga = -1;
- this._sx = 0;
- this._sy = 0;
- this._sw = sprite.texture.width;
- this._sh = sprite.texture.height;
- this._dx = sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
- this._dy = sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
- this._dw = sprite.texture.width;
- this._dh = sprite.texture.height;
- if(sprite.animations.currentFrame !== null) {
- this._sx = sprite.animations.currentFrame.x;
- this._sy = sprite.animations.currentFrame.y;
- if(sprite.animations.currentFrame.trimmed) {
- this._dx += sprite.animations.currentFrame.spriteSourceSizeX;
- this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
- this._sw = sprite.animations.currentFrame.spriteSourceSizeW;
- this._sh = sprite.animations.currentFrame.spriteSourceSizeH;
- this._dw = sprite.animations.currentFrame.spriteSourceSizeW;
- this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
- }
- }
- if(sprite.modified) {
- camera.texture.context.save();
- camera.texture.context.setTransform(sprite.transform.local.data[0], sprite.transform.local.data[3], sprite.transform.local.data[1], sprite.transform.local.data[4], this._dx, this._dy);
- this._dx = sprite.transform.origin.x * -this._dw;
- this._dy = sprite.transform.origin.y * -this._dh;
- } else {
- this._dx -= (this._dw * sprite.transform.origin.x);
- this._dy -= (this._dh * sprite.transform.origin.y);
- }
- if(sprite.crop) {
- this._sx += sprite.crop.x * sprite.transform.scale.x;
- this._sy += sprite.crop.y * sprite.transform.scale.y;
- this._sw = sprite.crop.width * sprite.transform.scale.x;
- this._sh = sprite.crop.height * sprite.transform.scale.y;
- this._dx += sprite.crop.x * sprite.transform.scale.x;
- this._dy += sprite.crop.y * sprite.transform.scale.y;
- this._dw = sprite.crop.width * sprite.transform.scale.x;
- this._dh = sprite.crop.height * sprite.transform.scale.y;
- }
- this._sx = Math.floor(this._sx);
- this._sy = Math.floor(this._sy);
- this._sw = Math.floor(this._sw);
- this._sh = Math.floor(this._sh);
- this._dx = Math.floor(this._dx);
- this._dy = Math.floor(this._dy);
- this._dw = Math.floor(this._dw);
- this._dh = Math.floor(this._dh);
- if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
- return false;
- }
- if(sprite.texture.globalCompositeOperation) {
- camera.texture.context.save();
- camera.texture.context.globalCompositeOperation = sprite.texture.globalCompositeOperation;
- }
- if(sprite.texture.alpha !== 1 && camera.texture.context.globalAlpha != sprite.texture.alpha) {
- this._ga = sprite.texture.context.globalAlpha;
- camera.texture.context.globalAlpha = sprite.texture.alpha;
- }
- if(sprite.texture.opaque) {
- camera.texture.context.fillStyle = sprite.texture.backgroundColor;
- camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
- }
- if(sprite.texture.loaded) {
- camera.texture.context.drawImage(sprite.texture.texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
- }
- if(sprite.modified || sprite.texture.globalCompositeOperation) {
- camera.texture.context.restore();
- }
- if(this._ga > -1) {
- camera.texture.context.globalAlpha = this._ga;
- }
- sprite.renderOrderID = this.game.renderer.renderCount;
- this.game.renderer.renderCount++;
- return true;
- };
- return SpriteRenderer;
- })();
- Canvas.SpriteRenderer = SpriteRenderer;
- })(Renderer.Canvas || (Renderer.Canvas = {}));
- var Canvas = Renderer.Canvas;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Canvas) {
- var TilemapRenderer = (function () {
- function TilemapRenderer(game) {
- this._ga = 1;
- this._dx = 0;
- this._dy = 0;
- this._dw = 0;
- this._dh = 0;
- this._tx = 0;
- this._ty = 0;
- this._tl = 0;
- this._maxX = 0;
- this._maxY = 0;
- this._startX = 0;
- this._startY = 0;
- this.game = game;
- }
- TilemapRenderer.prototype.render = function (camera, tilemap) {
- this._tl = tilemap.layers.length;
- for(var i = 0; i < this._tl; i++) {
- if(tilemap.layers[i].visible == false || tilemap.layers[i].alpha < 0.1) {
- continue;
- }
- var layer = tilemap.layers[i];
- this._maxX = this.game.math.ceil(camera.width / layer.tileWidth) + 1;
- this._maxY = this.game.math.ceil(camera.height / layer.tileHeight) + 1;
- this._startX = this.game.math.floor(camera.worldView.x / layer.tileWidth);
- this._startY = this.game.math.floor(camera.worldView.y / layer.tileHeight);
- 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;
- }
- 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;
- 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 TilemapRenderer;
- })();
- Canvas.TilemapRenderer = TilemapRenderer;
- })(Renderer.Canvas || (Renderer.Canvas = {}));
- var Canvas = Renderer.Canvas;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Renderer) {
- (function (Canvas) {
- var CanvasRenderer = (function () {
- function CanvasRenderer(game) {
- this._c = 0;
- this.game = game;
- this.cameraRenderer = new Phaser.Renderer.Canvas.CameraRenderer(game);
- this.groupRenderer = new Phaser.Renderer.Canvas.GroupRenderer(game);
- this.spriteRenderer = new Phaser.Renderer.Canvas.SpriteRenderer(game);
- this.geometryRenderer = new Phaser.Renderer.Canvas.GeometryRenderer(game);
- this.scrollZoneRenderer = new Phaser.Renderer.Canvas.ScrollZoneRenderer(game);
- this.tilemapRenderer = new Phaser.Renderer.Canvas.TilemapRenderer(game);
- }
- CanvasRenderer.prototype.render = function () {
- this._cameraList = this.game.world.getAllCameras();
- this.renderCount = 0;
- for(this._c = 0; this._c < this._cameraList.length; this._c++) {
- if(this._cameraList[this._c].visible) {
- this.cameraRenderer.preRender(this._cameraList[this._c]);
- this.game.world.group.render(this._cameraList[this._c]);
- this.cameraRenderer.postRender(this._cameraList[this._c]);
- }
- }
- this.renderTotal = this.renderCount;
- };
- CanvasRenderer.prototype.renderGameObject = function (camera, object) {
- if(object.type == Phaser.Types.SPRITE || object.type == Phaser.Types.BUTTON) {
- this.spriteRenderer.render(camera, object);
- } else if(object.type == Phaser.Types.SCROLLZONE) {
- this.scrollZoneRenderer.render(camera, object);
- } else if(object.type == Phaser.Types.TILEMAP) {
- this.tilemapRenderer.render(camera, object);
- }
- };
- return CanvasRenderer;
- })();
- Canvas.CanvasRenderer = CanvasRenderer;
- })(Renderer.Canvas || (Renderer.Canvas = {}));
- var Canvas = Renderer.Canvas;
- })(Phaser.Renderer || (Phaser.Renderer = {}));
- var Renderer = Phaser.Renderer;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var ParticleManager = (function () {
- function ParticleManager(proParticleCount, integrationType) {
- this.PARTICLE_CREATED = 'partilcleCreated';
- this.PARTICLE_UPDATE = 'partilcleUpdate';
- this.PARTICLE_SLEEP = 'particleSleep';
- this.PARTICLE_DEAD = 'partilcleDead';
- this.PROTON_UPDATE = 'protonUpdate';
- this.PROTON_UPDATE_AFTER = 'protonUpdateAfter';
- this.EMITTER_ADDED = 'emitterAdded';
- this.EMITTER_REMOVED = 'emitterRemoved';
- this.emitters = [];
- this.renderers = [];
- this.time = 0;
- this.oldTime = 0;
- this.amendChangeTabsBug = true;
- this.TextureBuffer = {
- };
- this.TextureCanvasBuffer = {
- };
- this.proParticleCount = Particles.ParticleUtils.initValue(proParticleCount, ParticleManager.POOL_MAX);
- this.integrationType = Particles.ParticleUtils.initValue(integrationType, ParticleManager.EULER);
- this.emitters = [];
- this.renderers = [];
- this.time = 0;
- this.oldTime = 0;
- ParticleManager.pool = new Phaser.Particles.ParticlePool(proParticleCount);
- ParticleManager.integrator = new Phaser.Particles.NumericalIntegration(this.integrationType);
- }
- ParticleManager.POOL_MAX = 1000;
- ParticleManager.TIME_STEP = 60;
- ParticleManager.MEASURE = 100;
- ParticleManager.EULER = 'euler';
- ParticleManager.RK2 = 'runge-kutta2';
- ParticleManager.RK4 = 'runge-kutta4';
- ParticleManager.VERLET = 'verlet';
- ParticleManager.prototype.addRender = function (render) {
- render.proton = this;
- this.renderers.push(render.proton);
- };
- ParticleManager.prototype.addEmitter = function (emitter) {
- this.emitters.push(emitter);
- emitter.parent = this;
- };
- ParticleManager.prototype.removeEmitter = function (emitter) {
- var index = this.emitters.indexOf(emitter);
- this.emitters.splice(index, 1);
- emitter.parent = null;
- };
- ParticleManager.prototype.update = function () {
- if(!this.oldTime) {
- this.oldTime = new Date().getTime();
- }
- var time = new Date().getTime();
- this.elapsed = (time - this.oldTime) / 1000;
- this.oldTime = time;
- if(this.elapsed > 0) {
- for(var i = 0; i < this.emitters.length; i++) {
- this.emitters[i].update(this.elapsed);
- }
- }
- };
- ParticleManager.prototype.amendChangeTabsBugHandler = function () {
- if(this.elapsed > .5) {
- this.oldTime = new Date().getTime();
- this.elapsed = 0;
- }
- };
- ParticleManager.prototype.getParticleNumber = function () {
- var total = 0;
- for(var i = 0; i < this.emitters.length; i++) {
- total += this.emitters[i].particles.length;
- }
- return total;
- };
- ParticleManager.prototype.destroy = function () {
- for(var i = 0; i < this.emitters.length; i++) {
- this.emitters[i].destory();
- delete this.emitters[i];
- }
- this.emitters = [];
- this.time = 0;
- this.oldTime = 0;
- ParticleManager.pool.release();
- };
- return ParticleManager;
- })();
- Particles.ParticleManager = ParticleManager;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var Particle = (function () {
- function Particle() {
- this.life = Infinity;
- this.age = 0;
- this.energy = 1;
- this.dead = false;
- this.sleep = false;
- this.target = null;
- this.sprite = null;
- this.parent = null;
- this.mass = 1;
- this.radius = 10;
- this.alpha = 1;
- this.scale = 1;
- this.rotation = 0;
- this.color = null;
- this.easing = Phaser.Easing.Linear.None;
- this.p = new Phaser.Vec2();
- this.v = new Phaser.Vec2();
- this.a = new Phaser.Vec2();
- this.old = {
- p: new Phaser.Vec2(),
- v: new Phaser.Vec2(),
- a: new Phaser.Vec2()
- };
- this.behaviours = [];
- this.id = 'particle_' + Particle.ID++;
- this.reset(true);
- }
- Particle.ID = 0;
- Particle.prototype.getDirection = function () {
- return Math.atan2(this.v.x, -this.v.y) * (180 / Math.PI);
- };
- Particle.prototype.reset = function (init) {
- this.life = Infinity;
- this.age = 0;
- this.energy = 1;
- this.dead = false;
- this.sleep = false;
- this.target = null;
- this.sprite = null;
- this.parent = null;
- this.mass = 1;
- this.radius = 10;
- this.alpha = 1;
- this.scale = 1;
- this.rotation = 0;
- this.color = null;
- this.easing = Phaser.Easing.Linear.None;
- if(init) {
- this.transform = {
- };
- this.p = new Phaser.Vec2();
- this.v = new Phaser.Vec2();
- this.a = new Phaser.Vec2();
- this.old = {
- p: new Phaser.Vec2(),
- v: new Phaser.Vec2(),
- a: new Phaser.Vec2()
- };
- this.behaviours = [];
- } else {
- Particles.ParticleUtils.destroyObject(this.transform);
- this.p.setTo(0, 0);
- this.v.setTo(0, 0);
- this.a.setTo(0, 0);
- this.old.p.setTo(0, 0);
- this.old.v.setTo(0, 0);
- this.old.a.setTo(0, 0);
- this.removeAllBehaviours();
- }
- this.transform.rgb = {
- r: 255,
- g: 255,
- b: 255
- };
- return this;
- };
- Particle.prototype.update = function (time, index) {
- if(!this.sleep) {
- this.age += time;
- var length = this.behaviours.length, i;
- for(i = 0; i < length; i++) {
- if(this.behaviours[i]) {
- this.behaviours[i].applyBehaviour(this, time, index);
- }
- }
- }
- if(this.age >= this.life) {
- this.destroy();
- } else {
- var scale = this.easing(this.age / this.life);
- this.energy = Math.max(1 - scale, 0);
- }
- };
- Particle.prototype.addBehaviour = function (behaviour) {
- this.behaviours.push(behaviour);
- if(behaviour.hasOwnProperty('parents')) {
- behaviour.parents.push(this);
- }
- behaviour.initialize(this);
- };
- Particle.prototype.addBehaviours = function (behaviours) {
- var length = behaviours.length, i;
- for(i = 0; i < length; i++) {
- this.addBehaviour(behaviours[i]);
- }
- };
- Particle.prototype.removeBehaviour = function (behaviour) {
- var index = this.behaviours.indexOf(behaviour);
- if(index > -1) {
- var outBehaviour = this.behaviours.splice(index, 1);
- }
- };
- Particle.prototype.removeAllBehaviours = function () {
- Particles.ParticleUtils.destroyArray(this.behaviours);
- };
- Particle.prototype.destroy = function () {
- this.removeAllBehaviours();
- this.energy = 0;
- this.dead = true;
- this.parent = null;
- };
- return Particle;
- })();
- Particles.Particle = Particle;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var Emitter = (function () {
- function Emitter(pObj) {
- this.initializes = [];
- this.particles = [];
- this.behaviours = [];
- this.emitTime = 0;
- this.emitTotalTimes = -1;
- this.initializes = [];
- this.particles = [];
- this.behaviours = [];
- this.emitTime = 0;
- this.emitTotalTimes = -1;
- this.damping = .006;
- this.bindEmitter = true;
- this.rate = new Phaser.Particles.Initializers.Rate(1, .1);
- this.id = 'emitter_' + Emitter.ID++;
- }
- Emitter.ID = 0;
- Emitter.prototype.emit = function (emitTime, life) {
- this.emitTime = 0;
- this.emitTotalTimes = Particles.ParticleUtils.initValue(emitTime, Infinity);
- if(life == true || life == 'life' || life == 'destroy') {
- if(emitTime == 'once') {
- this.life = 1;
- } else {
- this.life = this.emitTotalTimes;
- }
- } else if(!isNaN(life)) {
- this.life = life;
- }
- this.rate.init();
- };
- Emitter.prototype.stopEmit = function () {
- this.emitTotalTimes = -1;
- this.emitTime = 0;
- };
- Emitter.prototype.removeAllParticles = function () {
- for(var i = 0; i < this.particles.length; i++) {
- this.particles[i].dead = true;
- }
- };
- Emitter.prototype.createParticle = function (initialize, behaviour) {
- if (typeof initialize === "undefined") { initialize = null; }
- if (typeof behaviour === "undefined") { behaviour = null; }
- var particle = Particles.ParticleManager.pool.get();
- this.setupParticle(particle, initialize, behaviour);
- return particle;
- };
- Emitter.prototype.addSelfInitialize = function (pObj) {
- if(pObj['init']) {
- pObj.init(this);
- } else {
- }
- };
- Emitter.prototype.addInitialize = function () {
- var length = arguments.length, i;
- for(i = 0; i < length; i++) {
- this.initializes.push(arguments[i]);
- }
- };
- Emitter.prototype.removeInitialize = function (initializer) {
- var index = this.initializes.indexOf(initializer);
- if(index > -1) {
- this.initializes.splice(index, 1);
- }
- };
- Emitter.prototype.removeInitializers = function () {
- Particles.ParticleUtils.destroyArray(this.initializes);
- };
- Emitter.prototype.addBehaviour = function () {
- var length = arguments.length, i;
- for(i = 0; i < length; i++) {
- this.behaviours.push(arguments[i]);
- if(arguments[i].hasOwnProperty("parents")) {
- arguments[i].parents.push(this);
- }
- }
- };
- Emitter.prototype.removeBehaviour = function (behaviour) {
- var index = this.behaviours.indexOf(behaviour);
- if(index > -1) {
- this.behaviours.splice(index, 1);
- }
- };
- Emitter.prototype.removeAllBehaviours = function () {
- Particles.ParticleUtils.destroyArray(this.behaviours);
- };
- Emitter.prototype.integrate = function (time) {
- var damping = 1 - this.damping;
- Particles.ParticleManager.integrator.integrate(this, time, damping);
- var length = this.particles.length, i;
- for(i = 0; i < length; i++) {
- var particle = this.particles[i];
- particle.update(time, i);
- Particles.ParticleManager.integrator.integrate(particle, time, damping);
- }
- };
- Emitter.prototype.emitting = function (time) {
- if(this.emitTotalTimes == 1) {
- var length = this.rate.getValue(99999), i;
- for(i = 0; i < length; i++) {
- this.createParticle();
- }
- this.emitTotalTimes = 0;
- } else if(!isNaN(this.emitTotalTimes)) {
- this.emitTime += time;
- if(this.emitTime < this.emitTotalTimes) {
- var length = this.rate.getValue(time), i;
- for(i = 0; i < length; i++) {
- this.createParticle();
- }
- }
- }
- };
- Emitter.prototype.update = function (time) {
- this.age += time;
- if(this.age >= this.life || this.dead) {
- this.destroy();
- }
- this.emitting(time);
- this.integrate(time);
- var particle;
- var length = this.particles.length, k;
- for(k = length - 1; k >= 0; k--) {
- particle = this.particles[k];
- if(particle.dead) {
- Particles.ParticleManager.pool.set(particle);
- this.particles.splice(k, 1);
- }
- }
- };
- Emitter.prototype.setupParticle = function (particle, initialize, behaviour) {
- var initializes = this.initializes;
- var behaviours = this.behaviours;
- if(initialize) {
- if(initialize instanceof Array) {
- initializes = initialize;
- } else {
- initializes = [
- initialize
- ];
- }
- }
- if(behaviour) {
- if(behaviour instanceof Array) {
- behaviours = behaviour;
- } else {
- behaviours = [
- behaviour
- ];
- }
- }
- particle.addBehaviours(behaviours);
- particle.parent = this;
- this.particles.push(particle);
- };
- Emitter.prototype.destroy = function () {
- this.dead = true;
- this.emitTotalTimes = -1;
- if(this.particles.length == 0) {
- this.removeInitializers();
- this.removeAllBehaviours();
- if(this.parent) {
- this.parent.removeEmitter(this);
- }
- }
- };
- return Emitter;
- })();
- Particles.Emitter = Emitter;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var ParticlePool = (function () {
- function ParticlePool(num, releaseTime) {
- if (typeof releaseTime === "undefined") { releaseTime = 0; }
- this.poolList = [];
- this.timeoutID = 0;
- this.proParticleCount = Particles.ParticleUtils.initValue(num, 0);
- this.releaseTime = Particles.ParticleUtils.initValue(releaseTime, -1);
- this.poolList = [];
- this.timeoutID = 0;
- for(var i = 0; i < this.proParticleCount; i++) {
- this.add();
- }
- if(this.releaseTime > 0) {
- this.timeoutID = setTimeout(this.release, this.releaseTime / 1000);
- }
- }
- ParticlePool.prototype.create = function (newTypeParticleClass) {
- if (typeof newTypeParticleClass === "undefined") { newTypeParticleClass = null; }
- if(newTypeParticleClass) {
- return new newTypeParticleClass();
- } else {
- return new Phaser.Particles.Particle();
- }
- };
- ParticlePool.prototype.getCount = function () {
- return this.poolList.length;
- };
- ParticlePool.prototype.add = function () {
- return this.poolList.push(this.create());
- };
- ParticlePool.prototype.get = function () {
- if(this.poolList.length === 0) {
- return this.create();
- } else {
- return this.poolList.pop().reset();
- }
- };
- ParticlePool.prototype.set = function (particle) {
- if(this.poolList.length < Particles.ParticleManager.POOL_MAX) {
- return this.poolList.push(particle);
- }
- };
- ParticlePool.prototype.release = function () {
- for(var i = 0; i < this.poolList.length; i++) {
- if(this.poolList[i]['destroy']) {
- this.poolList[i].destroy();
- }
- delete this.poolList[i];
- }
- this.poolList = [];
- };
- return ParticlePool;
- })();
- Particles.ParticlePool = ParticlePool;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var ParticleUtils = (function () {
- function ParticleUtils() { }
- ParticleUtils.initValue = function initValue(value, defaults) {
- var value = (value != null && value != undefined) ? value : defaults;
- return value;
- };
- ParticleUtils.isArray = function isArray(value) {
- return typeof value === 'object' && value.hasOwnProperty('length');
- };
- ParticleUtils.destroyArray = function destroyArray(array) {
- array.length = 0;
- };
- ParticleUtils.destroyObject = function destroyObject(obj) {
- for(var o in obj) {
- delete obj[o];
- }
- };
- ParticleUtils.setSpanValue = function setSpanValue(a, b, c) {
- if (typeof b === "undefined") { b = null; }
- if (typeof c === "undefined") { c = null; }
- if(a instanceof Phaser.Particles.Span) {
- return a;
- } else {
- if(!b) {
- return new Phaser.Particles.Span(a);
- } else {
- if(!c) {
- return new Phaser.Particles.Span(a, b);
- } else {
- return new Phaser.Particles.Span(a, b, c);
- }
- }
- }
- };
- ParticleUtils.getSpanValue = function getSpanValue(pan) {
- if(pan instanceof Phaser.Particles.Span) {
- return pan.getValue();
- } else {
- return pan;
- }
- };
- ParticleUtils.randomAToB = function randomAToB(a, b, INT) {
- if (typeof INT === "undefined") { INT = null; }
- if(!INT) {
- return a + Math.random() * (b - a);
- } else {
- return Math.floor(Math.random() * (b - a)) + a;
- }
- };
- ParticleUtils.randomFloating = function randomFloating(center, f, INT) {
- return ParticleUtils.randomAToB(center - f, center + f, INT);
- };
- ParticleUtils.randomZone = function randomZone(display) {
- };
- ParticleUtils.degreeTransform = function degreeTransform(a) {
- return a * Math.PI / 180;
- };
- ParticleUtils.randomColor = function randomColor() {
- return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
- };
- ParticleUtils.setEasingByName = function setEasingByName(name) {
- switch(name) {
- case 'easeLinear':
- return Phaser.Easing.Linear.None;
- break;
- case 'easeInQuad':
- return Phaser.Easing.Quadratic.In;
- break;
- case 'easeOutQuad':
- return Phaser.Easing.Quadratic.Out;
- break;
- case 'easeInOutQuad':
- return Phaser.Easing.Quadratic.InOut;
- break;
- case 'easeInCubic':
- return Phaser.Easing.Cubic.In;
- break;
- case 'easeOutCubic':
- return Phaser.Easing.Cubic.Out;
- break;
- case 'easeInOutCubic':
- return Phaser.Easing.Cubic.InOut;
- break;
- case 'easeInQuart':
- return Phaser.Easing.Quartic.In;
- break;
- case 'easeOutQuart':
- return Phaser.Easing.Quartic.Out;
- break;
- case 'easeInOutQuart':
- return Phaser.Easing.Quartic.InOut;
- break;
- case 'easeInSine':
- return Phaser.Easing.Sinusoidal.In;
- break;
- case 'easeOutSine':
- return Phaser.Easing.Sinusoidal.Out;
- break;
- case 'easeInOutSine':
- return Phaser.Easing.Sinusoidal.InOut;
- break;
- case 'easeInExpo':
- return Phaser.Easing.Exponential.In;
- break;
- case 'easeOutExpo':
- return Phaser.Easing.Exponential.Out;
- break;
- case 'easeInOutExpo':
- return Phaser.Easing.Exponential.InOut;
- break;
- case 'easeInCirc':
- return Phaser.Easing.Circular.In;
- break;
- case 'easeOutCirc':
- return Phaser.Easing.Circular.Out;
- break;
- case 'easeInOutCirc':
- return Phaser.Easing.Circular.InOut;
- break;
- case 'easeInBack':
- return Phaser.Easing.Back.In;
- break;
- case 'easeOutBack':
- return Phaser.Easing.Back.Out;
- break;
- case 'easeInOutBack':
- return Phaser.Easing.Back.InOut;
- break;
- default:
- return Phaser.Easing.Linear.None;
- break;
- }
- };
- return ParticleUtils;
- })();
- Particles.ParticleUtils = ParticleUtils;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var Polar2D = (function () {
- function Polar2D(r, tha) {
- this.r = Math.abs(r) || 0;
- this.tha = tha || 0;
- }
- Polar2D.prototype.set = function (r, tha) {
- this.r = r;
- this.tha = tha;
- return this;
- };
- Polar2D.prototype.setR = function (r) {
- this.r = r;
- return this;
- };
- Polar2D.prototype.setTha = function (tha) {
- this.tha = tha;
- return this;
- };
- Polar2D.prototype.copy = function (p) {
- this.r = p.r;
- this.tha = p.tha;
- return this;
- };
- Polar2D.prototype.toVector = function () {
- return new Phaser.Vec2(this.getX(), this.getY());
- };
- Polar2D.prototype.getX = function () {
- return this.r * Math.sin(this.tha);
- };
- Polar2D.prototype.getY = function () {
- return -this.r * Math.cos(this.tha);
- };
- Polar2D.prototype.normalize = function () {
- this.r = 1;
- return this;
- };
- Polar2D.prototype.equals = function (v) {
- return ((v.r === this.r) && (v.tha === this.tha));
- };
- Polar2D.prototype.toArray = function () {
- return [
- this.r,
- this.tha
- ];
- };
- Polar2D.prototype.clear = function () {
- this.r = 0.0;
- this.tha = 0.0;
- return this;
- };
- Polar2D.prototype.clone = function () {
- return new Polar2D(this.r, this.tha);
- };
- return Polar2D;
- })();
- Particles.Polar2D = Polar2D;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var Span = (function () {
- function Span(a, b, center) {
- if (typeof b === "undefined") { b = null; }
- if (typeof center === "undefined") { center = null; }
- this.isArray = false;
- if(Particles.ParticleUtils.isArray(a)) {
- this.isArray = true;
- this.a = a;
- } else {
- this.a = Particles.ParticleUtils.initValue(a, 1);
- this.b = Particles.ParticleUtils.initValue(b, this.a);
- this.center = Particles.ParticleUtils.initValue(center, false);
- }
- }
- Span.prototype.getValue = function (INT) {
- if (typeof INT === "undefined") { INT = null; }
- if(this.isArray) {
- return this.a[Math.floor(this.a.length * Math.random())];
- } else {
- if(!this.center) {
- return Particles.ParticleUtils.randomAToB(this.a, this.b, INT);
- } else {
- return Particles.ParticleUtils.randomFloating(this.a, this.b, INT);
- }
- }
- };
- Span.getSpan = function getSpan(a, b, center) {
- return new Span(a, b, center);
- };
- return Span;
- })();
- Particles.Span = Span;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- var NumericalIntegration = (function () {
- function NumericalIntegration(type) {
- this.type = Particles.ParticleUtils.initValue(type, Particles.ParticleManager.EULER);
- }
- NumericalIntegration.prototype.integrate = function (particles, time, damping) {
- this.eulerIntegrate(particles, time, damping);
- };
- NumericalIntegration.prototype.eulerIntegrate = function (particle, time, damping) {
- if(!particle.sleep) {
- particle.old.p.copy(particle.p);
- particle.old.v.copy(particle.v);
- particle.a.multiplyScalar(1 / particle.mass);
- particle.v.add(particle.a.multiplyScalar(time));
- particle.p.add(particle.old.v.multiplyScalar(time));
- if(damping) {
- particle.v.multiplyScalar(damping);
- }
- particle.a.clear();
- }
- };
- return NumericalIntegration;
- })();
- Particles.NumericalIntegration = NumericalIntegration;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Behaviours) {
- var Behaviour = (function () {
- function Behaviour(life, easing) {
- this.id = 'Behaviour_' + Behaviour.ID++;
- this.life = Particles.ParticleUtils.initValue(life, Infinity);
- this.easing = Particles.ParticleUtils.setEasingByName(easing);
- this.age = 0;
- this.energy = 1;
- this.dead = false;
- this.parents = [];
- this.name = 'Behaviour';
- }
- Behaviour.prototype.normalizeForce = function (force) {
- return force.multiplyScalar(Particles.ParticleManager.MEASURE);
- };
- Behaviour.prototype.normalizeValue = function (value) {
- return value * Particles.ParticleManager.MEASURE;
- };
- Behaviour.prototype.initialize = function (particle) {
- };
- Behaviour.prototype.applyBehaviour = function (particle, time, index) {
- this.age += time;
- if(this.age >= this.life || this.dead) {
- this.energy = 0;
- this.dead = true;
- this.destroy();
- } else {
- var scale = this.easing(particle.age / particle.life);
- this.energy = Math.max(1 - scale, 0);
- }
- };
- Behaviour.prototype.destroy = function () {
- var index;
- var length = this.parents.length, i;
- for(i = 0; i < length; i++) {
- this.parents[i].removeBehaviour(this);
- }
- this.parents = [];
- };
- return Behaviour;
- })();
- Behaviours.Behaviour = Behaviour;
- })(Particles.Behaviours || (Particles.Behaviours = {}));
- var Behaviours = Particles.Behaviours;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Behaviours) {
- var RandomDrift = (function (_super) {
- __extends(RandomDrift, _super);
- function RandomDrift(driftX, driftY, delay, life, easing) {
- _super.call(this, life, easing);
- this.reset(driftX, driftY, delay);
- this.time = 0;
- this.name = "RandomDrift";
- }
- RandomDrift.prototype.reset = function (driftX, driftY, delay, life, easing) {
- if (typeof life === "undefined") { life = null; }
- if (typeof easing === "undefined") { easing = null; }
- this.panFoce = new Phaser.Vec2(driftX, driftY);
- this.panFoce = this.normalizeForce(this.panFoce);
- this.delay = delay;
- if(life) {
- this.life = Particles.ParticleUtils.initValue(life, Infinity);
- this.easing = Particles.ParticleUtils.initValue(easing, Phaser.Easing.Linear.None);
- }
- };
- RandomDrift.prototype.applyBehaviour = function (particle, time, index) {
- _super.prototype.applyBehaviour.call(this, particle, time, index);
- this.time += time;
- if(this.time >= this.delay) {
- particle.a.addXY(Particles.ParticleUtils.randomAToB(-this.panFoce.x, this.panFoce.x), Particles.ParticleUtils.randomAToB(-this.panFoce.y, this.panFoce.y));
- this.time = 0;
- }
- };
- return RandomDrift;
- })(Behaviours.Behaviour);
- Behaviours.RandomDrift = RandomDrift;
- })(Particles.Behaviours || (Particles.Behaviours = {}));
- var Behaviours = Particles.Behaviours;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Initializers) {
- var Initialize = (function () {
- function Initialize() { }
- Initialize.prototype.initialize = function (target) {
- };
- Initialize.prototype.reset = function (a, b, c) {
- };
- Initialize.prototype.init = function (emitter, particle) {
- if (typeof particle === "undefined") { particle = null; }
- if(particle) {
- this.initialize(particle);
- } else {
- this.initialize(emitter);
- }
- };
- return Initialize;
- })();
- Initializers.Initialize = Initialize;
- })(Particles.Initializers || (Particles.Initializers = {}));
- var Initializers = Particles.Initializers;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Initializers) {
- var Life = (function (_super) {
- __extends(Life, _super);
- function Life(a, b, c) {
- _super.call(this);
- this.lifePan = Particles.ParticleUtils.setSpanValue(a, b, c);
- }
- Life.prototype.initialize = function (target) {
- if(this.lifePan.a == Infinity) {
- target.life = Infinity;
- } else {
- target.life = this.lifePan.getValue();
- }
- };
- return Life;
- })(Initializers.Initialize);
- Initializers.Life = Life;
- })(Particles.Initializers || (Particles.Initializers = {}));
- var Initializers = Particles.Initializers;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Initializers) {
- var Mass = (function (_super) {
- __extends(Mass, _super);
- function Mass(a, b, c) {
- _super.call(this);
- this.massPan = Particles.ParticleUtils.setSpanValue(a, b, c);
- }
- Mass.prototype.initialize = function (target) {
- target.mass = this.massPan.getValue();
- };
- return Mass;
- })(Initializers.Initialize);
- Initializers.Mass = Mass;
- })(Particles.Initializers || (Particles.Initializers = {}));
- var Initializers = Particles.Initializers;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Initializers) {
- var Position = (function (_super) {
- __extends(Position, _super);
- function Position(zone) {
- _super.call(this);
- if(zone != null && zone != undefined) {
- this.zone = zone;
- } else {
- this.zone = new Phaser.Particles.Zones.PointZone();
- }
- }
- Position.prototype.reset = function (zone) {
- if(zone != null && zone != undefined) {
- this.zone = zone;
- } else {
- this.zone = new Phaser.Particles.Zones.PointZone();
- }
- };
- Position.prototype.initialize = function (target) {
- this.zone.getPosition();
- target.p.x = this.zone.vector.x;
- target.p.y = this.zone.vector.y;
- };
- return Position;
- })(Initializers.Initialize);
- Initializers.Position = Position;
- })(Particles.Initializers || (Particles.Initializers = {}));
- var Initializers = Particles.Initializers;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Initializers) {
- var Rate = (function (_super) {
- __extends(Rate, _super);
- function Rate(numpan, timepan) {
- _super.call(this);
- numpan = Particles.ParticleUtils.initValue(numpan, 1);
- timepan = Particles.ParticleUtils.initValue(timepan, 1);
- this.numPan = new Phaser.Particles.Span(numpan);
- this.timePan = new Phaser.Particles.Span(timepan);
- this.startTime = 0;
- this.nextTime = 0;
- this.init();
- }
- Rate.prototype.init = function () {
- this.startTime = 0;
- this.nextTime = this.timePan.getValue();
- };
- Rate.prototype.getValue = function (time) {
- this.startTime += time;
- if(this.startTime >= this.nextTime) {
- this.startTime = 0;
- this.nextTime = this.timePan.getValue();
- if(this.numPan.b == 1) {
- if(this.numPan.getValue(false) > 0.5) {
- return 1;
- } else {
- return 0;
- }
- } else {
- return this.numPan.getValue(true);
- }
- }
- return 0;
- };
- return Rate;
- })(Initializers.Initialize);
- Initializers.Rate = Rate;
- })(Particles.Initializers || (Particles.Initializers = {}));
- var Initializers = Particles.Initializers;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Initializers) {
- var Velocity = (function (_super) {
- __extends(Velocity, _super);
- function Velocity(rpan, thapan, type) {
- _super.call(this);
- this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
- this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
- this.type = Particles.ParticleUtils.initValue(type, 'vector');
- }
- Velocity.prototype.reset = function (rpan, thapan, type) {
- this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
- this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
- this.type = Particles.ParticleUtils.initValue(type, 'vector');
- };
- Velocity.prototype.normalizeVelocity = function (vr) {
- return vr * Particles.ParticleManager.MEASURE;
- };
- Velocity.prototype.initialize = function (target) {
- if(this.type == 'p' || this.type == 'P' || this.type == 'polar') {
- var polar2d = new Particles.Polar2D(this.normalizeVelocity(this.rPan.getValue()), this.thaPan.getValue() * Math.PI / 180);
- target.v.x = polar2d.getX();
- target.v.y = polar2d.getY();
- } else {
- target.v.x = this.normalizeVelocity(this.rPan.getValue());
- target.v.y = this.normalizeVelocity(this.thaPan.getValue());
- }
- };
- return Velocity;
- })(Initializers.Initialize);
- Initializers.Velocity = Velocity;
- })(Particles.Initializers || (Particles.Initializers = {}));
- var Initializers = Particles.Initializers;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Zones) {
- var Zone = (function () {
- function Zone() {
- this.vector = new Phaser.Vec2();
- this.random = 0;
- this.crossType = "dead";
- this.alert = true;
- }
- return Zone;
- })();
- Zones.Zone = Zone;
- })(Particles.Zones || (Particles.Zones = {}));
- var Zones = Particles.Zones;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- (function (Particles) {
- (function (Zones) {
- var PointZone = (function (_super) {
- __extends(PointZone, _super);
- function PointZone(x, y) {
- if (typeof x === "undefined") { x = 0; }
- if (typeof y === "undefined") { y = 0; }
- _super.call(this);
- this.x = x;
- this.y = y;
- }
- PointZone.prototype.getPosition = function () {
- return this.vector.setTo(this.x, this.y);
- };
- PointZone.prototype.crossing = function (particle) {
- if(this.alert) {
- alert('Sorry PointZone does not support crossing method');
- this.alert = false;
- }
- };
- return PointZone;
- })(Zones.Zone);
- Zones.PointZone = PointZone;
- })(Particles.Zones || (Particles.Zones = {}));
- var Zones = Particles.Zones;
- })(Phaser.Particles || (Phaser.Particles = {}));
- var Particles = Phaser.Particles;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var World = (function () {
- function World(game, width, height) {
- this._groupCounter = 0;
- this.game = game;
- this.cameras = new Phaser.CameraManager(this.game, 0, 0, width, height);
- this.bounds = new Phaser.Rectangle(0, 0, width, height);
- }
- World.prototype.getNextGroupID = function () {
- return this._groupCounter++;
- };
- World.prototype.boot = function () {
- this.group = new Phaser.Group(this.game, 0);
- };
- World.prototype.update = function () {
- this.group.update();
- this.cameras.update();
- };
- World.prototype.postUpdate = function () {
- this.group.postUpdate();
- this.cameras.postUpdate();
- };
- World.prototype.destroy = function () {
- this.group.destroy();
- this.cameras.destroy();
- };
- World.prototype.setSize = function (width, height, updateCameraBounds) {
- if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; }
- this.bounds.width = width;
- this.bounds.height = height;
- if(updateCameraBounds == true) {
- this.game.camera.setBounds(0, 0, width, height);
- }
- };
- Object.defineProperty(World.prototype, "width", {
- get: function () {
- return this.bounds.width;
- },
- set: function (value) {
- this.bounds.width = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(World.prototype, "height", {
- get: function () {
- return this.bounds.height;
- },
- set: function (value) {
- this.bounds.height = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(World.prototype, "centerX", {
- get: function () {
- return this.bounds.halfWidth;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(World.prototype, "centerY", {
- get: function () {
- return this.bounds.halfHeight;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(World.prototype, "randomX", {
- get: function () {
- return Math.round(Math.random() * this.bounds.width);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(World.prototype, "randomY", {
- get: function () {
- return Math.round(Math.random() * this.bounds.height);
- },
- enumerable: true,
- configurable: true
- });
- World.prototype.getAllCameras = function () {
- return this.cameras.getAll();
- };
- return World;
- })();
- Phaser.World = World;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Stage = (function () {
- function Stage(game, parent, width, height) {
- var _this = this;
- this._backgroundColor = 'rgb(0,0,0)';
- this.clear = true;
- this.disablePauseScreen = false;
- this.disableBootScreen = false;
- this.disableVisibilityChange = false;
- this.game = game;
- this.canvas = document.createElement('canvas');
- this.canvas.width = width;
- this.canvas.height = height;
- this.context = this.canvas.getContext('2d');
- Phaser.CanvasUtils.addToDOM(this.canvas, parent, true);
- Phaser.CanvasUtils.setTouchAction(this.canvas);
- this.canvas.oncontextmenu = function (event) {
- event.preventDefault();
- };
- this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
- this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
- this.scale = new Phaser.StageScaleMode(this.game, width, height);
- this.getOffset(this.canvas);
- this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, width, height);
- this.aspectRatio = width / height;
- document.addEventListener('visibilitychange', function (event) {
- return _this.visibilityChange(event);
- }, false);
- document.addEventListener('webkitvisibilitychange', function (event) {
- return _this.visibilityChange(event);
- }, false);
- document.addEventListener('pagehide', function (event) {
- return _this.visibilityChange(event);
- }, false);
- document.addEventListener('pageshow', function (event) {
- return _this.visibilityChange(event);
- }, false);
- window.onblur = function (event) {
- return _this.visibilityChange(event);
- };
- window.onfocus = function (event) {
- return _this.visibilityChange(event);
- };
- }
- Stage.prototype.boot = function () {
- this.bootScreen = new Phaser.BootScreen(this.game);
- this.pauseScreen = new Phaser.PauseScreen(this.game, this.width, this.height);
- this.orientationScreen = new Phaser.OrientationScreen(this.game);
- this.scale.setScreenSize(true);
- };
- Stage.prototype.update = function () {
- this.scale.update();
- this.context.setTransform(1, 0, 0, 1, 0, 0);
- if(this.clear || (this.game.paused && this.disablePauseScreen == false)) {
- if(this.game.device.patchAndroidClearRectBug) {
- this.context.fillStyle = this._backgroundColor;
- this.context.fillRect(0, 0, this.width, this.height);
- } else {
- this.context.clearRect(0, 0, this.width, this.height);
- }
- }
- if(this.game.paused && this.scale.incorrectOrientation) {
- this.orientationScreen.update();
- this.orientationScreen.render();
- return;
- }
- if(this.game.isRunning == false && this.disableBootScreen == false) {
- this.bootScreen.update();
- this.bootScreen.render();
- }
- if(this.game.paused && this.disablePauseScreen == false) {
- this.pauseScreen.update();
- this.pauseScreen.render();
- }
- };
- Stage.prototype.visibilityChange = function (event) {
- if(this.disableVisibilityChange) {
- return;
- }
- if(event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) {
- if(this.game.paused == false) {
- this.pauseGame();
- }
- } else {
- if(this.game.paused == true) {
- this.resumeGame();
- }
- }
- };
- Stage.prototype.enableOrientationCheck = function (forceLandscape, forcePortrait, imageKey) {
- if (typeof imageKey === "undefined") { imageKey = ''; }
- this.scale.forceLandscape = forceLandscape;
- this.scale.forcePortrait = forcePortrait;
- this.orientationScreen.enable(imageKey);
- if(forceLandscape || forcePortrait) {
- if((this.scale.isLandscape && forcePortrait) || (this.scale.isPortrait && forceLandscape)) {
- this.game.paused = true;
- this.scale.incorrectOrientation = true;
- } else {
- this.scale.incorrectOrientation = false;
- }
- }
- };
- Stage.prototype.pauseGame = function () {
- this.game.paused = true;
- if(this.disablePauseScreen == false && this.pauseScreen) {
- this.pauseScreen.onPaused();
- }
- this.saveCanvasValues();
- };
- Stage.prototype.resumeGame = function () {
- if(this.disablePauseScreen == false && this.pauseScreen) {
- this.pauseScreen.onResume();
- }
- this.restoreCanvasValues();
- this.game.paused = false;
- };
- Stage.prototype.getOffset = function (element, populateOffset) {
- if (typeof populateOffset === "undefined") { populateOffset = true; }
- var box = element.getBoundingClientRect();
- var clientTop = element.clientTop || document.body.clientTop || 0;
- var clientLeft = element.clientLeft || document.body.clientLeft || 0;
- var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop;
- var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft;
- if(populateOffset) {
- this.offset = new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
- return this.offset;
- } else {
- return new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
- }
- };
- Stage.prototype.saveCanvasValues = function () {
- this.strokeStyle = this.context.strokeStyle;
- this.lineWidth = this.context.lineWidth;
- this.fillStyle = this.context.fillStyle;
- };
- Stage.prototype.restoreCanvasValues = function () {
- this.context.strokeStyle = this.strokeStyle;
- this.context.lineWidth = this.lineWidth;
- this.context.fillStyle = this.fillStyle;
- if(this.game.device.patchAndroidClearRectBug) {
- this.context.fillStyle = this._backgroundColor;
- this.context.fillRect(0, 0, this.width, this.height);
- } else {
- this.context.clearRect(0, 0, this.width, this.height);
- }
- };
- Object.defineProperty(Stage.prototype, "backgroundColor", {
- get: function () {
- return this._backgroundColor;
- },
- set: function (color) {
- this.canvas.style.backgroundColor = color;
- this._backgroundColor = color;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "x", {
- get: function () {
- return this.bounds.x;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "y", {
- get: function () {
- return this.bounds.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "width", {
- get: function () {
- return this.bounds.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "height", {
- get: function () {
- return this.bounds.height;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "centerX", {
- get: function () {
- return this.bounds.halfWidth;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "centerY", {
- get: function () {
- return this.bounds.halfHeight;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "randomX", {
- get: function () {
- return Math.round(Math.random() * this.bounds.width);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Stage.prototype, "randomY", {
- get: function () {
- return Math.round(Math.random() * this.bounds.height);
- },
- enumerable: true,
- configurable: true
- });
- return Stage;
- })();
- Phaser.Stage = Stage;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var State = (function () {
- 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.sound = game.sound;
- this.stage = game.stage;
- this.time = game.time;
- this.tweens = game.tweens;
- this.world = game.world;
- }
- State.prototype.init = function () {
- };
- State.prototype.create = function () {
- };
- State.prototype.update = function () {
- };
- State.prototype.render = function () {
- };
- State.prototype.paused = function () {
- };
- State.prototype.destroy = function () {
- };
- return State;
- })();
- Phaser.State = State;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- var Game = (function () {
- function Game(callbackContext, parent, width, height, preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
- if (typeof parent === "undefined") { parent = ''; }
- if (typeof width === "undefined") { width = 800; }
- if (typeof height === "undefined") { height = 600; }
- if (typeof preloadCallback === "undefined") { preloadCallback = null; }
- if (typeof createCallback === "undefined") { createCallback = null; }
- if (typeof updateCallback === "undefined") { updateCallback = null; }
- if (typeof renderCallback === "undefined") { renderCallback = null; }
- if (typeof destroyCallback === "undefined") { destroyCallback = null; }
- var _this = this;
- this._loadComplete = false;
- this._paused = false;
- this._pendingState = null;
- this.state = null;
- this.onPreloadCallback = null;
- this.onCreateCallback = null;
- this.onUpdateCallback = null;
- this.onRenderCallback = null;
- this.onPreRenderCallback = null;
- this.onLoadUpdateCallback = null;
- this.onLoadRenderCallback = null;
- this.onPausedCallback = null;
- this.onDestroyCallback = null;
- this.isBooted = false;
- this.isRunning = false;
- if(window['PhaserGlobal'] && window['PhaserGlobal'].singleInstance) {
- if(Phaser.GAMES.length > 0) {
- console.log('Phaser detected an instance of this game already running, aborting');
- return;
- }
- }
- this.id = Phaser.GAMES.push(this) - 1;
- this.callbackContext = callbackContext;
- this.onPreloadCallback = preloadCallback;
- this.onCreateCallback = createCallback;
- this.onUpdateCallback = updateCallback;
- this.onRenderCallback = renderCallback;
- this.onDestroyCallback = destroyCallback;
- if(document.readyState === 'complete' || document.readyState === 'interactive') {
- setTimeout(function () {
- return Phaser.GAMES[_this.id].boot(parent, width, height);
- });
- } else {
- document.addEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot(parent, width, height), false);
- window.addEventListener('load', Phaser.GAMES[this.id].boot(parent, width, height), false);
- }
- }
- Game.prototype.boot = function (parent, width, height) {
- var _this = this;
- if(this.isBooted == true) {
- return;
- }
- if(!document.body) {
- setTimeout(function () {
- return Phaser.GAMES[_this.id].boot(parent, width, height);
- }, 13);
- } else {
- document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
- window.removeEventListener('load', Phaser.GAMES[this.id].boot);
- this.onPause = new Phaser.Signal();
- this.onResume = new Phaser.Signal();
- this.device = new Phaser.Device();
- this.net = new Phaser.Net(this);
- this.math = new Phaser.GameMath(this);
- this.stage = new Phaser.Stage(this, parent, width, height);
- this.world = new Phaser.World(this, width, height);
- this.add = new Phaser.GameObjectFactory(this);
- this.cache = new Phaser.Cache(this);
- this.load = new Phaser.Loader(this);
- this.time = new Phaser.TimeManager(this);
- this.tweens = new Phaser.TweenManager(this);
- this.input = new Phaser.InputManager(this);
- this.sound = new Phaser.SoundManager(this);
- this.rnd = new Phaser.RandomDataGenerator([
- (Date.now() * Math.random()).toString()
- ]);
- this.physics = new Phaser.Physics.PhysicsManager(this);
- this.plugins = new Phaser.PluginManager(this, this);
- this.load.onLoadComplete.add(this.loadComplete, this);
- this.setRenderer(Phaser.Types.RENDERER_CANVAS);
- this.world.boot();
- this.stage.boot();
- this.input.boot();
- this.isBooted = true;
- Phaser.DebugUtils.game = this;
- Phaser.ColorUtils.game = this;
- Phaser.DebugUtils.context = this.stage.context;
- if(this.onPreloadCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null) {
- this._raf = new Phaser.RequestAnimationFrame(this, this.bootLoop);
- } else {
- this.isRunning = true;
- this._loadComplete = false;
- this._raf = new Phaser.RequestAnimationFrame(this, this.loop);
- if(this._pendingState) {
- this.switchState(this._pendingState, false, false);
- } else {
- this.startState();
- }
- }
- }
- };
- Game.prototype.loadComplete = function () {
- this._loadComplete = true;
- this.onCreateCallback.call(this.callbackContext);
- };
- Game.prototype.bootLoop = function () {
- this.tweens.update();
- this.input.update();
- this.stage.update();
- };
- Game.prototype.pausedLoop = function () {
- this.tweens.update();
- this.input.update();
- this.stage.update();
- this.sound.update();
- if(this.onPausedCallback !== null) {
- this.onPausedCallback.call(this.callbackContext);
- }
- };
- Game.prototype.loop = function () {
- this.plugins.preUpdate();
- this.tweens.update();
- this.input.update();
- this.stage.update();
- this.sound.update();
- this.physics.update();
- this.world.update();
- this.plugins.update();
- if(this._loadComplete && this.onUpdateCallback) {
- this.onUpdateCallback.call(this.callbackContext);
- } else if(this._loadComplete == false && this.onLoadUpdateCallback) {
- this.onLoadUpdateCallback.call(this.callbackContext);
- }
- this.world.postUpdate();
- this.plugins.postUpdate();
- this.plugins.preRender();
- if(this._loadComplete && this.onPreRenderCallback) {
- this.onPreRenderCallback.call(this.callbackContext);
- }
- this.renderer.render();
- this.plugins.render();
- if(this._loadComplete && this.onRenderCallback) {
- this.onRenderCallback.call(this.callbackContext);
- } else if(this._loadComplete == false && this.onLoadRenderCallback) {
- this.onLoadRenderCallback.call(this.callbackContext);
- }
- this.plugins.postRender();
- };
- Game.prototype.startState = function () {
- if(this.onPreloadCallback !== null) {
- this.load.reset();
- this.onPreloadCallback.call(this.callbackContext);
- if(this.load.queueSize == 0) {
- if(this.onCreateCallback !== null) {
- this.onCreateCallback.call(this.callbackContext);
- }
- this._loadComplete = true;
- } else {
- this.load.onLoadComplete.add(this.loadComplete, this);
- this.load.start();
- }
- } else {
- if(this.onCreateCallback !== null) {
- this.onCreateCallback.call(this.callbackContext);
- }
- this._loadComplete = true;
- }
- };
- Game.prototype.setRenderer = function (renderer) {
- switch(renderer) {
- case Phaser.Types.RENDERER_AUTO_DETECT:
- this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
- break;
- case Phaser.Types.RENDERER_AUTO_DETECT:
- case Phaser.Types.RENDERER_CANVAS:
- this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
- break;
- }
- };
- Game.prototype.setCallbacks = function (preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
- if (typeof preloadCallback === "undefined") { preloadCallback = null; }
- if (typeof createCallback === "undefined") { createCallback = null; }
- if (typeof updateCallback === "undefined") { updateCallback = null; }
- if (typeof renderCallback === "undefined") { renderCallback = null; }
- if (typeof destroyCallback === "undefined") { destroyCallback = null; }
- this.onPreloadCallback = preloadCallback;
- this.onCreateCallback = createCallback;
- this.onUpdateCallback = updateCallback;
- this.onRenderCallback = renderCallback;
- this.onDestroyCallback = destroyCallback;
- };
- Game.prototype.switchState = function (state, clearWorld, clearCache) {
- if (typeof clearWorld === "undefined") { clearWorld = true; }
- if (typeof clearCache === "undefined") { clearCache = false; }
- if(this.isBooted == false) {
- this._pendingState = state;
- return;
- }
- if(this.onDestroyCallback !== null) {
- this.onDestroyCallback.call(this.callbackContext);
- }
- this.input.reset(true);
- if(typeof state === 'function') {
- this.state = new state(this);
- } else {
- this.state = state;
- }
- if(this.state['create'] || this.state['update']) {
- this.callbackContext = this.state;
- this.onPreloadCallback = null;
- this.onLoadRenderCallback = null;
- this.onLoadUpdateCallback = null;
- this.onCreateCallback = null;
- this.onUpdateCallback = null;
- this.onRenderCallback = null;
- this.onPreRenderCallback = null;
- this.onPausedCallback = null;
- this.onDestroyCallback = null;
- if(this.state['preload']) {
- this.onPreloadCallback = this.state['preload'];
- }
- if(this.state['loadRender']) {
- this.onLoadRenderCallback = this.state['loadRender'];
- }
- if(this.state['loadUpdate']) {
- this.onLoadUpdateCallback = this.state['loadUpdate'];
- }
- if(this.state['create']) {
- this.onCreateCallback = this.state['create'];
- }
- if(this.state['update']) {
- this.onUpdateCallback = this.state['update'];
- }
- if(this.state['preRender']) {
- this.onPreRenderCallback = this.state['preRender'];
- }
- if(this.state['render']) {
- this.onRenderCallback = this.state['render'];
- }
- if(this.state['paused']) {
- this.onPausedCallback = this.state['paused'];
- }
- if(this.state['destroy']) {
- this.onDestroyCallback = this.state['destroy'];
- }
- if(clearWorld) {
- this.world.destroy();
- if(clearCache == true) {
- this.cache.destroy();
- }
- }
- this._loadComplete = false;
- this.startState();
- } else {
- throw new Error("Invalid State object given. Must contain at least a create or update function.");
- }
- };
- Game.prototype.destroy = function () {
- this.callbackContext = null;
- this.onPreloadCallback = null;
- this.onLoadRenderCallback = null;
- this.onLoadUpdateCallback = null;
- this.onCreateCallback = null;
- this.onUpdateCallback = null;
- this.onRenderCallback = null;
- this.onPausedCallback = null;
- this.onDestroyCallback = null;
- this.cache = null;
- this.input = null;
- this.load = null;
- this.sound = null;
- this.stage = null;
- this.time = null;
- this.world = null;
- this.isBooted = false;
- };
- Object.defineProperty(Game.prototype, "paused", {
- get: function () {
- return this._paused;
- },
- set: function (value) {
- if(value == true && this._paused == false) {
- this._paused = true;
- this.onPause.dispatch();
- this.sound.pauseAll();
- this._raf.callback = this.pausedLoop;
- } else if(value == false && this._paused == true) {
- this._paused = false;
- this.onResume.dispatch();
- this.input.reset();
- this.sound.resumeAll();
- if(this.isRunning == false) {
- this._raf.callback = this.bootLoop;
- } else {
- this._raf.callback = this.loop;
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Game.prototype, "camera", {
- get: function () {
- return this.world.cameras.current;
- },
- enumerable: true,
- configurable: true
- });
- return Game;
- })();
- Phaser.Game = Game;
-})(Phaser || (Phaser = {}));
-var Phaser;
-(function (Phaser) {
- Phaser.VERSION = 'Phaser version 1.0.0';
- Phaser.GAMES = [];
-})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ Phaser.VERSION = 'Phaser version 1.0.0';
+ Phaser.GAMES = [];
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Types = (function () {
+ function Types() { }
+ Types.RENDERER_AUTO_DETECT = 0;
+ Types.RENDERER_HEADLESS = 1;
+ Types.RENDERER_CANVAS = 2;
+ Types.RENDERER_WEBGL = 3;
+ Types.CAMERA_TYPE_ORTHOGRAPHIC = 0;
+ Types.CAMERA_TYPE_ISOMETRIC = 1;
+ Types.CAMERA_FOLLOW_LOCKON = 0;
+ Types.CAMERA_FOLLOW_PLATFORMER = 1;
+ Types.CAMERA_FOLLOW_TOPDOWN = 2;
+ Types.CAMERA_FOLLOW_TOPDOWN_TIGHT = 3;
+ Types.GROUP = 0;
+ Types.SPRITE = 1;
+ Types.GEOMSPRITE = 2;
+ Types.PARTICLE = 3;
+ Types.EMITTER = 4;
+ Types.TILEMAP = 5;
+ Types.SCROLLZONE = 6;
+ Types.BUTTON = 7;
+ Types.DYNAMICTEXTURE = 8;
+ Types.GEOM_POINT = 0;
+ Types.GEOM_CIRCLE = 1;
+ Types.GEOM_RECTANGLE = 2;
+ Types.GEOM_LINE = 3;
+ Types.GEOM_POLYGON = 4;
+ Types.BODY_DISABLED = 0;
+ Types.BODY_STATIC = 1;
+ Types.BODY_KINETIC = 2;
+ Types.BODY_DYNAMIC = 3;
+ Types.OUT_OF_BOUNDS_KILL = 0;
+ Types.OUT_OF_BOUNDS_DESTROY = 1;
+ Types.OUT_OF_BOUNDS_PERSIST = 2;
+ Types.SORT_ASCENDING = -1;
+ Types.SORT_DESCENDING = 1;
+ Types.LEFT = 0x0001;
+ Types.RIGHT = 0x0010;
+ Types.UP = 0x0100;
+ Types.DOWN = 0x1000;
+ Types.NONE = 0;
+ Types.CEILING = 0x0100;
+ Types.FLOOR = 0x1000;
+ Types.WALL = 0x0001 | 0x0010;
+ Types.ANY = 0x0001 | 0x0010 | 0x0100 | 0x1000;
+ return Types;
+ })();
+ Phaser.Types = Types;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Point = (function () {
+ function Point(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ this.x = x;
+ this.y = y;
+ }
+ Point.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y);
+ };
+ Point.prototype.invert = function () {
+ return this.setTo(this.y, this.x);
+ };
+ Point.prototype.setTo = function (x, y) {
+ this.x = x;
+ this.y = y;
+ return this;
+ };
+ Point.prototype.toString = function () {
+ return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
+ };
+ return Point;
+ })();
+ Phaser.Point = Point;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Rectangle = (function () {
+ function Rectangle(x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+ Object.defineProperty(Rectangle.prototype, "halfWidth", {
+ get: function () {
+ return Math.round(this.width / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "halfHeight", {
+ get: function () {
+ return Math.round(this.height / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottom", {
+ get: function () {
+ return this.y + this.height;
+ },
+ set: function (value) {
+ if(value <= this.y) {
+ this.height = 0;
+ } else {
+ this.height = (this.y - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottomRight", {
+ set: function (value) {
+ this.right = value.x;
+ this.bottom = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "left", {
+ get: function () {
+ return this.x;
+ },
+ set: function (value) {
+ if(value >= this.right) {
+ this.width = 0;
+ } else {
+ this.width = this.right - value;
+ }
+ this.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "right", {
+ get: function () {
+ return this.x + this.width;
+ },
+ set: function (value) {
+ if(value <= this.x) {
+ this.width = 0;
+ } else {
+ this.width = this.x + value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "volume", {
+ get: function () {
+ return this.width * this.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "perimeter", {
+ get: function () {
+ return (this.width * 2) + (this.height * 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "top", {
+ get: function () {
+ return this.y;
+ },
+ set: function (value) {
+ if(value >= this.bottom) {
+ this.height = 0;
+ this.y = value;
+ } else {
+ this.height = (this.bottom - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "topLeft", {
+ set: function (value) {
+ this.x = value.x;
+ this.y = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "empty", {
+ get: function () {
+ return (!this.width || !this.height);
+ },
+ set: function (value) {
+ this.setTo(0, 0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Rectangle.prototype.offset = function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Rectangle.prototype.offsetPoint = function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Rectangle.prototype.setTo = function (x, y, width, height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ return this;
+ };
+ Rectangle.prototype.floor = function () {
+ this.x = Math.floor(this.x);
+ this.y = Math.floor(this.y);
+ };
+ Rectangle.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y, source.width, source.height);
+ };
+ Rectangle.prototype.toString = function () {
+ return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
+ };
+ return Rectangle;
+ })();
+ Phaser.Rectangle = Rectangle;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Circle = (function () {
+ function Circle(x, y, diameter) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof diameter === "undefined") { diameter = 0; }
+ this._diameter = 0;
+ this._radius = 0;
+ this.x = 0;
+ this.y = 0;
+ this.setTo(x, y, diameter);
+ }
+ Object.defineProperty(Circle.prototype, "diameter", {
+ get: function () {
+ return this._diameter;
+ },
+ set: function (value) {
+ if(value > 0) {
+ this._diameter = value;
+ this._radius = value * 0.5;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "radius", {
+ get: function () {
+ return this._radius;
+ },
+ set: function (value) {
+ if(value > 0) {
+ this._radius = value;
+ this._diameter = value * 2;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.circumference = function () {
+ return 2 * (Math.PI * this._radius);
+ };
+ Object.defineProperty(Circle.prototype, "bottom", {
+ get: function () {
+ return this.y + this._radius;
+ },
+ set: function (value) {
+ if(value < this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.y;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "left", {
+ get: function () {
+ return this.x - this._radius;
+ },
+ set: function (value) {
+ if(value > this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.x - value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "right", {
+ get: function () {
+ return this.x + this._radius;
+ },
+ set: function (value) {
+ if(value < this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.x;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "top", {
+ get: function () {
+ return this.y - this._radius;
+ },
+ set: function (value) {
+ if(value > this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.y - value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "area", {
+ get: function () {
+ if(this._radius > 0) {
+ return Math.PI * this._radius * this._radius;
+ } else {
+ return 0;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.setTo = function (x, y, diameter) {
+ this.x = x;
+ this.y = y;
+ this._diameter = diameter;
+ this._radius = diameter * 0.5;
+ return this;
+ };
+ Circle.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y, source.diameter);
+ };
+ Object.defineProperty(Circle.prototype, "empty", {
+ get: function () {
+ return (this._diameter == 0);
+ },
+ set: function (value) {
+ this.setTo(0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.offset = function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Circle.prototype.offsetPoint = function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Circle.prototype.toString = function () {
+ return "[{Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
+ };
+ return Circle;
+ })();
+ Phaser.Circle = Circle;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Line = (function () {
+ function Line(x1, y1, x2, y2) {
+ if (typeof x1 === "undefined") { x1 = 0; }
+ if (typeof y1 === "undefined") { y1 = 0; }
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ this.x1 = 0;
+ this.y1 = 0;
+ this.x2 = 0;
+ this.y2 = 0;
+ this.setTo(x1, y1, x2, y2);
+ }
+ Line.prototype.clone = function (output) {
+ if (typeof output === "undefined") { output = new Line(); }
+ return output.setTo(this.x1, this.y1, this.x2, this.y2);
+ };
+ Line.prototype.copyFrom = function (source) {
+ return this.setTo(source.x1, source.y1, source.x2, source.y2);
+ };
+ Line.prototype.copyTo = function (target) {
+ return target.copyFrom(this);
+ };
+ Line.prototype.setTo = function (x1, y1, x2, y2) {
+ if (typeof x1 === "undefined") { x1 = 0; }
+ if (typeof y1 === "undefined") { y1 = 0; }
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ return this;
+ };
+ Object.defineProperty(Line.prototype, "width", {
+ get: function () {
+ return Math.max(this.x1, this.x2) - Math.min(this.x1, this.x2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "height", {
+ get: function () {
+ return Math.max(this.y1, this.y2) - Math.min(this.y1, this.y2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "length", {
+ get: function () {
+ return Math.sqrt((this.x2 - this.x1) * (this.x2 - this.x1) + (this.y2 - this.y1) * (this.y2 - this.y1));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Line.prototype.getY = function (x) {
+ return this.slope * x + this.yIntercept;
+ };
+ Object.defineProperty(Line.prototype, "angle", {
+ get: function () {
+ return Math.atan2(this.x2 - this.x1, this.y2 - this.y1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "slope", {
+ get: function () {
+ return (this.y2 - this.y1) / (this.x2 - this.x1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "perpSlope", {
+ get: function () {
+ return -((this.x2 - this.x1) / (this.y2 - this.y1));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "yIntercept", {
+ get: function () {
+ return (this.y1 - this.slope * this.x1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Line.prototype.isPointOnLine = function (x, y) {
+ if((x - this.x1) * (this.y2 - this.y1) === (this.x2 - this.x1) * (y - this.y1)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Line.prototype.isPointOnLineSegment = function (x, y) {
+ var xMin = Math.min(this.x1, this.x2);
+ var xMax = Math.max(this.x1, this.x2);
+ var yMin = Math.min(this.y1, this.y2);
+ var yMax = Math.max(this.y1, this.y2);
+ if(this.isPointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Line.prototype.intersectLineLine = function (line) {
+ };
+ Line.prototype.toString = function () {
+ return "[{Line (x1=" + this.x1 + " y1=" + this.y1 + " x2=" + this.x2 + " y2=" + this.y2 + ")}]";
+ };
+ return Line;
+ })();
+ Phaser.Line = Line;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var GameMath = (function () {
+ function GameMath(game) {
+ this.cosTable = [];
+ this.sinTable = [];
+ this.game = game;
+ GameMath.sinA = [];
+ GameMath.cosA = [];
+ for(var i = 0; i < 360; i++) {
+ GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
+ GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
+ }
+ }
+ GameMath.PI = 3.141592653589793;
+ GameMath.PI_2 = 1.5707963267948965;
+ GameMath.PI_4 = 0.7853981633974483;
+ GameMath.PI_8 = 0.39269908169872413;
+ GameMath.PI_16 = 0.19634954084936206;
+ GameMath.TWO_PI = 6.283185307179586;
+ GameMath.THREE_PI_2 = 4.7123889803846895;
+ GameMath.E = 2.71828182845905;
+ GameMath.LN10 = 2.302585092994046;
+ GameMath.LN2 = 0.6931471805599453;
+ GameMath.LOG10E = 0.4342944819032518;
+ GameMath.LOG2E = 1.442695040888963387;
+ GameMath.SQRT1_2 = 0.7071067811865476;
+ GameMath.SQRT2 = 1.4142135623730951;
+ GameMath.DEG_TO_RAD = 0.017453292519943294444444444444444;
+ GameMath.RAD_TO_DEG = 57.295779513082325225835265587527;
+ GameMath.B_16 = 65536;
+ GameMath.B_31 = 2147483648;
+ GameMath.B_32 = 4294967296;
+ GameMath.B_48 = 281474976710656;
+ GameMath.B_53 = 9007199254740992;
+ GameMath.B_64 = 18446744073709551616;
+ GameMath.ONE_THIRD = 0.333333333333333333333333333333333;
+ GameMath.TWO_THIRDS = 0.666666666666666666666666666666666;
+ GameMath.ONE_SIXTH = 0.166666666666666666666666666666666;
+ GameMath.COS_PI_3 = 0.86602540378443864676372317075294;
+ GameMath.SIN_2PI_3 = 0.03654595;
+ GameMath.CIRCLE_ALPHA = 0.5522847498307933984022516322796;
+ GameMath.ON = true;
+ GameMath.OFF = false;
+ GameMath.SHORT_EPSILON = 0.1;
+ GameMath.PERC_EPSILON = 0.001;
+ GameMath.EPSILON = 0.0001;
+ GameMath.LONG_EPSILON = 0.00000001;
+ GameMath.prototype.fuzzyEqual = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.abs(a - b) < epsilon;
+ };
+ GameMath.prototype.fuzzyLessThan = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return a < b + epsilon;
+ };
+ GameMath.prototype.fuzzyGreaterThan = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return a > b - epsilon;
+ };
+ GameMath.prototype.fuzzyCeil = function (val, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.ceil(val - epsilon);
+ };
+ GameMath.prototype.fuzzyFloor = function (val, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.floor(val + epsilon);
+ };
+ GameMath.prototype.average = function () {
+ var args = [];
+ for (var _i = 0; _i < (arguments.length - 0); _i++) {
+ args[_i] = arguments[_i + 0];
+ }
+ var avg = 0;
+ for(var i = 0; i < args.length; i++) {
+ avg += args[i];
+ }
+ return avg / args.length;
+ };
+ GameMath.prototype.slam = function (value, target, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return (Math.abs(value - target) < epsilon) ? target : value;
+ };
+ GameMath.prototype.percentageMinMax = function (val, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ val -= min;
+ max -= min;
+ if(!max) {
+ return 0;
+ } else {
+ return val / max;
+ }
+ };
+ GameMath.prototype.sign = function (n) {
+ if(n) {
+ return n / Math.abs(n);
+ } else {
+ return 0;
+ }
+ };
+ GameMath.prototype.truncate = function (n) {
+ return (n > 0) ? Math.floor(n) : Math.ceil(n);
+ };
+ GameMath.prototype.shear = function (n) {
+ return n % 1;
+ };
+ GameMath.prototype.wrap = function (val, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ val -= min;
+ max -= min;
+ if(max == 0) {
+ return min;
+ }
+ val %= max;
+ val += min;
+ while(val < min) {
+ val += max;
+ }
+ return val;
+ };
+ GameMath.prototype.arithWrap = function (value, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ max -= min;
+ if(max == 0) {
+ return min;
+ }
+ return value - max * Math.floor((value - min) / max);
+ };
+ GameMath.prototype.clamp = function (input, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ return Math.max(min, Math.min(max, input));
+ };
+ GameMath.prototype.snapTo = function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.round(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToFloor = function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.floor(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToCeil = function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.ceil(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToInArray = function (input, arr, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(sort) {
+ arr.sort();
+ }
+ if(input < arr[0]) {
+ return arr[0];
+ }
+ var i = 1;
+ while(arr[i] < input) {
+ i++;
+ }
+ var low = arr[i - 1];
+ var high = (i < arr.length) ? arr[i] : Number.POSITIVE_INFINITY;
+ return ((high - input) <= (input - low)) ? high : low;
+ };
+ GameMath.prototype.roundTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.round(value * p) / p;
+ };
+ GameMath.prototype.floorTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.floor(value * p) / p;
+ };
+ GameMath.prototype.ceilTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.ceil(value * p) / p;
+ };
+ GameMath.prototype.interpolateFloat = function (a, b, weight) {
+ return (b - a) * weight + a;
+ };
+ GameMath.prototype.radiansToDegrees = function (angle) {
+ return angle * GameMath.RAD_TO_DEG;
+ };
+ GameMath.prototype.degreesToRadians = function (angle) {
+ return angle * GameMath.DEG_TO_RAD;
+ };
+ GameMath.prototype.angleBetween = function (x1, y1, x2, y2) {
+ return Math.atan2(y2 - y1, x2 - x1);
+ };
+ GameMath.prototype.normalizeAngle = function (angle, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ var rd = (radians) ? GameMath.PI : 180;
+ return this.wrap(angle, rd, -rd);
+ };
+ GameMath.prototype.nearestAngleBetween = function (a1, a2, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ var rd = (radians) ? GameMath.PI : 180;
+ a1 = this.normalizeAngle(a1, radians);
+ a2 = this.normalizeAngle(a2, radians);
+ if(a1 < -rd / 2 && a2 > rd / 2) {
+ a1 += rd * 2;
+ }
+ if(a2 < -rd / 2 && a1 > rd / 2) {
+ a2 += rd * 2;
+ }
+ return a2 - a1;
+ };
+ GameMath.prototype.normalizeAngleToAnother = function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ return ind + this.nearestAngleBetween(ind, dep, radians);
+ };
+ GameMath.prototype.normalizeAngleAfterAnother = function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ dep = this.normalizeAngle(dep - ind, radians);
+ return ind + dep;
+ };
+ GameMath.prototype.normalizeAngleBeforeAnother = function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ dep = this.normalizeAngle(ind - dep, radians);
+ return ind - dep;
+ };
+ GameMath.prototype.interpolateAngles = function (a1, a2, weight, radians, ease) {
+ if (typeof radians === "undefined") { radians = true; }
+ if (typeof ease === "undefined") { ease = null; }
+ a1 = this.normalizeAngle(a1, radians);
+ a2 = this.normalizeAngleToAnother(a2, a1, radians);
+ return (typeof ease === 'function') ? ease(weight, a1, a2 - a1, 1) : this.interpolateFloat(a1, a2, weight);
+ };
+ GameMath.prototype.logBaseOf = function (value, base) {
+ return Math.log(value) / Math.log(base);
+ };
+ GameMath.prototype.GCD = function (m, n) {
+ var r;
+ m = Math.abs(m);
+ n = Math.abs(n);
+ if(m < n) {
+ r = m;
+ m = n;
+ n = r;
+ }
+ while(true) {
+ r = m % n;
+ if(!r) {
+ return n;
+ }
+ m = n;
+ n = r;
+ }
+ return 1;
+ };
+ GameMath.prototype.LCM = function (m, n) {
+ return (m * n) / this.GCD(m, n);
+ };
+ GameMath.prototype.factorial = function (value) {
+ if(value == 0) {
+ return 1;
+ }
+ var res = value;
+ while(--value) {
+ res *= value;
+ }
+ return res;
+ };
+ GameMath.prototype.gammaFunction = function (value) {
+ return this.factorial(value - 1);
+ };
+ GameMath.prototype.fallingFactorial = function (base, exp) {
+ return this.factorial(base) / this.factorial(base - exp);
+ };
+ GameMath.prototype.risingFactorial = function (base, exp) {
+ return this.factorial(base + exp - 1) / this.factorial(base - 1);
+ };
+ GameMath.prototype.binCoef = function (n, k) {
+ return this.fallingFactorial(n, k) / this.factorial(k);
+ };
+ GameMath.prototype.risingBinCoef = function (n, k) {
+ return this.risingFactorial(n, k) / this.factorial(k);
+ };
+ GameMath.prototype.chanceRoll = function (chance) {
+ if (typeof chance === "undefined") { chance = 50; }
+ if(chance <= 0) {
+ return false;
+ } else if(chance >= 100) {
+ return true;
+ } else {
+ if(Math.random() * 100 >= chance) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ };
+ GameMath.prototype.maxAdd = function (value, amount, max) {
+ value += amount;
+ if(value > max) {
+ value = max;
+ }
+ return value;
+ };
+ GameMath.prototype.minSub = function (value, amount, min) {
+ value -= amount;
+ if(value < min) {
+ value = min;
+ }
+ return value;
+ };
+ GameMath.prototype.wrapValue = function (value, amount, max) {
+ var diff;
+ value = Math.abs(value);
+ amount = Math.abs(amount);
+ max = Math.abs(max);
+ diff = (value + amount) % max;
+ return diff;
+ };
+ GameMath.prototype.randomSign = function () {
+ return (Math.random() > 0.5) ? 1 : -1;
+ };
+ GameMath.prototype.isOdd = function (n) {
+ if(n & 1) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ GameMath.prototype.isEven = function (n) {
+ if(n & 1) {
+ return false;
+ } else {
+ return true;
+ }
+ };
+ GameMath.prototype.wrapAngle = function (angle) {
+ var result = angle;
+ if(angle >= -180 && angle <= 180) {
+ return angle;
+ }
+ result = (angle + 180) % 360;
+ if(result < 0) {
+ result += 360;
+ }
+ return result - 180;
+ };
+ GameMath.prototype.angleLimit = function (angle, min, max) {
+ var result = angle;
+ if(angle > max) {
+ result = max;
+ } else if(angle < min) {
+ result = min;
+ }
+ return result;
+ };
+ GameMath.prototype.linearInterpolation = function (v, k) {
+ var m = v.length - 1;
+ var f = m * k;
+ var i = Math.floor(f);
+ if(k < 0) {
+ return this.linear(v[0], v[1], f);
+ }
+ if(k > 1) {
+ return this.linear(v[m], v[m - 1], m - f);
+ }
+ return this.linear(v[i], v[i + 1 > m ? m : i + 1], f - i);
+ };
+ GameMath.prototype.bezierInterpolation = function (v, k) {
+ var b = 0;
+ var n = v.length - 1;
+ for(var i = 0; i <= n; i++) {
+ b += Math.pow(1 - k, n - i) * Math.pow(k, i) * v[i] * this.bernstein(n, i);
+ }
+ return b;
+ };
+ GameMath.prototype.catmullRomInterpolation = function (v, k) {
+ var m = v.length - 1;
+ var f = m * k;
+ var i = Math.floor(f);
+ if(v[0] === v[m]) {
+ if(k < 0) {
+ i = Math.floor(f = m * (1 + k));
+ }
+ return this.catmullRom(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
+ } else {
+ if(k < 0) {
+ return v[0] - (this.catmullRom(v[0], v[0], v[1], v[1], -f) - v[0]);
+ }
+ if(k > 1) {
+ return v[m] - (this.catmullRom(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
+ }
+ return this.catmullRom(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
+ }
+ };
+ GameMath.prototype.linear = function (p0, p1, t) {
+ return (p1 - p0) * t + p0;
+ };
+ GameMath.prototype.bernstein = function (n, i) {
+ return this.factorial(n) / this.factorial(i) / this.factorial(n - i);
+ };
+ GameMath.prototype.catmullRom = function (p0, p1, p2, p3, t) {
+ var v0 = (p2 - p0) * 0.5, v1 = (p3 - p1) * 0.5, t2 = t * t, t3 = t * t2;
+ return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
+ };
+ GameMath.prototype.difference = function (a, b) {
+ return Math.abs(a - b);
+ };
+ GameMath.prototype.getRandom = function (objects, startIndex, length) {
+ if (typeof startIndex === "undefined") { startIndex = 0; }
+ if (typeof length === "undefined") { length = 0; }
+ if(objects != null) {
+ var l = length;
+ if((l == 0) || (l > objects.length - startIndex)) {
+ l = objects.length - startIndex;
+ }
+ if(l > 0) {
+ return objects[startIndex + Math.floor(Math.random() * l)];
+ }
+ }
+ return null;
+ };
+ GameMath.prototype.floor = function (value) {
+ var n = value | 0;
+ return (value > 0) ? (n) : ((n != value) ? (n - 1) : (n));
+ };
+ GameMath.prototype.ceil = function (value) {
+ var n = value | 0;
+ return (value > 0) ? ((n != value) ? (n + 1) : (n)) : (n);
+ };
+ GameMath.prototype.sinCosGenerator = function (length, sinAmplitude, cosAmplitude, frequency) {
+ if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; }
+ if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; }
+ if (typeof frequency === "undefined") { frequency = 1.0; }
+ var sin = sinAmplitude;
+ var cos = cosAmplitude;
+ var frq = frequency * Math.PI / length;
+ this.cosTable = [];
+ this.sinTable = [];
+ for(var c = 0; c < length; c++) {
+ cos -= sin * frq;
+ sin += cos * frq;
+ this.cosTable[c] = cos;
+ this.sinTable[c] = sin;
+ }
+ return this.sinTable;
+ };
+ GameMath.prototype.shiftSinTable = function () {
+ if(this.sinTable) {
+ var s = this.sinTable.shift();
+ this.sinTable.push(s);
+ return s;
+ }
+ };
+ GameMath.prototype.shiftCosTable = function () {
+ if(this.cosTable) {
+ var s = this.cosTable.shift();
+ this.cosTable.push(s);
+ return s;
+ }
+ };
+ GameMath.prototype.shuffleArray = function (array) {
+ for(var i = array.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ }
+ return array;
+ };
+ GameMath.prototype.distanceBetween = function (x1, y1, x2, y2) {
+ var dx = x1 - x2;
+ var dy = y1 - y2;
+ return Math.sqrt(dx * dx + dy * dy);
+ };
+ GameMath.prototype.vectorLength = function (dx, dy) {
+ return Math.sqrt(dx * dx + dy * dy);
+ };
+ return GameMath;
+ })();
+ Phaser.GameMath = GameMath;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Vec2 = (function () {
+ function Vec2(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ this.x = x;
+ this.y = y;
+ return this;
+ }
+ Vec2.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y);
+ };
+ Vec2.prototype.setTo = function (x, y) {
+ this.x = x;
+ this.y = y;
+ return this;
+ };
+ Vec2.prototype.add = function (a) {
+ this.x += a.x;
+ this.y += a.y;
+ return this;
+ };
+ Vec2.prototype.subtract = function (v) {
+ this.x -= v.x;
+ this.y -= v.y;
+ return this;
+ };
+ Vec2.prototype.multiply = function (v) {
+ this.x *= v.x;
+ this.y *= v.y;
+ return this;
+ };
+ Vec2.prototype.divide = function (v) {
+ this.x /= v.x;
+ this.y /= v.y;
+ return this;
+ };
+ Vec2.prototype.length = function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vec2.prototype.lengthSq = function () {
+ return (this.x * this.x) + (this.y * this.y);
+ };
+ Vec2.prototype.normalize = function () {
+ var inv = (this.x != 0 || this.y != 0) ? 1 / Math.sqrt(this.x * this.x + this.y * this.y) : 0;
+ this.x *= inv;
+ this.y *= inv;
+ return this;
+ };
+ Vec2.prototype.dot = function (a) {
+ return ((this.x * a.x) + (this.y * a.y));
+ };
+ Vec2.prototype.cross = function (a) {
+ return ((this.x * a.y) - (this.y * a.x));
+ };
+ Vec2.prototype.projectionLength = function (a) {
+ var den = a.dot(a);
+ if(den == 0) {
+ return 0;
+ } else {
+ return Math.abs(this.dot(a) / den);
+ }
+ };
+ Vec2.prototype.angle = function (a) {
+ return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
+ };
+ Vec2.prototype.scale = function (x, y) {
+ this.x *= x;
+ this.y *= y || x;
+ return this;
+ };
+ Vec2.prototype.multiplyByScalar = function (scalar) {
+ this.x *= scalar;
+ this.y *= scalar;
+ return this;
+ };
+ Vec2.prototype.multiplyAddByScalar = function (a, scalar) {
+ this.x += a.x * scalar;
+ this.y += a.y * scalar;
+ return this;
+ };
+ Vec2.prototype.divideByScalar = function (scalar) {
+ this.x /= scalar;
+ this.y /= scalar;
+ return this;
+ };
+ Vec2.prototype.reverse = function () {
+ this.x = -this.x;
+ this.y = -this.y;
+ return this;
+ };
+ Vec2.prototype.equals = function (value) {
+ return (this.x == value && this.y == value);
+ };
+ Vec2.prototype.toString = function () {
+ return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ };
+ return Vec2;
+ })();
+ Phaser.Vec2 = Vec2;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Vec2Utils = (function () {
+ function Vec2Utils() { }
+ Vec2Utils.add = function add(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x + b.x, a.y + b.y);
+ };
+ Vec2Utils.subtract = function subtract(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x - b.x, a.y - b.y);
+ };
+ Vec2Utils.multiply = function multiply(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x * b.x, a.y * b.y);
+ };
+ Vec2Utils.divide = function divide(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x / b.x, a.y / b.y);
+ };
+ Vec2Utils.scale = function scale(a, s, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x * s, a.y * s);
+ };
+ Vec2Utils.multiplyAdd = function multiplyAdd(a, b, s, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x + b.x * s, a.y + b.y * s);
+ };
+ Vec2Utils.negative = function negative(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(-a.x, -a.y);
+ };
+ Vec2Utils.perp = function perp(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(-a.y, a.x);
+ };
+ Vec2Utils.rperp = function rperp(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.y, -a.x);
+ };
+ Vec2Utils.equals = function equals(a, b) {
+ return a.x == b.x && a.y == b.y;
+ };
+ Vec2Utils.epsilonEquals = function epsilonEquals(a, b, epsilon) {
+ return Math.abs(a.x - b.x) <= epsilon && Math.abs(a.y - b.y) <= epsilon;
+ };
+ Vec2Utils.distance = function distance(a, b) {
+ return Math.sqrt(Vec2Utils.distanceSq(a, b));
+ };
+ Vec2Utils.distanceSq = function distanceSq(a, b) {
+ return ((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y));
+ };
+ Vec2Utils.project = function project(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var amt = a.dot(b) / b.lengthSq();
+ if(amt != 0) {
+ out.setTo(amt * b.x, amt * b.y);
+ }
+ return out;
+ };
+ Vec2Utils.projectUnit = function projectUnit(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var amt = a.dot(b);
+ if(amt != 0) {
+ out.setTo(amt * b.x, amt * b.y);
+ }
+ return out;
+ };
+ Vec2Utils.normalRightHand = function normalRightHand(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.y * -1, a.x);
+ };
+ Vec2Utils.normalize = function normalize(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var m = a.length();
+ if(m != 0) {
+ out.setTo(a.x / m, a.y / m);
+ }
+ return out;
+ };
+ Vec2Utils.dot = function dot(a, b) {
+ return ((a.x * b.x) + (a.y * b.y));
+ };
+ Vec2Utils.cross = function cross(a, b) {
+ return ((a.x * b.y) - (a.y * b.x));
+ };
+ Vec2Utils.angle = function angle(a, b) {
+ return Math.atan2(a.x * b.y - a.y * b.x, a.x * b.x + a.y * b.y);
+ };
+ Vec2Utils.angleSq = function angleSq(a, b) {
+ return a.subtract(b).angle(b.subtract(a));
+ };
+ Vec2Utils.rotateAroundOrigin = function rotateAroundOrigin(a, b, theta, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var x = a.x - b.x;
+ var y = a.y - b.y;
+ return out.setTo(x * Math.cos(theta) - y * Math.sin(theta) + b.x, x * Math.sin(theta) + y * Math.cos(theta) + b.y);
+ };
+ Vec2Utils.rotate = function rotate(a, theta, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var c = Math.cos(theta);
+ var s = Math.sin(theta);
+ return out.setTo(a.x * c - a.y * s, a.x * s + a.y * c);
+ };
+ Vec2Utils.clone = function clone(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x, a.y);
+ };
+ return Vec2Utils;
+ })();
+ Phaser.Vec2Utils = Vec2Utils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Mat3 = (function () {
+ function Mat3() {
+ this.data = [
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1
+ ];
+ }
+ Object.defineProperty(Mat3.prototype, "a00", {
+ get: function () {
+ return this.data[0];
+ },
+ set: function (value) {
+ this.data[0] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a01", {
+ get: function () {
+ return this.data[1];
+ },
+ set: function (value) {
+ this.data[1] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a02", {
+ get: function () {
+ return this.data[2];
+ },
+ set: function (value) {
+ this.data[2] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a10", {
+ get: function () {
+ return this.data[3];
+ },
+ set: function (value) {
+ this.data[3] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a11", {
+ get: function () {
+ return this.data[4];
+ },
+ set: function (value) {
+ this.data[4] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a12", {
+ get: function () {
+ return this.data[5];
+ },
+ set: function (value) {
+ this.data[5] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a20", {
+ get: function () {
+ return this.data[6];
+ },
+ set: function (value) {
+ this.data[6] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a21", {
+ get: function () {
+ return this.data[7];
+ },
+ set: function (value) {
+ this.data[7] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a22", {
+ get: function () {
+ return this.data[8];
+ },
+ set: function (value) {
+ this.data[8] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Mat3.prototype.copyFromMat3 = function (source) {
+ this.data[0] = source.data[0];
+ this.data[1] = source.data[1];
+ this.data[2] = source.data[2];
+ this.data[3] = source.data[3];
+ this.data[4] = source.data[4];
+ this.data[5] = source.data[5];
+ this.data[6] = source.data[6];
+ this.data[7] = source.data[7];
+ this.data[8] = source.data[8];
+ return this;
+ };
+ Mat3.prototype.copyFromMat4 = function (source) {
+ this.data[0] = source[0];
+ this.data[1] = source[1];
+ this.data[2] = source[2];
+ this.data[3] = source[4];
+ this.data[4] = source[5];
+ this.data[5] = source[6];
+ this.data[6] = source[8];
+ this.data[7] = source[9];
+ this.data[8] = source[10];
+ return this;
+ };
+ Mat3.prototype.clone = function (out) {
+ if (typeof out === "undefined") { out = new Phaser.Mat3(); }
+ out[0] = this.data[0];
+ out[1] = this.data[1];
+ out[2] = this.data[2];
+ out[3] = this.data[3];
+ out[4] = this.data[4];
+ out[5] = this.data[5];
+ out[6] = this.data[6];
+ out[7] = this.data[7];
+ out[8] = this.data[8];
+ return out;
+ };
+ Mat3.prototype.identity = function () {
+ return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ };
+ Mat3.prototype.translate = function (v) {
+ this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
+ this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
+ this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
+ return this;
+ };
+ Mat3.prototype.setTemps = function () {
+ this._a00 = this.data[0];
+ this._a01 = this.data[1];
+ this._a02 = this.data[2];
+ this._a10 = this.data[3];
+ this._a11 = this.data[4];
+ this._a12 = this.data[5];
+ this._a20 = this.data[6];
+ this._a21 = this.data[7];
+ this._a22 = this.data[8];
+ };
+ Mat3.prototype.rotate = function (rad) {
+ this.setTemps();
+ var s = Phaser.GameMath.sinA[rad];
+ var c = Phaser.GameMath.cosA[rad];
+ this.data[0] = c * this._a00 + s * this._a10;
+ this.data[1] = c * this._a01 + s * this._a10;
+ this.data[2] = c * this._a02 + s * this._a12;
+ this.data[3] = c * this._a10 - s * this._a00;
+ this.data[4] = c * this._a11 - s * this._a01;
+ this.data[5] = c * this._a12 - s * this._a02;
+ return this;
+ };
+ Mat3.prototype.scale = function (v) {
+ this.data[0] = v.x * this.data[0];
+ this.data[1] = v.x * this.data[1];
+ this.data[2] = v.x * this.data[2];
+ this.data[3] = v.y * this.data[3];
+ this.data[4] = v.y * this.data[4];
+ this.data[5] = v.y * this.data[5];
+ return this;
+ };
+ Mat3.prototype.setTo = function (a00, a01, a02, a10, a11, a12, a20, a21, a22) {
+ this.data[0] = a00;
+ this.data[1] = a01;
+ this.data[2] = a02;
+ this.data[3] = a10;
+ this.data[4] = a11;
+ this.data[5] = a12;
+ this.data[6] = a20;
+ this.data[7] = a21;
+ this.data[8] = a22;
+ return this;
+ };
+ Mat3.prototype.toString = function () {
+ return '';
+ };
+ return Mat3;
+ })();
+ Phaser.Mat3 = Mat3;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Mat3Utils = (function () {
+ function Mat3Utils() { }
+ Mat3Utils.transpose = function transpose(source, dest) {
+ if (typeof dest === "undefined") { dest = null; }
+ if(dest === null) {
+ 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 = 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;
+ 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 = 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 = 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 = 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 = {}));
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ var QuadTree = (function (_super) {
+ __extends(QuadTree, _super);
+ function QuadTree(manager, x, y, width, height, parent) {
+ if (typeof parent === "undefined") { parent = null; }
+ _super.call(this, x, y, width, height);
+ QuadTree.physics = manager;
+ this._headA = this._tailA = new Phaser.LinkedList();
+ this._headB = this._tailB = new Phaser.LinkedList();
+ if(parent != null) {
+ if(parent._headA.object != null) {
+ this._iterator = parent._headA;
+ while(this._iterator != null) {
+ if(this._tailA.object != null) {
+ this._ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ this._ot.next = this._tailA;
+ }
+ this._tailA.object = this._iterator.object;
+ this._iterator = this._iterator.next;
+ }
+ }
+ if(parent._headB.object != null) {
+ this._iterator = parent._headB;
+ while(this._iterator != null) {
+ if(this._tailB.object != null) {
+ this._ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ this._ot.next = this._tailB;
+ }
+ this._tailB.object = this._iterator.object;
+ this._iterator = this._iterator.next;
+ }
+ }
+ } else {
+ QuadTree._min = (this.width + this.height) / (2 * QuadTree.divisions);
+ }
+ this._canSubdivide = (this.width > QuadTree._min) || (this.height > QuadTree._min);
+ this._northWestTree = null;
+ this._northEastTree = null;
+ this._southEastTree = null;
+ this._southWestTree = null;
+ this._leftEdge = this.x;
+ this._rightEdge = this.x + this.width;
+ this._halfWidth = this.width / 2;
+ this._midpointX = this._leftEdge + this._halfWidth;
+ this._topEdge = this.y;
+ this._bottomEdge = this.y + this.height;
+ this._halfHeight = this.height / 2;
+ this._midpointY = this._topEdge + this._halfHeight;
+ }
+ QuadTree.A_LIST = 0;
+ QuadTree.B_LIST = 1;
+ QuadTree.prototype.destroy = function () {
+ this._tailA.destroy();
+ this._tailB.destroy();
+ this._headA.destroy();
+ this._headB.destroy();
+ this._tailA = null;
+ this._tailB = null;
+ this._headA = null;
+ this._headB = null;
+ if(this._northWestTree != null) {
+ this._northWestTree.destroy();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.destroy();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.destroy();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.destroy();
+ }
+ this._northWestTree = null;
+ this._northEastTree = null;
+ this._southEastTree = null;
+ this._southWestTree = null;
+ QuadTree._object = null;
+ QuadTree._processingCallback = null;
+ QuadTree._notifyCallback = null;
+ };
+ QuadTree.prototype.load = function (objectOrGroup1, objectOrGroup2, notifyCallback, processCallback, context) {
+ if (typeof objectOrGroup2 === "undefined") { objectOrGroup2 = null; }
+ if (typeof notifyCallback === "undefined") { notifyCallback = null; }
+ if (typeof processCallback === "undefined") { processCallback = null; }
+ if (typeof context === "undefined") { context = null; }
+ this.add(objectOrGroup1, QuadTree.A_LIST);
+ if(objectOrGroup2 != null) {
+ this.add(objectOrGroup2, QuadTree.B_LIST);
+ QuadTree._useBothLists = true;
+ } else {
+ QuadTree._useBothLists = false;
+ }
+ QuadTree._notifyCallback = notifyCallback;
+ QuadTree._processingCallback = processCallback;
+ QuadTree._callbackContext = context;
+ };
+ QuadTree.prototype.add = function (objectOrGroup, list) {
+ QuadTree._list = list;
+ if(objectOrGroup.type == Phaser.Types.GROUP) {
+ this._i = 0;
+ this._members = objectOrGroup['members'];
+ this._l = objectOrGroup['length'];
+ while(this._i < this._l) {
+ this._basic = this._members[this._i++];
+ if(this._basic != null && this._basic.exists) {
+ if(this._basic.type == Phaser.Types.GROUP) {
+ this.add(this._basic, list);
+ } else {
+ QuadTree._object = this._basic;
+ if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
+ this.addObject();
+ }
+ }
+ }
+ }
+ } else {
+ QuadTree._object = objectOrGroup;
+ if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
+ this.addObject();
+ }
+ }
+ };
+ QuadTree.prototype.addObject = function () {
+ if(!this._canSubdivide || ((this._leftEdge >= QuadTree._object.body.bounds.x) && (this._rightEdge <= QuadTree._object.body.bounds.right) && (this._topEdge >= QuadTree._object.body.bounds.y) && (this._bottomEdge <= QuadTree._object.body.bounds.bottom))) {
+ this.addToList();
+ return;
+ }
+ if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) {
+ if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ return;
+ }
+ if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ return;
+ }
+ }
+ if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) {
+ if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ return;
+ }
+ if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ return;
+ }
+ }
+ if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ }
+ };
+ QuadTree.prototype.addToList = function () {
+ if(QuadTree._list == QuadTree.A_LIST) {
+ if(this._tailA.object != null) {
+ this._ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ this._ot.next = this._tailA;
+ }
+ this._tailA.object = QuadTree._object;
+ } else {
+ if(this._tailB.object != null) {
+ this._ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ this._ot.next = this._tailB;
+ }
+ this._tailB.object = QuadTree._object;
+ }
+ if(!this._canSubdivide) {
+ return;
+ }
+ if(this._northWestTree != null) {
+ this._northWestTree.addToList();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.addToList();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.addToList();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.addToList();
+ }
+ };
+ QuadTree.prototype.execute = function () {
+ this._overlapProcessed = false;
+ if(this._headA.object != null) {
+ this._iterator = this._headA;
+ while(this._iterator != null) {
+ QuadTree._object = this._iterator.object;
+ if(QuadTree._useBothLists) {
+ QuadTree._iterator = this._headB;
+ } else {
+ QuadTree._iterator = this._iterator.next;
+ }
+ if(QuadTree._object.exists && (QuadTree._object.body.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
+ this._overlapProcessed = true;
+ }
+ this._iterator = this._iterator.next;
+ }
+ }
+ if((this._northWestTree != null) && this._northWestTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._northEastTree != null) && this._northEastTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._southEastTree != null) && this._southEastTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._southWestTree != null) && this._southWestTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ return this._overlapProcessed;
+ };
+ QuadTree.prototype.overlapNode = function () {
+ this._overlapProcessed = false;
+ while(QuadTree._iterator != null) {
+ if(!QuadTree._object.exists || (QuadTree._object.body.allowCollisions <= 0)) {
+ break;
+ }
+ this._checkObject = QuadTree._iterator.object;
+ if((QuadTree._object === this._checkObject) || !this._checkObject.exists || (this._checkObject.body.allowCollisions <= 0)) {
+ QuadTree._iterator = QuadTree._iterator.next;
+ continue;
+ }
+ QuadTree._iterator = QuadTree._iterator.next;
+ }
+ return this._overlapProcessed;
+ };
+ return QuadTree;
+ })(Phaser.Rectangle);
+ Phaser.QuadTree = QuadTree;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var LinkedList = (function () {
+ function LinkedList() {
+ this.object = null;
+ this.next = null;
+ }
+ LinkedList.prototype.destroy = function () {
+ this.object = null;
+ if(this.next != null) {
+ this.next.destroy();
+ }
+ this.next = null;
+ };
+ return LinkedList;
+ })();
+ Phaser.LinkedList = LinkedList;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var RandomDataGenerator = (function () {
+ function RandomDataGenerator(seeds) {
+ if (typeof seeds === "undefined") { seeds = []; }
+ this.c = 1;
+ this.sow(seeds);
+ }
+ RandomDataGenerator.prototype.uint32 = function () {
+ return this.rnd.apply(this) * 0x100000000;
+ };
+ RandomDataGenerator.prototype.fract32 = function () {
+ return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;
+ };
+ RandomDataGenerator.prototype.rnd = function () {
+ var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10;
+ this.c = t | 0;
+ this.s0 = this.s1;
+ this.s1 = this.s2;
+ this.s2 = t - this.c;
+ return this.s2;
+ };
+ RandomDataGenerator.prototype.hash = function (data) {
+ var h, i, n;
+ n = 0xefc8249d;
+ data = data.toString();
+ for(i = 0; i < data.length; i++) {
+ n += data.charCodeAt(i);
+ h = 0.02519603282416938 * n;
+ n = h >>> 0;
+ h -= n;
+ h *= n;
+ n = h >>> 0;
+ h -= n;
+ n += h * 0x100000000;
+ }
+ return (n >>> 0) * 2.3283064365386963e-10;
+ };
+ RandomDataGenerator.prototype.sow = function (seeds) {
+ if (typeof seeds === "undefined") { seeds = []; }
+ this.s0 = this.hash(' ');
+ this.s1 = this.hash(this.s0);
+ this.s2 = this.hash(this.s1);
+ var seed;
+ for(var i = 0; seed = seeds[i++]; ) {
+ this.s0 -= this.hash(seed);
+ this.s0 += ~~(this.s0 < 0);
+ this.s1 -= this.hash(seed);
+ this.s1 += ~~(this.s1 < 0);
+ this.s2 -= this.hash(seed);
+ this.s2 += ~~(this.s2 < 0);
+ }
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "integer", {
+ get: function () {
+ return this.uint32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "frac", {
+ get: function () {
+ return this.fract32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "real", {
+ get: function () {
+ return this.uint32() + this.fract32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RandomDataGenerator.prototype.integerInRange = function (min, max) {
+ return Math.floor(this.realInRange(min, max));
+ };
+ RandomDataGenerator.prototype.realInRange = function (min, max) {
+ min = min || 0;
+ max = max || 0;
+ return this.frac * (max - min) + min;
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "normal", {
+ get: function () {
+ return 1 - 2 * this.frac;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "uuid", {
+ get: function () {
+ var a, b;
+ for(b = a = ''; a++ < 36; b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-') {
+ ;
+ }
+ return b;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RandomDataGenerator.prototype.pick = function (array) {
+ return array[this.integerInRange(0, array.length)];
+ };
+ RandomDataGenerator.prototype.weightedPick = function (array) {
+ return array[~~(Math.pow(this.frac, 2) * array.length)];
+ };
+ RandomDataGenerator.prototype.timestamp = function (min, max) {
+ if (typeof min === "undefined") { min = 946684800000; }
+ if (typeof max === "undefined") { max = 1577862000000; }
+ return this.realInRange(min, max);
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "angle", {
+ get: function () {
+ return this.integerInRange(-180, 180);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return RandomDataGenerator;
+ })();
+ Phaser.RandomDataGenerator = RandomDataGenerator;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Plugin = (function () {
+ function Plugin(game, parent) {
+ this.game = game;
+ this.parent = parent;
+ this.active = false;
+ this.visible = false;
+ this.hasPreUpdate = false;
+ this.hasUpdate = false;
+ this.hasPostUpdate = false;
+ this.hasPreRender = false;
+ this.hasRender = false;
+ this.hasPostRender = false;
+ }
+ Plugin.prototype.preUpdate = function () {
+ };
+ Plugin.prototype.update = function () {
+ };
+ Plugin.prototype.postUpdate = function () {
+ };
+ Plugin.prototype.preRender = function () {
+ };
+ Plugin.prototype.render = function () {
+ };
+ Plugin.prototype.postRender = function () {
+ };
+ Plugin.prototype.destroy = function () {
+ this.game = null;
+ this.parent = null;
+ this.active = false;
+ this.visible = false;
+ };
+ return Plugin;
+ })();
+ Phaser.Plugin = Plugin;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var PluginManager = (function () {
+ function PluginManager(game, parent) {
+ this.game = game;
+ this._parent = parent;
+ this.plugins = [];
+ }
+ PluginManager.prototype.add = function (plugin) {
+ var result = false;
+ if(typeof plugin === 'function') {
+ plugin = new plugin(this.game, this._parent);
+ } else {
+ plugin.game = this.game;
+ plugin.parent = this._parent;
+ }
+ if(typeof plugin['preUpdate'] === 'function') {
+ plugin.hasPreUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['update'] === 'function') {
+ plugin.hasUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['postUpdate'] === 'function') {
+ plugin.hasPostUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['preRender'] === 'function') {
+ plugin.hasPreRender = true;
+ result = true;
+ }
+ if(typeof plugin['render'] === 'function') {
+ plugin.hasRender = true;
+ result = true;
+ }
+ if(typeof plugin['postRender'] === 'function') {
+ plugin.hasPostRender = true;
+ result = true;
+ }
+ if(result == true) {
+ if(plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) {
+ plugin.active = true;
+ }
+ if(plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender) {
+ plugin.visible = true;
+ }
+ this._pluginsLength = this.plugins.push(plugin);
+ return plugin;
+ } else {
+ return null;
+ }
+ };
+ PluginManager.prototype.remove = function (plugin) {
+ this._pluginsLength--;
+ };
+ PluginManager.prototype.preUpdate = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) {
+ this.plugins[this._p].preUpdate();
+ }
+ }
+ };
+ PluginManager.prototype.update = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasUpdate) {
+ this.plugins[this._p].update();
+ }
+ }
+ };
+ PluginManager.prototype.postUpdate = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) {
+ this.plugins[this._p].postUpdate();
+ }
+ }
+ };
+ PluginManager.prototype.preRender = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) {
+ this.plugins[this._p].preRender();
+ }
+ }
+ };
+ PluginManager.prototype.render = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasRender) {
+ this.plugins[this._p].render();
+ }
+ }
+ };
+ PluginManager.prototype.postRender = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) {
+ this.plugins[this._p].postRender();
+ }
+ }
+ };
+ PluginManager.prototype.destroy = function () {
+ this.plugins.length = 0;
+ this._pluginsLength = 0;
+ this.game = null;
+ this._parent = null;
+ };
+ return PluginManager;
+ })();
+ Phaser.PluginManager = PluginManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Signal = (function () {
+ function Signal() {
+ this._bindings = [];
+ this._prevParams = null;
+ this.memorize = false;
+ this._shouldPropagate = true;
+ this.active = true;
+ }
+ Signal.VERSION = '1.0.0';
+ Signal.prototype.validateListener = function (listener, fnName) {
+ if(typeof listener !== 'function') {
+ throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName));
+ }
+ };
+ Signal.prototype._registerListener = function (listener, isOnce, listenerContext, priority) {
+ var prevIndex = this._indexOfListener(listener, listenerContext);
+ var binding;
+ if(prevIndex !== -1) {
+ binding = this._bindings[prevIndex];
+ if(binding.isOnce() !== isOnce) {
+ throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.');
+ }
+ } else {
+ binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
+ this._addBinding(binding);
+ }
+ if(this.memorize && this._prevParams) {
+ binding.execute(this._prevParams);
+ }
+ return binding;
+ };
+ Signal.prototype._addBinding = function (binding) {
+ var n = this._bindings.length;
+ do {
+ --n;
+ }while(this._bindings[n] && binding.priority <= this._bindings[n].priority);
+ this._bindings.splice(n + 1, 0, binding);
+ };
+ Signal.prototype._indexOfListener = function (listener, context) {
+ var n = this._bindings.length;
+ var cur;
+ while(n--) {
+ cur = this._bindings[n];
+ if(cur.getListener() === listener && cur.context === context) {
+ return n;
+ }
+ }
+ return -1;
+ };
+ Signal.prototype.has = function (listener, context) {
+ if (typeof context === "undefined") { context = null; }
+ return this._indexOfListener(listener, context) !== -1;
+ };
+ Signal.prototype.add = function (listener, listenerContext, priority) {
+ if (typeof listenerContext === "undefined") { listenerContext = null; }
+ if (typeof priority === "undefined") { priority = 0; }
+ this.validateListener(listener, 'add');
+ return this._registerListener(listener, false, listenerContext, priority);
+ };
+ Signal.prototype.addOnce = function (listener, listenerContext, priority) {
+ if (typeof listenerContext === "undefined") { listenerContext = null; }
+ if (typeof priority === "undefined") { priority = 0; }
+ this.validateListener(listener, 'addOnce');
+ return this._registerListener(listener, true, listenerContext, priority);
+ };
+ Signal.prototype.remove = function (listener, context) {
+ if (typeof context === "undefined") { context = null; }
+ this.validateListener(listener, 'remove');
+ var i = this._indexOfListener(listener, context);
+ if(i !== -1) {
+ this._bindings[i]._destroy();
+ this._bindings.splice(i, 1);
+ }
+ return listener;
+ };
+ Signal.prototype.removeAll = function () {
+ if(this._bindings) {
+ var n = this._bindings.length;
+ while(n--) {
+ this._bindings[n]._destroy();
+ }
+ this._bindings.length = 0;
+ }
+ };
+ Signal.prototype.getNumListeners = function () {
+ return this._bindings.length;
+ };
+ Signal.prototype.halt = function () {
+ this._shouldPropagate = false;
+ };
+ Signal.prototype.dispatch = function () {
+ var paramsArr = [];
+ for (var _i = 0; _i < (arguments.length - 0); _i++) {
+ paramsArr[_i] = arguments[_i + 0];
+ }
+ if(!this.active) {
+ return;
+ }
+ var n = this._bindings.length;
+ var bindings;
+ if(this.memorize) {
+ this._prevParams = paramsArr;
+ }
+ if(!n) {
+ return;
+ }
+ bindings = this._bindings.slice(0);
+ this._shouldPropagate = true;
+ do {
+ n--;
+ }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
+ };
+ Signal.prototype.forget = function () {
+ this._prevParams = null;
+ };
+ Signal.prototype.dispose = function () {
+ this.removeAll();
+ delete this._bindings;
+ delete this._prevParams;
+ };
+ Signal.prototype.toString = function () {
+ return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']';
+ };
+ return Signal;
+ })();
+ Phaser.Signal = Signal;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var SignalBinding = (function () {
+ function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
+ if (typeof priority === "undefined") { priority = 0; }
+ this.active = true;
+ this.params = null;
+ this._listener = listener;
+ this._isOnce = isOnce;
+ this.context = listenerContext;
+ this._signal = signal;
+ this.priority = priority || 0;
+ }
+ SignalBinding.prototype.execute = function (paramsArr) {
+ var handlerReturn;
+ var params;
+ if(this.active && !!this._listener) {
+ params = this.params ? this.params.concat(paramsArr) : paramsArr;
+ handlerReturn = this._listener.apply(this.context, params);
+ if(this._isOnce) {
+ this.detach();
+ }
+ }
+ return handlerReturn;
+ };
+ SignalBinding.prototype.detach = function () {
+ return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
+ };
+ SignalBinding.prototype.isBound = function () {
+ return (!!this._signal && !!this._listener);
+ };
+ SignalBinding.prototype.isOnce = function () {
+ return this._isOnce;
+ };
+ SignalBinding.prototype.getListener = function () {
+ return this._listener;
+ };
+ SignalBinding.prototype.getSignal = function () {
+ return this._signal;
+ };
+ SignalBinding.prototype._destroy = function () {
+ delete this._signal;
+ delete this._listener;
+ delete this.context;
+ };
+ SignalBinding.prototype.toString = function () {
+ return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']';
+ };
+ return SignalBinding;
+ })();
+ Phaser.SignalBinding = SignalBinding;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Group = (function () {
+ function Group(game, maxSize) {
+ if (typeof maxSize === "undefined") { maxSize = 0; }
+ this._sortIndex = '';
+ this._zCounter = 0;
+ this.ID = -1;
+ this.z = -1;
+ this.group = null;
+ this.modified = false;
+ this.game = game;
+ this.type = Phaser.Types.GROUP;
+ this.active = true;
+ this.exists = true;
+ this.visible = true;
+ this.members = [];
+ this.length = 0;
+ this._maxSize = maxSize;
+ this._marker = 0;
+ this._sortIndex = null;
+ this.ID = this.game.world.getNextGroupID();
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this.texture.opaque = false;
+ }
+ Group.prototype.getNextZIndex = function () {
+ return this._zCounter++;
+ };
+ Group.prototype.destroy = function () {
+ if(this.members != null) {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ this._member.destroy();
+ }
+ }
+ this.members.length = 0;
+ }
+ this._sortIndex = null;
+ };
+ Group.prototype.update = function () {
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.active) {
+ if(this._member.type != Phaser.Types.GROUP) {
+ this._member.preUpdate();
+ }
+ this._member.update();
+ }
+ }
+ };
+ Group.prototype.postUpdate = function () {
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.active) {
+ this._member.postUpdate();
+ }
+ }
+ };
+ Group.prototype.render = function (camera) {
+ if(camera.isHidden(this) == true) {
+ return;
+ }
+ this.game.renderer.groupRenderer.preRender(camera, this);
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) {
+ if(this._member.type == Phaser.Types.GROUP) {
+ this._member.render(camera);
+ } else {
+ this.game.renderer.renderGameObject(camera, this._member);
+ }
+ }
+ }
+ this.game.renderer.groupRenderer.postRender(camera, this);
+ };
+ Group.prototype.directRender = function (camera) {
+ this.game.renderer.groupRenderer.preRender(camera, this);
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists) {
+ if(this._member.type == Phaser.Types.GROUP) {
+ this._member.directRender(camera);
+ } else {
+ this.game.renderer.renderGameObject(this._member);
+ }
+ }
+ }
+ this.game.renderer.groupRenderer.postRender(camera, this);
+ };
+ Object.defineProperty(Group.prototype, "maxSize", {
+ get: function () {
+ return this._maxSize;
+ },
+ set: function (size) {
+ this._maxSize = size;
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ if(this._maxSize == 0 || this.members == null || (this._maxSize >= this.members.length)) {
+ return;
+ }
+ this._i = this._maxSize;
+ this._length = this.members.length;
+ while(this._i < this._length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ this._member.destroy();
+ }
+ }
+ this.length = this.members.length = this._maxSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Group.prototype.add = function (object) {
+ if(object.group && (object.group.ID == this.ID || (object.type == Phaser.Types.GROUP && object.ID == this.ID))) {
+ return object;
+ }
+ this._i = 0;
+ this._length = this.members.length;
+ while(this._i < this._length) {
+ if(this.members[this._i] == null) {
+ this.members[this._i] = object;
+ this.setObjectIDs(object);
+ if(this._i >= this.length) {
+ this.length = this._i + 1;
+ }
+ return object;
+ }
+ this._i++;
+ }
+ if(this._maxSize > 0) {
+ if(this.members.length >= this._maxSize) {
+ return object;
+ } else if(this.members.length * 2 <= this._maxSize) {
+ this.members.length *= 2;
+ } else {
+ this.members.length = this._maxSize;
+ }
+ } else {
+ this.members.length *= 2;
+ }
+ this.members[this._i] = object;
+ this.length = this._i + 1;
+ this.setObjectIDs(object);
+ return object;
+ };
+ Group.prototype.addNewSprite = function (x, y, key, frame) {
+ if (typeof key === "undefined") { key = ''; }
+ if (typeof frame === "undefined") { frame = null; }
+ return this.add(new Phaser.Sprite(this.game, x, y, key, frame));
+ };
+ Group.prototype.setObjectIDs = function (object, zIndex) {
+ if (typeof zIndex === "undefined") { zIndex = -1; }
+ if(object.group !== null) {
+ object.group.remove(object);
+ }
+ object.group = this;
+ if(zIndex == -1) {
+ zIndex = this.getNextZIndex();
+ }
+ object.z = zIndex;
+ if(object['events']) {
+ object['events'].onAddedToGroup.dispatch(object, this, object.z);
+ }
+ };
+ Group.prototype.recycle = function (objectClass) {
+ if (typeof objectClass === "undefined") { objectClass = null; }
+ if(this._maxSize > 0) {
+ if(this.length < this._maxSize) {
+ if(objectClass == null) {
+ return null;
+ }
+ return this.add(new objectClass(this.game));
+ } else {
+ this._member = this.members[this._marker++];
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ return this._member;
+ }
+ } else {
+ this._member = this.getFirstAvailable(objectClass);
+ if(this._member != null) {
+ return this._member;
+ }
+ if(objectClass == null) {
+ return null;
+ }
+ return this.add(new objectClass(this.game));
+ }
+ };
+ Group.prototype.remove = function (object, splice) {
+ if (typeof splice === "undefined") { splice = false; }
+ this._i = this.members.indexOf(object);
+ if(this._i < 0 || (this._i >= this.members.length)) {
+ return null;
+ }
+ if(splice) {
+ this.members.splice(this._i, 1);
+ this.length--;
+ } else {
+ this.members[this._i] = null;
+ }
+ if(object['events']) {
+ object['events'].onRemovedFromGroup.dispatch(object, this);
+ }
+ object.group = null;
+ object.z = -1;
+ return object;
+ };
+ Group.prototype.replace = function (oldObject, newObject) {
+ this._i = this.members.indexOf(oldObject);
+ if(this._i < 0 || (this._i >= this.members.length)) {
+ return null;
+ }
+ this.setObjectIDs(newObject, this.members[this._i].z);
+ this.remove(this.members[this._i]);
+ this.members[this._i] = newObject;
+ return newObject;
+ };
+ Group.prototype.swap = function (child1, child2, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(child1.group.ID != this.ID || child2.group.ID != this.ID || child1 === child2) {
+ return false;
+ }
+ var tempZ = child1.z;
+ child1.z = child2.z;
+ child2.z = tempZ;
+ if(sort) {
+ this.sort();
+ }
+ return true;
+ };
+ Group.prototype.bringToTop = function (child) {
+ var oldZ = child.z;
+ if(!child || child.group == null || child.group.ID != this.ID) {
+ return false;
+ }
+ 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;
+ }
+ }
+ if(child.z == topZ) {
+ return false;
+ }
+ child.z = topZ + 1;
+ this.sort();
+ for(var i = 0; i < this.length; i++) {
+ if(this.members[i]) {
+ this.members[i].z = i;
+ }
+ }
+ return true;
+ };
+ Group.prototype.sort = function (index, order) {
+ if (typeof index === "undefined") { index = 'z'; }
+ if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
+ var _this = this;
+ this._sortIndex = index;
+ this._sortOrder = order;
+ this.members.sort(function (a, b) {
+ return _this.sortHandler(a, b);
+ });
+ };
+ Group.prototype.sortHandler = function (obj1, obj2) {
+ if(!obj1 || !obj2) {
+ return 0;
+ }
+ if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ Group.prototype.setAll = function (variableName, value, recurse) {
+ if (typeof recurse === "undefined") { recurse = true; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recurse && this._member.type == Phaser.Types.GROUP) {
+ this._member.setAll(variableName, value, recurse);
+ } else {
+ this._member[variableName] = value;
+ }
+ }
+ }
+ };
+ Group.prototype.callAll = function (functionName, recurse) {
+ if (typeof recurse === "undefined") { recurse = true; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recurse && this._member.type == Phaser.Types.GROUP) {
+ this._member.callAll(functionName, recurse);
+ } else {
+ this._member[functionName]();
+ }
+ }
+ }
+ };
+ Group.prototype.forEach = function (callback, recursive) {
+ if (typeof recursive === "undefined") { recursive = false; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recursive && this._member.type == Phaser.Types.GROUP) {
+ this._member.forEach(callback, true);
+ } else {
+ callback.call(this, this._member);
+ }
+ }
+ }
+ };
+ Group.prototype.forEachAlive = function (context, callback, recursive) {
+ if (typeof recursive === "undefined") { recursive = false; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.alive) {
+ if(recursive && this._member.type == Phaser.Types.GROUP) {
+ this._member.forEachAlive(context, callback, true);
+ } else {
+ callback.call(context, this._member);
+ }
+ }
+ }
+ };
+ Group.prototype.getFirstAvailable = function (objectClass) {
+ if (typeof objectClass === "undefined") { objectClass = null; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && !this._member.exists && ((objectClass == null) || (typeof this._member === objectClass))) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstNull = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ if(this.members[this._i] == null) {
+ return this._i;
+ } else {
+ this._i++;
+ }
+ }
+ return -1;
+ };
+ Group.prototype.getFirstExtant = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstAlive = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && this._member.exists && this._member.alive) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstDead = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && !this._member.alive) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.countLiving = function () {
+ this._count = -1;
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(this._count < 0) {
+ this._count = 0;
+ }
+ if(this._member.exists && this._member.alive) {
+ this._count++;
+ }
+ }
+ }
+ return this._count;
+ };
+ Group.prototype.countDead = function () {
+ this._count = -1;
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(this._count < 0) {
+ this._count = 0;
+ }
+ if(!this._member.alive) {
+ this._count++;
+ }
+ }
+ }
+ return this._count;
+ };
+ Group.prototype.getRandom = function (startIndex, length) {
+ if (typeof startIndex === "undefined") { startIndex = 0; }
+ if (typeof length === "undefined") { length = 0; }
+ if(length == 0) {
+ length = this.length;
+ }
+ return this.game.math.getRandom(this.members, startIndex, length);
+ };
+ Group.prototype.clear = function () {
+ this.length = this.members.length = 0;
+ };
+ Group.prototype.kill = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && this._member.exists) {
+ this._member.kill();
+ }
+ }
+ };
+ return Group;
+ })();
+ Phaser.Group = Group;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Camera = (function () {
+ function Camera(game, id, x, y, width, height) {
+ this._target = null;
+ this.worldBounds = null;
+ this.modified = false;
+ this.deadzone = null;
+ this.visible = true;
+ this.z = -1;
+ this.game = game;
+ this.ID = id;
+ this.z = id;
+ width = this.game.math.clamp(width, this.game.stage.width, 1);
+ height = this.game.math.clamp(height, this.game.stage.height, 1);
+ this.worldView = new Phaser.Rectangle(0, 0, width, height);
+ this.screenView = new Phaser.Rectangle(x, y, width, height);
+ this.plugins = new Phaser.PluginManager(this.game, this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this._canvas = document.createElement('canvas');
+ this._canvas.width = width;
+ this._canvas.height = height;
+ this._renderLocal = true;
+ this.texture.canvas = this._canvas;
+ this.texture.context = this.texture.canvas.getContext('2d');
+ this.texture.backgroundColor = this.game.stage.backgroundColor;
+ this.scale = this.transform.scale;
+ this.alpha = this.texture.alpha;
+ this.origin = this.transform.origin;
+ this.crop = this.texture.crop;
+ }
+ Object.defineProperty(Camera.prototype, "alpha", {
+ get: function () {
+ return this.texture.alpha;
+ },
+ set: function (value) {
+ this.texture.alpha = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "directToStage", {
+ set: function (value) {
+ if(value) {
+ this._renderLocal = false;
+ this.texture.canvas = this.game.stage.canvas;
+ Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
+ } else {
+ this._renderLocal = true;
+ this.texture.canvas = this._canvas;
+ Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
+ }
+ this.texture.context = this.texture.canvas.getContext('2d');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Camera.prototype.hide = function (object) {
+ object.texture.hideFromCamera(this);
+ };
+ Camera.prototype.isHidden = function (object) {
+ return object.texture.isHidden(this);
+ };
+ Camera.prototype.show = function (object) {
+ object.texture.showToCamera(this);
+ };
+ Camera.prototype.follow = function (target, style) {
+ if (typeof style === "undefined") { style = Phaser.Types.CAMERA_FOLLOW_LOCKON; }
+ this._target = target;
+ var helper;
+ switch(style) {
+ case Phaser.Types.CAMERA_FOLLOW_PLATFORMER:
+ var w = this.width / 8;
+ var h = this.height / 3;
+ this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_TOPDOWN:
+ helper = Math.max(this.width, this.height) / 4;
+ this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT:
+ helper = Math.max(this.width, this.height) / 8;
+ this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_LOCKON:
+ default:
+ this.deadzone = null;
+ break;
+ }
+ };
+ Camera.prototype.focusOnXY = function (x, y) {
+ x += (x > 0) ? 0.0000001 : -0.0000001;
+ y += (y > 0) ? 0.0000001 : -0.0000001;
+ this.worldView.x = Math.round(x - this.worldView.halfWidth);
+ this.worldView.y = Math.round(y - this.worldView.halfHeight);
+ };
+ Camera.prototype.focusOn = function (point) {
+ point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
+ point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
+ this.worldView.x = Math.round(point.x - this.worldView.halfWidth);
+ this.worldView.y = Math.round(point.y - this.worldView.halfHeight);
+ };
+ Camera.prototype.setBounds = function (x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ if(this.worldBounds == null) {
+ this.worldBounds = new Phaser.Rectangle();
+ }
+ this.worldBounds.setTo(x, y, width, height);
+ this.worldView.x = x;
+ this.worldView.y = y;
+ this.update();
+ };
+ Camera.prototype.update = function () {
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ this.plugins.preUpdate();
+ if(this._target !== null) {
+ if(this.deadzone == null) {
+ this.focusOnXY(this._target.x, this._target.y);
+ } else {
+ var edge;
+ var targetX = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
+ var targetY = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
+ edge = targetX - this.deadzone.x;
+ if(this.worldView.x > edge) {
+ this.worldView.x = edge;
+ }
+ edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
+ if(this.worldView.x < edge) {
+ this.worldView.x = edge;
+ }
+ edge = targetY - this.deadzone.y;
+ if(this.worldView.y > edge) {
+ this.worldView.y = edge;
+ }
+ edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
+ if(this.worldView.y < edge) {
+ this.worldView.y = edge;
+ }
+ }
+ }
+ if(this.worldBounds !== null) {
+ if(this.worldView.x < this.worldBounds.left) {
+ this.worldView.x = this.worldBounds.left;
+ }
+ if(this.worldView.x > this.worldBounds.right - this.width) {
+ this.worldView.x = (this.worldBounds.right - this.width) + 1;
+ }
+ if(this.worldView.y < this.worldBounds.top) {
+ this.worldView.y = this.worldBounds.top;
+ }
+ if(this.worldView.y > this.worldBounds.bottom - this.height) {
+ this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
+ }
+ }
+ this.worldView.floor();
+ this.plugins.update();
+ };
+ Camera.prototype.postUpdate = function () {
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ if(this.worldBounds !== null) {
+ if(this.worldView.x < this.worldBounds.left) {
+ this.worldView.x = this.worldBounds.left;
+ }
+ if(this.worldView.x > this.worldBounds.right - this.width) {
+ this.worldView.x = this.worldBounds.right - this.width;
+ }
+ if(this.worldView.y < this.worldBounds.top) {
+ this.worldView.y = this.worldBounds.top;
+ }
+ if(this.worldView.y > this.worldBounds.bottom - this.height) {
+ this.worldView.y = this.worldBounds.bottom - this.height;
+ }
+ }
+ this.worldView.floor();
+ this.plugins.postUpdate();
+ };
+ Camera.prototype.destroy = function () {
+ this.game.world.cameras.removeCamera(this.ID);
+ this.plugins.destroy();
+ };
+ Object.defineProperty(Camera.prototype, "x", {
+ get: function () {
+ return this.worldView.x;
+ },
+ set: function (value) {
+ this.worldView.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "y", {
+ get: function () {
+ return this.worldView.y;
+ },
+ set: function (value) {
+ this.worldView.y = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "width", {
+ get: function () {
+ return this.screenView.width;
+ },
+ set: function (value) {
+ this.screenView.width = value;
+ this.worldView.width = value;
+ if(value !== this.texture.canvas.width) {
+ this.texture.canvas.width = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "height", {
+ get: function () {
+ return this.screenView.height;
+ },
+ set: function (value) {
+ this.screenView.height = value;
+ this.worldView.height = value;
+ if(value !== this.texture.canvas.height) {
+ this.texture.canvas.height = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Camera.prototype.setPosition = function (x, y) {
+ this.screenView.x = x;
+ this.screenView.y = y;
+ };
+ Camera.prototype.setSize = function (width, height) {
+ this.screenView.width = width * this.transform.scale.x;
+ this.screenView.height = height * this.transform.scale.y;
+ this.worldView.width = width;
+ this.worldView.height = height;
+ if(width !== this.texture.canvas.width) {
+ this.texture.canvas.width = width;
+ }
+ if(height !== this.texture.canvas.height) {
+ this.texture.canvas.height = height;
+ }
+ };
+ Object.defineProperty(Camera.prototype, "rotation", {
+ get: function () {
+ return this.transform.rotation;
+ },
+ set: function (value) {
+ this.transform.rotation = this.game.math.wrap(value, 360, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Camera;
+ })();
+ Phaser.Camera = Camera;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var CameraManager = (function () {
+ function CameraManager(game, x, y, width, height) {
+ this._sortIndex = '';
+ this.game = game;
+ this._cameras = [];
+ this._cameraLength = 0;
+ this.defaultCamera = this.addCamera(x, y, width, height);
+ this.defaultCamera.directToStage = true;
+ this.current = this.defaultCamera;
+ }
+ CameraManager.prototype.getAll = function () {
+ return this._cameras;
+ };
+ CameraManager.prototype.update = function () {
+ for(var i = 0; i < this._cameras.length; i++) {
+ this._cameras[i].update();
+ }
+ };
+ CameraManager.prototype.postUpdate = function () {
+ for(var i = 0; i < this._cameras.length; i++) {
+ this._cameras[i].postUpdate();
+ }
+ };
+ CameraManager.prototype.addCamera = function (x, y, width, height) {
+ var newCam = new Phaser.Camera(this.game, this._cameraLength, x, y, width, height);
+ this._cameraLength = this._cameras.push(newCam);
+ return newCam;
+ };
+ CameraManager.prototype.removeCamera = function (id) {
+ for(var c = 0; c < this._cameras.length; c++) {
+ if(this._cameras[c].ID == id) {
+ if(this.current.ID === this._cameras[c].ID) {
+ this.current = null;
+ }
+ this._cameras.splice(c, 1);
+ return true;
+ }
+ }
+ return false;
+ };
+ CameraManager.prototype.swap = function (camera1, camera2, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(camera1.ID == camera2.ID) {
+ return false;
+ }
+ var tempZ = camera1.z;
+ camera1.z = camera2.z;
+ camera2.z = tempZ;
+ if(sort) {
+ this.sort();
+ }
+ return true;
+ };
+ CameraManager.prototype.getCameraUnderPoint = function (x, y) {
+ for(var c = this._cameraLength - 1; c >= 0; c--) {
+ if(this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) {
+ return this._cameras[c];
+ }
+ }
+ return null;
+ };
+ CameraManager.prototype.sort = function (index, order) {
+ if (typeof index === "undefined") { index = 'z'; }
+ if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
+ var _this = this;
+ this._sortIndex = index;
+ this._sortOrder = order;
+ this._cameras.sort(function (a, b) {
+ return _this.sortHandler(a, b);
+ });
+ };
+ CameraManager.prototype.sortHandler = function (obj1, obj2) {
+ if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ CameraManager.prototype.destroy = function () {
+ this._cameras.length = 0;
+ this.current = this.addCamera(0, 0, this.game.stage.width, this.game.stage.height);
+ };
+ return CameraManager;
+ })();
+ Phaser.CameraManager = CameraManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Display) {
+ var CSS3Filters = (function () {
+ function CSS3Filters(parent) {
+ this._blur = 0;
+ this._grayscale = 0;
+ this._sepia = 0;
+ this._brightness = 0;
+ this._contrast = 0;
+ this._hueRotate = 0;
+ this._invert = 0;
+ this._opacity = 0;
+ this._saturate = 0;
+ this.parent = parent;
+ }
+ CSS3Filters.prototype.setFilter = function (local, prefix, value, unit) {
+ this[local] = value;
+ if(this.parent) {
+ this.parent.style['-webkit-filter'] = prefix + '(' + value + unit + ')';
+ }
+ };
+ Object.defineProperty(CSS3Filters.prototype, "blur", {
+ get: function () {
+ return this._blur;
+ },
+ set: function (radius) {
+ this.setFilter('_blur', 'blur', radius, 'px');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "grayscale", {
+ get: function () {
+ return this._grayscale;
+ },
+ set: function (amount) {
+ this.setFilter('_grayscale', 'grayscale', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "sepia", {
+ get: function () {
+ return this._sepia;
+ },
+ set: function (amount) {
+ this.setFilter('_sepia', 'sepia', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "brightness", {
+ get: function () {
+ return this._brightness;
+ },
+ set: function (amount) {
+ this.setFilter('_brightness', 'brightness', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "contrast", {
+ get: function () {
+ return this._contrast;
+ },
+ set: function (amount) {
+ this.setFilter('_contrast', 'contrast', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "hueRotate", {
+ get: function () {
+ return this._hueRotate;
+ },
+ set: function (angle) {
+ this.setFilter('_hueRotate', 'hue-rotate', angle, 'deg');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "invert", {
+ get: function () {
+ return this._invert;
+ },
+ set: function (value) {
+ this.setFilter('_invert', 'invert', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "opacity", {
+ get: function () {
+ return this._opacity;
+ },
+ set: function (value) {
+ this.setFilter('_opacity', 'opacity', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "saturate", {
+ get: function () {
+ return this._saturate;
+ },
+ set: function (value) {
+ this.setFilter('_saturate', 'saturate', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return CSS3Filters;
+ })();
+ Display.CSS3Filters = CSS3Filters;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Display) {
+ var DynamicTexture = (function () {
+ function DynamicTexture(game, width, height) {
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this.globalCompositeOperation = null;
+ this.game = game;
+ this.type = Phaser.Types.DYNAMICTEXTURE;
+ this.canvas = document.createElement('canvas');
+ this.canvas.width = width;
+ this.canvas.height = height;
+ this.context = this.canvas.getContext('2d');
+ this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
+ this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ }
+ DynamicTexture.prototype.getPixel = function (x, y) {
+ var imageData = this.context.getImageData(x, y, 1, 1);
+ return Phaser.ColorUtils.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ DynamicTexture.prototype.getPixel32 = function (x, y) {
+ var imageData = this.context.getImageData(x, y, 1, 1);
+ return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ DynamicTexture.prototype.getPixels = function (rect) {
+ return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
+ };
+ DynamicTexture.prototype.setPixel = function (x, y, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(x, y, 1, 1);
+ };
+ DynamicTexture.prototype.setPixel32 = function (x, y, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(x, y, 1, 1);
+ };
+ DynamicTexture.prototype.setPixels = function (rect, input) {
+ this.context.putImageData(input, rect.x, rect.y);
+ };
+ DynamicTexture.prototype.fillRect = function (rect, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
+ DynamicTexture.prototype.pasteImage = function (key, frame, destX, destY, destWidth, destHeight) {
+ if (typeof frame === "undefined") { frame = -1; }
+ if (typeof destX === "undefined") { destX = 0; }
+ if (typeof destY === "undefined") { destY = 0; }
+ if (typeof destWidth === "undefined") { destWidth = null; }
+ if (typeof destHeight === "undefined") { destHeight = null; }
+ var texture = null;
+ var frameData;
+ this._sx = 0;
+ this._sy = 0;
+ this._dx = destX;
+ this._dy = destY;
+ if(frame > -1) {
+ } else {
+ texture = this.game.cache.getImage(key);
+ this._sw = texture.width;
+ this._sh = texture.height;
+ this._dw = texture.width;
+ this._dh = texture.height;
+ }
+ if(destWidth !== null) {
+ this._dw = destWidth;
+ }
+ if(destHeight !== null) {
+ this._dh = destHeight;
+ }
+ if(texture != null) {
+ this.context.drawImage(texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ }
+ };
+ DynamicTexture.prototype.copyPixels = function (sourceTexture, sourceRect, destPoint) {
+ if(Phaser.RectangleUtils.equals(sourceRect, this.bounds) == true) {
+ this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
+ } else {
+ this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
+ }
+ };
+ DynamicTexture.prototype.add = function (sprite) {
+ sprite.texture.canvas = this.canvas;
+ sprite.texture.context = this.context;
+ };
+ DynamicTexture.prototype.assignCanvasToGameObjects = function (objects) {
+ for(var i = 0; i < objects.length; i++) {
+ if(objects[i].texture) {
+ objects[i].texture.canvas = this.canvas;
+ objects[i].texture.context = this.context;
+ }
+ }
+ };
+ DynamicTexture.prototype.clear = function () {
+ this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
+ };
+ DynamicTexture.prototype.render = function (x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if(this.globalCompositeOperation) {
+ this.game.stage.context.save();
+ this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
+ }
+ this.game.stage.context.drawImage(this.canvas, x, y);
+ if(this.globalCompositeOperation) {
+ this.game.stage.context.restore();
+ }
+ };
+ Object.defineProperty(DynamicTexture.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(DynamicTexture.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return DynamicTexture;
+ })();
+ Display.DynamicTexture = DynamicTexture;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Display) {
+ var Texture = (function () {
+ function Texture(parent) {
+ this.imageTexture = null;
+ this.dynamicTexture = null;
+ this.loaded = false;
+ this.opaque = false;
+ this.backgroundColor = 'rgb(255,255,255)';
+ this.globalCompositeOperation = null;
+ this.renderRotation = true;
+ this.flippedX = false;
+ this.flippedY = false;
+ this.isDynamic = false;
+ this.game = parent.game;
+ this.parent = parent;
+ this.canvas = parent.game.stage.canvas;
+ this.context = parent.game.stage.context;
+ this.alpha = 1;
+ this.flippedX = false;
+ this.flippedY = false;
+ this._width = 16;
+ this._height = 16;
+ this.cameraBlacklist = [];
+ this._blacklist = 0;
+ }
+ Texture.prototype.hideFromCamera = function (camera) {
+ if(this.isHidden(camera) == false) {
+ this.cameraBlacklist.push(camera.ID);
+ this._blacklist++;
+ }
+ };
+ Texture.prototype.isHidden = function (camera) {
+ if(this._blacklist && this.cameraBlacklist.indexOf(camera.ID) !== -1) {
+ return true;
+ }
+ return false;
+ };
+ Texture.prototype.showToCamera = function (camera) {
+ if(this.isHidden(camera)) {
+ this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
+ this._blacklist--;
+ }
+ };
+ Texture.prototype.setTo = function (image, dynamic) {
+ if (typeof image === "undefined") { image = null; }
+ if (typeof dynamic === "undefined") { dynamic = null; }
+ if(dynamic) {
+ this.isDynamic = true;
+ this.dynamicTexture = dynamic;
+ this.texture = this.dynamicTexture.canvas;
+ } else {
+ this.isDynamic = false;
+ this.imageTexture = image;
+ this.texture = this.imageTexture;
+ this._width = image.width;
+ this._height = image.height;
+ }
+ this.loaded = true;
+ return this.parent;
+ };
+ Texture.prototype.loadImage = function (key, clearAnimations, updateBody) {
+ if (typeof clearAnimations === "undefined") { clearAnimations = true; }
+ if (typeof updateBody === "undefined") { updateBody = true; }
+ if(clearAnimations && this.parent['animations'] && this.parent['animations'].frameData !== null) {
+ this.parent.animations.destroy();
+ }
+ if(this.game.cache.getImage(key) !== null) {
+ this.setTo(this.game.cache.getImage(key), null);
+ this.cacheKey = key;
+ if(this.game.cache.isSpriteSheet(key) && this.parent['animations']) {
+ this.parent.animations.loadFrameData(this.parent.game.cache.getFrameData(key));
+ } else {
+ if(updateBody && this.parent['body']) {
+ this.parent.body.bounds.width = this.width;
+ this.parent.body.bounds.height = this.height;
+ }
+ }
+ }
+ };
+ Texture.prototype.loadDynamicTexture = function (texture) {
+ if(this.parent.animations.frameData !== null) {
+ this.parent.animations.destroy();
+ }
+ this.setTo(null, texture);
+ this.parent.texture.width = this.width;
+ this.parent.texture.height = this.height;
+ };
+ Object.defineProperty(Texture.prototype, "width", {
+ get: function () {
+ if(this.isDynamic) {
+ return this.dynamicTexture.width;
+ } else {
+ return this._width;
+ }
+ },
+ set: function (value) {
+ this._width = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Texture.prototype, "height", {
+ get: function () {
+ if(this.isDynamic) {
+ return this.dynamicTexture.height;
+ } else {
+ return this._height;
+ }
+ },
+ set: function (value) {
+ this._height = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Texture;
+ })();
+ Display.Texture = Texture;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Back = (function () {
+ function Back() { }
+ Back.In = function In(k) {
+ var s = 1.70158;
+ return k * k * ((s + 1) * k - s);
+ };
+ Back.Out = function Out(k) {
+ var s = 1.70158;
+ return --k * k * ((s + 1) * k + s) + 1;
+ };
+ Back.InOut = function InOut(k) {
+ var s = 1.70158 * 1.525;
+ if((k *= 2) < 1) {
+ return 0.5 * (k * k * ((s + 1) * k - s));
+ }
+ return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
+ };
+ return Back;
+ })();
+ Easing.Back = Back;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Bounce = (function () {
+ function Bounce() { }
+ Bounce.In = function In(k) {
+ return 1 - Phaser.Easing.Bounce.Out(1 - k);
+ };
+ Bounce.Out = function Out(k) {
+ if(k < (1 / 2.75)) {
+ return 7.5625 * k * k;
+ } else if(k < (2 / 2.75)) {
+ return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
+ } else if(k < (2.5 / 2.75)) {
+ return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
+ } else {
+ return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
+ }
+ };
+ Bounce.InOut = function InOut(k) {
+ if(k < 0.5) {
+ return Phaser.Easing.Bounce.In(k * 2) * 0.5;
+ }
+ return Phaser.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
+ };
+ return Bounce;
+ })();
+ Easing.Bounce = Bounce;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Circular = (function () {
+ function Circular() { }
+ Circular.In = function In(k) {
+ return 1 - Math.sqrt(1 - k * k);
+ };
+ Circular.Out = function Out(k) {
+ return Math.sqrt(1 - (--k * k));
+ };
+ Circular.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return -0.5 * (Math.sqrt(1 - k * k) - 1);
+ }
+ return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
+ };
+ return Circular;
+ })();
+ Easing.Circular = Circular;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Cubic = (function () {
+ function Cubic() { }
+ Cubic.In = function In(k) {
+ return k * k * k;
+ };
+ Cubic.Out = function Out(k) {
+ return --k * k * k + 1;
+ };
+ Cubic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k;
+ }
+ return 0.5 * ((k -= 2) * k * k + 2);
+ };
+ return Cubic;
+ })();
+ Easing.Cubic = Cubic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Elastic = (function () {
+ function Elastic() { }
+ Elastic.In = function In(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
+ };
+ Elastic.Out = function Out(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
+ };
+ Elastic.InOut = function InOut(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ if((k *= 2) < 1) {
+ return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
+ }
+ return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
+ };
+ return Elastic;
+ })();
+ Easing.Elastic = Elastic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Exponential = (function () {
+ function Exponential() { }
+ Exponential.In = function In(k) {
+ return k === 0 ? 0 : Math.pow(1024, k - 1);
+ };
+ Exponential.Out = function Out(k) {
+ return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
+ };
+ Exponential.InOut = function InOut(k) {
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if((k *= 2) < 1) {
+ return 0.5 * Math.pow(1024, k - 1);
+ }
+ return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
+ };
+ return Exponential;
+ })();
+ Easing.Exponential = Exponential;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Linear = (function () {
+ function Linear() { }
+ Linear.None = function None(k) {
+ return k;
+ };
+ return Linear;
+ })();
+ Easing.Linear = Linear;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Quadratic = (function () {
+ function Quadratic() { }
+ Quadratic.In = function In(k) {
+ return k * k;
+ };
+ Quadratic.Out = function Out(k) {
+ return k * (2 - k);
+ };
+ Quadratic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k;
+ }
+ return -0.5 * (--k * (k - 2) - 1);
+ };
+ return Quadratic;
+ })();
+ Easing.Quadratic = Quadratic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Quartic = (function () {
+ function Quartic() { }
+ Quartic.In = function In(k) {
+ return k * k * k * k;
+ };
+ Quartic.Out = function Out(k) {
+ return 1 - (--k * k * k * k);
+ };
+ Quartic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k * k;
+ }
+ return -0.5 * ((k -= 2) * k * k * k - 2);
+ };
+ return Quartic;
+ })();
+ Easing.Quartic = Quartic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Quintic = (function () {
+ function Quintic() { }
+ Quintic.In = function In(k) {
+ return k * k * k * k * k;
+ };
+ Quintic.Out = function Out(k) {
+ return --k * k * k * k * k + 1;
+ };
+ Quintic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k * k * k;
+ }
+ return 0.5 * ((k -= 2) * k * k * k * k + 2);
+ };
+ return Quintic;
+ })();
+ Easing.Quintic = Quintic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Sinusoidal = (function () {
+ function Sinusoidal() { }
+ Sinusoidal.In = function In(k) {
+ return 1 - Math.cos(k * Math.PI / 2);
+ };
+ Sinusoidal.Out = function Out(k) {
+ return Math.sin(k * Math.PI / 2);
+ };
+ Sinusoidal.InOut = function InOut(k) {
+ return 0.5 * (1 - Math.cos(Math.PI * k));
+ };
+ return Sinusoidal;
+ })();
+ Easing.Sinusoidal = Sinusoidal;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Tween = (function () {
+ function Tween(object, game) {
+ this._object = null;
+ this._pausedTime = 0;
+ this._valuesStart = {
+ };
+ this._valuesEnd = {
+ };
+ this._duration = 1000;
+ this._delayTime = 0;
+ this._startTime = null;
+ this._loop = false;
+ this._yoyo = false;
+ this._yoyoCount = 0;
+ this._chainedTweens = [];
+ this.isRunning = false;
+ this._object = object;
+ this.game = game;
+ this._manager = this.game.tweens;
+ this._interpolationFunction = this.game.math.linearInterpolation;
+ this._easingFunction = Phaser.Easing.Linear.None;
+ this._chainedTweens = [];
+ this.onStart = new Phaser.Signal();
+ this.onUpdate = new Phaser.Signal();
+ this.onComplete = new Phaser.Signal();
+ }
+ Tween.prototype.to = function (properties, duration, ease, autoStart, delay, loop, yoyo) {
+ if (typeof duration === "undefined") { duration = 1000; }
+ if (typeof ease === "undefined") { ease = null; }
+ if (typeof autoStart === "undefined") { autoStart = false; }
+ if (typeof delay === "undefined") { delay = 0; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof yoyo === "undefined") { yoyo = false; }
+ this._duration = duration;
+ this._valuesEnd = properties;
+ if(ease !== null) {
+ this._easingFunction = ease;
+ }
+ if(delay > 0) {
+ this._delayTime = delay;
+ }
+ this._loop = loop;
+ this._yoyo = yoyo;
+ this._yoyoCount = 0;
+ if(autoStart === true) {
+ return this.start();
+ } else {
+ return this;
+ }
+ };
+ Tween.prototype.loop = function (value) {
+ this._loop = value;
+ return this;
+ };
+ Tween.prototype.yoyo = function (value) {
+ this._yoyo = value;
+ this._yoyoCount = 0;
+ return this;
+ };
+ Tween.prototype.start = function (looped) {
+ if (typeof looped === "undefined") { looped = false; }
+ if(this.game === null || this._object === null) {
+ return;
+ }
+ if(looped == false) {
+ this._manager.add(this);
+ this.onStart.dispatch(this._object);
+ }
+ this._startTime = this.game.time.now + this._delayTime;
+ this.isRunning = true;
+ for(var property in this._valuesEnd) {
+ if(this._object[property] === null || !(property in this._object)) {
+ throw Error('Phaser.Tween interpolation of null value of non-existing property');
+ continue;
+ }
+ if(this._valuesEnd[property] instanceof Array) {
+ if(this._valuesEnd[property].length === 0) {
+ continue;
+ }
+ this._valuesEnd[property] = [
+ this._object[property]
+ ].concat(this._valuesEnd[property]);
+ }
+ if(looped == false) {
+ this._valuesStart[property] = this._object[property];
+ }
+ }
+ return this;
+ };
+ Tween.prototype.reverse = function () {
+ var tempObj = {
+ };
+ for(var property in this._valuesStart) {
+ tempObj[property] = this._valuesStart[property];
+ this._valuesStart[property] = this._valuesEnd[property];
+ this._valuesEnd[property] = tempObj[property];
+ }
+ this._yoyoCount++;
+ return this.start(true);
+ };
+ Tween.prototype.reset = function () {
+ for(var property in this._valuesStart) {
+ this._object[property] = this._valuesStart[property];
+ }
+ return this.start(true);
+ };
+ Tween.prototype.clear = function () {
+ this._chainedTweens = [];
+ this.onStart.removeAll();
+ this.onUpdate.removeAll();
+ this.onComplete.removeAll();
+ return this;
+ };
+ Tween.prototype.stop = function () {
+ if(this._manager !== null) {
+ this._manager.remove(this);
+ }
+ this.isRunning = false;
+ this.onComplete.dispose();
+ return this;
+ };
+ Object.defineProperty(Tween.prototype, "parent", {
+ set: function (value) {
+ this.game = value;
+ this._manager = this.game.tweens;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "delay", {
+ get: function () {
+ return this._delayTime;
+ },
+ set: function (amount) {
+ this._delayTime = amount;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "easing", {
+ get: function () {
+ return this._easingFunction;
+ },
+ set: function (easing) {
+ this._easingFunction = easing;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "interpolation", {
+ get: function () {
+ return this._interpolationFunction;
+ },
+ set: function (interpolation) {
+ this._interpolationFunction = interpolation;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Tween.prototype.chain = function (tween) {
+ this._chainedTweens.push(tween);
+ return this;
+ };
+ Tween.prototype.pause = function () {
+ this._paused = true;
+ };
+ Tween.prototype.resume = function () {
+ this._paused = false;
+ this._startTime += this.game.time.pauseDuration;
+ };
+ Tween.prototype.update = function (time) {
+ if(this._paused || time < this._startTime) {
+ return true;
+ }
+ this._tempElapsed = (time - this._startTime) / this._duration;
+ this._tempElapsed = this._tempElapsed > 1 ? 1 : this._tempElapsed;
+ this._tempValue = this._easingFunction(this._tempElapsed);
+ for(var property in this._valuesStart) {
+ if(this._valuesEnd[property] instanceof Array) {
+ this._object[property] = this._interpolationFunction(this._valuesEnd[property], this._tempValue);
+ } else {
+ this._object[property] = this._valuesStart[property] + (this._valuesEnd[property] - this._valuesStart[property]) * this._tempValue;
+ }
+ }
+ this.onUpdate.dispatch(this._object, this._tempValue);
+ if(this._tempElapsed == 1) {
+ if(this._yoyo) {
+ if(this._yoyoCount == 0) {
+ this.reverse();
+ return true;
+ } else {
+ if(this._loop == false) {
+ this.onComplete.dispatch(this._object);
+ for(var i = 0; i < this._chainedTweens.length; i++) {
+ this._chainedTweens[i].start();
+ }
+ return false;
+ } else {
+ this._yoyoCount = 0;
+ this.reverse();
+ return true;
+ }
+ }
+ }
+ if(this._loop) {
+ this._yoyoCount = 0;
+ this.reset();
+ return true;
+ } else {
+ this.onComplete.dispatch(this._object);
+ for(var i = 0; i < this._chainedTweens.length; i++) {
+ this._chainedTweens[i].start();
+ }
+ if(this._chainedTweens.length == 0) {
+ this.isRunning = false;
+ }
+ return false;
+ }
+ }
+ return true;
+ };
+ return Tween;
+ })();
+ Phaser.Tween = Tween;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var TweenManager = (function () {
+ function TweenManager(game) {
+ this.game = game;
+ this._tweens = [];
+ this.game.onPause.add(this.pauseAll, this);
+ this.game.onResume.add(this.resumeAll, this);
+ }
+ TweenManager.prototype.getAll = function () {
+ return this._tweens;
+ };
+ TweenManager.prototype.removeAll = function () {
+ this._tweens.length = 0;
+ };
+ TweenManager.prototype.create = function (object, localReference) {
+ if (typeof localReference === "undefined") { localReference = false; }
+ if(localReference) {
+ object['tween'] = new Phaser.Tween(object, this.game);
+ return object['tween'];
+ } else {
+ return new Phaser.Tween(object, this.game);
+ }
+ };
+ TweenManager.prototype.add = function (tween) {
+ tween.parent = this.game;
+ this._tweens.push(tween);
+ return tween;
+ };
+ TweenManager.prototype.remove = function (tween) {
+ var i = this._tweens.indexOf(tween);
+ if(i !== -1) {
+ this._tweens.splice(i, 1);
+ }
+ };
+ TweenManager.prototype.update = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ if(this._tweens[i].update(this.game.time.now)) {
+ i++;
+ } else {
+ this._tweens.splice(i, 1);
+ numTweens--;
+ }
+ }
+ return true;
+ };
+ TweenManager.prototype.pauseAll = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ this._tweens[i].pause();
+ i++;
+ }
+ };
+ TweenManager.prototype.resumeAll = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ this._tweens[i].resume();
+ i++;
+ }
+ };
+ return TweenManager;
+ })();
+ Phaser.TweenManager = TweenManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var TimeManager = (function () {
+ function TimeManager(game) {
+ this.physicsElapsed = 0;
+ this.time = 0;
+ this.pausedTime = 0;
+ this.now = 0;
+ this.delta = 0;
+ this.fps = 0;
+ this.fpsMin = 1000;
+ this.fpsMax = 0;
+ this.msMin = 1000;
+ this.msMax = 0;
+ this.frames = 0;
+ this._timeLastSecond = 0;
+ this.pauseDuration = 0;
+ this._pauseStarted = 0;
+ this.game = game;
+ this._started = 0;
+ this._timeLastSecond = this._started;
+ this.time = this._started;
+ this.game.onPause.add(this.gamePaused, this);
+ this.game.onResume.add(this.gameResumed, this);
+ }
+ Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", {
+ get: function () {
+ return (this.now - this._started) * 0.001;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TimeManager.prototype.update = function (raf) {
+ this.now = raf;
+ this.delta = this.now - this.time;
+ this.msMin = Math.min(this.msMin, this.delta);
+ this.msMax = Math.max(this.msMax, this.delta);
+ this.frames++;
+ if(this.now > this._timeLastSecond + 1000) {
+ this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
+ this.fpsMin = Math.min(this.fpsMin, this.fps);
+ this.fpsMax = Math.max(this.fpsMax, this.fps);
+ this._timeLastSecond = this.now;
+ this.frames = 0;
+ }
+ this.time = this.now;
+ this.physicsElapsed = 1.0 * (this.delta / 1000);
+ if(this.game.paused) {
+ this.pausedTime = this.now - this._pauseStarted;
+ }
+ };
+ TimeManager.prototype.gamePaused = function () {
+ this._pauseStarted = this.now;
+ };
+ TimeManager.prototype.gameResumed = function () {
+ this.delta = 0;
+ this.physicsElapsed = 0;
+ this.time = Date.now();
+ this.pauseDuration = this.pausedTime;
+ };
+ TimeManager.prototype.elapsedSince = function (since) {
+ return this.now - since;
+ };
+ TimeManager.prototype.elapsedSecondsSince = function (since) {
+ return (this.now - since) * 0.001;
+ };
+ TimeManager.prototype.reset = function () {
+ this._started = this.now;
+ };
+ return TimeManager;
+ })();
+ Phaser.TimeManager = TimeManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Net = (function () {
+ function Net(game) {
+ this.game = game;
+ }
+ Net.prototype.checkDomainName = function (domain) {
+ return window.location.hostname.indexOf(domain) !== -1;
+ };
+ Net.prototype.updateQueryString = function (key, value, redirect, url) {
+ if (typeof redirect === "undefined") { redirect = false; }
+ if (typeof url === "undefined") { url = ''; }
+ if(url == '') {
+ url = window.location.href;
+ }
+ var output = '';
+ var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
+ if(re.test(url)) {
+ if(typeof value !== 'undefined' && value !== null) {
+ output = url.replace(re, '$1' + key + "=" + value + '$2$3');
+ } else {
+ output = url.replace(re, '$1$3').replace(/(&|\?)$/, '');
+ }
+ } else {
+ if(typeof value !== 'undefined' && value !== null) {
+ var separator = url.indexOf('?') !== -1 ? '&' : '?';
+ var hash = url.split('#');
+ url = hash[0] + separator + key + '=' + value;
+ if(hash[1]) {
+ url += '#' + hash[1];
+ }
+ output = url;
+ } else {
+ output = url;
+ }
+ }
+ if(redirect) {
+ window.location.href = output;
+ } else {
+ return output;
+ }
+ };
+ Net.prototype.getQueryString = function (parameter) {
+ if (typeof parameter === "undefined") { parameter = ''; }
+ var output = {
+ };
+ var keyValues = location.search.substring(1).split('&');
+ for(var i in keyValues) {
+ var key = keyValues[i].split('=');
+ if(key.length > 1) {
+ if(parameter && parameter == this.decodeURI(key[0])) {
+ return this.decodeURI(key[1]);
+ } else {
+ output[this.decodeURI(key[0])] = this.decodeURI(key[1]);
+ }
+ }
+ }
+ return output;
+ };
+ Net.prototype.decodeURI = function (value) {
+ return decodeURIComponent(value.replace(/\+/g, " "));
+ };
+ return Net;
+ })();
+ Phaser.Net = Net;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Keyboard = (function () {
+ function Keyboard(game) {
+ this._keys = {
+ };
+ this._capture = {
+ };
+ this.disabled = false;
+ this.game = game;
+ }
+ Keyboard.prototype.start = function () {
+ var _this = this;
+ this._onKeyDown = function (event) {
+ return _this.onKeyDown(event);
+ };
+ this._onKeyUp = function (event) {
+ return _this.onKeyUp(event);
+ };
+ document.body.addEventListener('keydown', this._onKeyDown, false);
+ document.body.addEventListener('keyup', this._onKeyUp, false);
+ };
+ Keyboard.prototype.stop = function () {
+ document.body.removeEventListener('keydown', this._onKeyDown);
+ document.body.removeEventListener('keyup', this._onKeyUp);
+ };
+ Keyboard.prototype.addKeyCapture = function (keycode) {
+ if(typeof keycode === 'object') {
+ for(var i = 0; i < keycode.length; i++) {
+ this._capture[keycode[i]] = true;
+ }
+ } else {
+ this._capture[keycode] = true;
+ }
+ };
+ Keyboard.prototype.removeKeyCapture = function (keycode) {
+ delete this._capture[keycode];
+ };
+ Keyboard.prototype.clearCaptures = function () {
+ this._capture = {
+ };
+ };
+ Keyboard.prototype.onKeyDown = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ if(this._capture[event.keyCode]) {
+ event.preventDefault();
+ }
+ if(!this._keys[event.keyCode]) {
+ this._keys[event.keyCode] = {
+ isDown: true,
+ timeDown: this.game.time.now,
+ timeUp: 0
+ };
+ } else {
+ this._keys[event.keyCode].isDown = true;
+ this._keys[event.keyCode].timeDown = this.game.time.now;
+ }
+ };
+ Keyboard.prototype.onKeyUp = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ if(this._capture[event.keyCode]) {
+ event.preventDefault();
+ }
+ if(!this._keys[event.keyCode]) {
+ this._keys[event.keyCode] = {
+ isDown: false,
+ timeDown: 0,
+ timeUp: this.game.time.now
+ };
+ } else {
+ this._keys[event.keyCode].isDown = false;
+ this._keys[event.keyCode].timeUp = this.game.time.now;
+ }
+ };
+ Keyboard.prototype.reset = function () {
+ for(var key in this._keys) {
+ this._keys[key].isDown = false;
+ }
+ };
+ Keyboard.prototype.justPressed = function (keycode, duration) {
+ if (typeof duration === "undefined") { duration = 250; }
+ if(this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.prototype.justReleased = function (keycode, duration) {
+ if (typeof duration === "undefined") { duration = 250; }
+ if(this._keys[keycode] && this._keys[keycode].isDown === false && (this.game.time.now - this._keys[keycode].timeUp < duration)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.prototype.isDown = function (keycode) {
+ if(this._keys[keycode]) {
+ return this._keys[keycode].isDown;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.A = "A".charCodeAt(0);
+ Keyboard.B = "B".charCodeAt(0);
+ Keyboard.C = "C".charCodeAt(0);
+ Keyboard.D = "D".charCodeAt(0);
+ Keyboard.E = "E".charCodeAt(0);
+ Keyboard.F = "F".charCodeAt(0);
+ Keyboard.G = "G".charCodeAt(0);
+ Keyboard.H = "H".charCodeAt(0);
+ Keyboard.I = "I".charCodeAt(0);
+ Keyboard.J = "J".charCodeAt(0);
+ Keyboard.K = "K".charCodeAt(0);
+ Keyboard.L = "L".charCodeAt(0);
+ Keyboard.M = "M".charCodeAt(0);
+ Keyboard.N = "N".charCodeAt(0);
+ Keyboard.O = "O".charCodeAt(0);
+ Keyboard.P = "P".charCodeAt(0);
+ Keyboard.Q = "Q".charCodeAt(0);
+ Keyboard.R = "R".charCodeAt(0);
+ Keyboard.S = "S".charCodeAt(0);
+ Keyboard.T = "T".charCodeAt(0);
+ Keyboard.U = "U".charCodeAt(0);
+ Keyboard.V = "V".charCodeAt(0);
+ Keyboard.W = "W".charCodeAt(0);
+ Keyboard.X = "X".charCodeAt(0);
+ Keyboard.Y = "Y".charCodeAt(0);
+ Keyboard.Z = "Z".charCodeAt(0);
+ Keyboard.ZERO = "0".charCodeAt(0);
+ Keyboard.ONE = "1".charCodeAt(0);
+ Keyboard.TWO = "2".charCodeAt(0);
+ Keyboard.THREE = "3".charCodeAt(0);
+ Keyboard.FOUR = "4".charCodeAt(0);
+ Keyboard.FIVE = "5".charCodeAt(0);
+ Keyboard.SIX = "6".charCodeAt(0);
+ Keyboard.SEVEN = "7".charCodeAt(0);
+ Keyboard.EIGHT = "8".charCodeAt(0);
+ Keyboard.NINE = "9".charCodeAt(0);
+ Keyboard.NUMPAD_0 = 96;
+ Keyboard.NUMPAD_1 = 97;
+ Keyboard.NUMPAD_2 = 98;
+ Keyboard.NUMPAD_3 = 99;
+ Keyboard.NUMPAD_4 = 100;
+ Keyboard.NUMPAD_5 = 101;
+ Keyboard.NUMPAD_6 = 102;
+ Keyboard.NUMPAD_7 = 103;
+ Keyboard.NUMPAD_8 = 104;
+ Keyboard.NUMPAD_9 = 105;
+ Keyboard.NUMPAD_MULTIPLY = 106;
+ Keyboard.NUMPAD_ADD = 107;
+ Keyboard.NUMPAD_ENTER = 108;
+ Keyboard.NUMPAD_SUBTRACT = 109;
+ Keyboard.NUMPAD_DECIMAL = 110;
+ Keyboard.NUMPAD_DIVIDE = 111;
+ Keyboard.F1 = 112;
+ Keyboard.F2 = 113;
+ Keyboard.F3 = 114;
+ Keyboard.F4 = 115;
+ Keyboard.F5 = 116;
+ Keyboard.F6 = 117;
+ Keyboard.F7 = 118;
+ Keyboard.F8 = 119;
+ Keyboard.F9 = 120;
+ Keyboard.F10 = 121;
+ Keyboard.F11 = 122;
+ Keyboard.F12 = 123;
+ Keyboard.F13 = 124;
+ Keyboard.F14 = 125;
+ Keyboard.F15 = 126;
+ Keyboard.COLON = 186;
+ Keyboard.EQUALS = 187;
+ Keyboard.UNDERSCORE = 189;
+ Keyboard.QUESTION_MARK = 191;
+ Keyboard.TILDE = 192;
+ Keyboard.OPEN_BRACKET = 219;
+ Keyboard.BACKWARD_SLASH = 220;
+ Keyboard.CLOSED_BRACKET = 221;
+ Keyboard.QUOTES = 222;
+ Keyboard.BACKSPACE = 8;
+ Keyboard.TAB = 9;
+ Keyboard.CLEAR = 12;
+ Keyboard.ENTER = 13;
+ Keyboard.SHIFT = 16;
+ Keyboard.CONTROL = 17;
+ Keyboard.ALT = 18;
+ Keyboard.CAPS_LOCK = 20;
+ Keyboard.ESC = 27;
+ Keyboard.SPACEBAR = 32;
+ Keyboard.PAGE_UP = 33;
+ Keyboard.PAGE_DOWN = 34;
+ Keyboard.END = 35;
+ Keyboard.HOME = 36;
+ Keyboard.LEFT = 37;
+ Keyboard.UP = 38;
+ Keyboard.RIGHT = 39;
+ Keyboard.DOWN = 40;
+ Keyboard.INSERT = 45;
+ Keyboard.DELETE = 46;
+ Keyboard.HELP = 47;
+ Keyboard.NUM_LOCK = 144;
+ return Keyboard;
+ })();
+ Phaser.Keyboard = Keyboard;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Mouse = (function () {
+ function Mouse(game) {
+ this.disabled = false;
+ this.mouseDownCallback = null;
+ this.mouseMoveCallback = null;
+ this.mouseUpCallback = null;
+ this.game = game;
+ this.callbackContext = this.game;
+ }
+ Mouse.LEFT_BUTTON = 0;
+ Mouse.MIDDLE_BUTTON = 1;
+ Mouse.RIGHT_BUTTON = 2;
+ Mouse.prototype.start = function () {
+ var _this = this;
+ if(this.game.device.android && this.game.device.chrome == false) {
+ return;
+ }
+ this._onMouseDown = function (event) {
+ return _this.onMouseDown(event);
+ };
+ this._onMouseMove = function (event) {
+ return _this.onMouseMove(event);
+ };
+ this._onMouseUp = function (event) {
+ return _this.onMouseUp(event);
+ };
+ this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
+ this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
+ this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
+ };
+ Mouse.prototype.onMouseDown = function (event) {
+ if(this.mouseDownCallback) {
+ this.mouseDownCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.start(event);
+ };
+ Mouse.prototype.onMouseMove = function (event) {
+ if(this.mouseMoveCallback) {
+ this.mouseMoveCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.move(event);
+ };
+ Mouse.prototype.onMouseUp = function (event) {
+ if(this.mouseUpCallback) {
+ this.mouseUpCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.stop(event);
+ };
+ Mouse.prototype.stop = function () {
+ this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown);
+ this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove);
+ this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp);
+ };
+ return Mouse;
+ })();
+ Phaser.Mouse = Mouse;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var MSPointer = (function () {
+ function MSPointer(game) {
+ this.disabled = false;
+ this.game = game;
+ }
+ MSPointer.prototype.start = function () {
+ var _this = this;
+ if(this.game.device.mspointer == true) {
+ this._onMSPointerDown = function (event) {
+ return _this.onPointerDown(event);
+ };
+ this._onMSPointerMove = function (event) {
+ return _this.onPointerMove(event);
+ };
+ this._onMSPointerUp = function (event) {
+ return _this.onPointerUp(event);
+ };
+ this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
+ this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
+ this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
+ }
+ };
+ MSPointer.prototype.onPointerDown = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.startPointer(event);
+ };
+ MSPointer.prototype.onPointerMove = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.updatePointer(event);
+ };
+ MSPointer.prototype.onPointerUp = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.stopPointer(event);
+ };
+ MSPointer.prototype.stop = function () {
+ if(this.game.device.mspointer == true) {
+ this.game.stage.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
+ this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
+ this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
+ }
+ };
+ return MSPointer;
+ })();
+ Phaser.MSPointer = MSPointer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Touch = (function () {
+ function Touch(game) {
+ this.disabled = false;
+ this.touchStartCallback = null;
+ this.touchMoveCallback = null;
+ this.touchEndCallback = null;
+ this.touchEnterCallback = null;
+ this.touchLeaveCallback = null;
+ this.touchCancelCallback = null;
+ this.game = game;
+ this.callbackContext = this.game;
+ }
+ Touch.prototype.start = function () {
+ var _this = this;
+ if(this.game.device.touch) {
+ this._onTouchStart = function (event) {
+ return _this.onTouchStart(event);
+ };
+ this._onTouchMove = function (event) {
+ return _this.onTouchMove(event);
+ };
+ this._onTouchEnd = function (event) {
+ return _this.onTouchEnd(event);
+ };
+ this._onTouchEnter = function (event) {
+ return _this.onTouchEnter(event);
+ };
+ this._onTouchLeave = function (event) {
+ return _this.onTouchLeave(event);
+ };
+ this._onTouchCancel = function (event) {
+ return _this.onTouchCancel(event);
+ };
+ this._documentTouchMove = function (event) {
+ return _this.consumeTouchMove(event);
+ };
+ this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false);
+ this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false);
+ this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false);
+ this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false);
+ this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false);
+ this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
+ document.addEventListener('touchmove', this._documentTouchMove, false);
+ }
+ };
+ Touch.prototype.consumeTouchMove = function (event) {
+ event.preventDefault();
+ };
+ Touch.prototype.onTouchStart = function (event) {
+ if(this.touchStartCallback) {
+ this.touchStartCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.startPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchCancel = function (event) {
+ if(this.touchCancelCallback) {
+ this.touchCancelCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.stopPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchEnter = function (event) {
+ if(this.touchEnterCallback) {
+ this.touchEnterCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ }
+ };
+ Touch.prototype.onTouchLeave = function (event) {
+ if(this.touchLeaveCallback) {
+ this.touchLeaveCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ }
+ };
+ Touch.prototype.onTouchMove = function (event) {
+ if(this.touchMoveCallback) {
+ this.touchMoveCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.updatePointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchEnd = function (event) {
+ if(this.touchEndCallback) {
+ this.touchEndCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.stopPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.stop = function () {
+ if(this.game.device.touch) {
+ this.game.stage.canvas.removeEventListener('touchstart', this._onTouchStart);
+ this.game.stage.canvas.removeEventListener('touchmove', this._onTouchMove);
+ this.game.stage.canvas.removeEventListener('touchend', this._onTouchEnd);
+ this.game.stage.canvas.removeEventListener('touchenter', this._onTouchEnter);
+ this.game.stage.canvas.removeEventListener('touchleave', this._onTouchLeave);
+ this.game.stage.canvas.removeEventListener('touchcancel', this._onTouchCancel);
+ document.removeEventListener('touchmove', this._documentTouchMove);
+ }
+ };
+ return Touch;
+ })();
+ Phaser.Touch = Touch;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Pointer = (function () {
+ function Pointer(game, id) {
+ this._holdSent = false;
+ this._history = [];
+ this._nextDrop = 0;
+ this._stateReset = false;
+ this.positionDown = null;
+ this.position = null;
+ this.circle = null;
+ this.withinGame = false;
+ this.clientX = -1;
+ this.clientY = -1;
+ this.pageX = -1;
+ this.pageY = -1;
+ this.screenX = -1;
+ this.screenY = -1;
+ this.x = -1;
+ this.y = -1;
+ this.isMouse = false;
+ this.isDown = false;
+ this.isUp = true;
+ this.timeDown = 0;
+ this.timeUp = 0;
+ this.previousTapTime = 0;
+ this.totalTouches = 0;
+ this.msSinceLastClick = Number.MAX_VALUE;
+ this.targetObject = null;
+ this.camera = null;
+ this.game = game;
+ this.id = id;
+ this.active = false;
+ this.position = new Phaser.Vec2();
+ this.positionDown = new Phaser.Vec2();
+ this.circle = new Phaser.Circle(0, 0, 44);
+ if(id == 0) {
+ this.isMouse = true;
+ }
+ }
+ Object.defineProperty(Pointer.prototype, "duration", {
+ get: function () {
+ if(this.isUp) {
+ return -1;
+ }
+ return this.game.time.now - this.timeDown;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Pointer.prototype, "worldX", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Pointer.prototype, "worldY", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Pointer.prototype.start = function (event) {
+ this.identifier = event.identifier;
+ this.target = event.target;
+ if(event.button) {
+ this.button = event.button;
+ }
+ if(this.game.paused == true && this.game.stage.scale.incorrectOrientation == false) {
+ this.game.stage.resumeGame();
+ return this;
+ }
+ this._history.length = 0;
+ this.active = true;
+ this.withinGame = true;
+ this.isDown = true;
+ this.isUp = false;
+ this.msSinceLastClick = this.game.time.now - this.timeDown;
+ this.timeDown = this.game.time.now;
+ this._holdSent = false;
+ this.move(event);
+ this.positionDown.setTo(this.x, this.y);
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.x = this.x;
+ this.game.input.y = this.y;
+ this.game.input.position.setTo(this.x, this.y);
+ this.game.input.onDown.dispatch(this);
+ this.game.input.resetSpeed(this.x, this.y);
+ }
+ this._stateReset = false;
+ this.totalTouches++;
+ if(this.isMouse == false) {
+ this.game.input.currentPointers++;
+ }
+ if(this.targetObject !== null) {
+ this.targetObject.input._touchedHandler(this);
+ }
+ return this;
+ };
+ Pointer.prototype.update = function () {
+ if(this.active) {
+ if(this._holdSent == false && this.duration >= this.game.input.holdRate) {
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.onHold.dispatch(this);
+ }
+ this._holdSent = true;
+ }
+ if(this.game.input.recordPointerHistory && this.game.time.now >= this._nextDrop) {
+ this._nextDrop = this.game.time.now + this.game.input.recordRate;
+ this._history.push({
+ x: this.position.x,
+ y: this.position.y
+ });
+ if(this._history.length > this.game.input.recordLimit) {
+ this._history.shift();
+ }
+ }
+ this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y);
+ }
+ };
+ Pointer.prototype.move = function (event) {
+ if(this.game.input.pollLocked) {
+ return;
+ }
+ if(event.button) {
+ this.button = event.button;
+ }
+ this.clientX = event.clientX;
+ this.clientY = event.clientY;
+ this.pageX = event.pageX;
+ this.pageY = event.pageY;
+ this.screenX = event.screenX;
+ this.screenY = event.screenY;
+ this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
+ this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
+ this.position.setTo(this.x, this.y);
+ this.circle.x = this.x;
+ this.circle.y = this.y;
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.activePointer = this;
+ this.game.input.x = this.x;
+ this.game.input.y = this.y;
+ this.game.input.position.setTo(this.game.input.x, this.game.input.y);
+ this.game.input.circle.x = this.game.input.x;
+ this.game.input.circle.y = this.game.input.y;
+ }
+ if(this.game.paused) {
+ return this;
+ }
+ if(this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true) {
+ if(this.targetObject.input.update(this) == false) {
+ this.targetObject = null;
+ }
+ return this;
+ }
+ this._highestRenderOrderID = -1;
+ this._highestRenderObject = -1;
+ this._highestInputPriorityID = -1;
+ for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
+ if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) {
+ if(this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID)) {
+ this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID;
+ this._highestRenderObject = i;
+ this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID;
+ }
+ }
+ }
+ if(this._highestRenderObject == -1) {
+ if(this.targetObject !== null) {
+ this.targetObject.input._pointerOutHandler(this);
+ this.targetObject = null;
+ }
+ } else {
+ if(this.targetObject == null) {
+ this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
+ this.targetObject.input._pointerOverHandler(this);
+ } else {
+ if(this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) {
+ if(this.targetObject.input.update(this) == false) {
+ this.targetObject = null;
+ }
+ } else {
+ this.targetObject.input._pointerOutHandler(this);
+ this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
+ this.targetObject.input._pointerOverHandler(this);
+ }
+ }
+ }
+ return this;
+ };
+ Pointer.prototype.leave = function (event) {
+ this.withinGame = false;
+ this.move(event);
+ };
+ Pointer.prototype.stop = function (event) {
+ if(this._stateReset) {
+ event.preventDefault();
+ return;
+ }
+ this.timeUp = this.game.time.now;
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.onUp.dispatch(this);
+ if(this.duration >= 0 && this.duration <= this.game.input.tapRate) {
+ if(this.timeUp - this.previousTapTime < this.game.input.doubleTapRate) {
+ this.game.input.onTap.dispatch(this, true);
+ } else {
+ this.game.input.onTap.dispatch(this, false);
+ }
+ this.previousTapTime = this.timeUp;
+ }
+ }
+ if(this.id > 0) {
+ this.active = false;
+ }
+ this.withinGame = false;
+ this.isDown = false;
+ this.isUp = true;
+ if(this.isMouse == false) {
+ this.game.input.currentPointers--;
+ }
+ for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
+ if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) {
+ this.game.input.inputObjects[i].input._releasedHandler(this);
+ }
+ }
+ if(this.targetObject) {
+ this.targetObject.input._releasedHandler(this);
+ }
+ this.targetObject = null;
+ return this;
+ };
+ Pointer.prototype.justPressed = function (duration) {
+ if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; }
+ if(this.isDown === true && (this.timeDown + duration) > this.game.time.now) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Pointer.prototype.justReleased = function (duration) {
+ if (typeof duration === "undefined") { duration = this.game.input.justReleasedRate; }
+ if(this.isUp === true && (this.timeUp + duration) > this.game.time.now) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Pointer.prototype.reset = function () {
+ if(this.isMouse == false) {
+ this.active = false;
+ }
+ this.identifier = null;
+ this.isDown = false;
+ this.isUp = true;
+ this.totalTouches = 0;
+ this._holdSent = false;
+ this._history.length = 0;
+ this._stateReset = true;
+ if(this.targetObject && this.targetObject.input) {
+ this.targetObject.input._releasedHandler(this);
+ }
+ this.targetObject = null;
+ };
+ Pointer.prototype.toString = function () {
+ return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
+ };
+ return Pointer;
+ })();
+ Phaser.Pointer = Pointer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var InputHandler = (function () {
+ function InputHandler(parent) {
+ this.priorityID = 0;
+ this.indexID = 0;
+ this.isDragged = false;
+ this.dragPixelPerfect = false;
+ this.allowHorizontalDrag = true;
+ this.allowVerticalDrag = true;
+ this.bringToTop = false;
+ this.snapOnDrag = false;
+ this.snapOnRelease = false;
+ this.snapX = 0;
+ this.snapY = 0;
+ this.draggable = false;
+ this.boundsRect = null;
+ this.boundsSprite = null;
+ this.consumePointerEvent = false;
+ this.game = parent.game;
+ this._parent = parent;
+ this.enabled = false;
+ }
+ InputHandler.prototype.pointerX = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].x;
+ };
+ InputHandler.prototype.pointerY = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].y;
+ };
+ InputHandler.prototype.pointerDown = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isDown;
+ };
+ InputHandler.prototype.pointerUp = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isUp;
+ };
+ InputHandler.prototype.pointerTimeDown = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeDown;
+ };
+ InputHandler.prototype.pointerTimeUp = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeUp;
+ };
+ InputHandler.prototype.pointerOver = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isOver;
+ };
+ InputHandler.prototype.pointerOut = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isOut;
+ };
+ InputHandler.prototype.pointerTimeOver = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeOver;
+ };
+ InputHandler.prototype.pointerTimeOut = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeOut;
+ };
+ InputHandler.prototype.pointerDragged = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isDragged;
+ };
+ InputHandler.prototype.start = function (priority, checkBody, useHandCursor) {
+ if (typeof priority === "undefined") { priority = 0; }
+ if (typeof checkBody === "undefined") { checkBody = false; }
+ if (typeof useHandCursor === "undefined") { useHandCursor = false; }
+ if(this.enabled == false) {
+ this.checkBody = checkBody;
+ this.useHandCursor = useHandCursor;
+ this.priorityID = priority;
+ this._pointerData = [];
+ for(var i = 0; i < 10; i++) {
+ this._pointerData.push({
+ id: i,
+ x: 0,
+ y: 0,
+ isDown: false,
+ isUp: false,
+ isOver: false,
+ isOut: false,
+ timeOver: 0,
+ timeOut: 0,
+ timeDown: 0,
+ timeUp: 0,
+ downDuration: 0,
+ isDragged: false
+ });
+ }
+ this.snapOffset = new Phaser.Point();
+ this.enabled = true;
+ this.game.input.addGameObject(this._parent);
+ if(this._parent.events.onInputOver == null) {
+ this._parent.events.onInputOver = new Phaser.Signal();
+ this._parent.events.onInputOut = new Phaser.Signal();
+ this._parent.events.onInputDown = new Phaser.Signal();
+ this._parent.events.onInputUp = new Phaser.Signal();
+ this._parent.events.onDragStart = new Phaser.Signal();
+ this._parent.events.onDragStop = new Phaser.Signal();
+ }
+ }
+ return this._parent;
+ };
+ InputHandler.prototype.reset = function () {
+ this.enabled = false;
+ for(var i = 0; i < 10; i++) {
+ this._pointerData[i] = {
+ id: i,
+ x: 0,
+ y: 0,
+ isDown: false,
+ isUp: false,
+ isOver: false,
+ isOut: false,
+ timeOver: 0,
+ timeOut: 0,
+ timeDown: 0,
+ timeUp: 0,
+ downDuration: 0,
+ isDragged: false
+ };
+ }
+ };
+ InputHandler.prototype.stop = function () {
+ if(this.enabled == false) {
+ return;
+ } else {
+ this.enabled = false;
+ this.game.input.removeGameObject(this.indexID);
+ }
+ };
+ InputHandler.prototype.destroy = function () {
+ if(this.enabled) {
+ this.enabled = false;
+ this.game.input.removeGameObject(this.indexID);
+ }
+ };
+ InputHandler.prototype.checkPointerOver = function (pointer) {
+ if(this.enabled == false || this._parent.visible == false) {
+ return false;
+ } else {
+ return Phaser.SpriteUtils.overlapsPointer(this._parent, pointer);
+ }
+ };
+ InputHandler.prototype.update = function (pointer) {
+ if(this.enabled == false || this._parent.visible == false) {
+ this._pointerOutHandler(pointer);
+ return false;
+ }
+ if(this.draggable && this._draggedPointerID == pointer.id) {
+ return this.updateDrag(pointer);
+ } else if(this._pointerData[pointer.id].isOver == true) {
+ if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
+ this._pointerData[pointer.id].x = pointer.x - this._parent.x;
+ this._pointerData[pointer.id].y = pointer.y - this._parent.y;
+ return true;
+ } else {
+ this._pointerOutHandler(pointer);
+ return false;
+ }
+ }
+ };
+ InputHandler.prototype._pointerOverHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isOver == false) {
+ this._pointerData[pointer.id].isOver = true;
+ this._pointerData[pointer.id].isOut = false;
+ this._pointerData[pointer.id].timeOver = this.game.time.now;
+ this._pointerData[pointer.id].x = pointer.x - this._parent.x;
+ this._pointerData[pointer.id].y = pointer.y - this._parent.y;
+ if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
+ this.game.stage.canvas.style.cursor = "pointer";
+ }
+ this._parent.events.onInputOver.dispatch(this._parent, pointer);
+ }
+ };
+ InputHandler.prototype._pointerOutHandler = function (pointer) {
+ this._pointerData[pointer.id].isOver = false;
+ this._pointerData[pointer.id].isOut = true;
+ this._pointerData[pointer.id].timeOut = this.game.time.now;
+ if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
+ this.game.stage.canvas.style.cursor = "default";
+ }
+ this._parent.events.onInputOut.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype._touchedHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) {
+ this._pointerData[pointer.id].isDown = true;
+ this._pointerData[pointer.id].isUp = false;
+ this._pointerData[pointer.id].timeDown = this.game.time.now;
+ this._parent.events.onInputDown.dispatch(this._parent, pointer);
+ if(this.draggable && this.isDragged == false) {
+ this.startDrag(pointer);
+ }
+ if(this.bringToTop) {
+ this._parent.bringToTop();
+ }
+ }
+ return this.consumePointerEvent;
+ };
+ InputHandler.prototype._releasedHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isDown && pointer.isUp) {
+ this._pointerData[pointer.id].isDown = false;
+ this._pointerData[pointer.id].isUp = true;
+ this._pointerData[pointer.id].timeUp = this.game.time.now;
+ this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
+ if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
+ this._parent.events.onInputUp.dispatch(this._parent, pointer);
+ } else {
+ if(this.useHandCursor) {
+ this.game.stage.canvas.style.cursor = "default";
+ }
+ }
+ if(this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
+ this.stopDrag(pointer);
+ }
+ }
+ };
+ InputHandler.prototype.updateDrag = function (pointer) {
+ if(pointer.isUp) {
+ this.stopDrag(pointer);
+ return false;
+ }
+ if(this.allowHorizontalDrag) {
+ this._parent.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
+ }
+ if(this.allowVerticalDrag) {
+ this._parent.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
+ }
+ if(this.boundsRect) {
+ this.checkBoundsRect();
+ }
+ if(this.boundsSprite) {
+ this.checkBoundsSprite();
+ }
+ if(this.snapOnDrag) {
+ this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
+ this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
+ }
+ return true;
+ };
+ InputHandler.prototype.justOver = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay);
+ };
+ InputHandler.prototype.justOut = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay));
+ };
+ InputHandler.prototype.justPressed = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay);
+ };
+ InputHandler.prototype.justReleased = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay));
+ };
+ InputHandler.prototype.overDuration = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if(this._pointerData[pointer].isOver) {
+ return this.game.time.now - this._pointerData[pointer].timeOver;
+ }
+ return -1;
+ };
+ InputHandler.prototype.downDuration = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if(this._pointerData[pointer].isDown) {
+ return this.game.time.now - this._pointerData[pointer].timeDown;
+ }
+ return -1;
+ };
+ InputHandler.prototype.enableDrag = function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
+ if (typeof lockCenter === "undefined") { lockCenter = false; }
+ if (typeof bringToTop === "undefined") { bringToTop = false; }
+ if (typeof pixelPerfect === "undefined") { pixelPerfect = false; }
+ if (typeof alphaThreshold === "undefined") { alphaThreshold = 255; }
+ if (typeof boundsRect === "undefined") { boundsRect = null; }
+ if (typeof boundsSprite === "undefined") { boundsSprite = null; }
+ this._dragPoint = new Phaser.Point();
+ this.draggable = true;
+ this.bringToTop = bringToTop;
+ this.dragOffset = new Phaser.Point();
+ this.dragFromCenter = lockCenter;
+ this.dragPixelPerfect = pixelPerfect;
+ this.dragPixelPerfectAlpha = alphaThreshold;
+ if(boundsRect) {
+ this.boundsRect = boundsRect;
+ }
+ if(boundsSprite) {
+ this.boundsSprite = boundsSprite;
+ }
+ };
+ InputHandler.prototype.disableDrag = function () {
+ if(this._pointerData) {
+ for(var i = 0; i < 10; i++) {
+ this._pointerData[i].isDragged = false;
+ }
+ }
+ this.draggable = false;
+ this.isDragged = false;
+ this._draggedPointerID = -1;
+ };
+ InputHandler.prototype.startDrag = function (pointer) {
+ this.isDragged = true;
+ this._draggedPointerID = pointer.id;
+ this._pointerData[pointer.id].isDragged = true;
+ if(this.dragFromCenter) {
+ this._parent.transform.centerOn(pointer.worldX, pointer.worldY);
+ this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
+ } else {
+ this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
+ }
+ this.updateDrag(pointer);
+ if(this.bringToTop) {
+ this._parent.bringToTop();
+ }
+ this._parent.events.onDragStart.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype.stopDrag = function (pointer) {
+ this.isDragged = false;
+ this._draggedPointerID = -1;
+ this._pointerData[pointer.id].isDragged = false;
+ if(this.snapOnRelease) {
+ this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
+ this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
+ }
+ this._parent.events.onDragStop.dispatch(this._parent, pointer);
+ this._parent.events.onInputUp.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype.setDragLock = function (allowHorizontal, allowVertical) {
+ if (typeof allowHorizontal === "undefined") { allowHorizontal = true; }
+ if (typeof allowVertical === "undefined") { allowVertical = true; }
+ this.allowHorizontalDrag = allowHorizontal;
+ this.allowVerticalDrag = allowVertical;
+ };
+ InputHandler.prototype.enableSnap = function (snapX, snapY, onDrag, onRelease) {
+ if (typeof onDrag === "undefined") { onDrag = true; }
+ if (typeof onRelease === "undefined") { onRelease = false; }
+ this.snapOnDrag = onDrag;
+ this.snapOnRelease = onRelease;
+ this.snapX = snapX;
+ this.snapY = snapY;
+ };
+ InputHandler.prototype.disableSnap = function () {
+ this.snapOnDrag = false;
+ this.snapOnRelease = false;
+ };
+ InputHandler.prototype.checkBoundsRect = function () {
+ if(this._parent.x < this.boundsRect.left) {
+ this._parent.x = this.boundsRect.x;
+ } else if((this._parent.x + this._parent.width) > this.boundsRect.right) {
+ this._parent.x = this.boundsRect.right - this._parent.width;
+ }
+ if(this._parent.y < this.boundsRect.top) {
+ this._parent.y = this.boundsRect.top;
+ } else if((this._parent.y + this._parent.height) > this.boundsRect.bottom) {
+ this._parent.y = this.boundsRect.bottom - this._parent.height;
+ }
+ };
+ InputHandler.prototype.checkBoundsSprite = function () {
+ if(this._parent.x < this.boundsSprite.x) {
+ this._parent.x = this.boundsSprite.x;
+ } else if((this._parent.x + this._parent.width) > (this.boundsSprite.x + this.boundsSprite.width)) {
+ this._parent.x = (this.boundsSprite.x + this.boundsSprite.width) - this._parent.width;
+ }
+ if(this._parent.y < this.boundsSprite.y) {
+ this._parent.y = this.boundsSprite.y;
+ } else if((this._parent.y + this._parent.height) > (this.boundsSprite.y + this.boundsSprite.height)) {
+ this._parent.y = (this.boundsSprite.y + this.boundsSprite.height) - this._parent.height;
+ }
+ };
+ return InputHandler;
+ })();
+ Components.InputHandler = InputHandler;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var InputManager = (function () {
+ function InputManager(game) {
+ this.pollRate = 0;
+ this._pollCounter = 0;
+ this._oldPosition = null;
+ this._x = 0;
+ this._y = 0;
+ this.disabled = false;
+ this.multiInputOverride = InputManager.MOUSE_TOUCH_COMBINE;
+ this.position = null;
+ this.speed = null;
+ this.circle = null;
+ this.scale = null;
+ this.maxPointers = 10;
+ this.currentPointers = 0;
+ this.tapRate = 200;
+ this.doubleTapRate = 300;
+ this.holdRate = 2000;
+ this.justPressedRate = 200;
+ this.justReleasedRate = 200;
+ this.recordPointerHistory = false;
+ this.recordRate = 100;
+ this.recordLimit = 100;
+ this.pointer3 = null;
+ this.pointer4 = null;
+ this.pointer5 = null;
+ this.pointer6 = null;
+ this.pointer7 = null;
+ this.pointer8 = null;
+ this.pointer9 = null;
+ this.pointer10 = null;
+ this.activePointer = null;
+ this.inputObjects = [];
+ this.totalTrackedObjects = 0;
+ this.game = game;
+ this.mousePointer = new Phaser.Pointer(this.game, 0);
+ this.pointer1 = new Phaser.Pointer(this.game, 1);
+ this.pointer2 = new Phaser.Pointer(this.game, 2);
+ this.mouse = new Phaser.Mouse(this.game);
+ this.keyboard = new Phaser.Keyboard(this.game);
+ this.touch = new Phaser.Touch(this.game);
+ this.mspointer = new Phaser.MSPointer(this.game);
+ this.onDown = new Phaser.Signal();
+ this.onUp = new Phaser.Signal();
+ this.onTap = new Phaser.Signal();
+ this.onHold = new Phaser.Signal();
+ this.scale = new Phaser.Vec2(1, 1);
+ this.speed = new Phaser.Vec2();
+ this.position = new Phaser.Vec2();
+ this._oldPosition = new Phaser.Vec2();
+ this.circle = new Phaser.Circle(0, 0, 44);
+ this.activePointer = this.mousePointer;
+ this.currentPointers = 0;
+ this.hitCanvas = document.createElement('canvas');
+ this.hitCanvas.width = 1;
+ this.hitCanvas.height = 1;
+ this.hitContext = this.hitCanvas.getContext('2d');
+ }
+ InputManager.MOUSE_OVERRIDES_TOUCH = 0;
+ InputManager.TOUCH_OVERRIDES_MOUSE = 1;
+ InputManager.MOUSE_TOUCH_COMBINE = 2;
+ Object.defineProperty(InputManager.prototype, "camera", {
+ get: function () {
+ return this.activePointer.camera;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "x", {
+ get: function () {
+ return this._x;
+ },
+ set: function (value) {
+ this._x = Math.floor(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "y", {
+ get: function () {
+ return this._y;
+ },
+ set: function (value) {
+ this._y = Math.floor(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.addPointer = function () {
+ var next = 0;
+ for(var i = 10; i > 0; i--) {
+ if(this['pointer' + i] === null) {
+ next = i;
+ }
+ }
+ if(next == 0) {
+ throw new Error("You can only have 10 Pointer objects");
+ return null;
+ } else {
+ this['pointer' + next] = new Phaser.Pointer(this.game, next);
+ return this['pointer' + next];
+ }
+ };
+ InputManager.prototype.boot = function () {
+ this.mouse.start();
+ this.keyboard.start();
+ this.touch.start();
+ this.mspointer.start();
+ this.mousePointer.active = true;
+ };
+ InputManager.prototype.addGameObject = function (object) {
+ for(var i = 0; i < this.inputObjects.length; i++) {
+ if(this.inputObjects[i] == null) {
+ this.inputObjects[i] = object;
+ object.input.indexID = i;
+ this.totalTrackedObjects++;
+ return;
+ }
+ }
+ object.input.indexID = this.inputObjects.length;
+ this.inputObjects.push(object);
+ this.totalTrackedObjects++;
+ };
+ InputManager.prototype.removeGameObject = function (index) {
+ if(this.inputObjects[index]) {
+ this.inputObjects[index] = null;
+ }
+ };
+ Object.defineProperty(InputManager.prototype, "pollLocked", {
+ get: function () {
+ return (this.pollRate > 0 && this._pollCounter < this.pollRate);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.update = function () {
+ if(this.pollRate > 0 && this._pollCounter < this.pollRate) {
+ this._pollCounter++;
+ return;
+ }
+ this.speed.x = this.position.x - this._oldPosition.x;
+ this.speed.y = this.position.y - this._oldPosition.y;
+ this._oldPosition.copyFrom(this.position);
+ this.mousePointer.update();
+ this.pointer1.update();
+ this.pointer2.update();
+ if(this.pointer3) {
+ this.pointer3.update();
+ }
+ if(this.pointer4) {
+ this.pointer4.update();
+ }
+ if(this.pointer5) {
+ this.pointer5.update();
+ }
+ if(this.pointer6) {
+ this.pointer6.update();
+ }
+ if(this.pointer7) {
+ this.pointer7.update();
+ }
+ if(this.pointer8) {
+ this.pointer8.update();
+ }
+ if(this.pointer9) {
+ this.pointer9.update();
+ }
+ if(this.pointer10) {
+ this.pointer10.update();
+ }
+ this._pollCounter = 0;
+ };
+ InputManager.prototype.reset = function (hard) {
+ if (typeof hard === "undefined") { hard = false; }
+ this.keyboard.reset();
+ this.mousePointer.reset();
+ for(var i = 1; i <= 10; i++) {
+ if(this['pointer' + i]) {
+ this['pointer' + i].reset();
+ }
+ }
+ this.currentPointers = 0;
+ this.game.stage.canvas.style.cursor = "default";
+ if(hard == true) {
+ this.onDown.dispose();
+ this.onUp.dispose();
+ this.onTap.dispose();
+ this.onHold.dispose();
+ this.onDown = new Phaser.Signal();
+ this.onUp = new Phaser.Signal();
+ this.onTap = new Phaser.Signal();
+ this.onHold = new Phaser.Signal();
+ for(var i = 0; i < this.totalTrackedObjects; i++) {
+ if(this.inputObjects[i] && this.inputObjects[i].input) {
+ this.inputObjects[i].input.reset();
+ }
+ }
+ this.inputObjects.length = 0;
+ this.totalTrackedObjects = 0;
+ }
+ this._pollCounter = 0;
+ };
+ InputManager.prototype.resetSpeed = function (x, y) {
+ this._oldPosition.setTo(x, y);
+ this.speed.setTo(0, 0);
+ };
+ Object.defineProperty(InputManager.prototype, "totalInactivePointers", {
+ get: function () {
+ return 10 - this.currentPointers;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "totalActivePointers", {
+ get: function () {
+ this.currentPointers = 0;
+ for(var i = 1; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active) {
+ this.currentPointers++;
+ }
+ }
+ return this.currentPointers;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.startPointer = function (event) {
+ if(this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) {
+ return null;
+ }
+ if(this.pointer1.active == false) {
+ return this.pointer1.start(event);
+ } else if(this.pointer2.active == false) {
+ return this.pointer2.start(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active == false) {
+ return this['pointer' + i].start(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.updatePointer = function (event) {
+ if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
+ return this.pointer1.move(event);
+ } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
+ return this.pointer2.move(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
+ return this['pointer' + i].move(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.stopPointer = function (event) {
+ if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
+ return this.pointer1.stop(event);
+ } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
+ return this.pointer2.stop(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
+ return this['pointer' + i].stop(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.getPointer = function (state) {
+ if (typeof state === "undefined") { state = false; }
+ if(this.pointer1.active == state) {
+ return this.pointer1;
+ } else if(this.pointer2.active == state) {
+ return this.pointer2;
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active == state) {
+ return this['pointer' + i];
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.getPointerFromIdentifier = function (identifier) {
+ if(this.pointer1.identifier == identifier) {
+ return this.pointer1;
+ } else if(this.pointer2.identifier == identifier) {
+ return this.pointer2;
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].identifier == identifier) {
+ return this['pointer' + i];
+ }
+ }
+ }
+ return null;
+ };
+ Object.defineProperty(InputManager.prototype, "worldX", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "worldY", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.getDistance = function (pointer1, pointer2) {
+ return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position);
+ };
+ InputManager.prototype.getAngle = function (pointer1, pointer2) {
+ return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
+ };
+ InputManager.prototype.pixelPerfectCheck = function (sprite, pointer, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ this.hitContext.clearRect(0, 0, 1, 1);
+ return true;
+ };
+ return InputManager;
+ })();
+ Phaser.InputManager = InputManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Device = (function () {
+ function Device() {
+ this.patchAndroidClearRectBug = false;
+ this.desktop = false;
+ this.iOS = false;
+ this.android = false;
+ this.chromeOS = false;
+ this.linux = false;
+ this.macOS = false;
+ this.windows = false;
+ this.canvas = false;
+ this.file = false;
+ this.fileSystem = false;
+ this.localStorage = false;
+ this.webGL = false;
+ this.worker = false;
+ this.touch = false;
+ this.mspointer = false;
+ this.css3D = false;
+ this.arora = false;
+ this.chrome = false;
+ this.epiphany = false;
+ this.firefox = false;
+ this.ie = false;
+ this.ieVersion = 0;
+ this.mobileSafari = false;
+ this.midori = false;
+ this.opera = false;
+ this.safari = false;
+ this.webApp = false;
+ this.audioData = false;
+ this.webAudio = false;
+ this.ogg = false;
+ this.opus = false;
+ this.mp3 = false;
+ this.wav = false;
+ this.m4a = false;
+ this.webm = false;
+ this.iPhone = false;
+ this.iPhone4 = false;
+ this.iPad = false;
+ this.pixelRatio = 0;
+ this._checkAudio();
+ this._checkBrowser();
+ this._checkCSS3D();
+ this._checkDevice();
+ this._checkFeatures();
+ this._checkOS();
+ }
+ Device.prototype._checkOS = function () {
+ var ua = navigator.userAgent;
+ if(/Android/.test(ua)) {
+ this.android = true;
+ } else if(/CrOS/.test(ua)) {
+ this.chromeOS = true;
+ } else if(/iP[ao]d|iPhone/i.test(ua)) {
+ this.iOS = true;
+ } else if(/Linux/.test(ua)) {
+ this.linux = true;
+ } else if(/Mac OS/.test(ua)) {
+ this.macOS = true;
+ } else if(/Windows/.test(ua)) {
+ this.windows = true;
+ }
+ if(this.windows || this.macOS || this.linux) {
+ this.desktop = true;
+ }
+ };
+ Device.prototype._checkFeatures = function () {
+ this.canvas = !!window['CanvasRenderingContext2D'];
+ try {
+ this.localStorage = !!localStorage.getItem;
+ } catch (error) {
+ this.localStorage = false;
+ }
+ this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
+ this.fileSystem = !!window['requestFileSystem'];
+ this.webGL = !!window['WebGLRenderingContext'];
+ this.worker = !!window['Worker'];
+ if('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
+ this.touch = true;
+ }
+ if(window.navigator.msPointerEnabled) {
+ this.mspointer = true;
+ }
+ };
+ Device.prototype._checkBrowser = function () {
+ var ua = navigator.userAgent;
+ if(/Arora/.test(ua)) {
+ this.arora = true;
+ } else if(/Chrome/.test(ua)) {
+ this.chrome = true;
+ } else if(/Epiphany/.test(ua)) {
+ this.epiphany = true;
+ } else if(/Firefox/.test(ua)) {
+ this.firefox = true;
+ } else if(/Mobile Safari/.test(ua)) {
+ this.mobileSafari = true;
+ } else if(/MSIE (\d+\.\d+);/.test(ua)) {
+ this.ie = true;
+ this.ieVersion = parseInt(RegExp.$1);
+ } else if(/Midori/.test(ua)) {
+ this.midori = true;
+ } else if(/Opera/.test(ua)) {
+ this.opera = true;
+ } else if(/Safari/.test(ua)) {
+ this.safari = true;
+ }
+ if(navigator['standalone']) {
+ this.webApp = true;
+ }
+ };
+ Device.prototype.canPlayAudio = function (type) {
+ if(type == 'mp3' && this.mp3) {
+ return true;
+ } else if(type == 'ogg' && (this.ogg || this.opus)) {
+ return true;
+ } else if(type == 'm4a' && this.m4a) {
+ return true;
+ } else if(type == 'wav' && this.wav) {
+ return true;
+ } else if(type == 'webm' && this.webm) {
+ return true;
+ }
+ return false;
+ };
+ Device.prototype._checkAudio = function () {
+ this.audioData = !!(window['Audio']);
+ this.webAudio = !!(window['webkitAudioContext'] || window['AudioContext']);
+ var audioElement = document.createElement('audio');
+ var result = false;
+ try {
+ if(result = !!audioElement.canPlayType) {
+ if(audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
+ this.ogg = true;
+ }
+ if(audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '')) {
+ this.opus = true;
+ }
+ if(audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
+ this.mp3 = true;
+ }
+ if(audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
+ this.wav = true;
+ }
+ if(audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
+ this.m4a = true;
+ }
+ if(audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
+ this.webm = true;
+ }
+ }
+ } catch (e) {
+ }
+ };
+ Device.prototype._checkDevice = function () {
+ this.pixelRatio = window['devicePixelRatio'] || 1;
+ this.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
+ this.iPhone4 = (this.pixelRatio == 2 && this.iPhone);
+ this.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
+ };
+ Device.prototype._checkCSS3D = function () {
+ var el = document.createElement('p');
+ var has3d;
+ var transforms = {
+ 'webkitTransform': '-webkit-transform',
+ 'OTransform': '-o-transform',
+ 'msTransform': '-ms-transform',
+ 'MozTransform': '-moz-transform',
+ 'transform': 'transform'
+ };
+ document.body.insertBefore(el, null);
+ for(var t in transforms) {
+ if(el.style[t] !== undefined) {
+ el.style[t] = "translate3d(1px,1px,1px)";
+ has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
+ }
+ }
+ document.body.removeChild(el);
+ this.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
+ };
+ Device.prototype.isConsoleOpen = function () {
+ if(window.console && window.console['firebug']) {
+ return true;
+ }
+ if(window.console) {
+ console.profile();
+ console.profileEnd();
+ if(console.clear) {
+ console.clear();
+ }
+ return console['profiles'].length > 0;
+ }
+ return false;
+ };
+ return Device;
+ })();
+ Phaser.Device = Device;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var RequestAnimationFrame = (function () {
+ function RequestAnimationFrame(game, callback) {
+ this._isSetTimeOut = false;
+ this.isRunning = false;
+ this.game = game;
+ this.callback = callback;
+ var vendors = [
+ 'ms',
+ 'moz',
+ 'webkit',
+ 'o'
+ ];
+ for(var x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
+ window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
+ window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
+ }
+ this.start();
+ }
+ RequestAnimationFrame.prototype.isUsingSetTimeOut = function () {
+ return this._isSetTimeOut;
+ };
+ RequestAnimationFrame.prototype.isUsingRAF = function () {
+ return this._isSetTimeOut === true;
+ };
+ RequestAnimationFrame.prototype.start = function (callback) {
+ if (typeof callback === "undefined") { callback = null; }
+ var _this = this;
+ if(callback) {
+ this.callback = callback;
+ }
+ if(!window.requestAnimationFrame) {
+ this._isSetTimeOut = true;
+ this._onLoop = function () {
+ return _this.SetTimeoutUpdate();
+ };
+ this._timeOutID = window.setTimeout(this._onLoop, 0);
+ } else {
+ this._isSetTimeOut = false;
+ this._onLoop = function () {
+ return _this.RAFUpdate(0);
+ };
+ window.requestAnimationFrame(this._onLoop);
+ }
+ this.isRunning = true;
+ };
+ RequestAnimationFrame.prototype.stop = function () {
+ if(this._isSetTimeOut) {
+ clearTimeout(this._timeOutID);
+ } else {
+ window.cancelAnimationFrame;
+ }
+ this.isRunning = false;
+ };
+ RequestAnimationFrame.prototype.RAFUpdate = function (time) {
+ var _this = this;
+ this.game.time.update(time);
+ if(this.callback) {
+ this.callback.call(this.game);
+ }
+ this._onLoop = function (time) {
+ return _this.RAFUpdate(time);
+ };
+ window.requestAnimationFrame(this._onLoop);
+ };
+ RequestAnimationFrame.prototype.SetTimeoutUpdate = function () {
+ var _this = this;
+ this.game.time.update(Date.now());
+ this._onLoop = function () {
+ return _this.SetTimeoutUpdate();
+ };
+ this._timeOutID = window.setTimeout(this._onLoop, 16);
+ if(this.callback) {
+ this.callback.call(this.game);
+ }
+ };
+ return RequestAnimationFrame;
+ })();
+ Phaser.RequestAnimationFrame = RequestAnimationFrame;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var StageScaleMode = (function () {
+ function StageScaleMode(game, width, height) {
+ var _this = this;
+ this._startHeight = 0;
+ this.forceLandscape = false;
+ this.forcePortrait = false;
+ this.incorrectOrientation = false;
+ this.pageAlignHorizontally = false;
+ this.pageAlignVeritcally = false;
+ this.minWidth = null;
+ this.maxWidth = null;
+ this.minHeight = null;
+ this.maxHeight = null;
+ this.width = 0;
+ this.height = 0;
+ this.maxIterations = 5;
+ this.game = game;
+ this.enterLandscape = new Phaser.Signal();
+ this.enterPortrait = new Phaser.Signal();
+ if(window['orientation']) {
+ this.orientation = window['orientation'];
+ } else {
+ if(window.outerWidth > window.outerHeight) {
+ this.orientation = 90;
+ } else {
+ this.orientation = 0;
+ }
+ }
+ this.scaleFactor = new Phaser.Vec2(1, 1);
+ this.aspectRatio = 0;
+ this.minWidth = width;
+ this.minHeight = height;
+ this.maxWidth = width;
+ this.maxHeight = height;
+ window.addEventListener('orientationchange', function (event) {
+ return _this.checkOrientation(event);
+ }, false);
+ window.addEventListener('resize', function (event) {
+ return _this.checkResize(event);
+ }, false);
+ }
+ StageScaleMode.EXACT_FIT = 0;
+ StageScaleMode.NO_SCALE = 1;
+ StageScaleMode.SHOW_ALL = 2;
+ Object.defineProperty(StageScaleMode.prototype, "isFullScreen", {
+ get: function () {
+ if(document['fullscreenElement'] === null || document['mozFullScreenElement'] === null || document['webkitFullscreenElement'] === null) {
+ return false;
+ }
+ return true;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ StageScaleMode.prototype.startFullScreen = function () {
+ if(this.isFullScreen) {
+ return;
+ }
+ var element = this.game.stage.canvas;
+ if(element['requestFullScreen']) {
+ element['requestFullScreen']();
+ } else if(element['mozRequestFullScreen']) {
+ element['mozRequestFullScreen']();
+ } else if(element['webkitRequestFullScreen']) {
+ element['webkitRequestFullScreen']();
+ }
+ };
+ StageScaleMode.prototype.stopFullScreen = function () {
+ if(document['cancelFullScreen']) {
+ document['cancelFullScreen']();
+ } else if(document['mozCancelFullScreen']) {
+ document['mozCancelFullScreen']();
+ } else if(document['webkitCancelFullScreen']) {
+ document['webkitCancelFullScreen']();
+ }
+ };
+ StageScaleMode.prototype.update = function () {
+ if(this.forceLandscape || this.forcePortrait) {
+ this.checkOrientationState();
+ }
+ };
+ StageScaleMode.prototype.checkOrientationState = function () {
+ if(this.incorrectOrientation) {
+ if((this.forceLandscape && window.innerWidth > window.innerHeight) || (this.forcePortrait && window.innerHeight > window.innerWidth)) {
+ this.game.paused = false;
+ this.incorrectOrientation = false;
+ this.refresh();
+ }
+ } else {
+ if((this.forceLandscape && window.innerWidth < window.innerHeight) || (this.forcePortrait && window.innerHeight < window.innerWidth)) {
+ this.game.paused = true;
+ this.incorrectOrientation = true;
+ this.refresh();
+ }
+ }
+ };
+ Object.defineProperty(StageScaleMode.prototype, "isPortrait", {
+ get: function () {
+ return this.orientation == 0 || this.orientation == 180;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(StageScaleMode.prototype, "isLandscape", {
+ get: function () {
+ return this.orientation === 90 || this.orientation === -90;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ StageScaleMode.prototype.checkOrientation = function (event) {
+ this.orientation = window['orientation'];
+ if(this.isLandscape) {
+ this.enterLandscape.dispatch(this.orientation, true, false);
+ } else {
+ this.enterPortrait.dispatch(this.orientation, false, true);
+ }
+ if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
+ this.refresh();
+ }
+ };
+ StageScaleMode.prototype.checkResize = function (event) {
+ if(window.outerWidth > window.outerHeight) {
+ this.orientation = 90;
+ } else {
+ this.orientation = 0;
+ }
+ if(this.isLandscape) {
+ this.enterLandscape.dispatch(this.orientation, true, false);
+ } else {
+ this.enterPortrait.dispatch(this.orientation, false, true);
+ }
+ if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
+ this.refresh();
+ }
+ };
+ StageScaleMode.prototype.refresh = function () {
+ var _this = this;
+ if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
+ document.documentElement['style'].minHeight = '2000px';
+ this._startHeight = window.innerHeight;
+ if(this.game.device.android && this.game.device.chrome == false) {
+ window.scrollTo(0, 1);
+ } else {
+ window.scrollTo(0, 0);
+ }
+ }
+ if(this._check == null && this.maxIterations > 0) {
+ this._iterations = this.maxIterations;
+ this._check = window.setInterval(function () {
+ return _this.setScreenSize();
+ }, 10);
+ this.setScreenSize();
+ }
+ };
+ StageScaleMode.prototype.setScreenSize = function (force) {
+ if (typeof force === "undefined") { force = false; }
+ if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
+ if(this.game.device.android && this.game.device.chrome == false) {
+ window.scrollTo(0, 1);
+ } else {
+ window.scrollTo(0, 0);
+ }
+ }
+ this._iterations--;
+ if(force || window.innerHeight > this._startHeight || this._iterations < 0) {
+ document.documentElement['style'].minHeight = window.innerHeight + 'px';
+ if(this.incorrectOrientation == true) {
+ this.setMaximum();
+ } else if(this.game.stage.scaleMode == StageScaleMode.EXACT_FIT) {
+ this.setExactFit();
+ } else if(this.game.stage.scaleMode == StageScaleMode.SHOW_ALL) {
+ this.setShowAll();
+ }
+ this.setSize();
+ clearInterval(this._check);
+ this._check = null;
+ }
+ };
+ StageScaleMode.prototype.setSize = function () {
+ if(this.incorrectOrientation == false) {
+ if(this.maxWidth && this.width > this.maxWidth) {
+ this.width = this.maxWidth;
+ }
+ if(this.maxHeight && this.height > this.maxHeight) {
+ this.height = this.maxHeight;
+ }
+ if(this.minWidth && this.width < this.minWidth) {
+ this.width = this.minWidth;
+ }
+ if(this.minHeight && this.height < this.minHeight) {
+ this.height = this.minHeight;
+ }
+ }
+ this.game.stage.canvas.style.width = this.width + 'px';
+ this.game.stage.canvas.style.height = this.height + 'px';
+ this.game.input.scale.setTo(this.game.stage.width / this.width, this.game.stage.height / this.height);
+ if(this.pageAlignHorizontally) {
+ if(this.width < window.innerWidth && this.incorrectOrientation == false) {
+ this.game.stage.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px';
+ } else {
+ this.game.stage.canvas.style.marginLeft = '0px';
+ }
+ }
+ if(this.pageAlignVeritcally) {
+ if(this.height < window.innerHeight && this.incorrectOrientation == false) {
+ this.game.stage.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px';
+ } else {
+ this.game.stage.canvas.style.marginTop = '0px';
+ }
+ }
+ this.game.stage.getOffset(this.game.stage.canvas);
+ this.aspectRatio = this.width / this.height;
+ this.scaleFactor.x = this.game.stage.width / this.width;
+ this.scaleFactor.y = this.game.stage.height / this.height;
+ };
+ StageScaleMode.prototype.setMaximum = function () {
+ this.width = window.innerWidth;
+ this.height = window.innerHeight;
+ };
+ StageScaleMode.prototype.setShowAll = function () {
+ var multiplier = Math.min((window.innerHeight / this.game.stage.height), (window.innerWidth / this.game.stage.width));
+ this.width = Math.round(this.game.stage.width * multiplier);
+ this.height = Math.round(this.game.stage.height * multiplier);
+ };
+ StageScaleMode.prototype.setExactFit = function () {
+ if(this.maxWidth && window.innerWidth > this.maxWidth) {
+ this.width = this.maxWidth;
+ } else {
+ this.width = window.innerWidth;
+ }
+ if(this.maxHeight && window.innerHeight > this.maxHeight) {
+ this.height = this.maxHeight;
+ } else {
+ this.height = window.innerHeight;
+ }
+ };
+ return StageScaleMode;
+ })();
+ Phaser.StageScaleMode = StageScaleMode;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var BootScreen = (function () {
+ function BootScreen(game) {
+ this._logoData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAAZCAYAAADdYmvFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAstJREFUeNrsWlFuwjAMbavdZGcAcRm4AXzvCPuGG8BlEJxhZ+l4TJ48z3actGGthqUI1MaO/V6cmIT2/fW10eTt46NvKshtvDZlG31yfOL9a/ldU6x4IZ0GQs0gS217enMkJYr5ixXkYrFoVqtV1kDn8/n+KfXw/Hq9Nin7h8MhScB2u3Xtav2ivsNWrh7XLcWMYqA4eUZ1kj0MAifHJEeKFojWzyIH+rL/0Cwif2AX9nN1oQOgrTg8XcTFx+ScdEOJ4WBxXQ1EjRyrn0cOzzQLzFyQSQcgw/5Qkkr0JVEQpNIdhL4vm4DL5fLulNTHcy6Uxl4/6iMLiePx2KzX6/v30+n0aynUlrnSeNq2/VN9bgM4dFPdNPmsJnIg/PuQbJmLdFN3UNu0SzbyJ0GOWJVWZE/QMkY+owrqXxGEdZA37BVyX6lJTipT6J1lf7fbqc+xh8nYeIvikatP+PGW0nEJ4jOydHYOIcfKnmgWoZDQSIIeio4Sf1IthYWskCO4vqQ6lFYjl8tl9L1H67PZbMz3VO3t93uVXHofmUjReLyMwHi5eCb3ICwJj5ZU9nCg+SzUgPYyif+2epTk4pkkyDp+eXTlZu2BkUybEkklePZfK9lPuTnc07vbmt1bYulHBeNQgx18SsH4ni/cV2rSLtqNDNUH2JQ2SsXS57Y9PHlfumkwCdICt5rnkNdPjpMiIEWgRlAJSdF4SvCQMWj+VyfI0h8D/EgWSYKiJKXi8VrOhJUxaFiFCOKKUJAtR78k9eX4USLHXqLGXOIiWUT4Vj9JiP4W0io3VDz8AJXblNWQrOimLjIGy/9uLICH6mrVmFbxEFHauzmc0fGJJmPg/v+6D0oB7N2bj0FsNHtSWTQniWTR931QlHXvasDTHXLjqY0/1/8hSDxACD+lAGH8dKQbQk5N3TFtzDmLWutvV0+pL5FVoHvCNG35FGAAayS4KUoKC9QAAAAASUVORK5CYII=";
+ this._color1 = {
+ r: 20,
+ g: 20,
+ b: 20
+ };
+ this._color2 = {
+ r: 200,
+ g: 200,
+ b: 200
+ };
+ this._fade = null;
+ this.game = game;
+ this._logo = new Image();
+ this._logo.src = this._logoData;
+ }
+ BootScreen.prototype.update = function () {
+ if(this._fade == null) {
+ this.colorCycle();
+ }
+ this._color1.r = Math.round(this._color1.r);
+ this._color1.g = Math.round(this._color1.g);
+ this._color1.b = Math.round(this._color1.b);
+ this._color2.r = Math.round(this._color2.r);
+ this._color2.g = Math.round(this._color2.g);
+ this._color2.b = Math.round(this._color2.b);
+ };
+ BootScreen.prototype.render = function () {
+ var grd = this.game.stage.context.createLinearGradient(0, 0, 0, this.game.stage.height);
+ grd.addColorStop(0, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
+ grd.addColorStop(0.5, 'rgb(' + this._color2.r + ', ' + this._color2.g + ', ' + this._color2.b + ')');
+ grd.addColorStop(1, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
+ this.game.stage.context.fillStyle = grd;
+ this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
+ this.game.stage.context.shadowOffsetX = 0;
+ this.game.stage.context.shadowOffsetY = 0;
+ if(this._logo) {
+ this.game.stage.context.drawImage(this._logo, 32, 32);
+ }
+ this.game.stage.context.shadowColor = 'rgb(0,0,0)';
+ this.game.stage.context.shadowOffsetX = 1;
+ this.game.stage.context.shadowOffsetY = 1;
+ this.game.stage.context.shadowBlur = 0;
+ this.game.stage.context.fillStyle = 'rgb(255,255,255)';
+ this.game.stage.context.font = 'bold 18px Arial';
+ this.game.stage.context.textBaseline = 'top';
+ this.game.stage.context.fillText(Phaser.VERSION, 32, 64 + 32);
+ this.game.stage.context.fillText('Game Size: ' + this.game.stage.width + ' x ' + this.game.stage.height, 32, 64 + 64);
+ this.game.stage.context.fillText('www.photonstorm.com', 32, 64 + 96);
+ this.game.stage.context.font = '16px Arial';
+ this.game.stage.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 64 + 160);
+ this.game.stage.context.fillText('functions in the Game constructor or use Game.switchState()', 32, 64 + 184);
+ };
+ BootScreen.prototype.colorCycle = function () {
+ this._fade = this.game.add.tween(this._color2);
+ this._fade.to({
+ r: Math.random() * 250,
+ g: Math.random() * 250,
+ b: Math.random() * 250
+ }, 3000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.colorCycle, this);
+ this._fade.start();
+ };
+ return BootScreen;
+ })();
+ Phaser.BootScreen = BootScreen;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var OrientationScreen = (function () {
+ function OrientationScreen(game) {
+ this._enabled = false;
+ this.game = game;
+ }
+ OrientationScreen.prototype.enable = function (imageKey) {
+ this._enabled = true;
+ this.image = this.game.cache.getImage(imageKey);
+ };
+ OrientationScreen.prototype.update = function () {
+ };
+ OrientationScreen.prototype.render = function () {
+ if(this._enabled) {
+ this.game.stage.context.drawImage(this.image, 0, 0, this.image.width, this.image.height, 0, 0, this.game.stage.width, this.game.stage.height);
+ }
+ };
+ return OrientationScreen;
+ })();
+ Phaser.OrientationScreen = OrientationScreen;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var PauseScreen = (function () {
+ function PauseScreen(game, width, height) {
+ this.game = game;
+ this._canvas = document.createElement('canvas');
+ this._canvas.width = width;
+ this._canvas.height = height;
+ this._context = this._canvas.getContext('2d');
+ }
+ PauseScreen.prototype.onPaused = function () {
+ this._context.clearRect(0, 0, this._canvas.width, this._canvas.height);
+ this._context.drawImage(this.game.stage.canvas, 0, 0);
+ this._color = {
+ r: 255,
+ g: 255,
+ b: 255
+ };
+ this.fadeOut();
+ };
+ PauseScreen.prototype.onResume = function () {
+ this._fade.stop();
+ this.game.tweens.remove(this._fade);
+ };
+ PauseScreen.prototype.update = function () {
+ this._color.r = Math.round(this._color.r);
+ this._color.g = Math.round(this._color.g);
+ this._color.b = Math.round(this._color.b);
+ };
+ PauseScreen.prototype.render = function () {
+ this.game.stage.context.drawImage(this._canvas, 0, 0);
+ this.game.stage.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
+ this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
+ var arrowWidth = Math.round(this.game.stage.width / 2);
+ var arrowHeight = Math.round(this.game.stage.height / 2);
+ var sx = this.game.stage.centerX - arrowWidth / 2;
+ var sy = this.game.stage.centerY - arrowHeight / 2;
+ this.game.stage.context.beginPath();
+ this.game.stage.context.moveTo(sx, sy);
+ this.game.stage.context.lineTo(sx, sy + arrowHeight);
+ this.game.stage.context.lineTo(sx + arrowWidth, this.game.stage.centerY);
+ this.game.stage.context.fillStyle = 'rgba(' + this._color.r + ', ' + this._color.g + ', ' + this._color.b + ', 0.8)';
+ this.game.stage.context.fill();
+ this.game.stage.context.closePath();
+ };
+ PauseScreen.prototype.fadeOut = function () {
+ this._fade = this.game.add.tween(this._color);
+ this._fade.to({
+ r: 50,
+ g: 50,
+ b: 50
+ }, 1000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.fadeIn, this);
+ this._fade.start();
+ };
+ PauseScreen.prototype.fadeIn = function () {
+ this._fade = this.game.add.tween(this._color);
+ this._fade.to({
+ r: 255,
+ g: 255,
+ b: 255
+ }, 1000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.fadeOut, this);
+ this._fade.start();
+ };
+ return PauseScreen;
+ })();
+ Phaser.PauseScreen = PauseScreen;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var SoundManager = (function () {
+ function SoundManager(game) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = false;
+ this.noAudio = false;
+ this.context = null;
+ this._muted = false;
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.onSoundDecode = new Phaser.Signal();
+ this.game = game;
+ this._volume = 1;
+ this._muted = false;
+ this._sounds = [];
+ if(this.game.device.iOS && this.game.device.webAudio == false) {
+ this.channels = 1;
+ }
+ if(this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) {
+ this.game.input.touch.callbackContext = this;
+ this.game.input.touch.touchStartCallback = this.unlock;
+ this.game.input.mouse.callbackContext = this;
+ this.game.input.mouse.mouseDownCallback = this.unlock;
+ this.touchLocked = true;
+ } else {
+ this.touchLocked = false;
+ }
+ if(window['PhaserGlobal']) {
+ if(window['PhaserGlobal'].disableAudio == true) {
+ this.usingWebAudio = false;
+ this.noAudio = true;
+ return;
+ }
+ if(window['PhaserGlobal'].disableWebAudio == true) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = true;
+ this.noAudio = false;
+ return;
+ }
+ }
+ this.usingWebAudio = true;
+ this.noAudio = false;
+ if(!!window['AudioContext']) {
+ this.context = new window['AudioContext']();
+ } else if(!!window['webkitAudioContext']) {
+ this.context = new window['webkitAudioContext']();
+ } else if(!!window['Audio']) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = true;
+ } else {
+ this.usingWebAudio = false;
+ this.noAudio = true;
+ }
+ if(this.context !== null) {
+ if(typeof this.context.createGain === 'undefined') {
+ this.masterGain = this.context.createGainNode();
+ } else {
+ this.masterGain = this.context.createGain();
+ }
+ this.masterGain.gain.value = 1;
+ this.masterGain.connect(this.context.destination);
+ }
+ }
+ SoundManager.prototype.unlock = function () {
+ if(this.touchLocked == false) {
+ return;
+ }
+ if(this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false)) {
+ var buffer = this.context.createBuffer(1, 1, 22050);
+ this._unlockSource = this.context.createBufferSource();
+ this._unlockSource.buffer = buffer;
+ this._unlockSource.connect(this.context.destination);
+ this._unlockSource.noteOn(0);
+ } else {
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.game.input.touch.callbackContext = null;
+ this.game.input.touch.touchStartCallback = null;
+ this.game.input.mouse.callbackContext = null;
+ this.game.input.mouse.mouseDownCallback = null;
+ }
+ };
+ Object.defineProperty(SoundManager.prototype, "mute", {
+ get: function () {
+ return this._muted;
+ },
+ set: function (value) {
+ if(value) {
+ if(this._muted) {
+ return;
+ }
+ this._muted = true;
+ if(this.usingWebAudio) {
+ this._muteVolume = this.masterGain.gain.value;
+ this.masterGain.gain.value = 0;
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].mute = true;
+ }
+ }
+ } else {
+ if(this._muted == false) {
+ return;
+ }
+ this._muted = false;
+ if(this.usingWebAudio) {
+ this.masterGain.gain.value = this._muteVolume;
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].mute = false;
+ }
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(SoundManager.prototype, "volume", {
+ get: function () {
+ if(this.usingWebAudio) {
+ return this.masterGain.gain.value;
+ } else {
+ return this._volume;
+ }
+ },
+ set: function (value) {
+ value = this.game.math.clamp(value, 1, 0);
+ this._volume = value;
+ if(this.usingWebAudio) {
+ this.masterGain.gain.value = value;
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].volume = this._sounds[i].volume * value;
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ SoundManager.prototype.stopAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].stop();
+ }
+ }
+ };
+ SoundManager.prototype.pauseAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].pause();
+ }
+ }
+ };
+ SoundManager.prototype.resumeAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].resume();
+ }
+ }
+ };
+ SoundManager.prototype.decode = function (key, sound) {
+ if (typeof sound === "undefined") { sound = null; }
+ var soundData = this.game.cache.getSoundData(key);
+ if(soundData) {
+ if(this.game.cache.isSoundDecoded(key) === false) {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+ var that = this;
+ this.context.decodeAudioData(soundData, function (buffer) {
+ that.game.cache.decodedSound(key, buffer);
+ if(sound) {
+ that.onSoundDecode.dispatch(sound);
+ }
+ });
+ }
+ }
+ };
+ SoundManager.prototype.update = function () {
+ if(this.touchLocked) {
+ if(this.game.device.webAudio && this._unlockSource !== null) {
+ if((this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.game.input.touch.callbackContext = null;
+ this.game.input.touch.touchStartCallback = null;
+ }
+ }
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ this._sounds[i].update();
+ }
+ };
+ SoundManager.prototype.add = function (key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ var sound = new Phaser.Sound(this.game, key, volume, loop);
+ this._sounds.push(sound);
+ return sound;
+ };
+ return SoundManager;
+ })();
+ Phaser.SoundManager = SoundManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Sound = (function () {
+ function Sound(game, key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.context = null;
+ this._buffer = null;
+ this._muted = false;
+ this.usingWebAudio = false;
+ this.usingAudioTag = false;
+ this.name = '';
+ this.autoplay = false;
+ this.totalDuration = 0;
+ this.startTime = 0;
+ this.currentTime = 0;
+ this.duration = 0;
+ this.stopTime = 0;
+ this.paused = false;
+ this.loop = false;
+ this.isPlaying = false;
+ this.currentMarker = '';
+ this.pendingPlayback = false;
+ this.override = false;
+ this.game = game;
+ this.usingWebAudio = this.game.sound.usingWebAudio;
+ this.usingAudioTag = this.game.sound.usingAudioTag;
+ this.key = key;
+ if(this.usingWebAudio) {
+ this.context = this.game.sound.context;
+ this.masterGainNode = this.game.sound.masterGain;
+ if(typeof this.context.createGain === 'undefined') {
+ this.gainNode = this.context.createGainNode();
+ } else {
+ this.gainNode = this.context.createGain();
+ }
+ this.gainNode.gain.value = volume * this.game.sound.volume;
+ this.gainNode.connect(this.masterGainNode);
+ } else {
+ if(this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false) {
+ this._sound = this.game.cache.getSoundData(key);
+ this.totalDuration = this._sound.duration;
+ } else {
+ this.game.cache.onSoundUnlock.add(this.soundHasUnlocked, this);
+ }
+ }
+ this._volume = volume;
+ this.loop = loop;
+ this.markers = {
+ };
+ this.onDecoded = new Phaser.Signal();
+ this.onPlay = new Phaser.Signal();
+ this.onPause = new Phaser.Signal();
+ this.onResume = new Phaser.Signal();
+ this.onLoop = new Phaser.Signal();
+ this.onStop = new Phaser.Signal();
+ this.onMute = new Phaser.Signal();
+ this.onMarkerComplete = new Phaser.Signal();
+ }
+ Sound.prototype.soundHasUnlocked = function (key) {
+ if(key == this.key) {
+ this._sound = this.game.cache.getSoundData(this.key);
+ this.totalDuration = this._sound.duration;
+ }
+ };
+ Object.defineProperty(Sound.prototype, "isDecoding", {
+ get: function () {
+ return this.game.cache.getSound(this.key).isDecoding;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sound.prototype, "isDecoded", {
+ get: function () {
+ return this.game.cache.isSoundDecoded(this.key);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sound.prototype.addMarker = function (name, start, stop, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.markers[name] = {
+ name: name,
+ start: start,
+ stop: stop,
+ volume: volume,
+ duration: stop - start,
+ loop: loop
+ };
+ };
+ Sound.prototype.removeMarker = function (name) {
+ delete this.markers[name];
+ };
+ Sound.prototype.update = function () {
+ if(this.pendingPlayback && this.game.cache.isSoundReady(this.key)) {
+ this.pendingPlayback = false;
+ this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
+ }
+ if(this.isPlaying) {
+ this.currentTime = this.game.time.now - this.startTime;
+ if(this.currentTime >= this.duration) {
+ if(this.usingWebAudio) {
+ if(this.loop) {
+ this.onLoop.dispatch(this);
+ if(this.currentMarker == '') {
+ this.currentTime = 0;
+ this.startTime = this.game.time.now;
+ } else {
+ this.play(this.currentMarker, 0, this.volume, true, true);
+ }
+ } else {
+ this.stop();
+ }
+ } else {
+ if(this.loop) {
+ this.onLoop.dispatch(this);
+ this.play(this.currentMarker, 0, this.volume, true, true);
+ } else {
+ this.stop();
+ }
+ }
+ }
+ }
+ };
+ Sound.prototype.play = function (marker, position, volume, loop, forceRestart) {
+ if (typeof marker === "undefined") { marker = ''; }
+ if (typeof position === "undefined") { position = 0; }
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof forceRestart === "undefined") { forceRestart = false; }
+ if(this.isPlaying == true && forceRestart == false && this.override == false) {
+ return;
+ }
+ if(this.isPlaying && this.override) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.stop === 'undefined') {
+ this._sound.noteOff(0);
+ } else {
+ this._sound.stop(0);
+ }
+ } else if(this.usingAudioTag) {
+ this._sound.pause();
+ this._sound.currentTime = 0;
+ }
+ }
+ this.currentMarker = marker;
+ if(marker !== '' && this.markers[marker]) {
+ this.position = this.markers[marker].start;
+ this.volume = this.markers[marker].volume;
+ this.loop = this.markers[marker].loop;
+ this.duration = this.markers[marker].duration * 1000;
+ this._tempMarker = marker;
+ this._tempPosition = this.position;
+ this._tempVolume = this.volume;
+ this._tempLoop = this.loop;
+ } else {
+ this.position = position;
+ this.volume = volume;
+ this.loop = loop;
+ this.duration = 0;
+ this._tempMarker = marker;
+ this._tempPosition = position;
+ this._tempVolume = volume;
+ this._tempLoop = loop;
+ }
+ if(this.usingWebAudio) {
+ if(this.game.cache.isSoundDecoded(this.key)) {
+ if(this._buffer == null) {
+ this._buffer = this.game.cache.getSoundData(this.key);
+ }
+ this._sound = this.context.createBufferSource();
+ this._sound.buffer = this._buffer;
+ this._sound.connect(this.gainNode);
+ this.totalDuration = this._sound.buffer.duration;
+ if(this.duration == 0) {
+ this.duration = this.totalDuration * 1000;
+ }
+ if(this.loop && marker == '') {
+ this._sound.loop = true;
+ }
+ if(typeof this._sound.start === 'undefined') {
+ this._sound.noteGrainOn(0, this.position, this.duration / 1000);
+ } else {
+ this._sound.start(0, this.position, this.duration / 1000);
+ }
+ this.isPlaying = true;
+ this.startTime = this.game.time.now;
+ this.currentTime = 0;
+ this.stopTime = this.startTime + this.duration;
+ this.onPlay.dispatch(this);
+ } else {
+ this.pendingPlayback = true;
+ if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false) {
+ this.game.sound.decode(this.key, this);
+ }
+ }
+ } else {
+ if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).locked) {
+ this.game.cache.reloadSound(this.key);
+ this.pendingPlayback = true;
+ } else {
+ if(this._sound && this._sound.readyState == 4) {
+ if(this.duration == 0) {
+ this.duration = this.totalDuration * 1000;
+ }
+ this._sound.currentTime = this.position;
+ this._sound.muted = this._muted;
+ if(this._muted) {
+ this._sound.volume = 0;
+ } else {
+ this._sound.volume = this._volume;
+ }
+ this._sound.play();
+ this.isPlaying = true;
+ this.startTime = this.game.time.now;
+ this.currentTime = 0;
+ this.stopTime = this.startTime + this.duration;
+ this.onPlay.dispatch(this);
+ } else {
+ this.pendingPlayback = true;
+ }
+ }
+ }
+ };
+ Sound.prototype.restart = function (marker, position, volume, loop) {
+ if (typeof marker === "undefined") { marker = ''; }
+ if (typeof position === "undefined") { position = 0; }
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.play(marker, position, volume, loop, true);
+ };
+ Sound.prototype.pause = function () {
+ if(this.isPlaying && this._sound) {
+ this.stop();
+ this.isPlaying = false;
+ this.paused = true;
+ this.onPause.dispatch(this);
+ }
+ };
+ Sound.prototype.resume = function () {
+ if(this.paused && this._sound) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.start === 'undefined') {
+ this._sound.noteGrainOn(0, this.position, this.duration);
+ } else {
+ this._sound.start(0, this.position, this.duration);
+ }
+ } else {
+ this._sound.play();
+ }
+ this.isPlaying = true;
+ this.paused = false;
+ this.onResume.dispatch(this);
+ }
+ };
+ Sound.prototype.stop = function () {
+ if(this.isPlaying && this._sound) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.stop === 'undefined') {
+ this._sound.noteOff(0);
+ } else {
+ this._sound.stop(0);
+ }
+ } else if(this.usingAudioTag) {
+ this._sound.pause();
+ this._sound.currentTime = 0;
+ }
+ }
+ this.isPlaying = false;
+ var prevMarker = this.currentMarker;
+ this.currentMarker = '';
+ this.onStop.dispatch(this, prevMarker);
+ };
+ Object.defineProperty(Sound.prototype, "mute", {
+ get: function () {
+ return this._muted;
+ },
+ set: function (value) {
+ if(value) {
+ this._muted = true;
+ if(this.usingWebAudio) {
+ this._muteVolume = this.gainNode.gain.value;
+ this.gainNode.gain.value = 0;
+ } else if(this.usingAudioTag && this._sound) {
+ this._muteVolume = this._sound.volume;
+ this._sound.volume = 0;
+ }
+ } else {
+ this._muted = false;
+ if(this.usingWebAudio) {
+ this.gainNode.gain.value = this._muteVolume;
+ } else if(this.usingAudioTag && this._sound) {
+ this._sound.volume = this._muteVolume;
+ }
+ }
+ this.onMute.dispatch(this);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sound.prototype, "volume", {
+ get: function () {
+ return this._volume;
+ },
+ set: function (value) {
+ this._volume = value;
+ if(this.usingWebAudio) {
+ this.gainNode.gain.value = value;
+ } else if(this.usingAudioTag && this._sound) {
+ this._sound.volume = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Sound;
+ })();
+ Phaser.Sound = Sound;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Animation = (function () {
+ function Animation(game, parent, frameData, name, frames, delay, looped) {
+ this.game = game;
+ this._parent = parent;
+ this._frames = frames;
+ this._frameData = frameData;
+ this.name = name;
+ this.delay = 1000 / delay;
+ this.looped = looped;
+ this.isFinished = false;
+ this.isPlaying = false;
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ }
+ Object.defineProperty(Animation.prototype, "frameTotal", {
+ get: function () {
+ return this._frames.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Animation.prototype, "frame", {
+ get: function () {
+ if(this.currentFrame !== null) {
+ return this.currentFrame.index;
+ } else {
+ return this._frameIndex;
+ }
+ },
+ set: function (value) {
+ this.currentFrame = this._frameData.getFrame(value);
+ if(this.currentFrame !== null) {
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ this._frameIndex = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Animation.prototype.play = function (frameRate, loop) {
+ if (typeof frameRate === "undefined") { frameRate = null; }
+ if (typeof loop === "undefined") { loop = null; }
+ if(frameRate !== null) {
+ this.delay = 1000 / frameRate;
+ }
+ if(loop !== null) {
+ this.looped = loop;
+ }
+ this.isPlaying = true;
+ this.isFinished = false;
+ this._timeLastFrame = this.game.time.now;
+ this._timeNextFrame = this.game.time.now + this.delay;
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ this._parent.events.onAnimationStart.dispatch(this._parent, this);
+ return this;
+ };
+ Animation.prototype.restart = function () {
+ this.isPlaying = true;
+ this.isFinished = false;
+ this._timeLastFrame = this.game.time.now;
+ this._timeNextFrame = this.game.time.now + this.delay;
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ };
+ Animation.prototype.stop = function () {
+ this.isPlaying = false;
+ this.isFinished = true;
+ };
+ Animation.prototype.update = function () {
+ if(this.isPlaying == true && this.game.time.now >= this._timeNextFrame) {
+ this._frameIndex++;
+ if(this._frameIndex == this._frames.length) {
+ if(this.looped) {
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ this._parent.events.onAnimationLoop.dispatch(this._parent, this);
+ } else {
+ this.onComplete();
+ }
+ } else {
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ }
+ this._timeLastFrame = this.game.time.now;
+ this._timeNextFrame = this.game.time.now + this.delay;
+ return true;
+ }
+ return false;
+ };
+ Animation.prototype.destroy = function () {
+ this.game = null;
+ this._parent = null;
+ this._frames = null;
+ this._frameData = null;
+ this.currentFrame = null;
+ this.isPlaying = false;
+ };
+ Animation.prototype.onComplete = function () {
+ this.isPlaying = false;
+ this.isFinished = true;
+ this._parent.events.onAnimationComplete.dispatch(this._parent, this);
+ };
+ return Animation;
+ })();
+ Phaser.Animation = Animation;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var AnimationManager = (function () {
+ function AnimationManager(parent) {
+ this._frameData = null;
+ this.autoUpdateBounds = true;
+ this.currentFrame = null;
+ this._parent = parent;
+ this.game = parent.game;
+ this._anims = {
+ };
+ }
+ AnimationManager.prototype.loadFrameData = function (frameData) {
+ this._frameData = frameData;
+ this.frame = 0;
+ };
+ AnimationManager.prototype.add = function (name, frames, frameRate, loop, useNumericIndex) {
+ if (typeof frames === "undefined") { frames = null; }
+ if (typeof frameRate === "undefined") { frameRate = 60; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
+ if(this._frameData == null) {
+ return;
+ }
+ if(this._parent.events.onAnimationStart == null) {
+ this._parent.events.onAnimationStart = new Phaser.Signal();
+ this._parent.events.onAnimationComplete = new Phaser.Signal();
+ this._parent.events.onAnimationLoop = new Phaser.Signal();
+ }
+ if(frames == null) {
+ frames = this._frameData.getFrameIndexes();
+ } else {
+ if(this.validateFrames(frames, useNumericIndex) == false) {
+ throw Error('Invalid frames given to Animation ' + name);
+ return;
+ }
+ }
+ if(useNumericIndex == false) {
+ frames = this._frameData.getFrameIndexesByName(frames);
+ }
+ this._anims[name] = new Phaser.Animation(this.game, this._parent, this._frameData, name, frames, frameRate, loop);
+ this.currentAnim = this._anims[name];
+ this.currentFrame = this.currentAnim.currentFrame;
+ return this._anims[name];
+ };
+ AnimationManager.prototype.validateFrames = function (frames, useNumericIndex) {
+ for(var i = 0; i < frames.length; i++) {
+ if(useNumericIndex == true) {
+ if(frames[i] > this._frameData.total) {
+ return false;
+ }
+ } else {
+ if(this._frameData.checkFrameName(frames[i]) == false) {
+ return false;
+ }
+ }
+ }
+ return true;
+ };
+ AnimationManager.prototype.play = function (name, frameRate, loop) {
+ if (typeof frameRate === "undefined") { frameRate = null; }
+ if (typeof loop === "undefined") { loop = null; }
+ if(this._anims[name]) {
+ if(this.currentAnim == this._anims[name]) {
+ if(this.currentAnim.isPlaying == false) {
+ return this.currentAnim.play(frameRate, loop);
+ }
+ } else {
+ this.currentAnim = this._anims[name];
+ return this.currentAnim.play(frameRate, loop);
+ }
+ }
+ };
+ AnimationManager.prototype.stop = function (name) {
+ if(this._anims[name]) {
+ this.currentAnim = this._anims[name];
+ this.currentAnim.stop();
+ }
+ };
+ AnimationManager.prototype.update = function () {
+ if(this.currentAnim && this.currentAnim.update() == true) {
+ this.currentFrame = this.currentAnim.currentFrame;
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ }
+ };
+ Object.defineProperty(AnimationManager.prototype, "frameData", {
+ get: function () {
+ return this._frameData;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(AnimationManager.prototype, "frameTotal", {
+ get: function () {
+ if(this._frameData) {
+ return this._frameData.total;
+ } else {
+ return -1;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(AnimationManager.prototype, "frame", {
+ get: function () {
+ return this._frameIndex;
+ },
+ set: function (value) {
+ if(this._frameData && this._frameData.getFrame(value) !== null) {
+ this.currentFrame = this._frameData.getFrame(value);
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ if(this.autoUpdateBounds && this._parent['body']) {
+ this._parent.body.bounds.width = this.currentFrame.width;
+ this._parent.body.bounds.height = this.currentFrame.height;
+ }
+ this._frameIndex = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(AnimationManager.prototype, "frameName", {
+ get: function () {
+ return this.currentFrame.name;
+ },
+ set: function (value) {
+ if(this._frameData && this._frameData.getFrameByName(value)) {
+ this.currentFrame = this._frameData.getFrameByName(value);
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ this._frameIndex = this.currentFrame.index;
+ } else {
+ throw new Error("Cannot set frameName: " + value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ AnimationManager.prototype.destroy = function () {
+ this._anims = {
+ };
+ this._frameData = null;
+ this._frameIndex = 0;
+ this.currentAnim = null;
+ this.currentFrame = null;
+ };
+ return AnimationManager;
+ })();
+ Components.AnimationManager = AnimationManager;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Frame = (function () {
+ function Frame(x, y, width, height, name) {
+ this.name = '';
+ this.rotated = false;
+ this.rotationDirection = 'cw';
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.name = name;
+ this.rotated = false;
+ this.trimmed = false;
+ }
+ Frame.prototype.setRotation = function (rotated, rotationDirection) {
+ };
+ Frame.prototype.setTrim = function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
+ this.trimmed = trimmed;
+ if(trimmed) {
+ this.width = actualWidth;
+ this.height = actualHeight;
+ this.sourceSizeW = actualWidth;
+ this.sourceSizeH = actualHeight;
+ this.spriteSourceSizeX = destX;
+ this.spriteSourceSizeY = destY;
+ this.spriteSourceSizeW = destWidth;
+ this.spriteSourceSizeH = destHeight;
+ }
+ };
+ return Frame;
+ })();
+ Phaser.Frame = Frame;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var FrameData = (function () {
+ function FrameData() {
+ this._frames = [];
+ this._frameNames = [];
+ }
+ Object.defineProperty(FrameData.prototype, "total", {
+ get: function () {
+ return this._frames.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ FrameData.prototype.addFrame = function (frame) {
+ frame.index = this._frames.length;
+ this._frames.push(frame);
+ if(frame.name !== '') {
+ this._frameNames[frame.name] = frame.index;
+ }
+ return frame;
+ };
+ FrameData.prototype.getFrame = function (index) {
+ if(this._frames[index]) {
+ return this._frames[index];
+ }
+ return null;
+ };
+ FrameData.prototype.getFrameByName = function (name) {
+ if(this._frameNames[name] !== '') {
+ return this._frames[this._frameNames[name]];
+ }
+ return null;
+ };
+ FrameData.prototype.checkFrameName = function (name) {
+ if(this._frameNames[name] == null) {
+ return false;
+ }
+ return true;
+ };
+ FrameData.prototype.getFrameRange = function (start, end, output) {
+ if (typeof output === "undefined") { output = []; }
+ for(var i = start; i <= end; i++) {
+ output.push(this._frames[i]);
+ }
+ return output;
+ };
+ FrameData.prototype.getFrameIndexes = function (output) {
+ if (typeof output === "undefined") { output = []; }
+ output.length = 0;
+ for(var i = 0; i < this._frames.length; i++) {
+ output.push(i);
+ }
+ return output;
+ };
+ FrameData.prototype.getFrameIndexesByName = function (input) {
+ var output = [];
+ for(var i = 0; i < input.length; i++) {
+ if(this.getFrameByName(input[i])) {
+ output.push(this.getFrameByName(input[i]).index);
+ }
+ }
+ return output;
+ };
+ FrameData.prototype.getAllFrames = function () {
+ return this._frames;
+ };
+ FrameData.prototype.getFrames = function (range) {
+ var output = [];
+ for(var i = 0; i < range.length; i++) {
+ output.push(this._frames[i]);
+ }
+ return output;
+ };
+ return FrameData;
+ })();
+ Phaser.FrameData = FrameData;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Cache = (function () {
+ function Cache(game) {
+ this.onSoundUnlock = new Phaser.Signal();
+ this.game = game;
+ this._canvases = {
+ };
+ this._images = {
+ };
+ this._sounds = {
+ };
+ this._text = {
+ };
+ }
+ Cache.prototype.addCanvas = function (key, canvas, context) {
+ this._canvases[key] = {
+ canvas: canvas,
+ context: context
+ };
+ };
+ Cache.prototype.addSpriteSheet = function (key, url, data, frameWidth, frameHeight, frameMax) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: true,
+ frameWidth: frameWidth,
+ frameHeight: frameHeight
+ };
+ this._images[key].frameData = Phaser.AnimationLoader.parseSpriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
+ };
+ Cache.prototype.addTextureAtlas = function (key, url, data, atlasData, format) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: true
+ };
+ if(format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ this._images[key].frameData = Phaser.AnimationLoader.parseJSONData(this.game, atlasData);
+ } else if(format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING) {
+ this._images[key].frameData = Phaser.AnimationLoader.parseXMLData(this.game, atlasData, format);
+ }
+ };
+ Cache.prototype.addImage = function (key, url, data) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: false
+ };
+ };
+ Cache.prototype.addSound = function (key, url, data, webAudio, audioTag) {
+ if (typeof webAudio === "undefined") { webAudio = true; }
+ if (typeof audioTag === "undefined") { audioTag = false; }
+ var locked = this.game.sound.touchLocked;
+ var decoded = false;
+ if(audioTag) {
+ decoded = true;
+ }
+ this._sounds[key] = {
+ url: url,
+ data: data,
+ locked: locked,
+ isDecoding: false,
+ decoded: decoded,
+ webAudio: webAudio,
+ audioTag: audioTag
+ };
+ };
+ Cache.prototype.reloadSound = function (key) {
+ var _this = this;
+ if(this._sounds[key]) {
+ this._sounds[key].data.src = this._sounds[key].url;
+ this._sounds[key].data.addEventListener('canplaythrough', function () {
+ return _this.reloadSoundComplete(key);
+ }, false);
+ this._sounds[key].data.load();
+ }
+ };
+ Cache.prototype.reloadSoundComplete = function (key) {
+ if(this._sounds[key]) {
+ this._sounds[key].locked = false;
+ this.onSoundUnlock.dispatch(key);
+ }
+ };
+ Cache.prototype.updateSound = function (key, property, value) {
+ if(this._sounds[key]) {
+ this._sounds[key][property] = value;
+ }
+ };
+ Cache.prototype.decodedSound = function (key, data) {
+ this._sounds[key].data = data;
+ this._sounds[key].decoded = true;
+ this._sounds[key].isDecoding = false;
+ };
+ Cache.prototype.addText = function (key, url, data) {
+ this._text[key] = {
+ url: url,
+ data: data
+ };
+ };
+ Cache.prototype.getCanvas = function (key) {
+ if(this._canvases[key]) {
+ return this._canvases[key].canvas;
+ }
+ return null;
+ };
+ Cache.prototype.getImage = function (key) {
+ if(this._images[key]) {
+ return this._images[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.getFrameData = function (key) {
+ if(this._images[key] && this._images[key].spriteSheet == true) {
+ return this._images[key].frameData;
+ }
+ return null;
+ };
+ Cache.prototype.getSound = function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key];
+ }
+ return null;
+ };
+ Cache.prototype.getSoundData = function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.isSoundDecoded = function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key].decoded;
+ }
+ };
+ Cache.prototype.isSoundReady = function (key) {
+ if(this._sounds[key] && this._sounds[key].decoded == true && this._sounds[key].locked == false) {
+ return true;
+ }
+ return false;
+ };
+ Cache.prototype.isSpriteSheet = function (key) {
+ if(this._images[key]) {
+ return this._images[key].spriteSheet;
+ }
+ };
+ Cache.prototype.getText = function (key) {
+ if(this._text[key]) {
+ return this._text[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.getImageKeys = function () {
+ var output = [];
+ for(var item in this._images) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.getSoundKeys = function () {
+ var output = [];
+ for(var item in this._sounds) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.getTextKeys = function () {
+ var output = [];
+ for(var item in this._text) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.removeCanvas = function (key) {
+ delete this._canvases[key];
+ };
+ Cache.prototype.removeImage = function (key) {
+ delete this._images[key];
+ };
+ Cache.prototype.removeSound = function (key) {
+ delete this._sounds[key];
+ };
+ Cache.prototype.removeText = function (key) {
+ delete this._text[key];
+ };
+ Cache.prototype.destroy = function () {
+ for(var item in this._canvases) {
+ delete this._canvases[item['key']];
+ }
+ for(var item in this._images) {
+ delete this._images[item['key']];
+ }
+ for(var item in this._sounds) {
+ delete this._sounds[item['key']];
+ }
+ for(var item in this._text) {
+ delete this._text[item['key']];
+ }
+ };
+ return Cache;
+ })();
+ Phaser.Cache = Cache;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Loader = (function () {
+ function Loader(game) {
+ this.crossOrigin = '';
+ this.baseURL = '';
+ this.game = game;
+ this._keys = [];
+ this._fileList = {
+ };
+ this._xhr = new XMLHttpRequest();
+ this._queueSize = 0;
+ this.isLoading = false;
+ this.onFileComplete = new Phaser.Signal();
+ this.onFileError = new Phaser.Signal();
+ this.onLoadStart = new Phaser.Signal();
+ this.onLoadComplete = new Phaser.Signal();
+ }
+ Loader.TEXTURE_ATLAS_JSON_ARRAY = 0;
+ Loader.TEXTURE_ATLAS_JSON_HASH = 1;
+ Loader.TEXTURE_ATLAS_XML_STARLING = 2;
+ Loader.prototype.reset = function () {
+ this._queueSize = 0;
+ this.isLoading = false;
+ };
+ Object.defineProperty(Loader.prototype, "queueSize", {
+ get: function () {
+ return this._queueSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Loader.prototype.image = function (key, url, overwrite) {
+ if (typeof overwrite === "undefined") { overwrite = false; }
+ if(overwrite == true || this.checkKeyExists(key) == false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'image',
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.spritesheet = function (key, url, frameWidth, frameHeight, frameMax) {
+ if (typeof frameMax === "undefined") { frameMax = -1; }
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'spritesheet',
+ key: key,
+ url: url,
+ data: null,
+ frameWidth: frameWidth,
+ frameHeight: frameHeight,
+ frameMax: frameMax,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.atlas = function (key, textureURL, atlasURL, atlasData, format) {
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ if (typeof format === "undefined") { format = Loader.TEXTURE_ATLAS_JSON_ARRAY; }
+ if(this.checkKeyExists(key) === false) {
+ if(atlasURL !== null) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ atlasURL: atlasURL,
+ data: null,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ } else {
+ if(format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ if(typeof atlasData === 'string') {
+ atlasData = JSON.parse(atlasData);
+ }
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ data: null,
+ atlasURL: null,
+ atlasData: atlasData,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ } else if(format == Loader.TEXTURE_ATLAS_XML_STARLING) {
+ if(typeof atlasData === 'string') {
+ var xml;
+ try {
+ if(window['DOMParser']) {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ } else {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ } catch (e) {
+ xml = undefined;
+ }
+ if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
+ throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
+ } else {
+ atlasData = xml;
+ }
+ }
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ data: null,
+ atlasURL: null,
+ atlasData: atlasData,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ }
+ }
+ };
+ Loader.prototype.audio = function (key, urls, autoDecode) {
+ if (typeof autoDecode === "undefined") { autoDecode = true; }
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'audio',
+ key: key,
+ url: urls,
+ data: null,
+ buffer: null,
+ error: false,
+ loaded: false,
+ autoDecode: autoDecode
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.text = function (key, url) {
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'text',
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.removeFile = function (key) {
+ delete this._fileList[key];
+ };
+ Loader.prototype.removeAll = function () {
+ this._fileList = {
+ };
+ };
+ Loader.prototype.start = function () {
+ if(this.isLoading) {
+ return;
+ }
+ this.progress = 0;
+ this.hasLoaded = false;
+ this.isLoading = true;
+ this.onLoadStart.dispatch(this.queueSize);
+ if(this._keys.length > 0) {
+ this._progressChunk = 100 / this._keys.length;
+ this.loadFile();
+ } else {
+ this.progress = 100;
+ this.hasLoaded = true;
+ this.onLoadComplete.dispatch();
+ }
+ };
+ Loader.prototype.loadFile = function () {
+ var _this = this;
+ var file = this._fileList[this._keys.pop()];
+ switch(file.type) {
+ case 'image':
+ case 'spritesheet':
+ case 'textureatlas':
+ file.data = new Image();
+ file.data.name = file.key;
+ file.data.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.crossOrigin = this.crossOrigin;
+ file.data.src = this.baseURL + file.url;
+ break;
+ case 'audio':
+ file.url = this.getAudioURL(file.url);
+ if(file.url !== null) {
+ if(this.game.sound.usingWebAudio) {
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "arraybuffer";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ } else if(this.game.sound.usingAudioTag) {
+ if(this.game.sound.touchLocked) {
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ this.fileComplete(file.key);
+ } else {
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
+ file.data.load();
+ }
+ }
+ }
+ break;
+ case 'text':
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "text";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ break;
+ }
+ };
+ Loader.prototype.getAudioURL = function (urls) {
+ var extension;
+ for(var i = 0; i < urls.length; i++) {
+ extension = urls[i].toLowerCase();
+ extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
+ if(this.game.device.canPlayAudio(extension)) {
+ return urls[i];
+ }
+ }
+ return null;
+ };
+ Loader.prototype.fileError = function (key) {
+ this._fileList[key].loaded = true;
+ this._fileList[key].error = true;
+ this.onFileError.dispatch(key);
+ throw new Error("Phaser.Loader error loading file: " + key);
+ this.nextFile(key, false);
+ };
+ Loader.prototype.fileComplete = function (key) {
+ var _this = this;
+ if(!this._fileList[key]) {
+ throw new Error('Phaser.Loader fileComplete invalid key ' + key);
+ return;
+ }
+ this._fileList[key].loaded = true;
+ var file = this._fileList[key];
+ var loadNext = true;
+ switch(file.type) {
+ case 'image':
+ this.game.cache.addImage(file.key, file.url, file.data);
+ break;
+ case 'spritesheet':
+ this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax);
+ break;
+ case 'textureatlas':
+ if(file.atlasURL == null) {
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
+ } else {
+ loadNext = false;
+ this._xhr.open("GET", this.baseURL + file.atlasURL, true);
+ this._xhr.responseType = "text";
+ if(file.format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ this._xhr.onload = function () {
+ return _this.jsonLoadComplete(file.key);
+ };
+ } else if(file.format == Loader.TEXTURE_ATLAS_XML_STARLING) {
+ this._xhr.onload = function () {
+ return _this.xmlLoadComplete(file.key);
+ };
+ }
+ this._xhr.onerror = function () {
+ return _this.dataLoadError(file.key);
+ };
+ this._xhr.send();
+ }
+ break;
+ case 'audio':
+ if(this.game.sound.usingWebAudio) {
+ file.data = this._xhr.response;
+ this.game.cache.addSound(file.key, file.url, file.data, true, false);
+ if(file.autoDecode) {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+ var that = this;
+ var key = file.key;
+ this.game.sound.context.decodeAudioData(file.data, function (buffer) {
+ if(buffer) {
+ that.game.cache.decodedSound(key, buffer);
+ }
+ });
+ }
+ } else {
+ file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete);
+ this.game.cache.addSound(file.key, file.url, file.data, false, true);
+ }
+ break;
+ case 'text':
+ file.data = this._xhr.response;
+ this.game.cache.addText(file.key, file.url, file.data);
+ break;
+ }
+ if(loadNext) {
+ this.nextFile(key, true);
+ }
+ };
+ Loader.prototype.jsonLoadComplete = function (key) {
+ var data = JSON.parse(this._xhr.response);
+ var file = this._fileList[key];
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.dataLoadError = function (key) {
+ var file = this._fileList[key];
+ file.error = true;
+ throw new Error("Phaser.Loader dataLoadError: " + key);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.xmlLoadComplete = function (key) {
+ var atlasData = this._xhr.response;
+ var xml;
+ try {
+ if(window['DOMParser']) {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ } else {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ } catch (e) {
+ xml = undefined;
+ }
+ if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
+ throw new Error("Phaser.Loader. Invalid XML given");
+ }
+ var file = this._fileList[key];
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.nextFile = function (previousKey, success) {
+ this.progress = Math.round(this.progress + this._progressChunk);
+ if(this.progress > 100) {
+ this.progress = 100;
+ }
+ this.onFileComplete.dispatch(this.progress, previousKey, success, this._queueSize - this._keys.length, this._queueSize);
+ if(this._keys.length > 0) {
+ this.loadFile();
+ } else {
+ this.hasLoaded = true;
+ this.isLoading = false;
+ this.removeAll();
+ this.onLoadComplete.dispatch();
+ }
+ };
+ Loader.prototype.checkKeyExists = function (key) {
+ if(this._fileList[key]) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ return Loader;
+ })();
+ Phaser.Loader = Loader;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var AnimationLoader = (function () {
+ function AnimationLoader() { }
+ AnimationLoader.parseSpriteSheet = function parseSpriteSheet(game, key, frameWidth, frameHeight, frameMax) {
+ var img = game.cache.getImage(key);
+ if(img == null) {
+ return null;
+ }
+ var width = img.width;
+ var height = img.height;
+ var row = Math.round(width / frameWidth);
+ var column = Math.round(height / frameHeight);
+ var total = row * column;
+ if(frameMax !== -1) {
+ total = frameMax;
+ }
+ if(width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
+ throw new Error("AnimationLoader.parseSpriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
+ return null;
+ }
+ var data = new Phaser.FrameData();
+ var x = 0;
+ var y = 0;
+ for(var i = 0; i < total; i++) {
+ data.addFrame(new Phaser.Frame(x, y, frameWidth, frameHeight, ''));
+ x += frameWidth;
+ if(x === width) {
+ x = 0;
+ y += frameHeight;
+ }
+ }
+ return data;
+ };
+ AnimationLoader.parseJSONData = function parseJSONData(game, json) {
+ if(!json['frames']) {
+ console.log(json);
+ throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
+ }
+ var data = new Phaser.FrameData();
+ var frames = json['frames'];
+ var newFrame;
+ for(var i = 0; i < frames.length; i++) {
+ newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
+ newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
+ }
+ return data;
+ };
+ AnimationLoader.parseXMLData = function parseXMLData(game, xml, format) {
+ if(!xml.getElementsByTagName('TextureAtlas')) {
+ throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing tag");
+ }
+ var data = new Phaser.FrameData();
+ var frames = xml.getElementsByTagName('SubTexture');
+ var newFrame;
+ for(var i = 0; i < frames.length; i++) {
+ var frame = frames[i].attributes;
+ newFrame = data.addFrame(new Phaser.Frame(frame.x.nodeValue, frame.y.nodeValue, frame.width.nodeValue, frame.height.nodeValue, frame.name.nodeValue));
+ if(frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0') {
+ newFrame.setTrim(true, frame.width.nodeValue, frame.height.nodeValue, Math.abs(frame.frameX.nodeValue), Math.abs(frame.frameY.nodeValue), frame.frameWidth.nodeValue, frame.frameHeight.nodeValue);
+ }
+ }
+ return data;
+ };
+ return AnimationLoader;
+ })();
+ Phaser.AnimationLoader = AnimationLoader;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Tile = (function () {
+ function Tile(game, tilemap, index, width, height) {
+ this.mass = 1.0;
+ this.collideLeft = false;
+ this.collideRight = false;
+ this.collideUp = false;
+ this.collideDown = false;
+ this.separateX = true;
+ this.separateY = true;
+ this.game = game;
+ this.tilemap = tilemap;
+ this.index = index;
+ this.width = width;
+ this.height = height;
+ this.allowCollisions = Phaser.Types.NONE;
+ }
+ Tile.prototype.destroy = function () {
+ this.tilemap = null;
+ };
+ Tile.prototype.setCollision = function (collision, resetCollisions, separateX, separateY) {
+ if(resetCollisions) {
+ this.resetCollision();
+ }
+ this.separateX = separateX;
+ this.separateY = separateY;
+ this.allowCollisions = collision;
+ if(collision & Phaser.Types.ANY) {
+ this.collideLeft = true;
+ this.collideRight = true;
+ this.collideUp = true;
+ this.collideDown = true;
+ return;
+ }
+ if(collision & Phaser.Types.LEFT || collision & Phaser.Types.WALL) {
+ this.collideLeft = true;
+ }
+ if(collision & Phaser.Types.RIGHT || collision & Phaser.Types.WALL) {
+ this.collideRight = true;
+ }
+ if(collision & Phaser.Types.UP || collision & Phaser.Types.CEILING) {
+ this.collideUp = true;
+ }
+ if(collision & Phaser.Types.DOWN || collision & Phaser.Types.CEILING) {
+ this.collideDown = true;
+ }
+ };
+ Tile.prototype.resetCollision = function () {
+ this.allowCollisions = Phaser.Types.NONE;
+ this.collideLeft = false;
+ this.collideRight = false;
+ this.collideUp = false;
+ this.collideDown = false;
+ };
+ Tile.prototype.toString = function () {
+ return "[{Tile (index=" + this.index + " collisions=" + this.allowCollisions + " width=" + this.width + " height=" + this.height + ")}]";
+ };
+ return Tile;
+ })();
+ Phaser.Tile = Tile;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Tilemap = (function () {
+ function Tilemap(game, key, mapData, format, resizeWorld, tileWidth, tileHeight) {
+ if (typeof resizeWorld === "undefined") { resizeWorld = true; }
+ if (typeof tileWidth === "undefined") { tileWidth = 0; }
+ if (typeof tileHeight === "undefined") { tileHeight = 0; }
+ this.z = -1;
+ this.renderOrderID = 0;
+ this.collisionCallback = null;
+ this.game = game;
+ this.type = Phaser.Types.TILEMAP;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.tiles = [];
+ this.layers = [];
+ this.mapFormat = format;
+ switch(format) {
+ case Tilemap.FORMAT_CSV:
+ this.parseCSV(game.cache.getText(mapData), key, tileWidth, tileHeight);
+ break;
+ case Tilemap.FORMAT_TILED_JSON:
+ this.parseTiledJSON(game.cache.getText(mapData), key);
+ break;
+ }
+ if(this.currentLayer && resizeWorld) {
+ this.game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
+ }
+ }
+ Tilemap.FORMAT_CSV = 0;
+ Tilemap.FORMAT_TILED_JSON = 1;
+ Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) {
+ var layer = new Phaser.TilemapLayer(this, 0, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
+ data = data.trim();
+ var rows = data.split("\n");
+ for(var i = 0; i < rows.length; i++) {
+ var column = rows[i].split(",");
+ if(column.length > 0) {
+ layer.addColumn(column);
+ }
+ }
+ layer.updateBounds();
+ var tileQuantity = layer.parseTileOffsets();
+ this.currentLayer = layer;
+ this.collisionLayer = layer;
+ this.layers.push(layer);
+ this.generateTiles(tileQuantity);
+ };
+ Tilemap.prototype.parseTiledJSON = function (data, key) {
+ data = data.trim();
+ var json = JSON.parse(data);
+ for(var i = 0; i < json.layers.length; i++) {
+ var layer = new Phaser.TilemapLayer(this, i, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
+ if(!json.layers[i].data) {
+ continue;
+ }
+ layer.alpha = json.layers[i].opacity;
+ layer.visible = json.layers[i].visible;
+ layer.tileMargin = json.tilesets[0].margin;
+ layer.tileSpacing = json.tilesets[0].spacing;
+ var c = 0;
+ var row;
+ for(var t = 0; t < json.layers[i].data.length; t++) {
+ if(c == 0) {
+ row = [];
+ }
+ row.push(json.layers[i].data[t]);
+ c++;
+ if(c == json.layers[i].width) {
+ layer.addColumn(row);
+ c = 0;
+ }
+ }
+ layer.updateBounds();
+ var tileQuantity = layer.parseTileOffsets();
+ this.currentLayer = layer;
+ this.collisionLayer = layer;
+ this.layers.push(layer);
+ }
+ this.generateTiles(tileQuantity);
+ };
+ Tilemap.prototype.generateTiles = function (qty) {
+ for(var i = 0; i < qty; i++) {
+ this.tiles.push(new Phaser.Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
+ }
+ };
+ Object.defineProperty(Tilemap.prototype, "widthInPixels", {
+ get: function () {
+ return this.currentLayer.widthInPixels;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tilemap.prototype, "heightInPixels", {
+ get: function () {
+ return this.currentLayer.heightInPixels;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Tilemap.prototype.setCollisionCallback = function (context, callback) {
+ this.collisionCallbackContext = context;
+ this.collisionCallback = callback;
+ };
+ Tilemap.prototype.setCollisionRange = function (start, end, collision, resetCollisions, separateX, separateY) {
+ if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
+ if (typeof resetCollisions === "undefined") { resetCollisions = false; }
+ if (typeof separateX === "undefined") { separateX = true; }
+ if (typeof separateY === "undefined") { separateY = true; }
+ for(var i = start; i < end; i++) {
+ this.tiles[i].setCollision(collision, resetCollisions, separateX, separateY);
+ }
+ };
+ Tilemap.prototype.setCollisionByIndex = function (values, collision, resetCollisions, separateX, separateY) {
+ if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
+ if (typeof resetCollisions === "undefined") { resetCollisions = false; }
+ if (typeof separateX === "undefined") { separateX = true; }
+ if (typeof separateY === "undefined") { separateY = true; }
+ for(var i = 0; i < values.length; i++) {
+ this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
+ }
+ };
+ Tilemap.prototype.getTileByIndex = function (value) {
+ if(this.tiles[value]) {
+ return this.tiles[value];
+ }
+ return null;
+ };
+ Tilemap.prototype.getTile = function (x, y, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileIndex(x, y)];
+ };
+ Tilemap.prototype.getTileFromWorldXY = function (x, y, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
+ };
+ Tilemap.prototype.getTileFromInputXY = function (layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.worldX, this.game.input.worldY)];
+ };
+ Tilemap.prototype.getTileOverlaps = function (object) {
+ return this.currentLayer.getTileOverlaps(object);
+ };
+ Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
+ if (typeof objectOrGroup === "undefined") { objectOrGroup = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof context === "undefined") { context = null; }
+ if(callback !== null && context !== null) {
+ this.collisionCallback = callback;
+ this.collisionCallbackContext = context;
+ }
+ if(objectOrGroup == null) {
+ objectOrGroup = this.game.world.group;
+ }
+ if(objectOrGroup.isGroup == false) {
+ this.collideGameObject(objectOrGroup);
+ } else {
+ objectOrGroup.forEachAlive(this, this.collideGameObject, true);
+ }
+ };
+ Tilemap.prototype.collideGameObject = function (object) {
+ if(object.body.type == Phaser.Types.BODY_DYNAMIC && object.exists == true && object.body.allowCollisions != Phaser.Types.NONE) {
+ this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
+ if(this.collisionCallback !== null && this._tempCollisionData.length > 0) {
+ this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Tilemap.prototype.putTile = function (x, y, index, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ this.layers[layer].putTile(x, y, index);
+ };
+ Tilemap.prototype.preUpdate = function () {
+ };
+ Tilemap.prototype.update = function () {
+ };
+ Tilemap.prototype.postUpdate = function () {
+ };
+ Tilemap.prototype.destroy = function () {
+ this.texture = null;
+ this.transform = null;
+ this.tiles.length = 0;
+ this.layers.length = 0;
+ };
+ return Tilemap;
+ })();
+ Phaser.Tilemap = Tilemap;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var TilemapLayer = (function () {
+ function TilemapLayer(parent, id, key, mapFormat, name, tileWidth, tileHeight) {
+ this.exists = true;
+ this.visible = true;
+ this.widthInTiles = 0;
+ this.heightInTiles = 0;
+ this.widthInPixels = 0;
+ this.heightInPixels = 0;
+ this.tileMargin = 0;
+ this.tileSpacing = 0;
+ this.parent = parent;
+ this.game = parent.game;
+ this.ID = id;
+ this.name = name;
+ this.mapFormat = mapFormat;
+ this.tileWidth = tileWidth;
+ this.tileHeight = tileHeight;
+ this.boundsInTiles = new Phaser.Rectangle();
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ if(key !== null) {
+ this.texture.loadImage(key, false);
+ } else {
+ this.texture.opaque = true;
+ }
+ this.alpha = this.texture.alpha;
+ this.mapData = [];
+ this._tempTileBlock = [];
+ }
+ TilemapLayer.prototype.putTileWorldXY = function (x, y, index) {
+ 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;
+ }
+ }
+ };
+ TilemapLayer.prototype.putTile = function (x, y, index) {
+ if(y >= 0 && y < this.mapData.length) {
+ if(x >= 0 && x < this.mapData[y].length) {
+ this.mapData[y][x] = index;
+ }
+ }
+ };
+ TilemapLayer.prototype.swapTile = function (tileA, tileB, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ if (typeof height === "undefined") { height = this.heightInTiles; }
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ if(this._tempTileBlock[r].tile.index == tileA) {
+ this._tempTileBlock[r].newIndex = true;
+ }
+ if(this._tempTileBlock[r].tile.index == tileB) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileA;
+ }
+ }
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ if(this._tempTileBlock[r].newIndex == true) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
+ }
+ }
+ };
+ TilemapLayer.prototype.fillTile = function (index, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ 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] = index;
+ }
+ };
+ TilemapLayer.prototype.randomiseTiles = function (tiles, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ 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);
+ }
+ };
+ TilemapLayer.prototype.replaceTile = function (tileA, tileB, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ if (typeof height === "undefined") { height = this.heightInTiles; }
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ if(this._tempTileBlock[r].tile.index == tileA) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
+ }
+ }
+ };
+ TilemapLayer.prototype.getTileBlock = function (x, y, width, height) {
+ var output = [];
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ output.push({
+ x: this._tempTileBlock[r].x,
+ y: this._tempTileBlock[r].y,
+ tile: this._tempTileBlock[r].tile
+ });
+ }
+ return output;
+ };
+ TilemapLayer.prototype.getTileFromWorldXY = function (x, y) {
+ 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 = function (object) {
+ if(object.body.bounds.x < 0 || object.body.bounds.x > this.widthInPixels || object.body.bounds.y < 0 || object.body.bounds.bottom > this.heightInPixels) {
+ return;
+ }
+ 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._tempBlockResults = [];
+ this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
+ return this._tempBlockResults;
+ };
+ TilemapLayer.prototype.getTempBlock = function (x, y, width, height, collisionOnly) {
+ if (typeof collisionOnly === "undefined") { collisionOnly = false; }
+ if(x < 0) {
+ x = 0;
+ }
+ if(y < 0) {
+ y = 0;
+ }
+ if(width > this.widthInTiles) {
+ width = this.widthInTiles;
+ }
+ if(height > this.heightInTiles) {
+ height = this.heightInTiles;
+ }
+ this._tempTileBlock = [];
+ for(var ty = y; ty < y + height; ty++) {
+ for(var tx = x; tx < x + width; tx++) {
+ if(collisionOnly) {
+ 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]]
+ });
+ }
+ } else {
+ if(this.mapData[ty] && this.mapData[ty][tx]) {
+ this._tempTileBlock.push({
+ x: tx,
+ y: ty,
+ tile: this.parent.tiles[this.mapData[ty][tx]]
+ });
+ }
+ }
+ }
+ }
+ };
+ TilemapLayer.prototype.getTileIndex = function (x, y) {
+ if(y >= 0 && y < this.mapData.length) {
+ if(x >= 0 && x < this.mapData[y].length) {
+ return this.mapData[y][x];
+ }
+ }
+ return null;
+ };
+ TilemapLayer.prototype.addColumn = function (column) {
+ var data = [];
+ for(var c = 0; c < column.length; c++) {
+ data[c] = parseInt(column[c]);
+ }
+ if(this.widthInTiles == 0) {
+ this.widthInTiles = data.length;
+ this.widthInPixels = this.widthInTiles * this.tileWidth;
+ }
+ this.mapData.push(data);
+ this.heightInTiles++;
+ this.heightInPixels += this.tileHeight;
+ };
+ TilemapLayer.prototype.updateBounds = function () {
+ this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
+ };
+ TilemapLayer.prototype.parseTileOffsets = function () {
+ this.tileOffsets = [];
+ var i = 0;
+ if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) {
+ 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] = {
+ x: tx,
+ y: ty
+ };
+ i++;
+ }
+ }
+ return this.tileOffsets.length;
+ };
+ return TilemapLayer;
+ })();
+ Phaser.TilemapLayer = TilemapLayer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var PhysicsManager = (function () {
+ function PhysicsManager(game) {
+ this._length = 0;
+ this.grav = 0.2;
+ this.drag = 1;
+ this.bounce = 0.3;
+ this.friction = 0.05;
+ this.min_f = 0;
+ this.max_f = 1;
+ this.min_b = 0;
+ this.max_b = 1;
+ this.min_g = 0;
+ this.max_g = 1;
+ this.xmin = 0;
+ this.xmax = 800;
+ this.ymin = 0;
+ this.ymax = 600;
+ this.objrad = 24;
+ this.tilerad = 24 * 2;
+ this.objspeed = 0.2;
+ this.maxspeed = 20;
+ this.game = game;
+ }
+ PhysicsManager.prototype.update = function () {
+ };
+ PhysicsManager.prototype.updateMotion = function (body) {
+ this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
+ body.angularVelocity += this._velocityDelta;
+ body.sprite.transform.rotation += body.angularVelocity * this.game.time.physicsElapsed;
+ body.angularVelocity += this._velocityDelta;
+ this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
+ body.velocity.x += this._velocityDelta;
+ this._delta = body.velocity.x * this.game.time.physicsElapsed;
+ body.aabb.pos.x += this._delta;
+ body.deltaX = this._delta;
+ this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
+ body.velocity.y += this._velocityDelta;
+ this._delta = body.velocity.y * this.game.time.physicsElapsed;
+ body.aabb.pos.y += this._delta;
+ body.deltaY = this._delta;
+ };
+ PhysicsManager.prototype.computeVelocity = function (velocity, gravity, acceleration, drag, max) {
+ if (typeof gravity === "undefined") { gravity = 0; }
+ if (typeof acceleration === "undefined") { acceleration = 0; }
+ if (typeof drag === "undefined") { drag = 0; }
+ if (typeof max === "undefined") { max = 10000; }
+ if(acceleration !== 0) {
+ velocity += (acceleration + gravity) * this.game.time.physicsElapsed;
+ } else if(drag !== 0) {
+ this._drag = drag * this.game.time.physicsElapsed;
+ if(velocity - this._drag > 0) {
+ velocity = velocity - this._drag;
+ } else if(velocity + this._drag < 0) {
+ velocity += this._drag;
+ } else {
+ velocity = 0;
+ }
+ }
+ if(velocity != 0) {
+ if(velocity > max) {
+ velocity = max;
+ } else if(velocity < -max) {
+ velocity = -max;
+ }
+ }
+ return velocity;
+ };
+ return PhysicsManager;
+ })();
+ Physics.PhysicsManager = PhysicsManager;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var Body = (function () {
+ function Body(sprite, type) {
+ this.angularVelocity = 0;
+ this.angularAcceleration = 0;
+ this.angularDrag = 0;
+ this.maxAngular = 10000;
+ this.deltaX = 0;
+ this.deltaY = 0;
+ this.sprite = sprite;
+ this.game = sprite.game;
+ this.type = type;
+ this.aabb = new Phaser.Physics.AABB(sprite.game, sprite.x, sprite.y, sprite.width, sprite.height);
+ this.velocity = new Phaser.Vec2();
+ this.acceleration = new Phaser.Vec2();
+ this.drag = new Phaser.Vec2();
+ this.gravity = new Phaser.Vec2();
+ this.maxVelocity = new Phaser.Vec2(10000, 10000);
+ this.angularVelocity = 0;
+ this.angularAcceleration = 0;
+ this.angularDrag = 0;
+ this.maxAngular = 10000;
+ this.allowCollisions = Phaser.Types.ANY;
+ }
+ return Body;
+ })();
+ Physics.Body = Body;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var AABB = (function () {
+ function AABB(game, x, y, width, height) {
+ this.type = 0;
+ this._vx = 0;
+ this._vy = 0;
+ this._deltaX = 0;
+ this._deltaY = 0;
+ this.game = game;
+ this.pos = new Phaser.Vec2(x, y);
+ this.oldpos = new Phaser.Vec2(x, y);
+ this.width = Math.abs(width);
+ this.height = Math.abs(height);
+ this.velocity = new Phaser.Vec2();
+ this.acceleration = new Phaser.Vec2();
+ this.bounce = new Phaser.Vec2(0, 0);
+ this.drag = new Phaser.Vec2(0, 0);
+ this.gravity = new Phaser.Vec2(0, 0);
+ this.maxVelocity = new Phaser.Vec2(1000, 1000);
+ this.aabbTileProjections = {
+ };
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.AABB22Deg.CollideS;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.AABB22Deg.CollideB;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.AABB45Deg.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.AABB67Deg.CollideS;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.AABB67Deg.CollideB;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.AABBConcave.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.AABBConvex.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.AABBFull.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.AABBHalf.Collide;
+ }
+ AABB.COL_NONE = 0;
+ AABB.COL_AXIS = 1;
+ AABB.COL_OTHER = 2;
+ AABB.prototype.update = function () {
+ this.integrateVerlet();
+ if(this.acceleration.x != 0) {
+ this.velocity.x += (this.acceleration.x * this.game.time.physicsElapsed);
+ }
+ if(this.acceleration.y != 0) {
+ this.velocity.y += (this.acceleration.y * this.game.time.physicsElapsed);
+ }
+ this._vx = this.velocity.x * this.game.time.physicsElapsed;
+ this._vy = this.velocity.y * this.game.time.physicsElapsed;
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+ this._deltaX = Math.min(20, Math.max(-20, vx + this._vx));
+ this._deltaY = Math.min(20, Math.max(-20, vy + this._vy));
+ this.pos.x = this.oldpos.x + this._deltaX;
+ this.pos.y = this.oldpos.y + this._deltaY;
+ };
+ AABB.prototype.Nupdate = function () {
+ this.integrateVerlet();
+ var p = this.pos;
+ var o = this.oldpos;
+ var vx = p.x - o.x;
+ var vy = p.y - o.y;
+ var newx = Math.min(20, Math.max(-20, vx + this._vx));
+ var newy = Math.min(20, Math.max(-20, vy + this._vy));
+ this.pos.x = o.x + newx;
+ this.pos.y = o.y + newy;
+ };
+ AABB.prototype.updateFlixel = function () {
+ this.oldpos.x = this.pos.x;
+ this.oldpos.y = this.pos.y;
+ this._vx = (this.game.physics.computeVelocity(this.velocity.x, this.gravity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
+ this.velocity.x += this._vx;
+ this._deltaX = this.velocity.x * this.game.time.physicsElapsed;
+ this._vy = (this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
+ this.velocity.y += this._vy;
+ this._deltaY = this.velocity.y * this.game.time.physicsElapsed;
+ this.pos.x += this._deltaX;
+ this.pos.y += this._deltaY;
+ };
+ AABB.prototype.FFupdate = function () {
+ this.oldpos.x = this.pos.x;
+ this.oldpos.y = this.pos.y;
+ if(this.acceleration.x != 0) {
+ this.velocity.x += (this.acceleration.x / 1000 * this.game.time.delta);
+ }
+ if(this.acceleration.y != 0) {
+ this.velocity.y += (this.acceleration.y / 1000 * this.game.time.delta);
+ }
+ this._vx = ((this.velocity.x / 1000) * this.game.time.delta);
+ this._vy = ((this.velocity.y / 1000) * this.game.time.delta);
+ if(this._vx != 0) {
+ if(this.drag.x != 0) {
+ this._vx * this.drag.x;
+ }
+ if(this.gravity.x != 0) {
+ this._vx * this.gravity.x;
+ }
+ if(this.velocity.x > this.maxVelocity.x) {
+ this.velocity.x = this.maxVelocity.x;
+ } else if(this.velocity.x < -this.maxVelocity.x) {
+ this.velocity.x = -this.maxVelocity.x;
+ }
+ }
+ if(this._vy != 0) {
+ if(this.drag.y != 0) {
+ this._vy * this.drag.y;
+ }
+ if(this.gravity.y != 0) {
+ this._vy * this.gravity.y;
+ }
+ if(this.velocity.y > this.maxVelocity.y) {
+ this.velocity.y = this.maxVelocity.y;
+ } else if(this.velocity.y < -this.maxVelocity.y) {
+ this.velocity.y = -this.maxVelocity.y;
+ }
+ }
+ this.pos.x += this._vx;
+ this.pos.y += this._vy;
+ };
+ AABB.prototype.integrateVerlet = function () {
+ var ox = this.oldpos.x;
+ var oy = this.oldpos.y;
+ this.oldpos.x = this.pos.x;
+ this.oldpos.y = this.pos.y;
+ this.pos.x += (this.drag.x * this.pos.x) - (this.drag.x * ox) + this.gravity.x;
+ this.pos.y += (this.drag.y * this.pos.y) - (this.drag.y * oy) + this.gravity.y;
+ };
+ AABB.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = vx - nx;
+ var ty = vy - ny;
+ var bx = 0;
+ var by = 0;
+ var fx = 0;
+ var fy = 0;
+ if(dp < 0) {
+ var f = 0.05;
+ fx = tx * f;
+ fy = ty * f;
+ var b = 1 + 0.5;
+ bx = (nx * b);
+ by = (ny * b);
+ }
+ this.pos.x += px;
+ this.pos.y += py;
+ this.oldpos.x += px + bx + fx;
+ this.oldpos.y += py + by + fy;
+ };
+ AABB.prototype.TWEAKEDreportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ var dp = (this._vx * dx + this._vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = this._vx - nx;
+ var ty = this._vy - ny;
+ this.pos.x += px;
+ this.pos.y += py;
+ if(dp < 0) {
+ this.velocity.x += nx;
+ this.velocity.y += ny;
+ if(dx !== 0) {
+ this.velocity.x *= -1 * this.bounce.x;
+ }
+ if(dy !== 0) {
+ this.velocity.y *= -1 * this.bounce.y;
+ }
+ }
+ };
+ AABB.prototype.collideAABBVsTile = function (tile) {
+ var pos = this.pos;
+ var c = tile;
+ var tx = c.pos.x;
+ var ty = c.pos.y;
+ var txw = c.xw;
+ var tyw = c.yw;
+ var dx = pos.x - tx;
+ var px = (txw + this.width) - Math.abs(dx);
+ if(0 < px) {
+ var dy = pos.y - ty;
+ var py = (tyw + this.height) - Math.abs(dy);
+ if(0 < py) {
+ if(px < py) {
+ if(dx < 0) {
+ px *= -1;
+ py = 0;
+ } else {
+ py = 0;
+ }
+ } else {
+ if(dy < 0) {
+ px = 0;
+ py *= -1;
+ } else {
+ px = 0;
+ }
+ }
+ this.resolveBoxTile(px, py, this, c);
+ }
+ }
+ };
+ AABB.prototype.collideAABBVsWorldBounds = function () {
+ var p = this.pos;
+ var xw = this.width;
+ var yw = this.height;
+ var XMIN = 0;
+ var XMAX = 800;
+ var YMIN = 0;
+ var YMAX = 600;
+ var dx = XMIN - (p.x - xw);
+ if(0 < dx) {
+ this.reportCollisionVsWorld(dx, 0, 1, 0, null);
+ } else {
+ dx = (p.x + xw) - XMAX;
+ if(0 < dx) {
+ this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ var dy = YMIN - (p.y - yw);
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, dy, 0, 1, null);
+ } else {
+ dy = (p.y + yw) - YMAX;
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ AABB.prototype.resolveBoxTile = function (x, y, box, t) {
+ if(0 < t.ID) {
+ return this.aabbTileProjections[t.CTYPE](x, y, box, t);
+ } else {
+ return false;
+ }
+ };
+ AABB.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.strokeRect(this.pos.x - this.width, this.pos.y - this.height, this.width * 2, this.height * 2);
+ context.stroke();
+ context.closePath();
+ context.fillStyle = 'rgb(0,255,0)';
+ context.fillRect(this.pos.x, this.pos.y, 2, 2);
+ };
+ return AABB;
+ })();
+ Physics.AABB = AABB;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var Circle = (function () {
+ function Circle(game, x, y, radius) {
+ this.type = 1;
+ this.game = game;
+ this.pos = new Phaser.Vec2(x, y);
+ this.oldpos = new Phaser.Vec2(x, y);
+ this.radius = radius;
+ this.circleTileProjections = {
+ };
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.Circle22Deg.CollideS;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.Circle22Deg.CollideB;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.Circle45Deg.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.Circle67Deg.CollideS;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.Circle67Deg.CollideB;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.CircleConcave.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.CircleConvex.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.CircleFull.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.CircleHalf.Collide;
+ }
+ Circle.COL_NONE = 0;
+ Circle.COL_AXIS = 1;
+ Circle.COL_OTHER = 2;
+ Circle.prototype.integrateVerlet = function () {
+ var d = 1;
+ var g = 0.2;
+ var p = this.pos;
+ var o = this.oldpos;
+ var px;
+ var py;
+ var ox = o.x;
+ var oy = o.y;
+ o.x = px = p.x;
+ o.y = py = p.y;
+ p.x += (d * px) - (d * ox);
+ p.y += (d * py) - (d * oy) + g;
+ };
+ Circle.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ var p = this.pos;
+ var o = this.oldpos;
+ var vx = p.x - o.x;
+ var vy = p.y - o.y;
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = vx - nx;
+ var ty = vy - ny;
+ var b, bx, by, f, fx, fy;
+ if(dp < 0) {
+ f = 0.05;
+ fx = tx * f;
+ fy = ty * f;
+ b = 1 + 0.3;
+ bx = (nx * b);
+ by = (ny * b);
+ } else {
+ bx = by = fx = fy = 0;
+ }
+ p.x += px;
+ p.y += py;
+ o.x += px + bx + fx;
+ o.y += py + by + fy;
+ };
+ Circle.prototype.collideCircleVsWorldBounds = function () {
+ var p = this.pos;
+ var r = this.radius;
+ var XMIN = 0;
+ var XMAX = 800;
+ var YMIN = 0;
+ var YMAX = 600;
+ var dx = XMIN - (p.x - r);
+ if(0 < dx) {
+ this.reportCollisionVsWorld(dx, 0, 1, 0, null);
+ } else {
+ dx = (p.x + r) - XMAX;
+ if(0 < dx) {
+ this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ var dy = YMIN - (p.y - r);
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, dy, 0, 1, null);
+ } else {
+ dy = (p.y + r) - YMAX;
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ Circle.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2);
+ context.stroke();
+ context.closePath();
+ if(this.oH == 1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x - this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ } else if(this.oH == -1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x + this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ }
+ if(this.oV == 1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y - this.radius);
+ context.stroke();
+ context.closePath();
+ } else if(this.oV == -1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y + this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ }
+ };
+ Circle.prototype.collideCircleVsTile = function (tile) {
+ var pos = this.pos;
+ var r = this.radius;
+ var c = tile;
+ var tx = c.pos.x;
+ var ty = c.pos.y;
+ var txw = c.xw;
+ var tyw = c.yw;
+ var dx = pos.x - tx;
+ var px = (txw + r) - Math.abs(dx);
+ if(0 < px) {
+ var dy = pos.y - ty;
+ var py = (tyw + r) - Math.abs(dy);
+ if(0 < py) {
+ this.oH = 0;
+ this.oV = 0;
+ if(dx < -txw) {
+ this.oH = -1;
+ } else if(txw < dx) {
+ this.oH = 1;
+ }
+ if(dy < -tyw) {
+ this.oV = -1;
+ } else if(tyw < dy) {
+ this.oV = 1;
+ }
+ this.resolveCircleTile(px, py, this.oH, this.oV, this, c);
+ }
+ }
+ };
+ Circle.prototype.resolveCircleTile = function (x, y, oH, oV, obj, t) {
+ if(0 < t.ID) {
+ return this.circleTileProjections[t.CTYPE](x, y, oH, oV, obj, t);
+ } else {
+ console.log("resolveCircleTile() was called with an empty (or unknown) tile!: ID=" + t.ID + " (" + t.i + "," + t.j + ")");
+ return false;
+ }
+ };
+ return Circle;
+ })();
+ Physics.Circle = Circle;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var TileMapCell = (function () {
+ function TileMapCell(game, x, y, xw, yw) {
+ this.game = game;
+ this.ID = TileMapCell.TID_EMPTY;
+ this.CTYPE = TileMapCell.CTYPE_EMPTY;
+ this.pos = new Phaser.Vec2(x, y);
+ this.xw = xw;
+ this.yw = yw;
+ this.minx = this.pos.x - this.xw;
+ this.maxx = this.pos.x + this.xw;
+ this.miny = this.pos.y - this.yw;
+ this.maxy = this.pos.y + this.yw;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ }
+ TileMapCell.TID_EMPTY = 0;
+ TileMapCell.TID_FULL = 1;
+ TileMapCell.TID_45DEGpn = 2;
+ TileMapCell.TID_45DEGnn = 3;
+ TileMapCell.TID_45DEGnp = 4;
+ TileMapCell.TID_45DEGpp = 5;
+ TileMapCell.TID_CONCAVEpn = 6;
+ TileMapCell.TID_CONCAVEnn = 7;
+ TileMapCell.TID_CONCAVEnp = 8;
+ TileMapCell.TID_CONCAVEpp = 9;
+ TileMapCell.TID_CONVEXpn = 10;
+ TileMapCell.TID_CONVEXnn = 11;
+ TileMapCell.TID_CONVEXnp = 12;
+ TileMapCell.TID_CONVEXpp = 13;
+ TileMapCell.TID_22DEGpnS = 14;
+ TileMapCell.TID_22DEGnnS = 15;
+ TileMapCell.TID_22DEGnpS = 16;
+ TileMapCell.TID_22DEGppS = 17;
+ TileMapCell.TID_22DEGpnB = 18;
+ TileMapCell.TID_22DEGnnB = 19;
+ TileMapCell.TID_22DEGnpB = 20;
+ TileMapCell.TID_22DEGppB = 21;
+ TileMapCell.TID_67DEGpnS = 22;
+ TileMapCell.TID_67DEGnnS = 23;
+ TileMapCell.TID_67DEGnpS = 24;
+ TileMapCell.TID_67DEGppS = 25;
+ TileMapCell.TID_67DEGpnB = 26;
+ TileMapCell.TID_67DEGnnB = 27;
+ TileMapCell.TID_67DEGnpB = 28;
+ TileMapCell.TID_67DEGppB = 29;
+ TileMapCell.TID_HALFd = 30;
+ TileMapCell.TID_HALFr = 31;
+ TileMapCell.TID_HALFu = 32;
+ TileMapCell.TID_HALFl = 33;
+ TileMapCell.CTYPE_EMPTY = 0;
+ TileMapCell.CTYPE_FULL = 1;
+ TileMapCell.CTYPE_45DEG = 2;
+ TileMapCell.CTYPE_CONCAVE = 6;
+ TileMapCell.CTYPE_CONVEX = 10;
+ TileMapCell.CTYPE_22DEGs = 14;
+ TileMapCell.CTYPE_22DEGb = 18;
+ TileMapCell.CTYPE_67DEGs = 22;
+ TileMapCell.CTYPE_67DEGb = 26;
+ TileMapCell.CTYPE_HALF = 30;
+ TileMapCell.prototype.SetState = function (ID) {
+ if(ID == TileMapCell.TID_EMPTY) {
+ this.Clear();
+ } else {
+ this.ID = ID;
+ this.UpdateType();
+ }
+ return this;
+ };
+ TileMapCell.prototype.Clear = function () {
+ this.ID = TileMapCell.TID_EMPTY;
+ this.UpdateType();
+ };
+ TileMapCell.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,255,0)';
+ context.strokeRect(this.minx, this.miny, this.xw * 2, this.yw * 2);
+ context.strokeRect(this.pos.x, this.pos.y, 2, 2);
+ context.closePath();
+ };
+ TileMapCell.prototype.UpdateType = function () {
+ if(0 < this.ID) {
+ if(this.ID < TileMapCell.CTYPE_45DEG) {
+ this.CTYPE = TileMapCell.CTYPE_FULL;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID < TileMapCell.CTYPE_CONCAVE) {
+ this.CTYPE = TileMapCell.CTYPE_45DEG;
+ if(this.ID == TileMapCell.TID_45DEGpn) {
+ console.log('set tile as 45deg pn');
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else if(this.ID == TileMapCell.TID_45DEGnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else if(this.ID == TileMapCell.TID_45DEGnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else if(this.ID == TileMapCell.TID_45DEGpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_CONVEX) {
+ this.CTYPE = TileMapCell.CTYPE_CONCAVE;
+ if(this.ID == TileMapCell.TID_CONCAVEpn) {
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_22DEGs) {
+ this.CTYPE = TileMapCell.CTYPE_CONVEX;
+ if(this.ID == TileMapCell.TID_CONVEXpn) {
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_22DEGb) {
+ this.CTYPE = TileMapCell.CTYPE_22DEGs;
+ if(this.ID == TileMapCell.TID_22DEGpnS) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnnS) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnpS) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGppS) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_67DEGs) {
+ this.CTYPE = TileMapCell.CTYPE_22DEGb;
+ if(this.ID == TileMapCell.TID_22DEGpnB) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnnB) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnpB) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGppB) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_67DEGb) {
+ this.CTYPE = TileMapCell.CTYPE_67DEGs;
+ if(this.ID == TileMapCell.TID_67DEGpnS) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnnS) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnpS) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGppS) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_HALF) {
+ this.CTYPE = TileMapCell.CTYPE_67DEGb;
+ if(this.ID == TileMapCell.TID_67DEGpnB) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnnB) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnpB) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGppB) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else {
+ return false;
+ }
+ } else {
+ this.CTYPE = TileMapCell.CTYPE_HALF;
+ if(this.ID == TileMapCell.TID_HALFd) {
+ this.signx = 0;
+ this.signy = -1;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFu) {
+ this.signx = 0;
+ this.signy = 1;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFl) {
+ this.signx = 1;
+ this.signy = 0;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFr) {
+ this.signx = -1;
+ this.signy = 0;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else {
+ return false;
+ }
+ }
+ } else {
+ this.CTYPE = TileMapCell.CTYPE_EMPTY;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ }
+ };
+ return TileMapCell;
+ })();
+ Physics.TileMapCell = TileMapCell;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABB22Deg = (function () {
+ function AABB22Deg() { }
+ AABB22Deg.CollideS = function CollideS(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var py = obj.pos.y - (signy * obj.height);
+ var penY = t.pos.y - py;
+ if(0 < (penY * signy)) {
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ var aY = Math.abs(penY);
+ if(lenP < lenN) {
+ if(aY < lenP) {
+ obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ }
+ } else {
+ if(aY < lenN) {
+ obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ AABB22Deg.CollideB = function CollideB(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB22Deg;
+ })();
+ Projection.AABB22Deg = AABB22Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABB45Deg = (function () {
+ function AABB45Deg() { }
+ AABB45Deg.Collide = function Collide(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - t.pos.x;
+ var oy = (obj.pos.y - (signy * obj.height)) - t.pos.y;
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB45Deg;
+ })();
+ Projection.AABB45Deg = AABB45Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABB67Deg = (function () {
+ function AABB67Deg() { }
+ AABB67Deg.CollideS = function CollideS(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var px = obj.pos.x - (signx * obj.width);
+ var penX = t.pos.x - px;
+ if(0 < (penX * signx)) {
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ var aX = Math.abs(penX);
+ if(lenP < lenN) {
+ if(aX < lenP) {
+ obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ }
+ } else {
+ if(aX < lenN) {
+ obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ AABB67Deg.CollideB = function CollideB(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB67Deg;
+ })();
+ Projection.AABB67Deg = AABB67Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBConcave = (function () {
+ function AABBConcave() { }
+ AABBConcave.Collide = function Collide(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (t.pos.x + (signx * t.xw)) - (obj.pos.x - (signx * obj.width));
+ var oy = (t.pos.y + (signy * t.yw)) - (obj.pos.y - (signy * obj.height));
+ var twid = t.xw * 2;
+ var rad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = len - rad;
+ if(0 < pen) {
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBConcave;
+ })();
+ Projection.AABBConcave = AABBConcave;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBConvex = (function () {
+ function AABBConvex() { }
+ AABBConvex.Collide = function Collide(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var twid = t.xw * 2;
+ var rad = Math.sqrt(twid * twid + 0);
+ var pen = rad - len;
+ if(((signx * ox) < 0) || ((signy * oy) < 0)) {
+ var lenP = Math.sqrt(x * x + y * y);
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBConvex;
+ })();
+ Projection.AABBConvex = AABBConvex;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBFull = (function () {
+ function AABBFull() { }
+ AABBFull.Collide = function Collide(x, y, obj, t) {
+ var l = Math.sqrt(x * x + y * y);
+ obj.reportCollisionVsWorld(x, y, x / l, y / l, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ };
+ return AABBFull;
+ })();
+ Projection.AABBFull = AABBFull;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBHalf = (function () {
+ function AABBHalf() { }
+ AABBHalf.Collide = function Collide(x, y, obj, t) {
+ var sx = t.signx;
+ var sy = t.signy;
+ var ox = (obj.pos.x - (sx * obj.width)) - t.pos.x;
+ var oy = (obj.pos.y - (sy * obj.height)) - t.pos.y;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBHalf;
+ })();
+ Projection.AABBHalf = AABBHalf;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var Circle22Deg = (function () {
+ function Circle22Deg() { }
+ Circle22Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ if(0 < (signy * oV)) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ var sx = t.sx;
+ var sy = t.sy;
+ var r = obj.radius;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - t.pos.y;
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = r - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ ox -= r * sx;
+ oy -= r * sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP;
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ var vx = t.pos.x - (signx * t.xw);
+ var vy = t.pos.y;
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ if((dy * signy) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x + (oH * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ Circle22Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(oH == 0) {
+ if(oV == 0) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP;
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y + (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - (t.pos.x + (signx * t.xw));
+ var oy = obj.pos.y - t.pos.y;
+ if((oy * signy) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ sx = (signx * 1) / slen;
+ sy = (signy * 2) / slen;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle22Deg;
+ })();
+ Projection.Circle22Deg = Circle22Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var Circle45Deg = (function () {
+ function Circle45Deg() { }
+ Circle45Deg.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = (obj.pos.x - (sx * obj.radius)) - t.pos.x;
+ var oy = (obj.pos.y - (sy * obj.radius)) - t.pos.y;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y + (oV * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x + (oH * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle45Deg;
+ })();
+ Projection.Circle45Deg = Circle45Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var Circle67Deg = (function () {
+ function Circle67Deg() { }
+ Circle67Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(0 < (signx * oH)) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = obj.pos.x - t.pos.x;
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = r - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ ox -= r * sx;
+ oy -= r * sy;
+ var dp = (ox * sx) + (oy * sy);
+ var lenP;
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ var vx = t.pos.x;
+ var vy = t.pos.y - (signy * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ if((dx * signx) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y + (oV * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ Circle67Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(oH == 0) {
+ if(oV == 0) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ var lenP;
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - t.pos.x;
+ var oy = obj.pos.y - (t.pos.y + (signy * t.yw));
+ if((ox * signx) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ var sx = (signx * 2) / slen;
+ var sy = (signy * 1) / slen;
+ var ox = obj.pos.x - (t.pos.x + (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle67Deg;
+ })();
+ Projection.Circle67Deg = Circle67Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleConcave = (function () {
+ function CircleConcave() { }
+ CircleConcave.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ var ox = (t.pos.x + (signx * t.xw)) - obj.pos.x;
+ var oy = (t.pos.y + (signy * t.yw)) - obj.pos.y;
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (len + obj.radius) - trad;
+ if(0 < pen) {
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ return Phaser.Physics.Circle.COL_NONE;
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x - (signx * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = 0;
+ dy = oV;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y - (signy * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH;
+ dy = 0;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleConcave;
+ })();
+ Projection.CircleConcave = CircleConcave;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleConvex = (function () {
+ function CircleConvex() { }
+ CircleConvex.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleConvex;
+ })();
+ Projection.CircleConvex = CircleConvex;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleFull = (function () {
+ function CircleFull() { }
+ CircleFull.Collide = function Collide(x, y, oH, oV, obj, t) {
+ if(oH == 0) {
+ if(oV == 0) {
+ if(x < y) {
+ var dx = obj.pos.x - t.pos.x;
+ if(dx < 0) {
+ obj.reportCollisionVsWorld(-x, 0, -1, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(x, 0, 1, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else {
+ var dy = obj.pos.y - t.pos.y;
+ if(dy < 0) {
+ obj.reportCollisionVsWorld(0, -y, 0, -1, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(0, y, 0, 1, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else if(oV == 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleFull;
+ })();
+ Projection.CircleFull = CircleFull;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleHalf = (function () {
+ function CircleHalf() { }
+ CircleHalf.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var celldp = (oH * signx + oV * signy);
+ if(0 < celldp) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ var r = obj.radius;
+ var ox = (obj.pos.x - (signx * r)) - t.pos.x;
+ var oy = (obj.pos.y - (signy * r)) - t.pos.y;
+ var sx = signx;
+ var sy = signy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if(celldp == 0) {
+ var r = obj.radius;
+ var dx = obj.pos.x - t.pos.x;
+ if((dx * signx) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var dy = obj.pos.y - (t.pos.y + oV * t.yw);
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = signx / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ }
+ } else if(oV == 0) {
+ if(celldp == 0) {
+ var r = obj.radius;
+ var dy = obj.pos.y - t.pos.y;
+ if((dy * signy) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var dx = obj.pos.x - (t.pos.x + oH * t.xw);
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = signx / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleHalf;
+ })();
+ Projection.CircleHalf = CircleHalf;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var Events = (function () {
+ function Events(parent) {
+ this.game = parent.game;
+ this._parent = parent;
+ this.onAddedToGroup = new Phaser.Signal();
+ this.onRemovedFromGroup = new Phaser.Signal();
+ this.onKilled = new Phaser.Signal();
+ this.onRevived = new Phaser.Signal();
+ this.onOutOfBounds = new Phaser.Signal();
+ }
+ return Events;
+ })();
+ Components.Events = Events;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Sprite = (function () {
+ function Sprite(game, x, y, key, frame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof frame === "undefined") { frame = null; }
+ this.modified = false;
+ this.x = 0;
+ this.y = 0;
+ this.z = -1;
+ this.renderOrderID = 0;
+ this.game = game;
+ this.type = Phaser.Types.SPRITE;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.x = x;
+ this.y = y;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.events = new Phaser.Components.Events(this);
+ this.animations = new Phaser.Components.AnimationManager(this);
+ this.input = new Phaser.Components.InputHandler(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ if(key !== null) {
+ this.texture.loadImage(key, false);
+ } else {
+ this.texture.opaque = true;
+ }
+ if(frame !== null) {
+ if(typeof frame == 'string') {
+ this.frameName = frame;
+ } else {
+ this.frame = frame;
+ }
+ }
+ this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
+ this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
+ this.transform.setCache();
+ this.body = new Phaser.Physics.Body(this, 0);
+ this.outOfBounds = false;
+ this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
+ this.scale = this.transform.scale;
+ this.alpha = this.texture.alpha;
+ this.origin = this.transform.origin;
+ this.crop = this.texture.crop;
+ }
+ Object.defineProperty(Sprite.prototype, "rotation", {
+ get: function () {
+ return this.transform.rotation;
+ },
+ set: function (value) {
+ this.transform.rotation = this.game.math.wrap(value, 360, 0);
+ if(this.body) {
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sprite.prototype.bringToTop = function () {
+ if(this.group) {
+ this.group.bringToTop(this);
+ }
+ };
+ Object.defineProperty(Sprite.prototype, "alpha", {
+ get: function () {
+ return this.texture.alpha;
+ },
+ set: function (value) {
+ this.texture.alpha = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "frame", {
+ get: function () {
+ return this.animations.frame;
+ },
+ set: function (value) {
+ this.animations.frame = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "frameName", {
+ get: function () {
+ return this.animations.frameName;
+ },
+ set: function (value) {
+ this.animations.frameName = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "width", {
+ get: function () {
+ return this.texture.width * this.transform.scale.x;
+ },
+ set: function (value) {
+ this.transform.scale.x = value / this.texture.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "height", {
+ get: function () {
+ return this.texture.height * this.transform.scale.y;
+ },
+ set: function (value) {
+ this.transform.scale.y = value / this.texture.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sprite.prototype.preUpdate = function () {
+ this.transform.update();
+ if(this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0) {
+ this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
+ } else {
+ this.worldView.x = this.x - (this.width * this.transform.origin.x);
+ }
+ if(this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0) {
+ this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
+ } else {
+ this.worldView.y = this.y - (this.height * this.transform.origin.y);
+ }
+ this.worldView.width = this.width;
+ this.worldView.height = this.height;
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ };
+ Sprite.prototype.update = function () {
+ };
+ Sprite.prototype.postUpdate = function () {
+ this.animations.update();
+ this.checkBounds();
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ };
+ Sprite.prototype.checkBounds = function () {
+ if(Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds)) {
+ this.outOfBounds = false;
+ } else {
+ if(this.outOfBounds == false) {
+ this.events.onOutOfBounds.dispatch(this);
+ }
+ this.outOfBounds = true;
+ if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL) {
+ this.kill();
+ } else if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY) {
+ this.destroy();
+ }
+ }
+ };
+ Sprite.prototype.destroy = function () {
+ this.input.destroy();
+ };
+ Sprite.prototype.kill = function (removeFromGroup) {
+ if (typeof removeFromGroup === "undefined") { removeFromGroup = false; }
+ this.alive = false;
+ this.exists = false;
+ if(removeFromGroup && this.group) {
+ }
+ this.events.onKilled.dispatch(this);
+ };
+ Sprite.prototype.revive = function () {
+ this.alive = true;
+ this.exists = true;
+ this.events.onRevived.dispatch(this);
+ };
+ return Sprite;
+ })();
+ Phaser.Sprite = Sprite;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var TransformManager = (function () {
+ function TransformManager(parent) {
+ this._dirty = false;
+ this.rotationOffset = 0;
+ this.rotation = 0;
+ this.game = parent.game;
+ this.parent = parent;
+ this.local = new Phaser.Mat3();
+ this.scrollFactor = new Phaser.Vec2(1, 1);
+ this.origin = new Phaser.Vec2();
+ this.scale = new Phaser.Vec2(1, 1);
+ this.skew = new Phaser.Vec2();
+ this.center = new Phaser.Point();
+ this.upperLeft = new Phaser.Point();
+ this.upperRight = new Phaser.Point();
+ this.bottomLeft = new Phaser.Point();
+ this.bottomRight = new Phaser.Point();
+ this._pos = new Phaser.Point();
+ this._scale = new Phaser.Point();
+ this._size = new Phaser.Point();
+ this._halfSize = new Phaser.Point();
+ this._offset = new Phaser.Point();
+ this._origin = new Phaser.Point();
+ this._sc = new Phaser.Point();
+ this._scA = new Phaser.Point();
+ }
+ Object.defineProperty(TransformManager.prototype, "distance", {
+ get: function () {
+ return this._distance;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "angleToCenter", {
+ get: function () {
+ return this._angle;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "offsetX", {
+ get: function () {
+ return this._offset.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "offsetY", {
+ get: function () {
+ return this._offset.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "halfWidth", {
+ get: function () {
+ return this._halfSize.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "halfHeight", {
+ get: function () {
+ return this._halfSize.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "sin", {
+ get: function () {
+ return this._sc.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "cos", {
+ get: function () {
+ return this._sc.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TransformManager.prototype.centerOn = function (x, y) {
+ this.parent.x = x + (this.parent.x - this.center.x);
+ this.parent.y = y + (this.parent.y - this.center.y);
+ };
+ TransformManager.prototype.setCache = function () {
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this._halfSize.x = this.parent.width / 2;
+ this._halfSize.y = this.parent.height / 2;
+ this._offset.x = this.origin.x * this.parent.width;
+ this._offset.y = this.origin.y * this.parent.height;
+ this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
+ this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
+ this._size.x = this.parent.width;
+ this._size.y = this.parent.height;
+ this._origin.x = this.origin.x;
+ this._origin.y = this.origin.y;
+ this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._prevRotation = this.rotation;
+ if(this.parent.texture && this.parent.texture.renderRotation) {
+ this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ } else {
+ this._sc.x = 0;
+ this._sc.y = 1;
+ }
+ this.center.x = this.parent.x + this._distance * this._scA.y;
+ this.center.y = this.parent.y + this._distance * this._scA.x;
+ this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this._flippedX = this.parent.texture.flippedX;
+ this._flippedY = this.parent.texture.flippedY;
+ };
+ TransformManager.prototype.update = function () {
+ this._dirty = false;
+ if(this.parent.width !== this._size.x || this.parent.height !== this._size.y || this.origin.x !== this._origin.x || this.origin.y !== this._origin.y) {
+ this._halfSize.x = this.parent.width / 2;
+ this._halfSize.y = this.parent.height / 2;
+ this._offset.x = this.origin.x * this.parent.width;
+ this._offset.y = this.origin.y * this.parent.height;
+ this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
+ this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
+ this._size.x = this.parent.width;
+ this._size.y = this.parent.height;
+ this._origin.x = this.origin.x;
+ this._origin.y = this.origin.y;
+ this._dirty = true;
+ }
+ if(this.rotation != this._prevRotation || this._dirty) {
+ this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ if(this.parent.texture.renderRotation) {
+ this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ } else {
+ this._sc.x = 0;
+ this._sc.y = 1;
+ }
+ this._prevRotation = this.rotation;
+ this._dirty = true;
+ }
+ if(this._dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y) {
+ this.center.x = this.parent.x + this._distance * this._scA.y;
+ this.center.y = this.parent.y + this._distance * this._scA.x;
+ this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this.local.data[2] = this.parent.x;
+ this.local.data[5] = this.parent.y;
+ }
+ if(this._dirty || this._flippedX != this.parent.texture.flippedX) {
+ this._flippedX = this.parent.texture.flippedX;
+ if(this._flippedX) {
+ this.local.data[0] = this._sc.y * -this.scale.x;
+ this.local.data[3] = (this._sc.x * -this.scale.x) + this.skew.x;
+ } else {
+ this.local.data[0] = this._sc.y * this.scale.x;
+ this.local.data[3] = (this._sc.x * this.scale.x) + this.skew.x;
+ }
+ }
+ if(this._dirty || this._flippedY != this.parent.texture.flippedY) {
+ this._flippedY = this.parent.texture.flippedY;
+ if(this._flippedY) {
+ this.local.data[4] = this._sc.y * -this.scale.y;
+ this.local.data[1] = -(this._sc.x * -this.scale.y) + this.skew.y;
+ } else {
+ this.local.data[4] = this._sc.y * this.scale.y;
+ this.local.data[1] = -(this._sc.x * this.scale.y) + this.skew.y;
+ }
+ }
+ };
+ return TransformManager;
+ })();
+ Components.TransformManager = TransformManager;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var ScrollRegion = (function () {
+ function ScrollRegion(x, y, width, height, speedX, speedY) {
+ this._anchorWidth = 0;
+ this._anchorHeight = 0;
+ this._inverseWidth = 0;
+ this._inverseHeight = 0;
+ this.visible = true;
+ this._A = new Phaser.Rectangle(x, y, width, height);
+ this._B = new Phaser.Rectangle(x, y, width, height);
+ this._C = new Phaser.Rectangle(x, y, width, height);
+ this._D = new Phaser.Rectangle(x, y, width, height);
+ this._scroll = new Phaser.Vec2();
+ this._bounds = new Phaser.Rectangle(x, y, width, height);
+ this.scrollSpeed = new Phaser.Vec2(speedX, speedY);
+ }
+ ScrollRegion.prototype.update = function (delta) {
+ this._scroll.x += this.scrollSpeed.x;
+ this._scroll.y += this.scrollSpeed.y;
+ if(this._scroll.x > this._bounds.right) {
+ this._scroll.x = this._bounds.x;
+ }
+ if(this._scroll.x < this._bounds.x) {
+ this._scroll.x = this._bounds.right;
+ }
+ if(this._scroll.y > this._bounds.bottom) {
+ this._scroll.y = this._bounds.y;
+ }
+ if(this._scroll.y < this._bounds.y) {
+ this._scroll.y = this._bounds.bottom;
+ }
+ this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
+ this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
+ if(this._anchorWidth > this._bounds.width) {
+ this._anchorWidth = this._bounds.width;
+ }
+ if(this._anchorHeight > this._bounds.height) {
+ this._anchorHeight = this._bounds.height;
+ }
+ this._inverseWidth = this._bounds.width - this._anchorWidth;
+ this._inverseHeight = this._bounds.height - this._anchorHeight;
+ this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
+ this._B.y = this._scroll.y;
+ this._B.width = this._inverseWidth;
+ this._B.height = this._anchorHeight;
+ this._C.x = this._scroll.x;
+ this._C.width = this._anchorWidth;
+ this._C.height = this._inverseHeight;
+ this._D.width = this._inverseWidth;
+ this._D.height = this._inverseHeight;
+ };
+ ScrollRegion.prototype.render = function (context, texture, dx, dy, dw, dh) {
+ if(this.visible == false) {
+ return;
+ }
+ this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
+ this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
+ this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
+ this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
+ };
+ ScrollRegion.prototype.crop = function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
+ offsetX += destX;
+ offsetY += destY;
+ if(srcW > (destX + destW) - offsetX) {
+ srcW = (destX + destW) - offsetX;
+ }
+ if(srcH > (destY + destH) - offsetY) {
+ srcH = (destY + destH) - offsetY;
+ }
+ srcX = Math.floor(srcX);
+ srcY = Math.floor(srcY);
+ srcW = Math.floor(srcW);
+ srcH = Math.floor(srcH);
+ offsetX = Math.floor(offsetX + this._bounds.x);
+ offsetY = Math.floor(offsetY + this._bounds.y);
+ if(srcW > 0 && srcH > 0) {
+ context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
+ }
+ };
+ return ScrollRegion;
+ })();
+ Phaser.ScrollRegion = ScrollRegion;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var ScrollZone = (function (_super) {
+ __extends(ScrollZone, _super);
+ function ScrollZone(game, key, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ _super.call(this, game, x, y, key);
+ this.type = Phaser.Types.SCROLLZONE;
+ this.regions = [];
+ if(this.texture.loaded) {
+ if(width > this.width || height > this.height) {
+ this.createRepeatingTexture(width, height);
+ this.width = width;
+ this.height = height;
+ }
+ this.addRegion(0, 0, this.width, this.height);
+ if((width < this.width || height < this.height) && width !== 0 && height !== 0) {
+ this.width = width;
+ this.height = height;
+ }
+ }
+ }
+ ScrollZone.prototype.addRegion = function (x, y, width, height, speedX, speedY) {
+ if (typeof speedX === "undefined") { speedX = 0; }
+ if (typeof speedY === "undefined") { speedY = 0; }
+ if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
+ throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
+ return null;
+ }
+ this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
+ this.regions.push(this.currentRegion);
+ return this.currentRegion;
+ };
+ ScrollZone.prototype.setSpeed = function (x, y) {
+ if(this.currentRegion) {
+ this.currentRegion.scrollSpeed.setTo(x, y);
+ }
+ return this;
+ };
+ ScrollZone.prototype.update = function () {
+ for(var i = 0; i < this.regions.length; i++) {
+ this.regions[i].update(this.game.time.delta);
+ }
+ };
+ ScrollZone.prototype.createRepeatingTexture = function (regionWidth, regionHeight) {
+ var tileWidth = Math.ceil(this.width / regionWidth) * regionWidth;
+ var tileHeight = Math.ceil(this.height / regionHeight) * regionHeight;
+ var dt = new Phaser.Display.DynamicTexture(this.game, tileWidth, tileHeight);
+ dt.context.rect(0, 0, tileWidth, tileHeight);
+ dt.context.fillStyle = dt.context.createPattern(this.texture.imageTexture, "repeat");
+ dt.context.fill();
+ this.texture.loadDynamicTexture(dt);
+ };
+ return ScrollZone;
+ })(Phaser.Sprite);
+ Phaser.ScrollZone = ScrollZone;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var GameObjectFactory = (function () {
+ function GameObjectFactory(game) {
+ this.game = game;
+ this._world = this.game.world;
+ }
+ GameObjectFactory.prototype.camera = function (x, y, width, height) {
+ return this._world.cameras.addCamera(x, y, width, height);
+ };
+ GameObjectFactory.prototype.button = function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof callbackContext === "undefined") { callbackContext = null; }
+ if (typeof overFrame === "undefined") { overFrame = null; }
+ if (typeof outFrame === "undefined") { outFrame = null; }
+ if (typeof downFrame === "undefined") { downFrame = null; }
+ return this._world.group.add(new Phaser.UI.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
+ };
+ GameObjectFactory.prototype.sprite = function (x, y, key, frame) {
+ if (typeof key === "undefined") { key = ''; }
+ if (typeof frame === "undefined") { frame = null; }
+ return this._world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
+ };
+ GameObjectFactory.prototype.audio = function (key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ return this.game.sound.add(key, volume, loop);
+ };
+ GameObjectFactory.prototype.circle = function (x, y, radius) {
+ return new Phaser.Physics.Circle(this.game, x, y, radius);
+ };
+ GameObjectFactory.prototype.aabb = function (x, y, width, height) {
+ return new Phaser.Physics.AABB(this.game, x, y, Math.floor(width / 2), Math.floor(height / 2));
+ };
+ GameObjectFactory.prototype.cell = function (x, y, width, height, state) {
+ if (typeof state === "undefined") { state = Phaser.Physics.TileMapCell.TID_FULL; }
+ return new Phaser.Physics.TileMapCell(this.game, x, y, width, height).SetState(state);
+ };
+ GameObjectFactory.prototype.dynamicTexture = function (width, height) {
+ return new Phaser.Display.DynamicTexture(this.game, width, height);
+ };
+ GameObjectFactory.prototype.group = function (maxSize) {
+ if (typeof maxSize === "undefined") { maxSize = 0; }
+ return this._world.group.add(new Phaser.Group(this.game, maxSize));
+ };
+ GameObjectFactory.prototype.scrollZone = function (key, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ return this._world.group.add(new Phaser.ScrollZone(this.game, key, x, y, width, height));
+ };
+ GameObjectFactory.prototype.tilemap = function (key, mapData, format, resizeWorld, tileWidth, tileHeight) {
+ if (typeof resizeWorld === "undefined") { resizeWorld = true; }
+ if (typeof tileWidth === "undefined") { tileWidth = 0; }
+ if (typeof tileHeight === "undefined") { tileHeight = 0; }
+ return this._world.group.add(new Phaser.Tilemap(this.game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
+ };
+ GameObjectFactory.prototype.tween = function (obj, localReference) {
+ if (typeof localReference === "undefined") { localReference = false; }
+ return this.game.tweens.create(obj, localReference);
+ };
+ GameObjectFactory.prototype.existingSprite = function (sprite) {
+ return this._world.group.add(sprite);
+ };
+ GameObjectFactory.prototype.existingGroup = function (group) {
+ return this._world.group.add(group);
+ };
+ GameObjectFactory.prototype.existingButton = function (button) {
+ return this._world.group.add(button);
+ };
+ GameObjectFactory.prototype.existingScrollZone = function (scrollZone) {
+ return this._world.group.add(scrollZone);
+ };
+ GameObjectFactory.prototype.existingTilemap = function (tilemap) {
+ return this._world.group.add(tilemap);
+ };
+ GameObjectFactory.prototype.existingTween = function (tween) {
+ return this.game.tweens.add(tween);
+ };
+ return GameObjectFactory;
+ })();
+ Phaser.GameObjectFactory = GameObjectFactory;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (UI) {
+ var Button = (function (_super) {
+ __extends(Button, _super);
+ function Button(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof callbackContext === "undefined") { callbackContext = null; }
+ if (typeof overFrame === "undefined") { overFrame = null; }
+ if (typeof outFrame === "undefined") { outFrame = null; }
+ if (typeof downFrame === "undefined") { downFrame = null; }
+ _super.call(this, game, x, y, key, outFrame);
+ this._onOverFrameName = null;
+ this._onOutFrameName = null;
+ this._onDownFrameName = null;
+ this._onUpFrameName = null;
+ this._onOverFrameID = null;
+ this._onOutFrameID = null;
+ this._onDownFrameID = null;
+ this._onUpFrameID = null;
+ this.type = Phaser.Types.BUTTON;
+ if(typeof overFrame == 'string') {
+ this._onOverFrameName = overFrame;
+ } else {
+ this._onOverFrameID = overFrame;
+ }
+ if(typeof outFrame == 'string') {
+ this._onOutFrameName = outFrame;
+ this._onUpFrameName = outFrame;
+ } else {
+ this._onOutFrameID = outFrame;
+ this._onUpFrameID = outFrame;
+ }
+ if(typeof downFrame == 'string') {
+ this._onDownFrameName = downFrame;
+ } else {
+ this._onDownFrameID = downFrame;
+ }
+ this.onInputOver = new Phaser.Signal();
+ this.onInputOut = new Phaser.Signal();
+ this.onInputDown = new Phaser.Signal();
+ this.onInputUp = new Phaser.Signal();
+ if(callback) {
+ this.onInputUp.add(callback, callbackContext);
+ }
+ this.input.start(0, false, true);
+ this.events.onInputOver.add(this.onInputOverHandler, this);
+ this.events.onInputOut.add(this.onInputOutHandler, this);
+ this.events.onInputDown.add(this.onInputDownHandler, this);
+ this.events.onInputUp.add(this.onInputUpHandler, this);
+ }
+ Button.prototype.onInputOverHandler = function (pointer) {
+ if(this._onOverFrameName != null) {
+ this.frameName = this._onOverFrameName;
+ } else if(this._onOverFrameID != null) {
+ this.frame = this._onOverFrameID;
+ }
+ if(this.onInputOver) {
+ this.onInputOver.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputOutHandler = function (pointer) {
+ if(this._onOutFrameName != null) {
+ this.frameName = this._onOutFrameName;
+ } else if(this._onOutFrameID != null) {
+ this.frame = this._onOutFrameID;
+ }
+ if(this.onInputOut) {
+ this.onInputOut.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputDownHandler = function (pointer) {
+ if(this._onDownFrameName != null) {
+ this.frameName = this._onDownFrameName;
+ } else if(this._onDownFrameID != null) {
+ this.frame = this._onDownFrameID;
+ }
+ if(this.onInputDown) {
+ this.onInputDown.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputUpHandler = function (pointer) {
+ if(this._onUpFrameName != null) {
+ this.frameName = this._onUpFrameName;
+ } else if(this._onUpFrameID != null) {
+ this.frame = this._onUpFrameID;
+ }
+ if(this.onInputUp) {
+ this.onInputUp.dispatch(this, pointer);
+ }
+ };
+ Object.defineProperty(Button.prototype, "priorityID", {
+ get: function () {
+ return this.input.priorityID;
+ },
+ set: function (value) {
+ this.input.priorityID = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Button.prototype, "useHandCursor", {
+ get: function () {
+ return this.input.useHandCursor;
+ },
+ set: function (value) {
+ this.input.useHandCursor = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Button;
+ })(Phaser.Sprite);
+ UI.Button = Button;
+ })(Phaser.UI || (Phaser.UI = {}));
+ var UI = Phaser.UI;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var CanvasUtils = (function () {
+ function CanvasUtils() { }
+ CanvasUtils.getAspectRatio = function getAspectRatio(canvas) {
+ return canvas.width / canvas.height;
+ };
+ CanvasUtils.setBackgroundColor = function setBackgroundColor(canvas, color) {
+ if (typeof color === "undefined") { color = 'rgb(0,0,0)'; }
+ canvas.style.backgroundColor = color;
+ return canvas;
+ };
+ CanvasUtils.setTouchAction = function setTouchAction(canvas, value) {
+ if (typeof value === "undefined") { value = 'none'; }
+ canvas.style.msTouchAction = value;
+ canvas.style['ms-touch-action'] = value;
+ canvas.style['touch-action'] = value;
+ return canvas;
+ };
+ CanvasUtils.addToDOM = function addToDOM(canvas, parent, overflowHidden) {
+ if (typeof parent === "undefined") { parent = ''; }
+ if (typeof overflowHidden === "undefined") { overflowHidden = true; }
+ if((parent !== '' || parent !== null) && document.getElementById(parent)) {
+ document.getElementById(parent).appendChild(canvas);
+ if(overflowHidden) {
+ document.getElementById(parent).style.overflow = 'hidden';
+ }
+ } else {
+ document.body.appendChild(canvas);
+ }
+ return canvas;
+ };
+ CanvasUtils.setTransform = function setTransform(context, translateX, translateY, scaleX, scaleY, skewX, skewY) {
+ context.setTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
+ return context;
+ };
+ CanvasUtils.setSmoothingEnabled = function setSmoothingEnabled(context, value) {
+ context['imageSmoothingEnabled'] = value;
+ context['mozImageSmoothingEnabled'] = value;
+ context['oImageSmoothingEnabled'] = value;
+ context['webkitImageSmoothingEnabled'] = value;
+ context['msImageSmoothingEnabled'] = value;
+ return context;
+ };
+ CanvasUtils.setImageRenderingCrisp = function setImageRenderingCrisp(canvas) {
+ canvas.style['image-rendering'] = 'crisp-edges';
+ canvas.style['image-rendering'] = '-moz-crisp-edges';
+ canvas.style['image-rendering'] = '-webkit-optimize-contrast';
+ canvas.style.msInterpolationMode = 'nearest-neighbor';
+ return canvas;
+ };
+ CanvasUtils.setImageRenderingBicubic = function setImageRenderingBicubic(canvas) {
+ canvas.style['image-rendering'] = 'auto';
+ canvas.style.msInterpolationMode = 'bicubic';
+ return canvas;
+ };
+ return CanvasUtils;
+ })();
+ Phaser.CanvasUtils = CanvasUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var CircleUtils = (function () {
+ function CircleUtils() { }
+ CircleUtils.clone = function clone(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Circle(); }
+ return out.setTo(a.x, a.y, a.diameter);
+ };
+ CircleUtils.contains = function contains(a, x, y) {
+ if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
+ var dx = (a.x - x) * (a.x - x);
+ var dy = (a.y - y) * (a.y - y);
+ return (dx + dy) <= (a.radius * a.radius);
+ }
+ return false;
+ };
+ CircleUtils.containsPoint = function containsPoint(a, point) {
+ return CircleUtils.contains(a, point.x, point.y);
+ };
+ CircleUtils.containsCircle = function containsCircle(a, b) {
+ return true;
+ };
+ CircleUtils.distanceBetween = function distanceBetween(a, target, round) {
+ if (typeof round === "undefined") { round = false; }
+ var dx = a.x - target.x;
+ var dy = a.y - target.y;
+ if(round === true) {
+ return Math.round(Math.sqrt(dx * dx + dy * dy));
+ } else {
+ return Math.sqrt(dx * dx + dy * dy);
+ }
+ };
+ CircleUtils.equals = function equals(a, b) {
+ return (a.x == b.x && a.y == b.y && a.diameter == b.diameter);
+ };
+ CircleUtils.intersects = function intersects(a, b) {
+ return (Phaser.CircleUtils.distanceBetween(a, b) <= (a.radius + b.radius));
+ };
+ CircleUtils.circumferencePoint = function circumferencePoint(a, angle, asDegrees, out) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ if(asDegrees === true) {
+ angle = angle * Phaser.GameMath.DEG_TO_RAD;
+ }
+ return out.setTo(a.x + a.radius * Math.cos(angle), a.y + a.radius * Math.sin(angle));
+ };
+ CircleUtils.intersectsRectangle = function intersectsRectangle(c, r) {
+ var cx = Math.abs(c.x - r.x - r.halfWidth);
+ var xDist = r.halfWidth + c.radius;
+ if(cx > xDist) {
+ return false;
+ }
+ var cy = Math.abs(c.y - r.y - r.halfHeight);
+ var yDist = r.halfHeight + c.radius;
+ if(cy > yDist) {
+ return false;
+ }
+ if(cx <= r.halfWidth || cy <= r.halfHeight) {
+ return true;
+ }
+ var xCornerDist = cx - r.halfWidth;
+ var yCornerDist = cy - r.halfHeight;
+ var xCornerDistSq = xCornerDist * xCornerDist;
+ var yCornerDistSq = yCornerDist * yCornerDist;
+ var maxCornerDistSq = c.radius * c.radius;
+ return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
+ };
+ return CircleUtils;
+ })();
+ Phaser.CircleUtils = CircleUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var ColorUtils = (function () {
+ function ColorUtils() { }
+ ColorUtils.getColor32 = function getColor32(alpha, red, green, blue) {
+ return alpha << 24 | red << 16 | green << 8 | blue;
+ };
+ ColorUtils.getColor = function getColor(red, green, blue) {
+ return red << 16 | green << 8 | blue;
+ };
+ ColorUtils.getHSVColorWheel = function getHSVColorWheel(alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var colors = [];
+ for(var c = 0; c <= 359; c++) {
+ colors[c] = Phaser.ColorUtils.getWebRGB(Phaser.ColorUtils.HSVtoRGB(c, 1.0, 1.0, alpha));
+ }
+ return colors;
+ };
+ ColorUtils.hexToRGB = function hexToRGB(h) {
+ var hex16 = (h.charAt(0) == "#") ? h.substring(1, 7) : h;
+ var r = parseInt(hex16.substring(0, 2), 16);
+ var g = parseInt(hex16.substring(2, 4), 16);
+ var b = parseInt(hex16.substring(4, 6), 16);
+ return {
+ r: r,
+ g: g,
+ b: b
+ };
+ };
+ ColorUtils.getComplementHarmony = function getComplementHarmony(color) {
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
+ return Phaser.ColorUtils.HSVtoRGB(opposite, 1.0, 1.0);
+ };
+ ColorUtils.getAnalogousHarmony = function getAnalogousHarmony(color, threshold) {
+ if (typeof threshold === "undefined") { threshold = 30; }
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ if(threshold > 359 || threshold < 0) {
+ throw Error("Color Warning: Invalid threshold given to getAnalogousHarmony()");
+ }
+ var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 359 - threshold, 359);
+ var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, threshold, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(warmer, 1.0, 1.0),
+ color3: Phaser.ColorUtils.HSVtoRGB(colder, 1.0, 1.0),
+ hue1: hsv.hue,
+ hue2: warmer,
+ hue3: colder
+ };
+ };
+ ColorUtils.getSplitComplementHarmony = function getSplitComplementHarmony(color, threshold) {
+ if (typeof threshold === "undefined") { threshold = 30; }
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ if(threshold >= 359 || threshold <= 0) {
+ throw Error("Phaser.ColorUtils Warning: Invalid threshold given to getSplitComplementHarmony()");
+ }
+ var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
+ var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite - threshold, 359);
+ var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite + threshold, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(warmer, hsv.saturation, hsv.value),
+ color3: Phaser.ColorUtils.HSVtoRGB(colder, hsv.saturation, hsv.value),
+ hue1: hsv.hue,
+ hue2: warmer,
+ hue3: colder
+ };
+ };
+ ColorUtils.getTriadicHarmony = function getTriadicHarmony(color) {
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ var triadic1 = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 120, 359);
+ var triadic2 = Phaser.ColorUtils.game.math.wrapValue(triadic1, 120, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(triadic1, 1.0, 1.0),
+ color3: Phaser.ColorUtils.HSVtoRGB(triadic2, 1.0, 1.0)
+ };
+ };
+ ColorUtils.getColorInfo = function getColorInfo(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ var hsl = Phaser.ColorUtils.RGBtoHSV(color);
+ var result = Phaser.ColorUtils.RGBtoHexstring(color) + "\n";
+ result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n";
+ result = result.concat("Hue: " + hsl.hue + " Saturation: " + hsl.saturation + " Lightnes: " + hsl.lightness);
+ return result;
+ };
+ ColorUtils.RGBtoHexstring = function RGBtoHexstring(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ return "0x" + Phaser.ColorUtils.colorToHexstring(argb.alpha) + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
+ };
+ ColorUtils.RGBtoWebstring = function RGBtoWebstring(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ return "#" + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
+ };
+ ColorUtils.colorToHexstring = function colorToHexstring(color) {
+ var digits = "0123456789ABCDEF";
+ var lsd = color % 16;
+ var msd = (color - lsd) / 16;
+ var hexified = digits.charAt(msd) + digits.charAt(lsd);
+ return hexified;
+ };
+ ColorUtils.HSVtoRGB = function HSVtoRGB(h, s, v, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var result;
+ if(s == 0.0) {
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, v * 255, v * 255);
+ } else {
+ h = h / 60.0;
+ var f = h - Math.floor(h);
+ var p = v * (1.0 - s);
+ var q = v * (1.0 - s * f);
+ var t = v * (1.0 - s * (1.0 - f));
+ switch(Math.floor(h)) {
+ case 0:
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, t * 255, p * 255);
+ break;
+ case 1:
+ result = Phaser.ColorUtils.getColor32(alpha, q * 255, v * 255, p * 255);
+ break;
+ case 2:
+ result = Phaser.ColorUtils.getColor32(alpha, p * 255, v * 255, t * 255);
+ break;
+ case 3:
+ result = Phaser.ColorUtils.getColor32(alpha, p * 255, q * 255, v * 255);
+ break;
+ case 4:
+ result = Phaser.ColorUtils.getColor32(alpha, t * 255, p * 255, v * 255);
+ break;
+ case 5:
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, p * 255, q * 255);
+ break;
+ default:
+ throw new Error("Phaser.ColorUtils.HSVtoRGB : Unknown color");
+ }
+ }
+ return result;
+ };
+ ColorUtils.RGBtoHSV = function RGBtoHSV(color) {
+ var rgb = Phaser.ColorUtils.getRGB(color);
+ var red = rgb.red / 255;
+ var green = rgb.green / 255;
+ var blue = rgb.blue / 255;
+ var min = Math.min(red, green, blue);
+ var max = Math.max(red, green, blue);
+ var delta = max - min;
+ var lightness = (max + min) / 2;
+ var hue;
+ var saturation;
+ if(delta == 0) {
+ hue = 0;
+ saturation = 0;
+ } else {
+ if(lightness < 0.5) {
+ saturation = delta / (max + min);
+ } else {
+ saturation = delta / (2 - max - min);
+ }
+ var delta_r = (((max - red) / 6) + (delta / 2)) / delta;
+ var delta_g = (((max - green) / 6) + (delta / 2)) / delta;
+ var delta_b = (((max - blue) / 6) + (delta / 2)) / delta;
+ if(red == max) {
+ hue = delta_b - delta_g;
+ } else if(green == max) {
+ hue = (1 / 3) + delta_r - delta_b;
+ } else if(blue == max) {
+ hue = (2 / 3) + delta_g - delta_r;
+ }
+ if(hue < 0) {
+ hue += 1;
+ }
+ if(hue > 1) {
+ hue -= 1;
+ }
+ }
+ hue *= 360;
+ hue = Math.round(hue);
+ return {
+ hue: hue,
+ saturation: saturation,
+ lightness: lightness,
+ value: lightness
+ };
+ };
+ ColorUtils.interpolateColor = function interpolateColor(color1, color2, steps, currentStep, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var src1 = Phaser.ColorUtils.getRGB(color1);
+ var src2 = Phaser.ColorUtils.getRGB(color2);
+ var r = (((src2.red - src1.red) * currentStep) / steps) + src1.red;
+ var g = (((src2.green - src1.green) * currentStep) / steps) + src1.green;
+ var b = (((src2.blue - src1.blue) * currentStep) / steps) + src1.blue;
+ return Phaser.ColorUtils.getColor32(alpha, r, g, b);
+ };
+ ColorUtils.interpolateColorWithRGB = function interpolateColorWithRGB(color, r, g, b, steps, currentStep) {
+ var src = Phaser.ColorUtils.getRGB(color);
+ var or = (((r - src.red) * currentStep) / steps) + src.red;
+ var og = (((g - src.green) * currentStep) / steps) + src.green;
+ var ob = (((b - src.blue) * currentStep) / steps) + src.blue;
+ return Phaser.ColorUtils.getColor(or, og, ob);
+ };
+ ColorUtils.interpolateRGB = function interpolateRGB(r1, g1, b1, r2, g2, b2, steps, currentStep) {
+ var r = (((r2 - r1) * currentStep) / steps) + r1;
+ var g = (((g2 - g1) * currentStep) / steps) + g1;
+ var b = (((b2 - b1) * currentStep) / steps) + b1;
+ return Phaser.ColorUtils.getColor(r, g, b);
+ };
+ ColorUtils.getRandomColor = function getRandomColor(min, max, alpha) {
+ if (typeof min === "undefined") { min = 0; }
+ if (typeof max === "undefined") { max = 255; }
+ if (typeof alpha === "undefined") { alpha = 255; }
+ if(max > 255) {
+ return Phaser.ColorUtils.getColor(255, 255, 255);
+ }
+ if(min > max) {
+ return Phaser.ColorUtils.getColor(255, 255, 255);
+ }
+ var red = min + Math.round(Math.random() * (max - min));
+ var green = min + Math.round(Math.random() * (max - min));
+ var blue = min + Math.round(Math.random() * (max - min));
+ return Phaser.ColorUtils.getColor32(alpha, red, green, blue);
+ };
+ ColorUtils.getRGB = function getRGB(color) {
+ return {
+ alpha: color >>> 24,
+ red: color >> 16 & 0xFF,
+ green: color >> 8 & 0xFF,
+ blue: color & 0xFF
+ };
+ };
+ ColorUtils.getWebRGB = function getWebRGB(color) {
+ var alpha = (color >>> 24) / 255;
+ var red = color >> 16 & 0xFF;
+ var green = color >> 8 & 0xFF;
+ var blue = color & 0xFF;
+ return 'rgba(' + red.toString() + ',' + green.toString() + ',' + blue.toString() + ',' + alpha.toString() + ')';
+ };
+ ColorUtils.getAlpha = function getAlpha(color) {
+ return color >>> 24;
+ };
+ ColorUtils.getAlphaFloat = function getAlphaFloat(color) {
+ return (color >>> 24) / 255;
+ };
+ ColorUtils.getRed = function getRed(color) {
+ return color >> 16 & 0xFF;
+ };
+ ColorUtils.getGreen = function getGreen(color) {
+ return color >> 8 & 0xFF;
+ };
+ ColorUtils.getBlue = function getBlue(color) {
+ return color & 0xFF;
+ };
+ return ColorUtils;
+ })();
+ Phaser.ColorUtils = ColorUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var PointUtils = (function () {
+ function PointUtils() { }
+ PointUtils.add = function add(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x + b.x, a.y + b.y);
+ };
+ PointUtils.subtract = function subtract(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x - b.x, a.y - b.y);
+ };
+ PointUtils.multiply = function multiply(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x * b.x, a.y * b.y);
+ };
+ PointUtils.divide = function divide(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x / b.x, a.y / b.y);
+ };
+ PointUtils.clamp = function clamp(a, min, max) {
+ Phaser.PointUtils.clampX(a, min, max);
+ Phaser.PointUtils.clampY(a, min, max);
+ return a;
+ };
+ PointUtils.clampX = function clampX(a, min, max) {
+ a.x = Math.max(Math.min(a.x, max), min);
+ return a;
+ };
+ PointUtils.clampY = function clampY(a, min, max) {
+ a.y = Math.max(Math.min(a.y, max), min);
+ return a;
+ };
+ PointUtils.clone = function clone(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Point(); }
+ return output.setTo(a.x, a.y);
+ };
+ PointUtils.distanceBetween = function distanceBetween(a, b, round) {
+ if (typeof round === "undefined") { round = false; }
+ var dx = a.x - b.x;
+ var dy = a.y - b.y;
+ if(round === true) {
+ return Math.round(Math.sqrt(dx * dx + dy * dy));
+ } else {
+ return Math.sqrt(dx * dx + dy * dy);
+ }
+ };
+ PointUtils.equals = function equals(a, b) {
+ return (a.x == b.x && a.y == b.y);
+ };
+ PointUtils.rotate = function rotate(a, x, y, angle, asDegrees, distance) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof distance === "undefined") { distance = null; }
+ if(asDegrees) {
+ angle = angle * Phaser.GameMath.DEG_TO_RAD;
+ }
+ if(distance === null) {
+ distance = Math.sqrt(((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y)));
+ }
+ return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
+ };
+ PointUtils.rotateAroundPoint = function rotateAroundPoint(a, b, angle, asDegrees, distance) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof distance === "undefined") { distance = null; }
+ return Phaser.PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
+ };
+ return PointUtils;
+ })();
+ Phaser.PointUtils = PointUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var RectangleUtils = (function () {
+ function RectangleUtils() { }
+ RectangleUtils.getTopLeftAsPoint = function getTopLeftAsPoint(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x, a.y);
+ };
+ RectangleUtils.getBottomRightAsPoint = function getBottomRightAsPoint(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.right, a.bottom);
+ };
+ RectangleUtils.inflate = function inflate(a, dx, dy) {
+ a.x -= dx;
+ a.width += 2 * dx;
+ a.y -= dy;
+ a.height += 2 * dy;
+ return a;
+ };
+ RectangleUtils.inflatePoint = function inflatePoint(a, point) {
+ return Phaser.RectangleUtils.inflate(a, point.x, point.y);
+ };
+ RectangleUtils.size = function size(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Point(); }
+ return output.setTo(a.width, a.height);
+ };
+ RectangleUtils.clone = function clone(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Rectangle(); }
+ return output.setTo(a.x, a.y, a.width, a.height);
+ };
+ RectangleUtils.contains = function contains(a, x, y) {
+ return (x >= a.x && x <= a.right && y >= a.y && y <= a.bottom);
+ };
+ RectangleUtils.containsPoint = function containsPoint(a, point) {
+ return Phaser.RectangleUtils.contains(a, point.x, point.y);
+ };
+ RectangleUtils.containsRect = function containsRect(a, b) {
+ if(a.volume > b.volume) {
+ return false;
+ }
+ return (a.x >= b.x && a.y >= b.y && a.right <= b.right && a.bottom <= b.bottom);
+ };
+ RectangleUtils.equals = function equals(a, b) {
+ return (a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height);
+ };
+ RectangleUtils.intersection = function intersection(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
+ if(Phaser.RectangleUtils.intersects(a, b)) {
+ out.x = Math.max(a.x, b.x);
+ out.y = Math.max(a.y, b.y);
+ out.width = Math.min(a.right, b.right) - out.x;
+ out.height = Math.min(a.bottom, b.bottom) - out.y;
+ }
+ return out;
+ };
+ RectangleUtils.intersects = function intersects(a, b, tolerance) {
+ if (typeof tolerance === "undefined") { tolerance = 0; }
+ return !(a.left > b.right + tolerance || a.right < b.left - tolerance || a.top > b.bottom + tolerance || a.bottom < b.top - tolerance);
+ };
+ RectangleUtils.intersectsRaw = function intersectsRaw(a, left, right, top, bottom, tolerance) {
+ if (typeof tolerance === "undefined") { tolerance = 0; }
+ return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
+ };
+ RectangleUtils.union = function union(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
+ return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
+ };
+ return RectangleUtils;
+ })();
+ Phaser.RectangleUtils = RectangleUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var SpriteUtils = (function () {
+ function SpriteUtils() { }
+ SpriteUtils.updateCameraView = function updateCameraView(camera, sprite) {
+ if(sprite.rotation == 0 || sprite.texture.renderRotation == false) {
+ sprite.cameraView.x = Math.floor(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.width * sprite.transform.origin.x));
+ sprite.cameraView.y = Math.floor(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.height * sprite.transform.origin.y));
+ sprite.cameraView.width = sprite.width;
+ sprite.cameraView.height = sprite.height;
+ } else {
+ if(sprite.transform.origin.x == 0.5 && sprite.transform.origin.y == 0.5) {
+ Phaser.SpriteUtils._sin = sprite.transform.sin;
+ Phaser.SpriteUtils._cos = sprite.transform.cos;
+ if(Phaser.SpriteUtils._sin < 0) {
+ Phaser.SpriteUtils._sin = -Phaser.SpriteUtils._sin;
+ }
+ if(Phaser.SpriteUtils._cos < 0) {
+ Phaser.SpriteUtils._cos = -Phaser.SpriteUtils._cos;
+ }
+ sprite.cameraView.width = Math.round(sprite.height * Phaser.SpriteUtils._sin + sprite.width * Phaser.SpriteUtils._cos);
+ sprite.cameraView.height = Math.round(sprite.height * Phaser.SpriteUtils._cos + sprite.width * Phaser.SpriteUtils._sin);
+ sprite.cameraView.x = Math.round(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.cameraView.width * sprite.transform.origin.x));
+ sprite.cameraView.y = Math.round(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.cameraView.height * sprite.transform.origin.y));
+ } else {
+ sprite.cameraView.x = Math.min(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x);
+ sprite.cameraView.y = Math.min(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y);
+ sprite.cameraView.width = Math.max(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x) - sprite.cameraView.x;
+ sprite.cameraView.height = Math.max(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y) - sprite.cameraView.y;
+ }
+ }
+ return sprite.cameraView;
+ };
+ SpriteUtils.getAsPoints = function getAsPoints(sprite) {
+ var out = [];
+ out.push(new Phaser.Point(sprite.x, sprite.y));
+ out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y));
+ out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y + sprite.height));
+ out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
+ return out;
+ };
+ SpriteUtils.overlapsPointer = function overlapsPointer(sprite, pointer) {
+ if(sprite.transform.scrollFactor.equals(1)) {
+ return Phaser.SpriteUtils.overlapsXY(sprite, pointer.worldX, pointer.worldY);
+ } else if(sprite.transform.scrollFactor.equals(0)) {
+ return Phaser.SpriteUtils.overlapsXY(sprite, pointer.x, pointer.y);
+ } else {
+ var px = pointer.worldX * sprite.transform.scrollFactor.x;
+ var py = pointer.worldY * sprite.transform.scrollFactor.y;
+ return Phaser.SpriteUtils.overlapsXY(sprite, px, py);
+ }
+ };
+ SpriteUtils.overlapsXY = function overlapsXY(sprite, x, y) {
+ if((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0) {
+ return false;
+ }
+ if((x - sprite.transform.upperRight.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperRight.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) > 0) {
+ return false;
+ }
+ if((x - sprite.transform.upperLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) < 0) {
+ return false;
+ }
+ if((x - sprite.transform.bottomLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.bottomLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) > 0) {
+ return false;
+ }
+ return true;
+ };
+ SpriteUtils.overlapsPoint = function overlapsPoint(sprite, point) {
+ return Phaser.SpriteUtils.overlapsXY(sprite, point.x, point.y);
+ };
+ SpriteUtils.onScreen = function onScreen(sprite, camera) {
+ if (typeof camera === "undefined") { camera = null; }
+ if(camera == null) {
+ camera = sprite.game.camera;
+ }
+ Phaser.SpriteUtils.getScreenXY(sprite, SpriteUtils._tempPoint, camera);
+ return (Phaser.SpriteUtils._tempPoint.x + sprite.width > 0) && (Phaser.SpriteUtils._tempPoint.x < camera.width) && (Phaser.SpriteUtils._tempPoint.y + sprite.height > 0) && (Phaser.SpriteUtils._tempPoint.y < camera.height);
+ };
+ SpriteUtils.getScreenXY = function getScreenXY(sprite, point, camera) {
+ if (typeof point === "undefined") { point = null; }
+ if (typeof camera === "undefined") { camera = null; }
+ if(point == null) {
+ point = new Phaser.Point();
+ }
+ if(camera == null) {
+ camera = sprite.game.camera;
+ }
+ point.x = sprite.x - camera.x * sprite.transform.scrollFactor.x;
+ point.y = sprite.y - camera.y * sprite.transform.scrollFactor.y;
+ point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
+ point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
+ return point;
+ };
+ SpriteUtils.reset = function reset(sprite, x, y) {
+ sprite.revive();
+ sprite.x = x;
+ sprite.y = y;
+ return sprite;
+ };
+ SpriteUtils.setBounds = function setBounds(x, y, width, height) {
+ };
+ return SpriteUtils;
+ })();
+ Phaser.SpriteUtils = SpriteUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var DebugUtils = (function () {
+ function DebugUtils() { }
+ DebugUtils.font = '14px Courier';
+ DebugUtils.lineHeight = 16;
+ DebugUtils.renderShadow = true;
+ DebugUtils.start = function start(x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.currentX = x;
+ Phaser.DebugUtils.currentY = y;
+ Phaser.DebugUtils.currentColor = color;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.font = Phaser.DebugUtils.font;
+ };
+ DebugUtils.line = function line(text, x, y) {
+ if (typeof x === "undefined") { x = null; }
+ if (typeof y === "undefined") { y = null; }
+ if(x !== null) {
+ Phaser.DebugUtils.currentX = x;
+ }
+ if(y !== null) {
+ Phaser.DebugUtils.currentY = y;
+ }
+ if(Phaser.DebugUtils.renderShadow) {
+ Phaser.DebugUtils.context.fillStyle = 'rgb(0,0,0)';
+ Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX + 1, Phaser.DebugUtils.currentY + 1);
+ Phaser.DebugUtils.context.fillStyle = Phaser.DebugUtils.currentColor;
+ }
+ Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX, Phaser.DebugUtils.currentY);
+ Phaser.DebugUtils.currentY += Phaser.DebugUtils.lineHeight;
+ };
+ DebugUtils.renderSpriteCorners = function renderSpriteCorners(sprite, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,0,255)'; }
+ Phaser.DebugUtils.start(0, 0, color);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperLeft.x) + ' y: ' + Math.floor(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperRight.x) + ' y: ' + Math.floor(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomLeft.x) + ' y: ' + Math.floor(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomRight.x) + ' y: ' + Math.floor(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
+ };
+ DebugUtils.renderSoundInfo = function renderSoundInfo(sound, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback);
+ Phaser.DebugUtils.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding);
+ Phaser.DebugUtils.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying);
+ Phaser.DebugUtils.line('Time: ' + sound.currentTime);
+ Phaser.DebugUtils.line('Volume: ' + sound.volume + ' Muted: ' + sound.mute);
+ Phaser.DebugUtils.line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag);
+ if(sound.currentMarker !== '') {
+ Phaser.DebugUtils.line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration);
+ Phaser.DebugUtils.line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop);
+ Phaser.DebugUtils.line('Position: ' + sound.position);
+ }
+ };
+ DebugUtils.renderCameraInfo = function renderCameraInfo(camera, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Camera ID: ' + camera.ID + ' (' + camera.screenView.width + ' x ' + camera.screenView.height + ')');
+ Phaser.DebugUtils.line('X: ' + camera.x + ' Y: ' + camera.y + ' Rotation: ' + camera.transform.rotation);
+ Phaser.DebugUtils.line('WorldView X: ' + camera.worldView.x + ' Y: ' + camera.worldView.y + ' W: ' + camera.worldView.width + ' H: ' + camera.worldView.height);
+ Phaser.DebugUtils.line('ScreenView X: ' + camera.screenView.x + ' Y: ' + camera.screenView.y + ' W: ' + camera.screenView.width + ' H: ' + camera.screenView.height);
+ if(camera.worldBounds) {
+ Phaser.DebugUtils.line('Bounds: ' + camera.worldBounds.width + ' x ' + camera.worldBounds.height);
+ }
+ };
+ DebugUtils.renderPointer = function renderPointer(pointer, hideIfUp, downColor, upColor, color) {
+ if (typeof hideIfUp === "undefined") { hideIfUp = false; }
+ if (typeof downColor === "undefined") { downColor = 'rgba(0,255,0,0.5)'; }
+ if (typeof upColor === "undefined") { upColor = 'rgba(255,0,0,0.5)'; }
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ if(hideIfUp == true && pointer.isUp == true) {
+ return;
+ }
+ Phaser.DebugUtils.context.beginPath();
+ Phaser.DebugUtils.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2);
+ if(pointer.active) {
+ Phaser.DebugUtils.context.fillStyle = downColor;
+ } else {
+ Phaser.DebugUtils.context.fillStyle = upColor;
+ }
+ Phaser.DebugUtils.context.fill();
+ Phaser.DebugUtils.context.closePath();
+ Phaser.DebugUtils.context.beginPath();
+ Phaser.DebugUtils.context.moveTo(pointer.positionDown.x, pointer.positionDown.y);
+ Phaser.DebugUtils.context.lineTo(pointer.position.x, pointer.position.y);
+ Phaser.DebugUtils.context.lineWidth = 2;
+ Phaser.DebugUtils.context.stroke();
+ Phaser.DebugUtils.context.closePath();
+ Phaser.DebugUtils.start(pointer.x, pointer.y - 100, color);
+ Phaser.DebugUtils.line('ID: ' + pointer.id + " Active: " + pointer.active);
+ Phaser.DebugUtils.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY);
+ Phaser.DebugUtils.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y);
+ Phaser.DebugUtils.line('Duration: ' + pointer.duration + " ms");
+ };
+ DebugUtils.renderSpriteInputInfo = function renderSpriteInputInfo(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')');
+ Phaser.DebugUtils.line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1));
+ Phaser.DebugUtils.line('over: ' + sprite.input.pointerOver() + ' duration: ' + sprite.input.overDuration().toFixed(0));
+ Phaser.DebugUtils.line('down: ' + sprite.input.pointerDown() + ' duration: ' + sprite.input.downDuration().toFixed(0));
+ Phaser.DebugUtils.line('just over: ' + sprite.input.justOver() + ' just out: ' + sprite.input.justOut());
+ };
+ DebugUtils.renderInputInfo = function renderInputInfo(x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ if(Phaser.DebugUtils.game.input.camera) {
+ Phaser.DebugUtils.line('Input - Camera: ' + Phaser.DebugUtils.game.input.camera.ID);
+ } else {
+ Phaser.DebugUtils.line('Input - Camera: null');
+ }
+ Phaser.DebugUtils.line('X: ' + Phaser.DebugUtils.game.input.x + ' Y: ' + Phaser.DebugUtils.game.input.y);
+ Phaser.DebugUtils.line('World X: ' + Phaser.DebugUtils.game.input.worldX + ' World Y: ' + Phaser.DebugUtils.game.input.worldY);
+ Phaser.DebugUtils.line('Scale X: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1) + ' Scale Y: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1));
+ Phaser.DebugUtils.line('Screen X: ' + Phaser.DebugUtils.game.input.activePointer.screenX + ' Screen Y: ' + Phaser.DebugUtils.game.input.activePointer.screenY);
+ };
+ DebugUtils.renderSpriteWorldView = function renderSpriteWorldView(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')');
+ Phaser.DebugUtils.line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y);
+ Phaser.DebugUtils.line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1));
+ };
+ DebugUtils.renderSpriteWorldViewBounds = function renderSpriteWorldViewBounds(sprite, color) {
+ if (typeof color === "undefined") { color = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.renderRectangle(sprite.worldView, color);
+ };
+ DebugUtils.renderSpriteInfo = function renderSpriteInfo(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y);
+ Phaser.DebugUtils.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
+ Phaser.DebugUtils.line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
+ Phaser.DebugUtils.line('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1));
+ Phaser.DebugUtils.line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
+ Phaser.DebugUtils.line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
+ Phaser.DebugUtils.line('cameraView x: ' + sprite.cameraView.x + ' y: ' + sprite.cameraView.y + ' width: ' + sprite.cameraView.width + ' height: ' + sprite.cameraView.height);
+ Phaser.DebugUtils.line('inCamera: ' + Phaser.DebugUtils.game.renderer.spriteRenderer.inCamera(Phaser.DebugUtils.game.camera, sprite));
+ };
+ DebugUtils.renderSpriteBounds = function renderSpriteBounds(sprite, camera, color) {
+ if (typeof camera === "undefined") { camera = null; }
+ if (typeof color === "undefined") { color = 'rgba(0,255,0,0.2)'; }
+ if(camera == null) {
+ camera = Phaser.DebugUtils.game.camera;
+ }
+ var dx = sprite.worldView.x;
+ var dy = sprite.worldView.y;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
+ };
+ DebugUtils.renderPixel = function renderPixel(x, y, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(x, y, 1, 1);
+ };
+ DebugUtils.renderPoint = function renderPoint(point, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(point.x, point.y, 1, 1);
+ };
+ DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
+ DebugUtils.renderCircle = function renderCircle(circle, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
+ Phaser.DebugUtils.context.fill();
+ };
+ DebugUtils.renderText = function renderText(text, x, y, color, font) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ if (typeof font === "undefined") { font = '16px Courier'; }
+ Phaser.DebugUtils.context.font = font;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.fillText(text, x, y);
+ };
+ return DebugUtils;
+ })();
+ Phaser.DebugUtils = DebugUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Headless) {
+ var HeadlessRenderer = (function () {
+ function HeadlessRenderer(game) {
+ this.game = game;
+ }
+ HeadlessRenderer.prototype.render = function () {
+ };
+ HeadlessRenderer.prototype.renderGameObject = function (camera, object) {
+ };
+ return HeadlessRenderer;
+ })();
+ Headless.HeadlessRenderer = HeadlessRenderer;
+ })(Renderer.Headless || (Renderer.Headless = {}));
+ var Headless = Renderer.Headless;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var CameraRenderer = (function () {
+ function CameraRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._tx = 0;
+ this._ty = 0;
+ this._gac = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ CameraRenderer.prototype.preRender = function (camera) {
+ if(camera.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
+ return false;
+ }
+ if(this.game.device.patchAndroidClearRectBug) {
+ camera.texture.context.fillStyle = 'rgb(0,0,0)';
+ camera.texture.context.fillRect(0, 0, camera.width, camera.height);
+ } else {
+ camera.texture.context.clearRect(0, 0, camera.width, camera.height);
+ }
+ if(camera.texture.alpha !== 1 && camera.texture.context.globalAlpha != camera.texture.alpha) {
+ this._ga = camera.texture.context.globalAlpha;
+ camera.texture.context.globalAlpha = camera.texture.alpha;
+ }
+ if(camera.texture.opaque) {
+ camera.texture.context.fillStyle = camera.texture.backgroundColor;
+ camera.texture.context.fillRect(0, 0, camera.width, camera.height);
+ }
+ if(camera.texture.globalCompositeOperation) {
+ camera.texture.context.globalCompositeOperation = camera.texture.globalCompositeOperation;
+ }
+ camera.plugins.preRender();
+ };
+ CameraRenderer.prototype.postRender = function (camera) {
+ if(this._ga > -1) {
+ camera.texture.context.globalAlpha = this._ga;
+ }
+ camera.plugins.postRender();
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = camera.width;
+ this._sh = camera.height;
+ this._fx = camera.transform.scale.x;
+ this._fy = camera.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = camera.screenView.x;
+ this._dy = camera.screenView.y;
+ this._dw = camera.width;
+ this._dh = camera.height;
+ this.game.stage.context.save();
+ if(camera.texture.flippedX) {
+ this._fx = -camera.transform.scale.x;
+ }
+ if(camera.texture.flippedY) {
+ this._fy = -camera.transform.scale.y;
+ }
+ if(camera.modified) {
+ if(camera.transform.rotation !== 0 || camera.transform.rotationOffset !== 0) {
+ this._sin = Math.sin(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
+ this._cos = Math.cos(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
+ }
+ this.game.stage.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + camera.transform.skew.x, -(this._sin * this._fy) + camera.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
+ this._dx = camera.transform.origin.x * -this._dw;
+ this._dy = camera.transform.origin.y * -this._dh;
+ } else {
+ this._dx -= (this._dw * camera.transform.origin.x);
+ this._dy -= (this._dh * camera.transform.origin.y);
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
+ this.game.stage.context.restore();
+ return false;
+ }
+ this.game.stage.context.drawImage(camera.texture.canvas, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ this.game.stage.context.restore();
+ };
+ return CameraRenderer;
+ })();
+ Canvas.CameraRenderer = CameraRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var GeometryRenderer = (function () {
+ function GeometryRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ GeometryRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) {
+ if (typeof outline === "undefined") { outline = false; }
+ if (typeof fill === "undefined") { fill = true; }
+ if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; }
+ if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; }
+ if (typeof lineWidth === "undefined") { lineWidth = 1; }
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = circle.diameter;
+ this._sh = circle.diameter;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = camera.screenView.x + circle.x - camera.worldView.x;
+ this._dy = camera.screenView.y + circle.y - camera.worldView.y;
+ this._dw = circle.diameter;
+ this._dh = circle.diameter;
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ this.game.stage.saveCanvasValues();
+ context.save();
+ context.lineWidth = lineWidth;
+ context.strokeStyle = lineColor;
+ context.fillStyle = fillColor;
+ context.beginPath();
+ context.arc(this._dx, this._dy, circle.radius, 0, Math.PI * 2);
+ context.closePath();
+ if(outline) {
+ }
+ if(fill) {
+ context.fill();
+ }
+ context.restore();
+ this.game.stage.restoreCanvasValues();
+ return true;
+ };
+ return GeometryRenderer;
+ })();
+ Canvas.GeometryRenderer = GeometryRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var GroupRenderer = (function () {
+ function GroupRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ GroupRenderer.prototype.preRender = function (camera, group) {
+ if(group.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
+ return false;
+ }
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = group.texture.width;
+ this._sh = group.texture.height;
+ this._fx = group.transform.scale.x;
+ this._fy = group.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = group.texture.width;
+ this._dh = group.texture.height;
+ if(group.texture.globalCompositeOperation) {
+ group.texture.context.save();
+ group.texture.context.globalCompositeOperation = group.texture.globalCompositeOperation;
+ }
+ if(group.texture.alpha !== 1 && group.texture.context.globalAlpha !== group.texture.alpha) {
+ this._ga = group.texture.context.globalAlpha;
+ group.texture.context.globalAlpha = group.texture.alpha;
+ }
+ if(group.texture.flippedX) {
+ this._fx = -group.transform.scale.x;
+ }
+ if(group.texture.flippedY) {
+ this._fy = -group.transform.scale.y;
+ }
+ if(group.modified) {
+ if(group.transform.rotation !== 0 || group.transform.rotationOffset !== 0) {
+ this._sin = Math.sin(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
+ this._cos = Math.cos(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
+ }
+ group.texture.context.save();
+ group.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + group.transform.skew.x, -(this._sin * this._fy) + group.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
+ this._dx = -group.transform.origin.x;
+ this._dy = -group.transform.origin.y;
+ } else {
+ if(!group.transform.origin.equals(0)) {
+ this._dx -= group.transform.origin.x;
+ this._dy -= group.transform.origin.y;
+ }
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(group.texture.opaque) {
+ group.texture.context.fillStyle = group.texture.backgroundColor;
+ group.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
+ }
+ if(group.texture.loaded) {
+ group.texture.context.drawImage(group.texture.texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ }
+ return true;
+ };
+ GroupRenderer.prototype.postRender = function (camera, group) {
+ if(group.modified || group.texture.globalCompositeOperation) {
+ group.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ group.texture.context.globalAlpha = this._ga;
+ }
+ };
+ return GroupRenderer;
+ })();
+ Canvas.GroupRenderer = GroupRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var ScrollZoneRenderer = (function () {
+ function ScrollZoneRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ ScrollZoneRenderer.prototype.inCamera = function (camera, scrollZone) {
+ if(scrollZone.transform.scrollFactor.equals(0)) {
+ return true;
+ }
+ return true;
+ };
+ ScrollZoneRenderer.prototype.render = function (camera, scrollZone) {
+ if(scrollZone.transform.scale.x == 0 || scrollZone.transform.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false) {
+ return false;
+ }
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = scrollZone.width;
+ this._sh = scrollZone.height;
+ this._fx = scrollZone.transform.scale.x;
+ this._fy = scrollZone.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = (camera.screenView.x * scrollZone.transform.scrollFactor.x) + scrollZone.x - (camera.worldView.x * scrollZone.transform.scrollFactor.x);
+ this._dy = (camera.screenView.y * scrollZone.transform.scrollFactor.y) + scrollZone.y - (camera.worldView.y * scrollZone.transform.scrollFactor.y);
+ this._dw = scrollZone.width;
+ this._dh = scrollZone.height;
+ if(scrollZone.texture.alpha !== 1) {
+ this._ga = scrollZone.texture.context.globalAlpha;
+ scrollZone.texture.context.globalAlpha = scrollZone.texture.alpha;
+ }
+ if(scrollZone.texture.flippedX) {
+ this._fx = -scrollZone.transform.scale.x;
+ }
+ if(scrollZone.texture.flippedY) {
+ this._fy = -scrollZone.transform.scale.y;
+ }
+ if(scrollZone.modified) {
+ if(scrollZone.texture.renderRotation == true && (scrollZone.rotation !== 0 || scrollZone.transform.rotationOffset !== 0)) {
+ this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
+ this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
+ }
+ scrollZone.texture.context.save();
+ scrollZone.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + scrollZone.transform.skew.x, -(this._sin * this._fy) + scrollZone.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
+ this._dx = -scrollZone.transform.origin.x;
+ this._dy = -scrollZone.transform.origin.y;
+ } else {
+ if(!scrollZone.transform.origin.equals(0)) {
+ this._dx -= scrollZone.transform.origin.x;
+ this._dy -= scrollZone.transform.origin.y;
+ }
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ for(var i = 0; i < scrollZone.regions.length; i++) {
+ if(scrollZone.texture.isDynamic) {
+ scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
+ } else {
+ scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
+ }
+ }
+ if(scrollZone.modified) {
+ scrollZone.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ scrollZone.texture.context.globalAlpha = this._ga;
+ }
+ this.game.renderer.renderCount++;
+ return true;
+ };
+ return ScrollZoneRenderer;
+ })();
+ Canvas.ScrollZoneRenderer = ScrollZoneRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var SpriteRenderer = (function () {
+ function SpriteRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this.game = game;
+ }
+ SpriteRenderer.prototype.inCamera = function (camera, sprite) {
+ if(sprite.transform.scrollFactor.equals(0)) {
+ return true;
+ }
+ return Phaser.RectangleUtils.intersects(sprite.cameraView, camera.screenView);
+ };
+ SpriteRenderer.prototype.render = function (camera, sprite) {
+ Phaser.SpriteUtils.updateCameraView(camera, sprite);
+ if(sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
+ return false;
+ }
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = sprite.texture.width;
+ this._sh = sprite.texture.height;
+ this._dx = sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
+ this._dy = sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
+ this._dw = sprite.texture.width;
+ this._dh = sprite.texture.height;
+ if(sprite.animations.currentFrame !== null) {
+ this._sx = sprite.animations.currentFrame.x;
+ this._sy = sprite.animations.currentFrame.y;
+ if(sprite.animations.currentFrame.trimmed) {
+ this._dx += sprite.animations.currentFrame.spriteSourceSizeX;
+ this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
+ this._sw = sprite.animations.currentFrame.spriteSourceSizeW;
+ this._sh = sprite.animations.currentFrame.spriteSourceSizeH;
+ this._dw = sprite.animations.currentFrame.spriteSourceSizeW;
+ this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
+ }
+ }
+ if(sprite.modified) {
+ camera.texture.context.save();
+ camera.texture.context.setTransform(sprite.transform.local.data[0], sprite.transform.local.data[3], sprite.transform.local.data[1], sprite.transform.local.data[4], this._dx, this._dy);
+ this._dx = sprite.transform.origin.x * -this._dw;
+ this._dy = sprite.transform.origin.y * -this._dh;
+ } else {
+ this._dx -= (this._dw * sprite.transform.origin.x);
+ this._dy -= (this._dh * sprite.transform.origin.y);
+ }
+ if(sprite.crop) {
+ this._sx += sprite.crop.x * sprite.transform.scale.x;
+ this._sy += sprite.crop.y * sprite.transform.scale.y;
+ this._sw = sprite.crop.width * sprite.transform.scale.x;
+ this._sh = sprite.crop.height * sprite.transform.scale.y;
+ this._dx += sprite.crop.x * sprite.transform.scale.x;
+ this._dy += sprite.crop.y * sprite.transform.scale.y;
+ this._dw = sprite.crop.width * sprite.transform.scale.x;
+ this._dh = sprite.crop.height * sprite.transform.scale.y;
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
+ return false;
+ }
+ if(sprite.texture.globalCompositeOperation) {
+ camera.texture.context.save();
+ camera.texture.context.globalCompositeOperation = sprite.texture.globalCompositeOperation;
+ }
+ if(sprite.texture.alpha !== 1 && camera.texture.context.globalAlpha != sprite.texture.alpha) {
+ this._ga = sprite.texture.context.globalAlpha;
+ camera.texture.context.globalAlpha = sprite.texture.alpha;
+ }
+ if(sprite.texture.opaque) {
+ camera.texture.context.fillStyle = sprite.texture.backgroundColor;
+ camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
+ }
+ if(sprite.texture.loaded) {
+ camera.texture.context.drawImage(sprite.texture.texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ }
+ if(sprite.modified || sprite.texture.globalCompositeOperation) {
+ camera.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ camera.texture.context.globalAlpha = this._ga;
+ }
+ sprite.renderOrderID = this.game.renderer.renderCount;
+ this.game.renderer.renderCount++;
+ return true;
+ };
+ return SpriteRenderer;
+ })();
+ Canvas.SpriteRenderer = SpriteRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var TilemapRenderer = (function () {
+ function TilemapRenderer(game) {
+ this._ga = 1;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._tx = 0;
+ this._ty = 0;
+ this._tl = 0;
+ this._maxX = 0;
+ this._maxY = 0;
+ this._startX = 0;
+ this._startY = 0;
+ this.game = game;
+ }
+ TilemapRenderer.prototype.render = function (camera, tilemap) {
+ this._tl = tilemap.layers.length;
+ for(var i = 0; i < this._tl; i++) {
+ if(tilemap.layers[i].visible == false || tilemap.layers[i].alpha < 0.1) {
+ continue;
+ }
+ var layer = tilemap.layers[i];
+ this._maxX = this.game.math.ceil(camera.width / layer.tileWidth) + 1;
+ this._maxY = this.game.math.ceil(camera.height / layer.tileHeight) + 1;
+ this._startX = this.game.math.floor(camera.worldView.x / layer.tileWidth);
+ this._startY = this.game.math.floor(camera.worldView.y / layer.tileHeight);
+ 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;
+ }
+ 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;
+ 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 TilemapRenderer;
+ })();
+ Canvas.TilemapRenderer = TilemapRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var CanvasRenderer = (function () {
+ function CanvasRenderer(game) {
+ this._c = 0;
+ this.game = game;
+ this.cameraRenderer = new Phaser.Renderer.Canvas.CameraRenderer(game);
+ this.groupRenderer = new Phaser.Renderer.Canvas.GroupRenderer(game);
+ this.spriteRenderer = new Phaser.Renderer.Canvas.SpriteRenderer(game);
+ this.geometryRenderer = new Phaser.Renderer.Canvas.GeometryRenderer(game);
+ this.scrollZoneRenderer = new Phaser.Renderer.Canvas.ScrollZoneRenderer(game);
+ this.tilemapRenderer = new Phaser.Renderer.Canvas.TilemapRenderer(game);
+ }
+ CanvasRenderer.prototype.render = function () {
+ this._cameraList = this.game.world.getAllCameras();
+ this.renderCount = 0;
+ for(this._c = 0; this._c < this._cameraList.length; this._c++) {
+ if(this._cameraList[this._c].visible) {
+ this.cameraRenderer.preRender(this._cameraList[this._c]);
+ this.game.world.group.render(this._cameraList[this._c]);
+ this.cameraRenderer.postRender(this._cameraList[this._c]);
+ }
+ }
+ this.renderTotal = this.renderCount;
+ };
+ CanvasRenderer.prototype.renderGameObject = function (camera, object) {
+ if(object.type == Phaser.Types.SPRITE || object.type == Phaser.Types.BUTTON) {
+ this.spriteRenderer.render(camera, object);
+ } else if(object.type == Phaser.Types.SCROLLZONE) {
+ this.scrollZoneRenderer.render(camera, object);
+ } else if(object.type == Phaser.Types.TILEMAP) {
+ this.tilemapRenderer.render(camera, object);
+ }
+ };
+ return CanvasRenderer;
+ })();
+ Canvas.CanvasRenderer = CanvasRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var ParticleManager = (function () {
+ function ParticleManager(proParticleCount, integrationType) {
+ this.PARTICLE_CREATED = 'partilcleCreated';
+ this.PARTICLE_UPDATE = 'partilcleUpdate';
+ this.PARTICLE_SLEEP = 'particleSleep';
+ this.PARTICLE_DEAD = 'partilcleDead';
+ this.PROTON_UPDATE = 'protonUpdate';
+ this.PROTON_UPDATE_AFTER = 'protonUpdateAfter';
+ this.EMITTER_ADDED = 'emitterAdded';
+ this.EMITTER_REMOVED = 'emitterRemoved';
+ this.emitters = [];
+ this.renderers = [];
+ this.time = 0;
+ this.oldTime = 0;
+ this.amendChangeTabsBug = true;
+ this.TextureBuffer = {
+ };
+ this.TextureCanvasBuffer = {
+ };
+ this.proParticleCount = Particles.ParticleUtils.initValue(proParticleCount, ParticleManager.POOL_MAX);
+ this.integrationType = Particles.ParticleUtils.initValue(integrationType, ParticleManager.EULER);
+ this.emitters = [];
+ this.renderers = [];
+ this.time = 0;
+ this.oldTime = 0;
+ ParticleManager.pool = new Phaser.Particles.ParticlePool(proParticleCount);
+ ParticleManager.integrator = new Phaser.Particles.NumericalIntegration(this.integrationType);
+ }
+ ParticleManager.POOL_MAX = 1000;
+ ParticleManager.TIME_STEP = 60;
+ ParticleManager.MEASURE = 100;
+ ParticleManager.EULER = 'euler';
+ ParticleManager.RK2 = 'runge-kutta2';
+ ParticleManager.RK4 = 'runge-kutta4';
+ ParticleManager.VERLET = 'verlet';
+ ParticleManager.prototype.addRender = function (render) {
+ render.proton = this;
+ this.renderers.push(render.proton);
+ };
+ ParticleManager.prototype.addEmitter = function (emitter) {
+ this.emitters.push(emitter);
+ emitter.parent = this;
+ };
+ ParticleManager.prototype.removeEmitter = function (emitter) {
+ var index = this.emitters.indexOf(emitter);
+ this.emitters.splice(index, 1);
+ emitter.parent = null;
+ };
+ ParticleManager.prototype.update = function () {
+ if(!this.oldTime) {
+ this.oldTime = new Date().getTime();
+ }
+ var time = new Date().getTime();
+ this.elapsed = (time - this.oldTime) / 1000;
+ this.oldTime = time;
+ if(this.elapsed > 0) {
+ for(var i = 0; i < this.emitters.length; i++) {
+ this.emitters[i].update(this.elapsed);
+ }
+ }
+ };
+ ParticleManager.prototype.amendChangeTabsBugHandler = function () {
+ if(this.elapsed > .5) {
+ this.oldTime = new Date().getTime();
+ this.elapsed = 0;
+ }
+ };
+ ParticleManager.prototype.getParticleNumber = function () {
+ var total = 0;
+ for(var i = 0; i < this.emitters.length; i++) {
+ total += this.emitters[i].particles.length;
+ }
+ return total;
+ };
+ ParticleManager.prototype.destroy = function () {
+ for(var i = 0; i < this.emitters.length; i++) {
+ this.emitters[i].destory();
+ delete this.emitters[i];
+ }
+ this.emitters = [];
+ this.time = 0;
+ this.oldTime = 0;
+ ParticleManager.pool.release();
+ };
+ return ParticleManager;
+ })();
+ Particles.ParticleManager = ParticleManager;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Particle = (function () {
+ function Particle() {
+ this.life = Infinity;
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.sleep = false;
+ this.target = null;
+ this.sprite = null;
+ this.parent = null;
+ this.mass = 1;
+ this.radius = 10;
+ this.alpha = 1;
+ this.scale = 1;
+ this.rotation = 0;
+ this.color = null;
+ this.easing = Phaser.Easing.Linear.None;
+ this.p = new Phaser.Vec2();
+ this.v = new Phaser.Vec2();
+ this.a = new Phaser.Vec2();
+ this.old = {
+ p: new Phaser.Vec2(),
+ v: new Phaser.Vec2(),
+ a: new Phaser.Vec2()
+ };
+ this.behaviours = [];
+ this.id = 'particle_' + Particle.ID++;
+ this.reset(true);
+ }
+ Particle.ID = 0;
+ Particle.prototype.getDirection = function () {
+ return Math.atan2(this.v.x, -this.v.y) * (180 / Math.PI);
+ };
+ Particle.prototype.reset = function (init) {
+ this.life = Infinity;
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.sleep = false;
+ this.target = null;
+ this.sprite = null;
+ this.parent = null;
+ this.mass = 1;
+ this.radius = 10;
+ this.alpha = 1;
+ this.scale = 1;
+ this.rotation = 0;
+ this.color = null;
+ this.easing = Phaser.Easing.Linear.None;
+ if(init) {
+ this.transform = {
+ };
+ this.p = new Phaser.Vec2();
+ this.v = new Phaser.Vec2();
+ this.a = new Phaser.Vec2();
+ this.old = {
+ p: new Phaser.Vec2(),
+ v: new Phaser.Vec2(),
+ a: new Phaser.Vec2()
+ };
+ this.behaviours = [];
+ } else {
+ Particles.ParticleUtils.destroyObject(this.transform);
+ this.p.setTo(0, 0);
+ this.v.setTo(0, 0);
+ this.a.setTo(0, 0);
+ this.old.p.setTo(0, 0);
+ this.old.v.setTo(0, 0);
+ this.old.a.setTo(0, 0);
+ this.removeAllBehaviours();
+ }
+ this.transform.rgb = {
+ r: 255,
+ g: 255,
+ b: 255
+ };
+ return this;
+ };
+ Particle.prototype.update = function (time, index) {
+ if(!this.sleep) {
+ this.age += time;
+ var length = this.behaviours.length, i;
+ for(i = 0; i < length; i++) {
+ if(this.behaviours[i]) {
+ this.behaviours[i].applyBehaviour(this, time, index);
+ }
+ }
+ }
+ if(this.age >= this.life) {
+ this.destroy();
+ } else {
+ var scale = this.easing(this.age / this.life);
+ this.energy = Math.max(1 - scale, 0);
+ }
+ };
+ Particle.prototype.addBehaviour = function (behaviour) {
+ this.behaviours.push(behaviour);
+ if(behaviour.hasOwnProperty('parents')) {
+ behaviour.parents.push(this);
+ }
+ behaviour.initialize(this);
+ };
+ Particle.prototype.addBehaviours = function (behaviours) {
+ var length = behaviours.length, i;
+ for(i = 0; i < length; i++) {
+ this.addBehaviour(behaviours[i]);
+ }
+ };
+ Particle.prototype.removeBehaviour = function (behaviour) {
+ var index = this.behaviours.indexOf(behaviour);
+ if(index > -1) {
+ var outBehaviour = this.behaviours.splice(index, 1);
+ }
+ };
+ Particle.prototype.removeAllBehaviours = function () {
+ Particles.ParticleUtils.destroyArray(this.behaviours);
+ };
+ Particle.prototype.destroy = function () {
+ this.removeAllBehaviours();
+ this.energy = 0;
+ this.dead = true;
+ this.parent = null;
+ };
+ return Particle;
+ })();
+ Particles.Particle = Particle;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Emitter = (function () {
+ function Emitter(pObj) {
+ this.initializes = [];
+ this.particles = [];
+ this.behaviours = [];
+ this.emitTime = 0;
+ this.emitTotalTimes = -1;
+ this.initializes = [];
+ this.particles = [];
+ this.behaviours = [];
+ this.emitTime = 0;
+ this.emitTotalTimes = -1;
+ this.damping = .006;
+ this.bindEmitter = true;
+ this.rate = new Phaser.Particles.Initializers.Rate(1, .1);
+ this.id = 'emitter_' + Emitter.ID++;
+ }
+ Emitter.ID = 0;
+ Emitter.prototype.emit = function (emitTime, life) {
+ this.emitTime = 0;
+ this.emitTotalTimes = Particles.ParticleUtils.initValue(emitTime, Infinity);
+ if(life == true || life == 'life' || life == 'destroy') {
+ if(emitTime == 'once') {
+ this.life = 1;
+ } else {
+ this.life = this.emitTotalTimes;
+ }
+ } else if(!isNaN(life)) {
+ this.life = life;
+ }
+ this.rate.init();
+ };
+ Emitter.prototype.stopEmit = function () {
+ this.emitTotalTimes = -1;
+ this.emitTime = 0;
+ };
+ Emitter.prototype.removeAllParticles = function () {
+ for(var i = 0; i < this.particles.length; i++) {
+ this.particles[i].dead = true;
+ }
+ };
+ Emitter.prototype.createParticle = function (initialize, behaviour) {
+ if (typeof initialize === "undefined") { initialize = null; }
+ if (typeof behaviour === "undefined") { behaviour = null; }
+ var particle = Particles.ParticleManager.pool.get();
+ this.setupParticle(particle, initialize, behaviour);
+ return particle;
+ };
+ Emitter.prototype.addSelfInitialize = function (pObj) {
+ if(pObj['init']) {
+ pObj.init(this);
+ } else {
+ }
+ };
+ Emitter.prototype.addInitialize = function () {
+ var length = arguments.length, i;
+ for(i = 0; i < length; i++) {
+ this.initializes.push(arguments[i]);
+ }
+ };
+ Emitter.prototype.removeInitialize = function (initializer) {
+ var index = this.initializes.indexOf(initializer);
+ if(index > -1) {
+ this.initializes.splice(index, 1);
+ }
+ };
+ Emitter.prototype.removeInitializers = function () {
+ Particles.ParticleUtils.destroyArray(this.initializes);
+ };
+ Emitter.prototype.addBehaviour = function () {
+ var length = arguments.length, i;
+ for(i = 0; i < length; i++) {
+ this.behaviours.push(arguments[i]);
+ if(arguments[i].hasOwnProperty("parents")) {
+ arguments[i].parents.push(this);
+ }
+ }
+ };
+ Emitter.prototype.removeBehaviour = function (behaviour) {
+ var index = this.behaviours.indexOf(behaviour);
+ if(index > -1) {
+ this.behaviours.splice(index, 1);
+ }
+ };
+ Emitter.prototype.removeAllBehaviours = function () {
+ Particles.ParticleUtils.destroyArray(this.behaviours);
+ };
+ Emitter.prototype.integrate = function (time) {
+ var damping = 1 - this.damping;
+ Particles.ParticleManager.integrator.integrate(this, time, damping);
+ var length = this.particles.length, i;
+ for(i = 0; i < length; i++) {
+ var particle = this.particles[i];
+ particle.update(time, i);
+ Particles.ParticleManager.integrator.integrate(particle, time, damping);
+ }
+ };
+ Emitter.prototype.emitting = function (time) {
+ if(this.emitTotalTimes == 1) {
+ var length = this.rate.getValue(99999), i;
+ for(i = 0; i < length; i++) {
+ this.createParticle();
+ }
+ this.emitTotalTimes = 0;
+ } else if(!isNaN(this.emitTotalTimes)) {
+ this.emitTime += time;
+ if(this.emitTime < this.emitTotalTimes) {
+ var length = this.rate.getValue(time), i;
+ for(i = 0; i < length; i++) {
+ this.createParticle();
+ }
+ }
+ }
+ };
+ Emitter.prototype.update = function (time) {
+ this.age += time;
+ if(this.age >= this.life || this.dead) {
+ this.destroy();
+ }
+ this.emitting(time);
+ this.integrate(time);
+ var particle;
+ var length = this.particles.length, k;
+ for(k = length - 1; k >= 0; k--) {
+ particle = this.particles[k];
+ if(particle.dead) {
+ Particles.ParticleManager.pool.set(particle);
+ this.particles.splice(k, 1);
+ }
+ }
+ };
+ Emitter.prototype.setupParticle = function (particle, initialize, behaviour) {
+ var initializes = this.initializes;
+ var behaviours = this.behaviours;
+ if(initialize) {
+ if(initialize instanceof Array) {
+ initializes = initialize;
+ } else {
+ initializes = [
+ initialize
+ ];
+ }
+ }
+ if(behaviour) {
+ if(behaviour instanceof Array) {
+ behaviours = behaviour;
+ } else {
+ behaviours = [
+ behaviour
+ ];
+ }
+ }
+ particle.addBehaviours(behaviours);
+ particle.parent = this;
+ this.particles.push(particle);
+ };
+ Emitter.prototype.destroy = function () {
+ this.dead = true;
+ this.emitTotalTimes = -1;
+ if(this.particles.length == 0) {
+ this.removeInitializers();
+ this.removeAllBehaviours();
+ if(this.parent) {
+ this.parent.removeEmitter(this);
+ }
+ }
+ };
+ return Emitter;
+ })();
+ Particles.Emitter = Emitter;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var ParticlePool = (function () {
+ function ParticlePool(num, releaseTime) {
+ if (typeof releaseTime === "undefined") { releaseTime = 0; }
+ this.poolList = [];
+ this.timeoutID = 0;
+ this.proParticleCount = Particles.ParticleUtils.initValue(num, 0);
+ this.releaseTime = Particles.ParticleUtils.initValue(releaseTime, -1);
+ this.poolList = [];
+ this.timeoutID = 0;
+ for(var i = 0; i < this.proParticleCount; i++) {
+ this.add();
+ }
+ if(this.releaseTime > 0) {
+ this.timeoutID = setTimeout(this.release, this.releaseTime / 1000);
+ }
+ }
+ ParticlePool.prototype.create = function (newTypeParticleClass) {
+ if (typeof newTypeParticleClass === "undefined") { newTypeParticleClass = null; }
+ if(newTypeParticleClass) {
+ return new newTypeParticleClass();
+ } else {
+ return new Phaser.Particles.Particle();
+ }
+ };
+ ParticlePool.prototype.getCount = function () {
+ return this.poolList.length;
+ };
+ ParticlePool.prototype.add = function () {
+ return this.poolList.push(this.create());
+ };
+ ParticlePool.prototype.get = function () {
+ if(this.poolList.length === 0) {
+ return this.create();
+ } else {
+ return this.poolList.pop().reset();
+ }
+ };
+ ParticlePool.prototype.set = function (particle) {
+ if(this.poolList.length < Particles.ParticleManager.POOL_MAX) {
+ return this.poolList.push(particle);
+ }
+ };
+ ParticlePool.prototype.release = function () {
+ for(var i = 0; i < this.poolList.length; i++) {
+ if(this.poolList[i]['destroy']) {
+ this.poolList[i].destroy();
+ }
+ delete this.poolList[i];
+ }
+ this.poolList = [];
+ };
+ return ParticlePool;
+ })();
+ Particles.ParticlePool = ParticlePool;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var ParticleUtils = (function () {
+ function ParticleUtils() { }
+ ParticleUtils.initValue = function initValue(value, defaults) {
+ var value = (value != null && value != undefined) ? value : defaults;
+ return value;
+ };
+ ParticleUtils.isArray = function isArray(value) {
+ return typeof value === 'object' && value.hasOwnProperty('length');
+ };
+ ParticleUtils.destroyArray = function destroyArray(array) {
+ array.length = 0;
+ };
+ ParticleUtils.destroyObject = function destroyObject(obj) {
+ for(var o in obj) {
+ delete obj[o];
+ }
+ };
+ ParticleUtils.setSpanValue = function setSpanValue(a, b, c) {
+ if (typeof b === "undefined") { b = null; }
+ if (typeof c === "undefined") { c = null; }
+ if(a instanceof Phaser.Particles.Span) {
+ return a;
+ } else {
+ if(!b) {
+ return new Phaser.Particles.Span(a);
+ } else {
+ if(!c) {
+ return new Phaser.Particles.Span(a, b);
+ } else {
+ return new Phaser.Particles.Span(a, b, c);
+ }
+ }
+ }
+ };
+ ParticleUtils.getSpanValue = function getSpanValue(pan) {
+ if(pan instanceof Phaser.Particles.Span) {
+ return pan.getValue();
+ } else {
+ return pan;
+ }
+ };
+ ParticleUtils.randomAToB = function randomAToB(a, b, INT) {
+ if (typeof INT === "undefined") { INT = null; }
+ if(!INT) {
+ return a + Math.random() * (b - a);
+ } else {
+ return Math.floor(Math.random() * (b - a)) + a;
+ }
+ };
+ ParticleUtils.randomFloating = function randomFloating(center, f, INT) {
+ return ParticleUtils.randomAToB(center - f, center + f, INT);
+ };
+ ParticleUtils.randomZone = function randomZone(display) {
+ };
+ ParticleUtils.degreeTransform = function degreeTransform(a) {
+ return a * Math.PI / 180;
+ };
+ ParticleUtils.randomColor = function randomColor() {
+ return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
+ };
+ ParticleUtils.setEasingByName = function setEasingByName(name) {
+ switch(name) {
+ case 'easeLinear':
+ return Phaser.Easing.Linear.None;
+ break;
+ case 'easeInQuad':
+ return Phaser.Easing.Quadratic.In;
+ break;
+ case 'easeOutQuad':
+ return Phaser.Easing.Quadratic.Out;
+ break;
+ case 'easeInOutQuad':
+ return Phaser.Easing.Quadratic.InOut;
+ break;
+ case 'easeInCubic':
+ return Phaser.Easing.Cubic.In;
+ break;
+ case 'easeOutCubic':
+ return Phaser.Easing.Cubic.Out;
+ break;
+ case 'easeInOutCubic':
+ return Phaser.Easing.Cubic.InOut;
+ break;
+ case 'easeInQuart':
+ return Phaser.Easing.Quartic.In;
+ break;
+ case 'easeOutQuart':
+ return Phaser.Easing.Quartic.Out;
+ break;
+ case 'easeInOutQuart':
+ return Phaser.Easing.Quartic.InOut;
+ break;
+ case 'easeInSine':
+ return Phaser.Easing.Sinusoidal.In;
+ break;
+ case 'easeOutSine':
+ return Phaser.Easing.Sinusoidal.Out;
+ break;
+ case 'easeInOutSine':
+ return Phaser.Easing.Sinusoidal.InOut;
+ break;
+ case 'easeInExpo':
+ return Phaser.Easing.Exponential.In;
+ break;
+ case 'easeOutExpo':
+ return Phaser.Easing.Exponential.Out;
+ break;
+ case 'easeInOutExpo':
+ return Phaser.Easing.Exponential.InOut;
+ break;
+ case 'easeInCirc':
+ return Phaser.Easing.Circular.In;
+ break;
+ case 'easeOutCirc':
+ return Phaser.Easing.Circular.Out;
+ break;
+ case 'easeInOutCirc':
+ return Phaser.Easing.Circular.InOut;
+ break;
+ case 'easeInBack':
+ return Phaser.Easing.Back.In;
+ break;
+ case 'easeOutBack':
+ return Phaser.Easing.Back.Out;
+ break;
+ case 'easeInOutBack':
+ return Phaser.Easing.Back.InOut;
+ break;
+ default:
+ return Phaser.Easing.Linear.None;
+ break;
+ }
+ };
+ return ParticleUtils;
+ })();
+ Particles.ParticleUtils = ParticleUtils;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Polar2D = (function () {
+ function Polar2D(r, tha) {
+ this.r = Math.abs(r) || 0;
+ this.tha = tha || 0;
+ }
+ Polar2D.prototype.set = function (r, tha) {
+ this.r = r;
+ this.tha = tha;
+ return this;
+ };
+ Polar2D.prototype.setR = function (r) {
+ this.r = r;
+ return this;
+ };
+ Polar2D.prototype.setTha = function (tha) {
+ this.tha = tha;
+ return this;
+ };
+ Polar2D.prototype.copy = function (p) {
+ this.r = p.r;
+ this.tha = p.tha;
+ return this;
+ };
+ Polar2D.prototype.toVector = function () {
+ return new Phaser.Vec2(this.getX(), this.getY());
+ };
+ Polar2D.prototype.getX = function () {
+ return this.r * Math.sin(this.tha);
+ };
+ Polar2D.prototype.getY = function () {
+ return -this.r * Math.cos(this.tha);
+ };
+ Polar2D.prototype.normalize = function () {
+ this.r = 1;
+ return this;
+ };
+ Polar2D.prototype.equals = function (v) {
+ return ((v.r === this.r) && (v.tha === this.tha));
+ };
+ Polar2D.prototype.toArray = function () {
+ return [
+ this.r,
+ this.tha
+ ];
+ };
+ Polar2D.prototype.clear = function () {
+ this.r = 0.0;
+ this.tha = 0.0;
+ return this;
+ };
+ Polar2D.prototype.clone = function () {
+ return new Polar2D(this.r, this.tha);
+ };
+ return Polar2D;
+ })();
+ Particles.Polar2D = Polar2D;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Span = (function () {
+ function Span(a, b, center) {
+ if (typeof b === "undefined") { b = null; }
+ if (typeof center === "undefined") { center = null; }
+ this.isArray = false;
+ if(Particles.ParticleUtils.isArray(a)) {
+ this.isArray = true;
+ this.a = a;
+ } else {
+ this.a = Particles.ParticleUtils.initValue(a, 1);
+ this.b = Particles.ParticleUtils.initValue(b, this.a);
+ this.center = Particles.ParticleUtils.initValue(center, false);
+ }
+ }
+ Span.prototype.getValue = function (INT) {
+ if (typeof INT === "undefined") { INT = null; }
+ if(this.isArray) {
+ return this.a[Math.floor(this.a.length * Math.random())];
+ } else {
+ if(!this.center) {
+ return Particles.ParticleUtils.randomAToB(this.a, this.b, INT);
+ } else {
+ return Particles.ParticleUtils.randomFloating(this.a, this.b, INT);
+ }
+ }
+ };
+ Span.getSpan = function getSpan(a, b, center) {
+ return new Span(a, b, center);
+ };
+ return Span;
+ })();
+ Particles.Span = Span;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var NumericalIntegration = (function () {
+ function NumericalIntegration(type) {
+ this.type = Particles.ParticleUtils.initValue(type, Particles.ParticleManager.EULER);
+ }
+ NumericalIntegration.prototype.integrate = function (particles, time, damping) {
+ this.eulerIntegrate(particles, time, damping);
+ };
+ NumericalIntegration.prototype.eulerIntegrate = function (particle, time, damping) {
+ if(!particle.sleep) {
+ particle.old.p.copy(particle.p);
+ particle.old.v.copy(particle.v);
+ particle.a.multiplyScalar(1 / particle.mass);
+ particle.v.add(particle.a.multiplyScalar(time));
+ particle.p.add(particle.old.v.multiplyScalar(time));
+ if(damping) {
+ particle.v.multiplyScalar(damping);
+ }
+ particle.a.clear();
+ }
+ };
+ return NumericalIntegration;
+ })();
+ Particles.NumericalIntegration = NumericalIntegration;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Behaviours) {
+ var Behaviour = (function () {
+ function Behaviour(life, easing) {
+ this.id = 'Behaviour_' + Behaviour.ID++;
+ this.life = Particles.ParticleUtils.initValue(life, Infinity);
+ this.easing = Particles.ParticleUtils.setEasingByName(easing);
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.parents = [];
+ this.name = 'Behaviour';
+ }
+ Behaviour.prototype.normalizeForce = function (force) {
+ return force.multiplyScalar(Particles.ParticleManager.MEASURE);
+ };
+ Behaviour.prototype.normalizeValue = function (value) {
+ return value * Particles.ParticleManager.MEASURE;
+ };
+ Behaviour.prototype.initialize = function (particle) {
+ };
+ Behaviour.prototype.applyBehaviour = function (particle, time, index) {
+ this.age += time;
+ if(this.age >= this.life || this.dead) {
+ this.energy = 0;
+ this.dead = true;
+ this.destroy();
+ } else {
+ var scale = this.easing(particle.age / particle.life);
+ this.energy = Math.max(1 - scale, 0);
+ }
+ };
+ Behaviour.prototype.destroy = function () {
+ var index;
+ var length = this.parents.length, i;
+ for(i = 0; i < length; i++) {
+ this.parents[i].removeBehaviour(this);
+ }
+ this.parents = [];
+ };
+ return Behaviour;
+ })();
+ Behaviours.Behaviour = Behaviour;
+ })(Particles.Behaviours || (Particles.Behaviours = {}));
+ var Behaviours = Particles.Behaviours;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Behaviours) {
+ var RandomDrift = (function (_super) {
+ __extends(RandomDrift, _super);
+ function RandomDrift(driftX, driftY, delay, life, easing) {
+ _super.call(this, life, easing);
+ this.reset(driftX, driftY, delay);
+ this.time = 0;
+ this.name = "RandomDrift";
+ }
+ RandomDrift.prototype.reset = function (driftX, driftY, delay, life, easing) {
+ if (typeof life === "undefined") { life = null; }
+ if (typeof easing === "undefined") { easing = null; }
+ this.panFoce = new Phaser.Vec2(driftX, driftY);
+ this.panFoce = this.normalizeForce(this.panFoce);
+ this.delay = delay;
+ if(life) {
+ this.life = Particles.ParticleUtils.initValue(life, Infinity);
+ this.easing = Particles.ParticleUtils.initValue(easing, Phaser.Easing.Linear.None);
+ }
+ };
+ RandomDrift.prototype.applyBehaviour = function (particle, time, index) {
+ _super.prototype.applyBehaviour.call(this, particle, time, index);
+ this.time += time;
+ if(this.time >= this.delay) {
+ particle.a.addXY(Particles.ParticleUtils.randomAToB(-this.panFoce.x, this.panFoce.x), Particles.ParticleUtils.randomAToB(-this.panFoce.y, this.panFoce.y));
+ this.time = 0;
+ }
+ };
+ return RandomDrift;
+ })(Behaviours.Behaviour);
+ Behaviours.RandomDrift = RandomDrift;
+ })(Particles.Behaviours || (Particles.Behaviours = {}));
+ var Behaviours = Particles.Behaviours;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Initialize = (function () {
+ function Initialize() { }
+ Initialize.prototype.initialize = function (target) {
+ };
+ Initialize.prototype.reset = function (a, b, c) {
+ };
+ Initialize.prototype.init = function (emitter, particle) {
+ if (typeof particle === "undefined") { particle = null; }
+ if(particle) {
+ this.initialize(particle);
+ } else {
+ this.initialize(emitter);
+ }
+ };
+ return Initialize;
+ })();
+ Initializers.Initialize = Initialize;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Life = (function (_super) {
+ __extends(Life, _super);
+ function Life(a, b, c) {
+ _super.call(this);
+ this.lifePan = Particles.ParticleUtils.setSpanValue(a, b, c);
+ }
+ Life.prototype.initialize = function (target) {
+ if(this.lifePan.a == Infinity) {
+ target.life = Infinity;
+ } else {
+ target.life = this.lifePan.getValue();
+ }
+ };
+ return Life;
+ })(Initializers.Initialize);
+ Initializers.Life = Life;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Mass = (function (_super) {
+ __extends(Mass, _super);
+ function Mass(a, b, c) {
+ _super.call(this);
+ this.massPan = Particles.ParticleUtils.setSpanValue(a, b, c);
+ }
+ Mass.prototype.initialize = function (target) {
+ target.mass = this.massPan.getValue();
+ };
+ return Mass;
+ })(Initializers.Initialize);
+ Initializers.Mass = Mass;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Position = (function (_super) {
+ __extends(Position, _super);
+ function Position(zone) {
+ _super.call(this);
+ if(zone != null && zone != undefined) {
+ this.zone = zone;
+ } else {
+ this.zone = new Phaser.Particles.Zones.PointZone();
+ }
+ }
+ Position.prototype.reset = function (zone) {
+ if(zone != null && zone != undefined) {
+ this.zone = zone;
+ } else {
+ this.zone = new Phaser.Particles.Zones.PointZone();
+ }
+ };
+ Position.prototype.initialize = function (target) {
+ this.zone.getPosition();
+ target.p.x = this.zone.vector.x;
+ target.p.y = this.zone.vector.y;
+ };
+ return Position;
+ })(Initializers.Initialize);
+ Initializers.Position = Position;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Rate = (function (_super) {
+ __extends(Rate, _super);
+ function Rate(numpan, timepan) {
+ _super.call(this);
+ numpan = Particles.ParticleUtils.initValue(numpan, 1);
+ timepan = Particles.ParticleUtils.initValue(timepan, 1);
+ this.numPan = new Phaser.Particles.Span(numpan);
+ this.timePan = new Phaser.Particles.Span(timepan);
+ this.startTime = 0;
+ this.nextTime = 0;
+ this.init();
+ }
+ Rate.prototype.init = function () {
+ this.startTime = 0;
+ this.nextTime = this.timePan.getValue();
+ };
+ Rate.prototype.getValue = function (time) {
+ this.startTime += time;
+ if(this.startTime >= this.nextTime) {
+ this.startTime = 0;
+ this.nextTime = this.timePan.getValue();
+ if(this.numPan.b == 1) {
+ if(this.numPan.getValue(false) > 0.5) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } else {
+ return this.numPan.getValue(true);
+ }
+ }
+ return 0;
+ };
+ return Rate;
+ })(Initializers.Initialize);
+ Initializers.Rate = Rate;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Velocity = (function (_super) {
+ __extends(Velocity, _super);
+ function Velocity(rpan, thapan, type) {
+ _super.call(this);
+ this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
+ this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
+ this.type = Particles.ParticleUtils.initValue(type, 'vector');
+ }
+ Velocity.prototype.reset = function (rpan, thapan, type) {
+ this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
+ this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
+ this.type = Particles.ParticleUtils.initValue(type, 'vector');
+ };
+ Velocity.prototype.normalizeVelocity = function (vr) {
+ return vr * Particles.ParticleManager.MEASURE;
+ };
+ Velocity.prototype.initialize = function (target) {
+ if(this.type == 'p' || this.type == 'P' || this.type == 'polar') {
+ var polar2d = new Particles.Polar2D(this.normalizeVelocity(this.rPan.getValue()), this.thaPan.getValue() * Math.PI / 180);
+ target.v.x = polar2d.getX();
+ target.v.y = polar2d.getY();
+ } else {
+ target.v.x = this.normalizeVelocity(this.rPan.getValue());
+ target.v.y = this.normalizeVelocity(this.thaPan.getValue());
+ }
+ };
+ return Velocity;
+ })(Initializers.Initialize);
+ Initializers.Velocity = Velocity;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Zones) {
+ var Zone = (function () {
+ function Zone() {
+ this.vector = new Phaser.Vec2();
+ this.random = 0;
+ this.crossType = "dead";
+ this.alert = true;
+ }
+ return Zone;
+ })();
+ Zones.Zone = Zone;
+ })(Particles.Zones || (Particles.Zones = {}));
+ var Zones = Particles.Zones;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Zones) {
+ var PointZone = (function (_super) {
+ __extends(PointZone, _super);
+ function PointZone(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ _super.call(this);
+ this.x = x;
+ this.y = y;
+ }
+ PointZone.prototype.getPosition = function () {
+ return this.vector.setTo(this.x, this.y);
+ };
+ PointZone.prototype.crossing = function (particle) {
+ if(this.alert) {
+ alert('Sorry PointZone does not support crossing method');
+ this.alert = false;
+ }
+ };
+ return PointZone;
+ })(Zones.Zone);
+ Zones.PointZone = PointZone;
+ })(Particles.Zones || (Particles.Zones = {}));
+ var Zones = Particles.Zones;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var World = (function () {
+ function World(game, width, height) {
+ this._groupCounter = 0;
+ this.game = game;
+ this.cameras = new Phaser.CameraManager(this.game, 0, 0, width, height);
+ this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ }
+ World.prototype.getNextGroupID = function () {
+ return this._groupCounter++;
+ };
+ World.prototype.boot = function () {
+ this.group = new Phaser.Group(this.game, 0);
+ };
+ World.prototype.update = function () {
+ this.group.update();
+ this.cameras.update();
+ };
+ World.prototype.postUpdate = function () {
+ this.group.postUpdate();
+ this.cameras.postUpdate();
+ };
+ World.prototype.destroy = function () {
+ this.group.destroy();
+ this.cameras.destroy();
+ };
+ World.prototype.setSize = function (width, height, updateCameraBounds) {
+ if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; }
+ this.bounds.width = width;
+ this.bounds.height = height;
+ if(updateCameraBounds == true) {
+ this.game.camera.setBounds(0, 0, width, height);
+ }
+ };
+ Object.defineProperty(World.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ set: function (value) {
+ this.bounds.width = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ set: function (value) {
+ this.bounds.height = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "centerX", {
+ get: function () {
+ return this.bounds.halfWidth;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "centerY", {
+ get: function () {
+ return this.bounds.halfHeight;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "randomX", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.width);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "randomY", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.height);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ World.prototype.getAllCameras = function () {
+ return this.cameras.getAll();
+ };
+ return World;
+ })();
+ Phaser.World = World;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Stage = (function () {
+ function Stage(game, parent, width, height) {
+ var _this = this;
+ this._backgroundColor = 'rgb(0,0,0)';
+ this.clear = true;
+ this.disablePauseScreen = false;
+ this.disableBootScreen = false;
+ this.disableVisibilityChange = false;
+ this.game = game;
+ this.canvas = document.createElement('canvas');
+ this.canvas.width = width;
+ this.canvas.height = height;
+ this.context = this.canvas.getContext('2d');
+ Phaser.CanvasUtils.addToDOM(this.canvas, parent, true);
+ Phaser.CanvasUtils.setTouchAction(this.canvas);
+ this.canvas.oncontextmenu = function (event) {
+ event.preventDefault();
+ };
+ this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
+ this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
+ this.scale = new Phaser.StageScaleMode(this.game, width, height);
+ this.getOffset(this.canvas);
+ this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, width, height);
+ this.aspectRatio = width / height;
+ document.addEventListener('visibilitychange', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ document.addEventListener('webkitvisibilitychange', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ document.addEventListener('pagehide', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ document.addEventListener('pageshow', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ window.onblur = function (event) {
+ return _this.visibilityChange(event);
+ };
+ window.onfocus = function (event) {
+ return _this.visibilityChange(event);
+ };
+ }
+ Stage.prototype.boot = function () {
+ this.bootScreen = new Phaser.BootScreen(this.game);
+ this.pauseScreen = new Phaser.PauseScreen(this.game, this.width, this.height);
+ this.orientationScreen = new Phaser.OrientationScreen(this.game);
+ this.scale.setScreenSize(true);
+ };
+ Stage.prototype.update = function () {
+ this.scale.update();
+ this.context.setTransform(1, 0, 0, 1, 0, 0);
+ if(this.clear || (this.game.paused && this.disablePauseScreen == false)) {
+ if(this.game.device.patchAndroidClearRectBug) {
+ this.context.fillStyle = this._backgroundColor;
+ this.context.fillRect(0, 0, this.width, this.height);
+ } else {
+ this.context.clearRect(0, 0, this.width, this.height);
+ }
+ }
+ if(this.game.paused && this.scale.incorrectOrientation) {
+ this.orientationScreen.update();
+ this.orientationScreen.render();
+ return;
+ }
+ if(this.game.isRunning == false && this.disableBootScreen == false) {
+ this.bootScreen.update();
+ this.bootScreen.render();
+ }
+ if(this.game.paused && this.disablePauseScreen == false) {
+ this.pauseScreen.update();
+ this.pauseScreen.render();
+ }
+ };
+ Stage.prototype.visibilityChange = function (event) {
+ if(this.disableVisibilityChange) {
+ return;
+ }
+ if(event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) {
+ if(this.game.paused == false) {
+ this.pauseGame();
+ }
+ } else {
+ if(this.game.paused == true) {
+ this.resumeGame();
+ }
+ }
+ };
+ Stage.prototype.enableOrientationCheck = function (forceLandscape, forcePortrait, imageKey) {
+ if (typeof imageKey === "undefined") { imageKey = ''; }
+ this.scale.forceLandscape = forceLandscape;
+ this.scale.forcePortrait = forcePortrait;
+ this.orientationScreen.enable(imageKey);
+ if(forceLandscape || forcePortrait) {
+ if((this.scale.isLandscape && forcePortrait) || (this.scale.isPortrait && forceLandscape)) {
+ this.game.paused = true;
+ this.scale.incorrectOrientation = true;
+ } else {
+ this.scale.incorrectOrientation = false;
+ }
+ }
+ };
+ Stage.prototype.pauseGame = function () {
+ this.game.paused = true;
+ if(this.disablePauseScreen == false && this.pauseScreen) {
+ this.pauseScreen.onPaused();
+ }
+ this.saveCanvasValues();
+ };
+ Stage.prototype.resumeGame = function () {
+ if(this.disablePauseScreen == false && this.pauseScreen) {
+ this.pauseScreen.onResume();
+ }
+ this.restoreCanvasValues();
+ this.game.paused = false;
+ };
+ Stage.prototype.getOffset = function (element, populateOffset) {
+ if (typeof populateOffset === "undefined") { populateOffset = true; }
+ var box = element.getBoundingClientRect();
+ var clientTop = element.clientTop || document.body.clientTop || 0;
+ var clientLeft = element.clientLeft || document.body.clientLeft || 0;
+ var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop;
+ var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft;
+ if(populateOffset) {
+ this.offset = new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
+ return this.offset;
+ } else {
+ return new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
+ }
+ };
+ Stage.prototype.saveCanvasValues = function () {
+ this.strokeStyle = this.context.strokeStyle;
+ this.lineWidth = this.context.lineWidth;
+ this.fillStyle = this.context.fillStyle;
+ };
+ Stage.prototype.restoreCanvasValues = function () {
+ this.context.strokeStyle = this.strokeStyle;
+ this.context.lineWidth = this.lineWidth;
+ this.context.fillStyle = this.fillStyle;
+ if(this.game.device.patchAndroidClearRectBug) {
+ this.context.fillStyle = this._backgroundColor;
+ this.context.fillRect(0, 0, this.width, this.height);
+ } else {
+ this.context.clearRect(0, 0, this.width, this.height);
+ }
+ };
+ Object.defineProperty(Stage.prototype, "backgroundColor", {
+ get: function () {
+ return this._backgroundColor;
+ },
+ set: function (color) {
+ this.canvas.style.backgroundColor = color;
+ this._backgroundColor = color;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "x", {
+ get: function () {
+ return this.bounds.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "y", {
+ get: function () {
+ return this.bounds.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "centerX", {
+ get: function () {
+ return this.bounds.halfWidth;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "centerY", {
+ get: function () {
+ return this.bounds.halfHeight;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "randomX", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.width);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "randomY", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.height);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Stage;
+ })();
+ Phaser.Stage = Stage;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var State = (function () {
+ 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.sound = game.sound;
+ this.stage = game.stage;
+ this.time = game.time;
+ this.tweens = game.tweens;
+ this.world = game.world;
+ }
+ State.prototype.init = function () {
+ };
+ State.prototype.create = function () {
+ };
+ State.prototype.update = function () {
+ };
+ State.prototype.render = function () {
+ };
+ State.prototype.paused = function () {
+ };
+ State.prototype.destroy = function () {
+ };
+ return State;
+ })();
+ Phaser.State = State;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Game = (function () {
+ function Game(callbackContext, parent, width, height, preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
+ if (typeof parent === "undefined") { parent = ''; }
+ if (typeof width === "undefined") { width = 800; }
+ if (typeof height === "undefined") { height = 600; }
+ if (typeof preloadCallback === "undefined") { preloadCallback = null; }
+ if (typeof createCallback === "undefined") { createCallback = null; }
+ if (typeof updateCallback === "undefined") { updateCallback = null; }
+ if (typeof renderCallback === "undefined") { renderCallback = null; }
+ if (typeof destroyCallback === "undefined") { destroyCallback = null; }
+ var _this = this;
+ this._loadComplete = false;
+ this._paused = false;
+ this._pendingState = null;
+ this.state = null;
+ this.onPreloadCallback = null;
+ this.onCreateCallback = null;
+ this.onUpdateCallback = null;
+ this.onRenderCallback = null;
+ this.onPreRenderCallback = null;
+ this.onLoadUpdateCallback = null;
+ this.onLoadRenderCallback = null;
+ this.onPausedCallback = null;
+ this.onDestroyCallback = null;
+ this.isBooted = false;
+ this.isRunning = false;
+ if(window['PhaserGlobal'] && window['PhaserGlobal'].singleInstance) {
+ if(Phaser.GAMES.length > 0) {
+ console.log('Phaser detected an instance of this game already running, aborting');
+ return;
+ }
+ }
+ this.id = Phaser.GAMES.push(this) - 1;
+ this.callbackContext = callbackContext;
+ this.onPreloadCallback = preloadCallback;
+ this.onCreateCallback = createCallback;
+ this.onUpdateCallback = updateCallback;
+ this.onRenderCallback = renderCallback;
+ this.onDestroyCallback = destroyCallback;
+ if(document.readyState === 'complete' || document.readyState === 'interactive') {
+ setTimeout(function () {
+ return Phaser.GAMES[_this.id].boot(parent, width, height);
+ });
+ } else {
+ document.addEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot(parent, width, height), false);
+ window.addEventListener('load', Phaser.GAMES[this.id].boot(parent, width, height), false);
+ }
+ }
+ Game.prototype.boot = function (parent, width, height) {
+ var _this = this;
+ if(this.isBooted == true) {
+ return;
+ }
+ if(!document.body) {
+ setTimeout(function () {
+ return Phaser.GAMES[_this.id].boot(parent, width, height);
+ }, 13);
+ } else {
+ document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
+ window.removeEventListener('load', Phaser.GAMES[this.id].boot);
+ this.onPause = new Phaser.Signal();
+ this.onResume = new Phaser.Signal();
+ this.device = new Phaser.Device();
+ this.net = new Phaser.Net(this);
+ this.math = new Phaser.GameMath(this);
+ this.stage = new Phaser.Stage(this, parent, width, height);
+ this.world = new Phaser.World(this, width, height);
+ this.add = new Phaser.GameObjectFactory(this);
+ this.cache = new Phaser.Cache(this);
+ this.load = new Phaser.Loader(this);
+ this.time = new Phaser.TimeManager(this);
+ this.tweens = new Phaser.TweenManager(this);
+ this.input = new Phaser.InputManager(this);
+ this.sound = new Phaser.SoundManager(this);
+ this.rnd = new Phaser.RandomDataGenerator([
+ (Date.now() * Math.random()).toString()
+ ]);
+ this.physics = new Phaser.Physics.PhysicsManager(this);
+ this.plugins = new Phaser.PluginManager(this, this);
+ this.load.onLoadComplete.add(this.loadComplete, this);
+ this.setRenderer(Phaser.Types.RENDERER_CANVAS);
+ this.world.boot();
+ this.stage.boot();
+ this.input.boot();
+ this.isBooted = true;
+ Phaser.DebugUtils.game = this;
+ Phaser.ColorUtils.game = this;
+ Phaser.DebugUtils.context = this.stage.context;
+ if(this.onPreloadCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null) {
+ this._raf = new Phaser.RequestAnimationFrame(this, this.bootLoop);
+ } else {
+ this.isRunning = true;
+ this._loadComplete = false;
+ this._raf = new Phaser.RequestAnimationFrame(this, this.loop);
+ if(this._pendingState) {
+ this.switchState(this._pendingState, false, false);
+ } else {
+ this.startState();
+ }
+ }
+ }
+ };
+ Game.prototype.loadComplete = function () {
+ this._loadComplete = true;
+ this.onCreateCallback.call(this.callbackContext);
+ };
+ Game.prototype.bootLoop = function () {
+ this.tweens.update();
+ this.input.update();
+ this.stage.update();
+ };
+ Game.prototype.pausedLoop = function () {
+ this.tweens.update();
+ this.input.update();
+ this.stage.update();
+ this.sound.update();
+ if(this.onPausedCallback !== null) {
+ this.onPausedCallback.call(this.callbackContext);
+ }
+ };
+ Game.prototype.loop = function () {
+ this.plugins.preUpdate();
+ this.tweens.update();
+ this.input.update();
+ this.stage.update();
+ this.sound.update();
+ this.physics.update();
+ this.world.update();
+ this.plugins.update();
+ if(this._loadComplete && this.onUpdateCallback) {
+ this.onUpdateCallback.call(this.callbackContext);
+ } else if(this._loadComplete == false && this.onLoadUpdateCallback) {
+ this.onLoadUpdateCallback.call(this.callbackContext);
+ }
+ this.world.postUpdate();
+ this.plugins.postUpdate();
+ this.plugins.preRender();
+ if(this._loadComplete && this.onPreRenderCallback) {
+ this.onPreRenderCallback.call(this.callbackContext);
+ }
+ this.renderer.render();
+ this.plugins.render();
+ if(this._loadComplete && this.onRenderCallback) {
+ this.onRenderCallback.call(this.callbackContext);
+ } else if(this._loadComplete == false && this.onLoadRenderCallback) {
+ this.onLoadRenderCallback.call(this.callbackContext);
+ }
+ this.plugins.postRender();
+ };
+ Game.prototype.startState = function () {
+ if(this.onPreloadCallback !== null) {
+ this.load.reset();
+ this.onPreloadCallback.call(this.callbackContext);
+ if(this.load.queueSize == 0) {
+ if(this.onCreateCallback !== null) {
+ this.onCreateCallback.call(this.callbackContext);
+ }
+ this._loadComplete = true;
+ } else {
+ this.load.onLoadComplete.add(this.loadComplete, this);
+ this.load.start();
+ }
+ } else {
+ if(this.onCreateCallback !== null) {
+ this.onCreateCallback.call(this.callbackContext);
+ }
+ this._loadComplete = true;
+ }
+ };
+ Game.prototype.setRenderer = function (renderer) {
+ switch(renderer) {
+ case Phaser.Types.RENDERER_AUTO_DETECT:
+ this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
+ break;
+ case Phaser.Types.RENDERER_AUTO_DETECT:
+ case Phaser.Types.RENDERER_CANVAS:
+ this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
+ break;
+ }
+ };
+ Game.prototype.setCallbacks = function (preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
+ if (typeof preloadCallback === "undefined") { preloadCallback = null; }
+ if (typeof createCallback === "undefined") { createCallback = null; }
+ if (typeof updateCallback === "undefined") { updateCallback = null; }
+ if (typeof renderCallback === "undefined") { renderCallback = null; }
+ if (typeof destroyCallback === "undefined") { destroyCallback = null; }
+ this.onPreloadCallback = preloadCallback;
+ this.onCreateCallback = createCallback;
+ this.onUpdateCallback = updateCallback;
+ this.onRenderCallback = renderCallback;
+ this.onDestroyCallback = destroyCallback;
+ };
+ Game.prototype.switchState = function (state, clearWorld, clearCache) {
+ if (typeof clearWorld === "undefined") { clearWorld = true; }
+ if (typeof clearCache === "undefined") { clearCache = false; }
+ if(this.isBooted == false) {
+ this._pendingState = state;
+ return;
+ }
+ if(this.onDestroyCallback !== null) {
+ this.onDestroyCallback.call(this.callbackContext);
+ }
+ this.input.reset(true);
+ if(typeof state === 'function') {
+ this.state = new state(this);
+ } else {
+ this.state = state;
+ }
+ if(this.state['create'] || this.state['update']) {
+ this.callbackContext = this.state;
+ this.onPreloadCallback = null;
+ this.onLoadRenderCallback = null;
+ this.onLoadUpdateCallback = null;
+ this.onCreateCallback = null;
+ this.onUpdateCallback = null;
+ this.onRenderCallback = null;
+ this.onPreRenderCallback = null;
+ this.onPausedCallback = null;
+ this.onDestroyCallback = null;
+ if(this.state['preload']) {
+ this.onPreloadCallback = this.state['preload'];
+ }
+ if(this.state['loadRender']) {
+ this.onLoadRenderCallback = this.state['loadRender'];
+ }
+ if(this.state['loadUpdate']) {
+ this.onLoadUpdateCallback = this.state['loadUpdate'];
+ }
+ if(this.state['create']) {
+ this.onCreateCallback = this.state['create'];
+ }
+ if(this.state['update']) {
+ this.onUpdateCallback = this.state['update'];
+ }
+ if(this.state['preRender']) {
+ this.onPreRenderCallback = this.state['preRender'];
+ }
+ if(this.state['render']) {
+ this.onRenderCallback = this.state['render'];
+ }
+ if(this.state['paused']) {
+ this.onPausedCallback = this.state['paused'];
+ }
+ if(this.state['destroy']) {
+ this.onDestroyCallback = this.state['destroy'];
+ }
+ if(clearWorld) {
+ this.world.destroy();
+ if(clearCache == true) {
+ this.cache.destroy();
+ }
+ }
+ this._loadComplete = false;
+ this.startState();
+ } else {
+ throw new Error("Invalid State object given. Must contain at least a create or update function.");
+ }
+ };
+ Game.prototype.destroy = function () {
+ this.callbackContext = null;
+ this.onPreloadCallback = null;
+ this.onLoadRenderCallback = null;
+ this.onLoadUpdateCallback = null;
+ this.onCreateCallback = null;
+ this.onUpdateCallback = null;
+ this.onRenderCallback = null;
+ this.onPausedCallback = null;
+ this.onDestroyCallback = null;
+ this.cache = null;
+ this.input = null;
+ this.load = null;
+ this.sound = null;
+ this.stage = null;
+ this.time = null;
+ this.world = null;
+ this.isBooted = false;
+ };
+ Object.defineProperty(Game.prototype, "paused", {
+ get: function () {
+ return this._paused;
+ },
+ set: function (value) {
+ if(value == true && this._paused == false) {
+ this._paused = true;
+ this.onPause.dispatch();
+ this.sound.pauseAll();
+ this._raf.callback = this.pausedLoop;
+ } else if(value == false && this._paused == true) {
+ this._paused = false;
+ this.onResume.dispatch();
+ this.input.reset();
+ this.sound.resumeAll();
+ if(this.isRunning == false) {
+ this._raf.callback = this.bootLoop;
+ } else {
+ this._raf.callback = this.loop;
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Game.prototype, "camera", {
+ get: function () {
+ return this.world.cameras.current;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Game;
+ })();
+ Phaser.Game = Game;
+})(Phaser || (Phaser = {}));
diff --git a/Tests/phaser-mobile.css b/TS Tests/phaser-mobile.css
similarity index 100%
rename from Tests/phaser-mobile.css
rename to TS Tests/phaser-mobile.css
diff --git a/Tests/phaser.css b/TS Tests/phaser.css
similarity index 100%
rename from Tests/phaser.css
rename to TS Tests/phaser.css
diff --git a/Tests/physics/circle 1.js b/TS Tests/physics/circle 1.js
similarity index 69%
rename from Tests/physics/circle 1.js
rename to TS Tests/physics/circle 1.js
index c6e43519..6b35e540 100644
--- a/Tests/physics/circle 1.js
+++ b/TS Tests/physics/circle 1.js
@@ -14,9 +14,14 @@
function create() {
//this.ball = game.add.sprite(0, 0, 'ball');
carrot = game.add.sprite(300, 50, 'carrot');
+ // N+ motion version
+ carrot.body.aabb.drag.setTo(1, 1);
+ carrot.body.aabb.bounce.setTo(0.3, 0.3);
+ carrot.body.aabb.gravity.setTo(0, 0.3);
+ //carrot.body.aabb.bounce.setTo(0.5, 0.5);
//carrot.body.aabb.drag.x = 50;
//carrot.body.aabb.drag.y = 50;
- carrot.body.aabb.velocity.y = 250;
+ //carrot.body.aabb.velocity.y = 250;
//this.b = game.add.aabb(game.stage.randomX, 200, 22, 21);
//this.c = game.add.circle(200, 200, 16);
// pos is center, not upper-left
@@ -25,8 +30,10 @@
for(var i = 0; i < 10; i++) {
if(i % 2 == 0) {
tid = Phaser.Physics.TileMapCell.TID_CONCAVEpn;
- } else {
- tid = Phaser.Physics.TileMapCell.TID_CONCAVEnn;
+ //tid = Phaser.Physics.TileMapCell.TID_45DEGpn;
+ } else {
+ //tid = Phaser.Physics.TileMapCell.TID_CONCAVEnn;
+ tid = Phaser.Physics.TileMapCell.TID_45DEGnn;
}
//tid = Phaser.Physics.TileMapCell.TID_FULL;
this.cells.push(game.add.cell(100 + (i * 100), 400, 50, 50, tid));
@@ -54,24 +61,40 @@
{
carrot.body.aabb.acceleration.y = 200;
}
+
+ carrot.body.aabb.FFupdate();
+
*/
// This works but it's a static motion (no easing / acceleration)
//carrot.body.aabb.velocity.x = 0;
//carrot.body.aabb.velocity.y = 0;
+ /*
var s = 200;
- if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
- carrot.body.aabb.velocity.x = -s;
- } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
- carrot.body.aabb.velocity.x = s;
+
+ if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
+ {
+ carrot.body.aabb.velocity.x = -s;
}
- if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
- carrot.body.aabb.velocity.y = -s;
- } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
- carrot.body.aabb.velocity.y = s;
+ else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
+ {
+ carrot.body.aabb.velocity.x = s;
}
+
+ if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
+ {
+ carrot.body.aabb.velocity.y = -s;
+ }
+ else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
+ {
+ carrot.body.aabb.velocity.y = s;
+ }
+
+ carrot.body.aabb.FFupdate();
+
+ */
/*
- // This works but no acceleration and the gravity values are insanely sensitive
+ // N+ motion - This works but no acceleration and the gravity values are insanely sensitive
carrot.body.aabb._vx = 0;
carrot.body.aabb._vy = 0;
@@ -87,13 +110,30 @@
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
- carrot.body.aabb._vy = -0.4;
+ carrot.body.aabb._vy = -(0.2 + carrot.body.aabb.gravity.y);
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
carrot.body.aabb._vy = 0.2;
}
+
+ carrot.body.aabb.update();
+
*/
+ // N+ with Flixel Compute
+ carrot.body.aabb.velocity.x = 0;
+ carrot.body.aabb.velocity.y = 0;
+ var s = 50;
+ if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
+ carrot.body.aabb.velocity.x = -s;
+ } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
+ carrot.body.aabb.velocity.x = s;
+ }
+ if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
+ carrot.body.aabb.velocity.y = -s;
+ } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
+ carrot.body.aabb.velocity.y = s;
+ }
carrot.body.aabb.update();
carrot.body.aabb.collideAABBVsWorldBounds();
for(var i = 0; i < this.cells.length; i++) {
@@ -114,12 +154,12 @@
for(var i = 0; i < this.cells.length; i++) {
this.cells[i].render(game.stage.context);
}
- //Phaser.DebugUtils.renderText('dx: ' + carrot.body.deltaX, 32, 32);
- //Phaser.DebugUtils.renderText('dy: ' + carrot.body.deltaY, 32, 64);
- Phaser.DebugUtils.renderText('vx: ' + carrot.body.aabb.velocity.x, 32, 32);
- Phaser.DebugUtils.renderText('vy: ' + carrot.body.aabb.velocity.y, 32, 64);
- //Phaser.DebugUtils.renderText('delta: ' + game.time.delta, 32, 90);
- //Phaser.DebugUtils.renderText('phye: ' + game.time.physicsElapsed, 32, 110);
+ Phaser.DebugUtils.renderText('dx: ' + carrot.body.aabb._deltaX, 32, 32);
+ Phaser.DebugUtils.renderText('dy: ' + carrot.body.aabb._deltaY, 32, 64);
+ Phaser.DebugUtils.renderText('vx: ' + carrot.body.aabb.velocity.x, 432, 32);
+ Phaser.DebugUtils.renderText('vy: ' + carrot.body.aabb.velocity.y, 432, 64);
+ Phaser.DebugUtils.renderText('delta: ' + game.time.delta, 32, 90);
+ Phaser.DebugUtils.renderText('phye: ' + game.time.physicsElapsed, 32, 110);
Phaser.DebugUtils.renderText('vxd: ' + carrot.body.aabb._vx, 32, 130);
Phaser.DebugUtils.renderText('vyd: ' + carrot.body.aabb._vy, 32, 150);
}
diff --git a/Tests/physics/circle 1.ts b/TS Tests/physics/circle 1.ts
similarity index 71%
rename from Tests/physics/circle 1.ts
rename to TS Tests/physics/circle 1.ts
index 41d2b42c..90447164 100644
--- a/Tests/physics/circle 1.ts
+++ b/TS Tests/physics/circle 1.ts
@@ -23,9 +23,19 @@
//this.ball = game.add.sprite(0, 0, 'ball');
carrot = game.add.sprite(300, 50, 'carrot');
+
+ // N+ motion version
+ carrot.body.aabb.drag.setTo(1, 1);
+ carrot.body.aabb.bounce.setTo(0.3, 0.3);
+ carrot.body.aabb.gravity.setTo(0, 0.3);
+
+
+
+
+ //carrot.body.aabb.bounce.setTo(0.5, 0.5);
//carrot.body.aabb.drag.x = 50;
//carrot.body.aabb.drag.y = 50;
- carrot.body.aabb.velocity.y = 250;
+ //carrot.body.aabb.velocity.y = 250;
//this.b = game.add.aabb(game.stage.randomX, 200, 22, 21);
//this.c = game.add.circle(200, 200, 16);
@@ -40,10 +50,12 @@
if (i % 2 == 0)
{
tid = Phaser.Physics.TileMapCell.TID_CONCAVEpn;
+ //tid = Phaser.Physics.TileMapCell.TID_45DEGpn;
}
else
{
- tid = Phaser.Physics.TileMapCell.TID_CONCAVEnn;
+ //tid = Phaser.Physics.TileMapCell.TID_CONCAVEnn;
+ tid = Phaser.Physics.TileMapCell.TID_45DEGnn;
}
//tid = Phaser.Physics.TileMapCell.TID_FULL;
@@ -76,12 +88,16 @@
{
carrot.body.aabb.acceleration.y = 200;
}
+
+ carrot.body.aabb.FFupdate();
+
*/
// This works but it's a static motion (no easing / acceleration)
//carrot.body.aabb.velocity.x = 0;
//carrot.body.aabb.velocity.y = 0;
+ /*
var s = 200;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
@@ -102,9 +118,13 @@
carrot.body.aabb.velocity.y = s;
}
+ carrot.body.aabb.FFupdate();
+
+ */
+
/*
- // This works but no acceleration and the gravity values are insanely sensitive
+ // N+ motion - This works but no acceleration and the gravity values are insanely sensitive
carrot.body.aabb._vx = 0;
carrot.body.aabb._vy = 0;
@@ -120,17 +140,45 @@
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
- carrot.body.aabb._vy = -0.4;
+ carrot.body.aabb._vy = -(0.2 + carrot.body.aabb.gravity.y);
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
carrot.body.aabb._vy = 0.2;
}
- */
-
carrot.body.aabb.update();
+ */
+
+ // N+ with Flixel Compute
+ carrot.body.aabb.velocity.x = 0;
+ carrot.body.aabb.velocity.y = 0;
+
+ var s = 50;
+
+ if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
+ {
+ carrot.body.aabb.velocity.x = -s;
+ }
+ else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
+ {
+ carrot.body.aabb.velocity.x = s;
+ }
+
+ if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
+ {
+ carrot.body.aabb.velocity.y = -s;
+ }
+ else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
+ {
+ carrot.body.aabb.velocity.y = s;
+ }
+
+ carrot.body.aabb.update();
+
+
+
carrot.body.aabb.collideAABBVsWorldBounds();
for (var i = 0; i < this.cells.length; i++)
@@ -160,12 +208,12 @@
this.cells[i].render(game.stage.context);
}
- //Phaser.DebugUtils.renderText('dx: ' + carrot.body.deltaX, 32, 32);
- //Phaser.DebugUtils.renderText('dy: ' + carrot.body.deltaY, 32, 64);
- Phaser.DebugUtils.renderText('vx: ' + carrot.body.aabb.velocity.x, 32, 32);
- Phaser.DebugUtils.renderText('vy: ' + carrot.body.aabb.velocity.y, 32, 64);
- //Phaser.DebugUtils.renderText('delta: ' + game.time.delta, 32, 90);
- //Phaser.DebugUtils.renderText('phye: ' + game.time.physicsElapsed, 32, 110);
+ Phaser.DebugUtils.renderText('dx: ' + carrot.body.aabb._deltaX, 32, 32);
+ Phaser.DebugUtils.renderText('dy: ' + carrot.body.aabb._deltaY, 32, 64);
+ Phaser.DebugUtils.renderText('vx: ' + carrot.body.aabb.velocity.x, 432, 32);
+ Phaser.DebugUtils.renderText('vy: ' + carrot.body.aabb.velocity.y, 432, 64);
+ Phaser.DebugUtils.renderText('delta: ' + game.time.delta, 32, 90);
+ Phaser.DebugUtils.renderText('phye: ' + game.time.physicsElapsed, 32, 110);
Phaser.DebugUtils.renderText('vxd: ' + carrot.body.aabb._vx, 32, 130);
Phaser.DebugUtils.renderText('vyd: ' + carrot.body.aabb._vy, 32, 150);
diff --git a/Tests/physics/sprite bounds.js b/TS Tests/physics/sprite bounds.js
similarity index 100%
rename from Tests/physics/sprite bounds.js
rename to TS Tests/physics/sprite bounds.js
diff --git a/Tests/physics/sprite bounds.ts b/TS Tests/physics/sprite bounds.ts
similarity index 100%
rename from Tests/physics/sprite bounds.ts
rename to TS Tests/physics/sprite bounds.ts
diff --git a/Tests/scrollzones/ballscroller.js b/TS Tests/scrollzones/ballscroller.js
similarity index 100%
rename from Tests/scrollzones/ballscroller.js
rename to TS Tests/scrollzones/ballscroller.js
diff --git a/Tests/scrollzones/ballscroller.ts b/TS Tests/scrollzones/ballscroller.ts
similarity index 100%
rename from Tests/scrollzones/ballscroller.ts
rename to TS Tests/scrollzones/ballscroller.ts
diff --git a/Tests/scrollzones/blasteroids.js b/TS Tests/scrollzones/blasteroids.js
similarity index 100%
rename from Tests/scrollzones/blasteroids.js
rename to TS Tests/scrollzones/blasteroids.js
diff --git a/Tests/scrollzones/blasteroids.ts b/TS Tests/scrollzones/blasteroids.ts
similarity index 100%
rename from Tests/scrollzones/blasteroids.ts
rename to TS Tests/scrollzones/blasteroids.ts
diff --git a/Tests/scrollzones/parallax.js b/TS Tests/scrollzones/parallax.js
similarity index 100%
rename from Tests/scrollzones/parallax.js
rename to TS Tests/scrollzones/parallax.js
diff --git a/Tests/scrollzones/parallax.ts b/TS Tests/scrollzones/parallax.ts
similarity index 100%
rename from Tests/scrollzones/parallax.ts
rename to TS Tests/scrollzones/parallax.ts
diff --git a/Tests/scrollzones/region demo.js b/TS Tests/scrollzones/region demo.js
similarity index 100%
rename from Tests/scrollzones/region demo.js
rename to TS Tests/scrollzones/region demo.js
diff --git a/Tests/scrollzones/region demo.ts b/TS Tests/scrollzones/region demo.ts
similarity index 100%
rename from Tests/scrollzones/region demo.ts
rename to TS Tests/scrollzones/region demo.ts
diff --git a/Tests/scrollzones/scroll window.js b/TS Tests/scrollzones/scroll window.js
similarity index 100%
rename from Tests/scrollzones/scroll window.js
rename to TS Tests/scrollzones/scroll window.js
diff --git a/Tests/scrollzones/scroll window.ts b/TS Tests/scrollzones/scroll window.ts
similarity index 100%
rename from Tests/scrollzones/scroll window.ts
rename to TS Tests/scrollzones/scroll window.ts
diff --git a/Tests/scrollzones/simple scrollzone.js b/TS Tests/scrollzones/simple scrollzone.js
similarity index 100%
rename from Tests/scrollzones/simple scrollzone.js
rename to TS Tests/scrollzones/simple scrollzone.js
diff --git a/Tests/scrollzones/simple scrollzone.ts b/TS Tests/scrollzones/simple scrollzone.ts
similarity index 100%
rename from Tests/scrollzones/simple scrollzone.ts
rename to TS Tests/scrollzones/simple scrollzone.ts
diff --git a/Tests/scrollzones/skewed scroller.js b/TS Tests/scrollzones/skewed scroller.js
similarity index 100%
rename from Tests/scrollzones/skewed scroller.js
rename to TS Tests/scrollzones/skewed scroller.js
diff --git a/Tests/scrollzones/skewed scroller.ts b/TS Tests/scrollzones/skewed scroller.ts
similarity index 100%
rename from Tests/scrollzones/skewed scroller.ts
rename to TS Tests/scrollzones/skewed scroller.ts
diff --git a/Tests/sprites/alpha.js b/TS Tests/sprites/alpha.js
similarity index 100%
rename from Tests/sprites/alpha.js
rename to TS Tests/sprites/alpha.js
diff --git a/Tests/sprites/alpha.ts b/TS Tests/sprites/alpha.ts
similarity index 100%
rename from Tests/sprites/alpha.ts
rename to TS Tests/sprites/alpha.ts
diff --git a/Tests/sprites/animate by framename.js b/TS Tests/sprites/animate by framename.js
similarity index 100%
rename from Tests/sprites/animate by framename.js
rename to TS Tests/sprites/animate by framename.js
diff --git a/Tests/sprites/animate by framename.ts b/TS Tests/sprites/animate by framename.ts
similarity index 100%
rename from Tests/sprites/animate by framename.ts
rename to TS Tests/sprites/animate by framename.ts
diff --git a/Tests/sprites/animation 1.js b/TS Tests/sprites/animation 1.js
similarity index 100%
rename from Tests/sprites/animation 1.js
rename to TS Tests/sprites/animation 1.js
diff --git a/Tests/sprites/animation 1.ts b/TS Tests/sprites/animation 1.ts
similarity index 100%
rename from Tests/sprites/animation 1.ts
rename to TS Tests/sprites/animation 1.ts
diff --git a/Tests/sprites/animation 2.js b/TS Tests/sprites/animation 2.js
similarity index 100%
rename from Tests/sprites/animation 2.js
rename to TS Tests/sprites/animation 2.js
diff --git a/Tests/sprites/animation 2.ts b/TS Tests/sprites/animation 2.ts
similarity index 100%
rename from Tests/sprites/animation 2.ts
rename to TS Tests/sprites/animation 2.ts
diff --git a/Tests/sprites/create sprite 1.js b/TS Tests/sprites/create sprite 1.js
similarity index 100%
rename from Tests/sprites/create sprite 1.js
rename to TS Tests/sprites/create sprite 1.js
diff --git a/Tests/sprites/create sprite 1.ts b/TS Tests/sprites/create sprite 1.ts
similarity index 100%
rename from Tests/sprites/create sprite 1.ts
rename to TS Tests/sprites/create sprite 1.ts
diff --git a/Tests/sprites/origin 5.js b/TS Tests/sprites/origin 5.js
similarity index 100%
rename from Tests/sprites/origin 5.js
rename to TS Tests/sprites/origin 5.js
diff --git a/Tests/sprites/origin 5.ts b/TS Tests/sprites/origin 5.ts
similarity index 100%
rename from Tests/sprites/origin 5.ts
rename to TS Tests/sprites/origin 5.ts
diff --git a/Tests/sprites/out of screen.js b/TS Tests/sprites/out of screen.js
similarity index 100%
rename from Tests/sprites/out of screen.js
rename to TS Tests/sprites/out of screen.js
diff --git a/Tests/sprites/out of screen.ts b/TS Tests/sprites/out of screen.ts
similarity index 100%
rename from Tests/sprites/out of screen.ts
rename to TS Tests/sprites/out of screen.ts
diff --git a/Tests/sprites/rotate around.js b/TS Tests/sprites/rotate around.js
similarity index 100%
rename from Tests/sprites/rotate around.js
rename to TS Tests/sprites/rotate around.js
diff --git a/Tests/sprites/rotate around.ts b/TS Tests/sprites/rotate around.ts
similarity index 100%
rename from Tests/sprites/rotate around.ts
rename to TS Tests/sprites/rotate around.ts
diff --git a/Tests/sprites/scale sprite 1.js b/TS Tests/sprites/scale sprite 1.js
similarity index 100%
rename from Tests/sprites/scale sprite 1.js
rename to TS Tests/sprites/scale sprite 1.js
diff --git a/Tests/sprites/scale sprite 1.ts b/TS Tests/sprites/scale sprite 1.ts
similarity index 100%
rename from Tests/sprites/scale sprite 1.ts
rename to TS Tests/sprites/scale sprite 1.ts
diff --git a/Tests/sprites/scale sprite 2.js b/TS Tests/sprites/scale sprite 2.js
similarity index 100%
rename from Tests/sprites/scale sprite 2.js
rename to TS Tests/sprites/scale sprite 2.js
diff --git a/Tests/sprites/scale sprite 2.ts b/TS Tests/sprites/scale sprite 2.ts
similarity index 100%
rename from Tests/sprites/scale sprite 2.ts
rename to TS Tests/sprites/scale sprite 2.ts
diff --git a/Tests/sprites/scale sprite 3.js b/TS Tests/sprites/scale sprite 3.js
similarity index 100%
rename from Tests/sprites/scale sprite 3.js
rename to TS Tests/sprites/scale sprite 3.js
diff --git a/Tests/sprites/scale sprite 3.ts b/TS Tests/sprites/scale sprite 3.ts
similarity index 100%
rename from Tests/sprites/scale sprite 3.ts
rename to TS Tests/sprites/scale sprite 3.ts
diff --git a/Tests/sprites/scale sprite 4.js b/TS Tests/sprites/scale sprite 4.js
similarity index 100%
rename from Tests/sprites/scale sprite 4.js
rename to TS Tests/sprites/scale sprite 4.js
diff --git a/Tests/sprites/scale sprite 4.ts b/TS Tests/sprites/scale sprite 4.ts
similarity index 100%
rename from Tests/sprites/scale sprite 4.ts
rename to TS Tests/sprites/scale sprite 4.ts
diff --git a/Tests/sprites/scale sprite 5.js b/TS Tests/sprites/scale sprite 5.js
similarity index 100%
rename from Tests/sprites/scale sprite 5.js
rename to TS Tests/sprites/scale sprite 5.js
diff --git a/Tests/sprites/scale sprite 5.ts b/TS Tests/sprites/scale sprite 5.ts
similarity index 100%
rename from Tests/sprites/scale sprite 5.ts
rename to TS Tests/sprites/scale sprite 5.ts
diff --git a/Tests/sprites/sprite origin 1.js b/TS Tests/sprites/sprite origin 1.js
similarity index 100%
rename from Tests/sprites/sprite origin 1.js
rename to TS Tests/sprites/sprite origin 1.js
diff --git a/Tests/sprites/sprite origin 1.ts b/TS Tests/sprites/sprite origin 1.ts
similarity index 100%
rename from Tests/sprites/sprite origin 1.ts
rename to TS Tests/sprites/sprite origin 1.ts
diff --git a/Tests/sprites/sprite origin 2.js b/TS Tests/sprites/sprite origin 2.js
similarity index 100%
rename from Tests/sprites/sprite origin 2.js
rename to TS Tests/sprites/sprite origin 2.js
diff --git a/Tests/sprites/sprite origin 2.ts b/TS Tests/sprites/sprite origin 2.ts
similarity index 100%
rename from Tests/sprites/sprite origin 2.ts
rename to TS Tests/sprites/sprite origin 2.ts
diff --git a/Tests/sprites/sprite origin 3.js b/TS Tests/sprites/sprite origin 3.js
similarity index 100%
rename from Tests/sprites/sprite origin 3.js
rename to TS Tests/sprites/sprite origin 3.js
diff --git a/Tests/sprites/sprite origin 3.ts b/TS Tests/sprites/sprite origin 3.ts
similarity index 100%
rename from Tests/sprites/sprite origin 3.ts
rename to TS Tests/sprites/sprite origin 3.ts
diff --git a/Tests/sprites/sprite origin 4.js b/TS Tests/sprites/sprite origin 4.js
similarity index 100%
rename from Tests/sprites/sprite origin 4.js
rename to TS Tests/sprites/sprite origin 4.js
diff --git a/Tests/sprites/sprite origin 4.ts b/TS Tests/sprites/sprite origin 4.ts
similarity index 100%
rename from Tests/sprites/sprite origin 4.ts
rename to TS Tests/sprites/sprite origin 4.ts
diff --git a/Tests/stage/blur filter.js b/TS Tests/stage/blur filter.js
similarity index 100%
rename from Tests/stage/blur filter.js
rename to TS Tests/stage/blur filter.js
diff --git a/Tests/stage/blur filter.ts b/TS Tests/stage/blur filter.ts
similarity index 100%
rename from Tests/stage/blur filter.ts
rename to TS Tests/stage/blur filter.ts
diff --git a/Tests/stage/brightness filter.js b/TS Tests/stage/brightness filter.js
similarity index 100%
rename from Tests/stage/brightness filter.js
rename to TS Tests/stage/brightness filter.js
diff --git a/Tests/stage/brightness filter.ts b/TS Tests/stage/brightness filter.ts
similarity index 100%
rename from Tests/stage/brightness filter.ts
rename to TS Tests/stage/brightness filter.ts
diff --git a/Tests/stage/contrast filter.js b/TS Tests/stage/contrast filter.js
similarity index 100%
rename from Tests/stage/contrast filter.js
rename to TS Tests/stage/contrast filter.js
diff --git a/Tests/stage/contrast filter.ts b/TS Tests/stage/contrast filter.ts
similarity index 100%
rename from Tests/stage/contrast filter.ts
rename to TS Tests/stage/contrast filter.ts
diff --git a/Tests/stage/grayscale filter.js b/TS Tests/stage/grayscale filter.js
similarity index 100%
rename from Tests/stage/grayscale filter.js
rename to TS Tests/stage/grayscale filter.js
diff --git a/Tests/stage/grayscale filter.ts b/TS Tests/stage/grayscale filter.ts
similarity index 100%
rename from Tests/stage/grayscale filter.ts
rename to TS Tests/stage/grayscale filter.ts
diff --git a/Tests/stage/hue rotate filter.js b/TS Tests/stage/hue rotate filter.js
similarity index 100%
rename from Tests/stage/hue rotate filter.js
rename to TS Tests/stage/hue rotate filter.js
diff --git a/Tests/stage/hue rotate filter.ts b/TS Tests/stage/hue rotate filter.ts
similarity index 100%
rename from Tests/stage/hue rotate filter.ts
rename to TS Tests/stage/hue rotate filter.ts
diff --git a/Tests/stage/sepia filter.js b/TS Tests/stage/sepia filter.js
similarity index 100%
rename from Tests/stage/sepia filter.js
rename to TS Tests/stage/sepia filter.js
diff --git a/Tests/stage/sepia filter.ts b/TS Tests/stage/sepia filter.ts
similarity index 100%
rename from Tests/stage/sepia filter.ts
rename to TS Tests/stage/sepia filter.ts
diff --git a/Tests/states/javascript/FakeGame.js b/TS Tests/states/javascript/FakeGame.js
similarity index 100%
rename from Tests/states/javascript/FakeGame.js
rename to TS Tests/states/javascript/FakeGame.js
diff --git a/Tests/states/javascript/MainMenu.js b/TS Tests/states/javascript/MainMenu.js
similarity index 100%
rename from Tests/states/javascript/MainMenu.js
rename to TS Tests/states/javascript/MainMenu.js
diff --git a/Tests/states/javascript/index.html b/TS Tests/states/javascript/index.html
similarity index 100%
rename from Tests/states/javascript/index.html
rename to TS Tests/states/javascript/index.html
diff --git a/Tests/states/typescript/FakeGame.ts b/TS Tests/states/typescript/FakeGame.ts
similarity index 100%
rename from Tests/states/typescript/FakeGame.ts
rename to TS Tests/states/typescript/FakeGame.ts
diff --git a/Tests/states/typescript/MainMenu.ts b/TS Tests/states/typescript/MainMenu.ts
similarity index 100%
rename from Tests/states/typescript/MainMenu.ts
rename to TS Tests/states/typescript/MainMenu.ts
diff --git a/Tests/states/typescript/index.html b/TS Tests/states/typescript/index.html
similarity index 100%
rename from Tests/states/typescript/index.html
rename to TS Tests/states/typescript/index.html
diff --git a/Tests/textures/dynamic texture 1.js b/TS Tests/textures/dynamic texture 1.js
similarity index 100%
rename from Tests/textures/dynamic texture 1.js
rename to TS Tests/textures/dynamic texture 1.js
diff --git a/Tests/textures/dynamic texture 1.ts b/TS Tests/textures/dynamic texture 1.ts
similarity index 100%
rename from Tests/textures/dynamic texture 1.ts
rename to TS Tests/textures/dynamic texture 1.ts
diff --git a/Tests/textures/dynamic texture 2.js b/TS Tests/textures/dynamic texture 2.js
similarity index 100%
rename from Tests/textures/dynamic texture 2.js
rename to TS Tests/textures/dynamic texture 2.js
diff --git a/Tests/textures/dynamic texture 2.ts b/TS Tests/textures/dynamic texture 2.ts
similarity index 100%
rename from Tests/textures/dynamic texture 2.ts
rename to TS Tests/textures/dynamic texture 2.ts
diff --git a/Tests/textures/filter test.js b/TS Tests/textures/filter test.js
similarity index 100%
rename from Tests/textures/filter test.js
rename to TS Tests/textures/filter test.js
diff --git a/Tests/textures/filter test.ts b/TS Tests/textures/filter test.ts
similarity index 100%
rename from Tests/textures/filter test.ts
rename to TS Tests/textures/filter test.ts
diff --git a/Tests/textures/starling texture atlas.js b/TS Tests/textures/starling texture atlas.js
similarity index 100%
rename from Tests/textures/starling texture atlas.js
rename to TS Tests/textures/starling texture atlas.js
diff --git a/Tests/textures/starling texture atlas.ts b/TS Tests/textures/starling texture atlas.ts
similarity index 100%
rename from Tests/textures/starling texture atlas.ts
rename to TS Tests/textures/starling texture atlas.ts
diff --git a/Tests/textures/texture atlas 1.js b/TS Tests/textures/texture atlas 1.js
similarity index 100%
rename from Tests/textures/texture atlas 1.js
rename to TS Tests/textures/texture atlas 1.js
diff --git a/Tests/textures/texture atlas 1.ts b/TS Tests/textures/texture atlas 1.ts
similarity index 100%
rename from Tests/textures/texture atlas 1.ts
rename to TS Tests/textures/texture atlas 1.ts
diff --git a/Tests/textures/texture atlas 2.js b/TS Tests/textures/texture atlas 2.js
similarity index 100%
rename from Tests/textures/texture atlas 2.js
rename to TS Tests/textures/texture atlas 2.js
diff --git a/Tests/textures/texture atlas 2.ts b/TS Tests/textures/texture atlas 2.ts
similarity index 100%
rename from Tests/textures/texture atlas 2.ts
rename to TS Tests/textures/texture atlas 2.ts
diff --git a/Tests/textures/texture atlas 3.js b/TS Tests/textures/texture atlas 3.js
similarity index 100%
rename from Tests/textures/texture atlas 3.js
rename to TS Tests/textures/texture atlas 3.js
diff --git a/Tests/textures/texture atlas 3.ts b/TS Tests/textures/texture atlas 3.ts
similarity index 100%
rename from Tests/textures/texture atlas 3.ts
rename to TS Tests/textures/texture atlas 3.ts
diff --git a/Tests/textures/texture atlas 4.js b/TS Tests/textures/texture atlas 4.js
similarity index 100%
rename from Tests/textures/texture atlas 4.js
rename to TS Tests/textures/texture atlas 4.js
diff --git a/Tests/textures/texture atlas 4.ts b/TS Tests/textures/texture atlas 4.ts
similarity index 100%
rename from Tests/textures/texture atlas 4.ts
rename to TS Tests/textures/texture atlas 4.ts
diff --git a/Tests/tilemaps/csv tilemap.js b/TS Tests/tilemaps/csv tilemap.js
similarity index 100%
rename from Tests/tilemaps/csv tilemap.js
rename to TS Tests/tilemaps/csv tilemap.js
diff --git a/Tests/tilemaps/csv tilemap.ts b/TS Tests/tilemaps/csv tilemap.ts
similarity index 100%
rename from Tests/tilemaps/csv tilemap.ts
rename to TS Tests/tilemaps/csv tilemap.ts
diff --git a/Tests/tilemaps/map draw.js b/TS Tests/tilemaps/map draw.js
similarity index 100%
rename from Tests/tilemaps/map draw.js
rename to TS Tests/tilemaps/map draw.js
diff --git a/Tests/tilemaps/map draw.ts b/TS Tests/tilemaps/map draw.ts
similarity index 100%
rename from Tests/tilemaps/map draw.ts
rename to TS Tests/tilemaps/map draw.ts
diff --git a/Tests/tilemaps/tiled layers.js b/TS Tests/tilemaps/tiled layers.js
similarity index 100%
rename from Tests/tilemaps/tiled layers.js
rename to TS Tests/tilemaps/tiled layers.js
diff --git a/Tests/tilemaps/tiled layers.ts b/TS Tests/tilemaps/tiled layers.ts
similarity index 100%
rename from Tests/tilemaps/tiled layers.ts
rename to TS Tests/tilemaps/tiled layers.ts
diff --git a/Tests/tilemaps/tiled tilemap.js b/TS Tests/tilemaps/tiled tilemap.js
similarity index 100%
rename from Tests/tilemaps/tiled tilemap.js
rename to TS Tests/tilemaps/tiled tilemap.js
diff --git a/Tests/tilemaps/tiled tilemap.ts b/TS Tests/tilemaps/tiled tilemap.ts
similarity index 100%
rename from Tests/tilemaps/tiled tilemap.ts
rename to TS Tests/tilemaps/tiled tilemap.ts
diff --git a/Tests/tweens/bounce.js b/TS Tests/tweens/bounce.js
similarity index 100%
rename from Tests/tweens/bounce.js
rename to TS Tests/tweens/bounce.js
diff --git a/Tests/tweens/bounce.ts b/TS Tests/tweens/bounce.ts
similarity index 100%
rename from Tests/tweens/bounce.ts
rename to TS Tests/tweens/bounce.ts
diff --git a/Tests/tweens/easing example 1.js b/TS Tests/tweens/easing example 1.js
similarity index 100%
rename from Tests/tweens/easing example 1.js
rename to TS Tests/tweens/easing example 1.js
diff --git a/Tests/tweens/easing example 1.ts b/TS Tests/tweens/easing example 1.ts
similarity index 100%
rename from Tests/tweens/easing example 1.ts
rename to TS Tests/tweens/easing example 1.ts
diff --git a/Tests/tweens/easing example 2.js b/TS Tests/tweens/easing example 2.js
similarity index 100%
rename from Tests/tweens/easing example 2.js
rename to TS Tests/tweens/easing example 2.js
diff --git a/Tests/tweens/easing example 2.ts b/TS Tests/tweens/easing example 2.ts
similarity index 100%
rename from Tests/tweens/easing example 2.ts
rename to TS Tests/tweens/easing example 2.ts
diff --git a/Tests/tweens/easing example 3.js b/TS Tests/tweens/easing example 3.js
similarity index 100%
rename from Tests/tweens/easing example 3.js
rename to TS Tests/tweens/easing example 3.js
diff --git a/Tests/tweens/easing example 3.ts b/TS Tests/tweens/easing example 3.ts
similarity index 100%
rename from Tests/tweens/easing example 3.ts
rename to TS Tests/tweens/easing example 3.ts
diff --git a/Tests/tweens/easing example 4.js b/TS Tests/tweens/easing example 4.js
similarity index 100%
rename from Tests/tweens/easing example 4.js
rename to TS Tests/tweens/easing example 4.js
diff --git a/Tests/tweens/easing example 4.ts b/TS Tests/tweens/easing example 4.ts
similarity index 100%
rename from Tests/tweens/easing example 4.ts
rename to TS Tests/tweens/easing example 4.ts
diff --git a/Tests/tweens/easing example 5.js b/TS Tests/tweens/easing example 5.js
similarity index 100%
rename from Tests/tweens/easing example 5.js
rename to TS Tests/tweens/easing example 5.js
diff --git a/Tests/tweens/easing example 5.ts b/TS Tests/tweens/easing example 5.ts
similarity index 100%
rename from Tests/tweens/easing example 5.ts
rename to TS Tests/tweens/easing example 5.ts
diff --git a/Tests/tweens/easing example 6.js b/TS Tests/tweens/easing example 6.js
similarity index 100%
rename from Tests/tweens/easing example 6.js
rename to TS Tests/tweens/easing example 6.js
diff --git a/Tests/tweens/easing example 6.ts b/TS Tests/tweens/easing example 6.ts
similarity index 100%
rename from Tests/tweens/easing example 6.ts
rename to TS Tests/tweens/easing example 6.ts
diff --git a/Tests/tweens/pause test.js b/TS Tests/tweens/pause test.js
similarity index 100%
rename from Tests/tweens/pause test.js
rename to TS Tests/tweens/pause test.js
diff --git a/Tests/tweens/pause test.ts b/TS Tests/tweens/pause test.ts
similarity index 100%
rename from Tests/tweens/pause test.ts
rename to TS Tests/tweens/pause test.ts
diff --git a/Tests/tweens/tween loop 1.js b/TS Tests/tweens/tween loop 1.js
similarity index 100%
rename from Tests/tweens/tween loop 1.js
rename to TS Tests/tweens/tween loop 1.js
diff --git a/Tests/tweens/tween loop 1.ts b/TS Tests/tweens/tween loop 1.ts
similarity index 100%
rename from Tests/tweens/tween loop 1.ts
rename to TS Tests/tweens/tween loop 1.ts
diff --git a/Tests/tweens/tween loop 2.js b/TS Tests/tweens/tween loop 2.js
similarity index 100%
rename from Tests/tweens/tween loop 2.js
rename to TS Tests/tweens/tween loop 2.js
diff --git a/Tests/tweens/tween loop 2.ts b/TS Tests/tweens/tween loop 2.ts
similarity index 100%
rename from Tests/tweens/tween loop 2.ts
rename to TS Tests/tweens/tween loop 2.ts
diff --git a/build/phaser-debug.js b/build/phaser-debug.js
index b4d3a73f..20fcef2e 100644
--- a/build/phaser-debug.js
+++ b/build/phaser-debug.js
@@ -8458,7 +8458,6 @@ var Phaser;
velocity = 0;
}
}
- velocity += gravity;
if(velocity != 0) {
if(velocity > max) {
velocity = max;
@@ -8525,7 +8524,7 @@ var Phaser;
this.acceleration = new Phaser.Vec2();
this.bounce = new Phaser.Vec2(0, 0);
this.drag = new Phaser.Vec2(0, 0);
- this.gravity = new Phaser.Vec2(0, 2);
+ this.gravity = new Phaser.Vec2(0, 0);
this.maxVelocity = new Phaser.Vec2(1000, 1000);
this.aabbTileProjections = {
};
@@ -8543,6 +8542,34 @@ var Phaser;
AABB.COL_AXIS = 1;
AABB.COL_OTHER = 2;
AABB.prototype.update = function () {
+ this.integrateVerlet();
+ if(this.acceleration.x != 0) {
+ this.velocity.x += (this.acceleration.x * this.game.time.physicsElapsed);
+ }
+ if(this.acceleration.y != 0) {
+ this.velocity.y += (this.acceleration.y * this.game.time.physicsElapsed);
+ }
+ this._vx = this.velocity.x * this.game.time.physicsElapsed;
+ this._vy = this.velocity.y * this.game.time.physicsElapsed;
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+ this._deltaX = Math.min(20, Math.max(-20, vx + this._vx));
+ this._deltaY = Math.min(20, Math.max(-20, vy + this._vy));
+ this.pos.x = this.oldpos.x + this._deltaX;
+ this.pos.y = this.oldpos.y + this._deltaY;
+ };
+ AABB.prototype.Nupdate = function () {
+ this.integrateVerlet();
+ var p = this.pos;
+ var o = this.oldpos;
+ var vx = p.x - o.x;
+ var vy = p.y - o.y;
+ var newx = Math.min(20, Math.max(-20, vx + this._vx));
+ var newy = Math.min(20, Math.max(-20, vy + this._vy));
+ this.pos.x = o.x + newx;
+ this.pos.y = o.y + newy;
+ };
+ AABB.prototype.updateFlixel = function () {
this.oldpos.x = this.pos.x;
this.oldpos.y = this.pos.y;
this._vx = (this.game.physics.computeVelocity(this.velocity.x, this.gravity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
@@ -8595,16 +8622,40 @@ var Phaser;
this.pos.y += this._vy;
};
AABB.prototype.integrateVerlet = function () {
- var px = this.pos.x;
- var py = this.pos.y;
var ox = this.oldpos.x;
var oy = this.oldpos.y;
this.oldpos.x = this.pos.x;
this.oldpos.y = this.pos.y;
- this.pos.x += (this.drag.x * px) - (this.drag.x * ox) + this.gravity.x;
- this.pos.y += (this.drag.y * py) - (this.drag.y * oy) + this.gravity.y;
+ this.pos.x += (this.drag.x * this.pos.x) - (this.drag.x * ox) + this.gravity.x;
+ this.pos.y += (this.drag.y * this.pos.y) - (this.drag.y * oy) + this.gravity.y;
};
AABB.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = vx - nx;
+ var ty = vy - ny;
+ var bx = 0;
+ var by = 0;
+ var fx = 0;
+ var fy = 0;
+ if(dp < 0) {
+ var f = 0.05;
+ fx = tx * f;
+ fy = ty * f;
+ var b = 1 + 0.5;
+ bx = (nx * b);
+ by = (ny * b);
+ }
+ this.pos.x += px;
+ this.pos.y += py;
+ this.oldpos.x += px + bx + fx;
+ this.oldpos.y += py + by + fy;
+ };
+ AABB.prototype.TWEAKEDreportCollisionVsWorld = function (px, py, dx, dy, obj) {
if (typeof obj === "undefined") { obj = null; }
var dp = (this._vx * dx + this._vy * dy);
var nx = dp * dx;
@@ -8617,8 +8668,10 @@ var Phaser;
this.velocity.x += nx;
this.velocity.y += ny;
if(dx !== 0) {
+ this.velocity.x *= -1 * this.bounce.x;
}
if(dy !== 0) {
+ this.velocity.y *= -1 * this.bounce.y;
}
}
};
@@ -10692,6 +10745,7 @@ var Phaser;
this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
this.transform.setCache();
+ this.body = new Phaser.Physics.Body(this, 0);
this.outOfBounds = false;
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
this.scale = this.transform.scale;
diff --git a/build/phaser-release.js b/build/phaser-release.js
new file mode 100644
index 00000000..394aedf4
--- /dev/null
+++ b/build/phaser-release.js
@@ -0,0 +1,14470 @@
+var Phaser;
+(function (Phaser) {
+ Phaser.VERSION = 'Phaser version 1.0.0';
+ Phaser.GAMES = [];
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Types = (function () {
+ function Types() { }
+ Types.RENDERER_AUTO_DETECT = 0;
+ Types.RENDERER_HEADLESS = 1;
+ Types.RENDERER_CANVAS = 2;
+ Types.RENDERER_WEBGL = 3;
+ Types.CAMERA_TYPE_ORTHOGRAPHIC = 0;
+ Types.CAMERA_TYPE_ISOMETRIC = 1;
+ Types.CAMERA_FOLLOW_LOCKON = 0;
+ Types.CAMERA_FOLLOW_PLATFORMER = 1;
+ Types.CAMERA_FOLLOW_TOPDOWN = 2;
+ Types.CAMERA_FOLLOW_TOPDOWN_TIGHT = 3;
+ Types.GROUP = 0;
+ Types.SPRITE = 1;
+ Types.GEOMSPRITE = 2;
+ Types.PARTICLE = 3;
+ Types.EMITTER = 4;
+ Types.TILEMAP = 5;
+ Types.SCROLLZONE = 6;
+ Types.BUTTON = 7;
+ Types.DYNAMICTEXTURE = 8;
+ Types.GEOM_POINT = 0;
+ Types.GEOM_CIRCLE = 1;
+ Types.GEOM_RECTANGLE = 2;
+ Types.GEOM_LINE = 3;
+ Types.GEOM_POLYGON = 4;
+ Types.BODY_DISABLED = 0;
+ Types.BODY_STATIC = 1;
+ Types.BODY_KINETIC = 2;
+ Types.BODY_DYNAMIC = 3;
+ Types.OUT_OF_BOUNDS_KILL = 0;
+ Types.OUT_OF_BOUNDS_DESTROY = 1;
+ Types.OUT_OF_BOUNDS_PERSIST = 2;
+ Types.SORT_ASCENDING = -1;
+ Types.SORT_DESCENDING = 1;
+ Types.LEFT = 0x0001;
+ Types.RIGHT = 0x0010;
+ Types.UP = 0x0100;
+ Types.DOWN = 0x1000;
+ Types.NONE = 0;
+ Types.CEILING = 0x0100;
+ Types.FLOOR = 0x1000;
+ Types.WALL = 0x0001 | 0x0010;
+ Types.ANY = 0x0001 | 0x0010 | 0x0100 | 0x1000;
+ return Types;
+ })();
+ Phaser.Types = Types;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Point = (function () {
+ function Point(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ this.x = x;
+ this.y = y;
+ }
+ Point.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y);
+ };
+ Point.prototype.invert = function () {
+ return this.setTo(this.y, this.x);
+ };
+ Point.prototype.setTo = function (x, y) {
+ this.x = x;
+ this.y = y;
+ return this;
+ };
+ Point.prototype.toString = function () {
+ return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
+ };
+ return Point;
+ })();
+ Phaser.Point = Point;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Rectangle = (function () {
+ function Rectangle(x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+ Object.defineProperty(Rectangle.prototype, "halfWidth", {
+ get: function () {
+ return Math.round(this.width / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "halfHeight", {
+ get: function () {
+ return Math.round(this.height / 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottom", {
+ get: function () {
+ return this.y + this.height;
+ },
+ set: function (value) {
+ if(value <= this.y) {
+ this.height = 0;
+ } else {
+ this.height = (this.y - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "bottomRight", {
+ set: function (value) {
+ this.right = value.x;
+ this.bottom = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "left", {
+ get: function () {
+ return this.x;
+ },
+ set: function (value) {
+ if(value >= this.right) {
+ this.width = 0;
+ } else {
+ this.width = this.right - value;
+ }
+ this.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "right", {
+ get: function () {
+ return this.x + this.width;
+ },
+ set: function (value) {
+ if(value <= this.x) {
+ this.width = 0;
+ } else {
+ this.width = this.x + value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "volume", {
+ get: function () {
+ return this.width * this.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "perimeter", {
+ get: function () {
+ return (this.width * 2) + (this.height * 2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "top", {
+ get: function () {
+ return this.y;
+ },
+ set: function (value) {
+ if(value >= this.bottom) {
+ this.height = 0;
+ this.y = value;
+ } else {
+ this.height = (this.bottom - value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "topLeft", {
+ set: function (value) {
+ this.x = value.x;
+ this.y = value.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Rectangle.prototype, "empty", {
+ get: function () {
+ return (!this.width || !this.height);
+ },
+ set: function (value) {
+ this.setTo(0, 0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Rectangle.prototype.offset = function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Rectangle.prototype.offsetPoint = function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Rectangle.prototype.setTo = function (x, y, width, height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ return this;
+ };
+ Rectangle.prototype.floor = function () {
+ this.x = Math.floor(this.x);
+ this.y = Math.floor(this.y);
+ };
+ Rectangle.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y, source.width, source.height);
+ };
+ Rectangle.prototype.toString = function () {
+ return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
+ };
+ return Rectangle;
+ })();
+ Phaser.Rectangle = Rectangle;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Circle = (function () {
+ function Circle(x, y, diameter) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof diameter === "undefined") { diameter = 0; }
+ this._diameter = 0;
+ this._radius = 0;
+ this.x = 0;
+ this.y = 0;
+ this.setTo(x, y, diameter);
+ }
+ Object.defineProperty(Circle.prototype, "diameter", {
+ get: function () {
+ return this._diameter;
+ },
+ set: function (value) {
+ if(value > 0) {
+ this._diameter = value;
+ this._radius = value * 0.5;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "radius", {
+ get: function () {
+ return this._radius;
+ },
+ set: function (value) {
+ if(value > 0) {
+ this._radius = value;
+ this._diameter = value * 2;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.circumference = function () {
+ return 2 * (Math.PI * this._radius);
+ };
+ Object.defineProperty(Circle.prototype, "bottom", {
+ get: function () {
+ return this.y + this._radius;
+ },
+ set: function (value) {
+ if(value < this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.y;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "left", {
+ get: function () {
+ return this.x - this._radius;
+ },
+ set: function (value) {
+ if(value > this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.x - value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "right", {
+ get: function () {
+ return this.x + this._radius;
+ },
+ set: function (value) {
+ if(value < this.x) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = value - this.x;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "top", {
+ get: function () {
+ return this.y - this._radius;
+ },
+ set: function (value) {
+ if(value > this.y) {
+ this._radius = 0;
+ this._diameter = 0;
+ } else {
+ this.radius = this.y - value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Circle.prototype, "area", {
+ get: function () {
+ if(this._radius > 0) {
+ return Math.PI * this._radius * this._radius;
+ } else {
+ return 0;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.setTo = function (x, y, diameter) {
+ this.x = x;
+ this.y = y;
+ this._diameter = diameter;
+ this._radius = diameter * 0.5;
+ return this;
+ };
+ Circle.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y, source.diameter);
+ };
+ Object.defineProperty(Circle.prototype, "empty", {
+ get: function () {
+ return (this._diameter == 0);
+ },
+ set: function (value) {
+ this.setTo(0, 0, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Circle.prototype.offset = function (dx, dy) {
+ this.x += dx;
+ this.y += dy;
+ return this;
+ };
+ Circle.prototype.offsetPoint = function (point) {
+ return this.offset(point.x, point.y);
+ };
+ Circle.prototype.toString = function () {
+ return "[{Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
+ };
+ return Circle;
+ })();
+ Phaser.Circle = Circle;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Line = (function () {
+ function Line(x1, y1, x2, y2) {
+ if (typeof x1 === "undefined") { x1 = 0; }
+ if (typeof y1 === "undefined") { y1 = 0; }
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ this.x1 = 0;
+ this.y1 = 0;
+ this.x2 = 0;
+ this.y2 = 0;
+ this.setTo(x1, y1, x2, y2);
+ }
+ Line.prototype.clone = function (output) {
+ if (typeof output === "undefined") { output = new Line(); }
+ return output.setTo(this.x1, this.y1, this.x2, this.y2);
+ };
+ Line.prototype.copyFrom = function (source) {
+ return this.setTo(source.x1, source.y1, source.x2, source.y2);
+ };
+ Line.prototype.copyTo = function (target) {
+ return target.copyFrom(this);
+ };
+ Line.prototype.setTo = function (x1, y1, x2, y2) {
+ if (typeof x1 === "undefined") { x1 = 0; }
+ if (typeof y1 === "undefined") { y1 = 0; }
+ if (typeof x2 === "undefined") { x2 = 0; }
+ if (typeof y2 === "undefined") { y2 = 0; }
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ return this;
+ };
+ Object.defineProperty(Line.prototype, "width", {
+ get: function () {
+ return Math.max(this.x1, this.x2) - Math.min(this.x1, this.x2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "height", {
+ get: function () {
+ return Math.max(this.y1, this.y2) - Math.min(this.y1, this.y2);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "length", {
+ get: function () {
+ return Math.sqrt((this.x2 - this.x1) * (this.x2 - this.x1) + (this.y2 - this.y1) * (this.y2 - this.y1));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Line.prototype.getY = function (x) {
+ return this.slope * x + this.yIntercept;
+ };
+ Object.defineProperty(Line.prototype, "angle", {
+ get: function () {
+ return Math.atan2(this.x2 - this.x1, this.y2 - this.y1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "slope", {
+ get: function () {
+ return (this.y2 - this.y1) / (this.x2 - this.x1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "perpSlope", {
+ get: function () {
+ return -((this.x2 - this.x1) / (this.y2 - this.y1));
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Line.prototype, "yIntercept", {
+ get: function () {
+ return (this.y1 - this.slope * this.x1);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Line.prototype.isPointOnLine = function (x, y) {
+ if((x - this.x1) * (this.y2 - this.y1) === (this.x2 - this.x1) * (y - this.y1)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Line.prototype.isPointOnLineSegment = function (x, y) {
+ var xMin = Math.min(this.x1, this.x2);
+ var xMax = Math.max(this.x1, this.x2);
+ var yMin = Math.min(this.y1, this.y2);
+ var yMax = Math.max(this.y1, this.y2);
+ if(this.isPointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Line.prototype.intersectLineLine = function (line) {
+ };
+ Line.prototype.toString = function () {
+ return "[{Line (x1=" + this.x1 + " y1=" + this.y1 + " x2=" + this.x2 + " y2=" + this.y2 + ")}]";
+ };
+ return Line;
+ })();
+ Phaser.Line = Line;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var GameMath = (function () {
+ function GameMath(game) {
+ this.cosTable = [];
+ this.sinTable = [];
+ this.game = game;
+ GameMath.sinA = [];
+ GameMath.cosA = [];
+ for(var i = 0; i < 360; i++) {
+ GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
+ GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
+ }
+ }
+ GameMath.PI = 3.141592653589793;
+ GameMath.PI_2 = 1.5707963267948965;
+ GameMath.PI_4 = 0.7853981633974483;
+ GameMath.PI_8 = 0.39269908169872413;
+ GameMath.PI_16 = 0.19634954084936206;
+ GameMath.TWO_PI = 6.283185307179586;
+ GameMath.THREE_PI_2 = 4.7123889803846895;
+ GameMath.E = 2.71828182845905;
+ GameMath.LN10 = 2.302585092994046;
+ GameMath.LN2 = 0.6931471805599453;
+ GameMath.LOG10E = 0.4342944819032518;
+ GameMath.LOG2E = 1.442695040888963387;
+ GameMath.SQRT1_2 = 0.7071067811865476;
+ GameMath.SQRT2 = 1.4142135623730951;
+ GameMath.DEG_TO_RAD = 0.017453292519943294444444444444444;
+ GameMath.RAD_TO_DEG = 57.295779513082325225835265587527;
+ GameMath.B_16 = 65536;
+ GameMath.B_31 = 2147483648;
+ GameMath.B_32 = 4294967296;
+ GameMath.B_48 = 281474976710656;
+ GameMath.B_53 = 9007199254740992;
+ GameMath.B_64 = 18446744073709551616;
+ GameMath.ONE_THIRD = 0.333333333333333333333333333333333;
+ GameMath.TWO_THIRDS = 0.666666666666666666666666666666666;
+ GameMath.ONE_SIXTH = 0.166666666666666666666666666666666;
+ GameMath.COS_PI_3 = 0.86602540378443864676372317075294;
+ GameMath.SIN_2PI_3 = 0.03654595;
+ GameMath.CIRCLE_ALPHA = 0.5522847498307933984022516322796;
+ GameMath.ON = true;
+ GameMath.OFF = false;
+ GameMath.SHORT_EPSILON = 0.1;
+ GameMath.PERC_EPSILON = 0.001;
+ GameMath.EPSILON = 0.0001;
+ GameMath.LONG_EPSILON = 0.00000001;
+ GameMath.prototype.fuzzyEqual = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.abs(a - b) < epsilon;
+ };
+ GameMath.prototype.fuzzyLessThan = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return a < b + epsilon;
+ };
+ GameMath.prototype.fuzzyGreaterThan = function (a, b, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return a > b - epsilon;
+ };
+ GameMath.prototype.fuzzyCeil = function (val, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.ceil(val - epsilon);
+ };
+ GameMath.prototype.fuzzyFloor = function (val, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return Math.floor(val + epsilon);
+ };
+ GameMath.prototype.average = function () {
+ var args = [];
+ for (var _i = 0; _i < (arguments.length - 0); _i++) {
+ args[_i] = arguments[_i + 0];
+ }
+ var avg = 0;
+ for(var i = 0; i < args.length; i++) {
+ avg += args[i];
+ }
+ return avg / args.length;
+ };
+ GameMath.prototype.slam = function (value, target, epsilon) {
+ if (typeof epsilon === "undefined") { epsilon = 0.0001; }
+ return (Math.abs(value - target) < epsilon) ? target : value;
+ };
+ GameMath.prototype.percentageMinMax = function (val, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ val -= min;
+ max -= min;
+ if(!max) {
+ return 0;
+ } else {
+ return val / max;
+ }
+ };
+ GameMath.prototype.sign = function (n) {
+ if(n) {
+ return n / Math.abs(n);
+ } else {
+ return 0;
+ }
+ };
+ GameMath.prototype.truncate = function (n) {
+ return (n > 0) ? Math.floor(n) : Math.ceil(n);
+ };
+ GameMath.prototype.shear = function (n) {
+ return n % 1;
+ };
+ GameMath.prototype.wrap = function (val, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ val -= min;
+ max -= min;
+ if(max == 0) {
+ return min;
+ }
+ val %= max;
+ val += min;
+ while(val < min) {
+ val += max;
+ }
+ return val;
+ };
+ GameMath.prototype.arithWrap = function (value, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ max -= min;
+ if(max == 0) {
+ return min;
+ }
+ return value - max * Math.floor((value - min) / max);
+ };
+ GameMath.prototype.clamp = function (input, max, min) {
+ if (typeof min === "undefined") { min = 0; }
+ return Math.max(min, Math.min(max, input));
+ };
+ GameMath.prototype.snapTo = function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.round(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToFloor = function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.floor(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToCeil = function (input, gap, start) {
+ if (typeof start === "undefined") { start = 0; }
+ if(gap == 0) {
+ return input;
+ }
+ input -= start;
+ input = gap * Math.ceil(input / gap);
+ return start + input;
+ };
+ GameMath.prototype.snapToInArray = function (input, arr, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(sort) {
+ arr.sort();
+ }
+ if(input < arr[0]) {
+ return arr[0];
+ }
+ var i = 1;
+ while(arr[i] < input) {
+ i++;
+ }
+ var low = arr[i - 1];
+ var high = (i < arr.length) ? arr[i] : Number.POSITIVE_INFINITY;
+ return ((high - input) <= (input - low)) ? high : low;
+ };
+ GameMath.prototype.roundTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.round(value * p) / p;
+ };
+ GameMath.prototype.floorTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.floor(value * p) / p;
+ };
+ GameMath.prototype.ceilTo = function (value, place, base) {
+ if (typeof place === "undefined") { place = 0; }
+ if (typeof base === "undefined") { base = 10; }
+ var p = Math.pow(base, -place);
+ return Math.ceil(value * p) / p;
+ };
+ GameMath.prototype.interpolateFloat = function (a, b, weight) {
+ return (b - a) * weight + a;
+ };
+ GameMath.prototype.radiansToDegrees = function (angle) {
+ return angle * GameMath.RAD_TO_DEG;
+ };
+ GameMath.prototype.degreesToRadians = function (angle) {
+ return angle * GameMath.DEG_TO_RAD;
+ };
+ GameMath.prototype.angleBetween = function (x1, y1, x2, y2) {
+ return Math.atan2(y2 - y1, x2 - x1);
+ };
+ GameMath.prototype.normalizeAngle = function (angle, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ var rd = (radians) ? GameMath.PI : 180;
+ return this.wrap(angle, rd, -rd);
+ };
+ GameMath.prototype.nearestAngleBetween = function (a1, a2, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ var rd = (radians) ? GameMath.PI : 180;
+ a1 = this.normalizeAngle(a1, radians);
+ a2 = this.normalizeAngle(a2, radians);
+ if(a1 < -rd / 2 && a2 > rd / 2) {
+ a1 += rd * 2;
+ }
+ if(a2 < -rd / 2 && a1 > rd / 2) {
+ a2 += rd * 2;
+ }
+ return a2 - a1;
+ };
+ GameMath.prototype.normalizeAngleToAnother = function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ return ind + this.nearestAngleBetween(ind, dep, radians);
+ };
+ GameMath.prototype.normalizeAngleAfterAnother = function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ dep = this.normalizeAngle(dep - ind, radians);
+ return ind + dep;
+ };
+ GameMath.prototype.normalizeAngleBeforeAnother = function (dep, ind, radians) {
+ if (typeof radians === "undefined") { radians = true; }
+ dep = this.normalizeAngle(ind - dep, radians);
+ return ind - dep;
+ };
+ GameMath.prototype.interpolateAngles = function (a1, a2, weight, radians, ease) {
+ if (typeof radians === "undefined") { radians = true; }
+ if (typeof ease === "undefined") { ease = null; }
+ a1 = this.normalizeAngle(a1, radians);
+ a2 = this.normalizeAngleToAnother(a2, a1, radians);
+ return (typeof ease === 'function') ? ease(weight, a1, a2 - a1, 1) : this.interpolateFloat(a1, a2, weight);
+ };
+ GameMath.prototype.logBaseOf = function (value, base) {
+ return Math.log(value) / Math.log(base);
+ };
+ GameMath.prototype.GCD = function (m, n) {
+ var r;
+ m = Math.abs(m);
+ n = Math.abs(n);
+ if(m < n) {
+ r = m;
+ m = n;
+ n = r;
+ }
+ while(true) {
+ r = m % n;
+ if(!r) {
+ return n;
+ }
+ m = n;
+ n = r;
+ }
+ return 1;
+ };
+ GameMath.prototype.LCM = function (m, n) {
+ return (m * n) / this.GCD(m, n);
+ };
+ GameMath.prototype.factorial = function (value) {
+ if(value == 0) {
+ return 1;
+ }
+ var res = value;
+ while(--value) {
+ res *= value;
+ }
+ return res;
+ };
+ GameMath.prototype.gammaFunction = function (value) {
+ return this.factorial(value - 1);
+ };
+ GameMath.prototype.fallingFactorial = function (base, exp) {
+ return this.factorial(base) / this.factorial(base - exp);
+ };
+ GameMath.prototype.risingFactorial = function (base, exp) {
+ return this.factorial(base + exp - 1) / this.factorial(base - 1);
+ };
+ GameMath.prototype.binCoef = function (n, k) {
+ return this.fallingFactorial(n, k) / this.factorial(k);
+ };
+ GameMath.prototype.risingBinCoef = function (n, k) {
+ return this.risingFactorial(n, k) / this.factorial(k);
+ };
+ GameMath.prototype.chanceRoll = function (chance) {
+ if (typeof chance === "undefined") { chance = 50; }
+ if(chance <= 0) {
+ return false;
+ } else if(chance >= 100) {
+ return true;
+ } else {
+ if(Math.random() * 100 >= chance) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ };
+ GameMath.prototype.maxAdd = function (value, amount, max) {
+ value += amount;
+ if(value > max) {
+ value = max;
+ }
+ return value;
+ };
+ GameMath.prototype.minSub = function (value, amount, min) {
+ value -= amount;
+ if(value < min) {
+ value = min;
+ }
+ return value;
+ };
+ GameMath.prototype.wrapValue = function (value, amount, max) {
+ var diff;
+ value = Math.abs(value);
+ amount = Math.abs(amount);
+ max = Math.abs(max);
+ diff = (value + amount) % max;
+ return diff;
+ };
+ GameMath.prototype.randomSign = function () {
+ return (Math.random() > 0.5) ? 1 : -1;
+ };
+ GameMath.prototype.isOdd = function (n) {
+ if(n & 1) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ GameMath.prototype.isEven = function (n) {
+ if(n & 1) {
+ return false;
+ } else {
+ return true;
+ }
+ };
+ GameMath.prototype.wrapAngle = function (angle) {
+ var result = angle;
+ if(angle >= -180 && angle <= 180) {
+ return angle;
+ }
+ result = (angle + 180) % 360;
+ if(result < 0) {
+ result += 360;
+ }
+ return result - 180;
+ };
+ GameMath.prototype.angleLimit = function (angle, min, max) {
+ var result = angle;
+ if(angle > max) {
+ result = max;
+ } else if(angle < min) {
+ result = min;
+ }
+ return result;
+ };
+ GameMath.prototype.linearInterpolation = function (v, k) {
+ var m = v.length - 1;
+ var f = m * k;
+ var i = Math.floor(f);
+ if(k < 0) {
+ return this.linear(v[0], v[1], f);
+ }
+ if(k > 1) {
+ return this.linear(v[m], v[m - 1], m - f);
+ }
+ return this.linear(v[i], v[i + 1 > m ? m : i + 1], f - i);
+ };
+ GameMath.prototype.bezierInterpolation = function (v, k) {
+ var b = 0;
+ var n = v.length - 1;
+ for(var i = 0; i <= n; i++) {
+ b += Math.pow(1 - k, n - i) * Math.pow(k, i) * v[i] * this.bernstein(n, i);
+ }
+ return b;
+ };
+ GameMath.prototype.catmullRomInterpolation = function (v, k) {
+ var m = v.length - 1;
+ var f = m * k;
+ var i = Math.floor(f);
+ if(v[0] === v[m]) {
+ if(k < 0) {
+ i = Math.floor(f = m * (1 + k));
+ }
+ return this.catmullRom(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
+ } else {
+ if(k < 0) {
+ return v[0] - (this.catmullRom(v[0], v[0], v[1], v[1], -f) - v[0]);
+ }
+ if(k > 1) {
+ return v[m] - (this.catmullRom(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
+ }
+ return this.catmullRom(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
+ }
+ };
+ GameMath.prototype.linear = function (p0, p1, t) {
+ return (p1 - p0) * t + p0;
+ };
+ GameMath.prototype.bernstein = function (n, i) {
+ return this.factorial(n) / this.factorial(i) / this.factorial(n - i);
+ };
+ GameMath.prototype.catmullRom = function (p0, p1, p2, p3, t) {
+ var v0 = (p2 - p0) * 0.5, v1 = (p3 - p1) * 0.5, t2 = t * t, t3 = t * t2;
+ return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
+ };
+ GameMath.prototype.difference = function (a, b) {
+ return Math.abs(a - b);
+ };
+ GameMath.prototype.getRandom = function (objects, startIndex, length) {
+ if (typeof startIndex === "undefined") { startIndex = 0; }
+ if (typeof length === "undefined") { length = 0; }
+ if(objects != null) {
+ var l = length;
+ if((l == 0) || (l > objects.length - startIndex)) {
+ l = objects.length - startIndex;
+ }
+ if(l > 0) {
+ return objects[startIndex + Math.floor(Math.random() * l)];
+ }
+ }
+ return null;
+ };
+ GameMath.prototype.floor = function (value) {
+ var n = value | 0;
+ return (value > 0) ? (n) : ((n != value) ? (n - 1) : (n));
+ };
+ GameMath.prototype.ceil = function (value) {
+ var n = value | 0;
+ return (value > 0) ? ((n != value) ? (n + 1) : (n)) : (n);
+ };
+ GameMath.prototype.sinCosGenerator = function (length, sinAmplitude, cosAmplitude, frequency) {
+ if (typeof sinAmplitude === "undefined") { sinAmplitude = 1.0; }
+ if (typeof cosAmplitude === "undefined") { cosAmplitude = 1.0; }
+ if (typeof frequency === "undefined") { frequency = 1.0; }
+ var sin = sinAmplitude;
+ var cos = cosAmplitude;
+ var frq = frequency * Math.PI / length;
+ this.cosTable = [];
+ this.sinTable = [];
+ for(var c = 0; c < length; c++) {
+ cos -= sin * frq;
+ sin += cos * frq;
+ this.cosTable[c] = cos;
+ this.sinTable[c] = sin;
+ }
+ return this.sinTable;
+ };
+ GameMath.prototype.shiftSinTable = function () {
+ if(this.sinTable) {
+ var s = this.sinTable.shift();
+ this.sinTable.push(s);
+ return s;
+ }
+ };
+ GameMath.prototype.shiftCosTable = function () {
+ if(this.cosTable) {
+ var s = this.cosTable.shift();
+ this.cosTable.push(s);
+ return s;
+ }
+ };
+ GameMath.prototype.shuffleArray = function (array) {
+ for(var i = array.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ }
+ return array;
+ };
+ GameMath.prototype.distanceBetween = function (x1, y1, x2, y2) {
+ var dx = x1 - x2;
+ var dy = y1 - y2;
+ return Math.sqrt(dx * dx + dy * dy);
+ };
+ GameMath.prototype.vectorLength = function (dx, dy) {
+ return Math.sqrt(dx * dx + dy * dy);
+ };
+ return GameMath;
+ })();
+ Phaser.GameMath = GameMath;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Vec2 = (function () {
+ function Vec2(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ this.x = x;
+ this.y = y;
+ return this;
+ }
+ Vec2.prototype.copyFrom = function (source) {
+ return this.setTo(source.x, source.y);
+ };
+ Vec2.prototype.setTo = function (x, y) {
+ this.x = x;
+ this.y = y;
+ return this;
+ };
+ Vec2.prototype.add = function (a) {
+ this.x += a.x;
+ this.y += a.y;
+ return this;
+ };
+ Vec2.prototype.subtract = function (v) {
+ this.x -= v.x;
+ this.y -= v.y;
+ return this;
+ };
+ Vec2.prototype.multiply = function (v) {
+ this.x *= v.x;
+ this.y *= v.y;
+ return this;
+ };
+ Vec2.prototype.divide = function (v) {
+ this.x /= v.x;
+ this.y /= v.y;
+ return this;
+ };
+ Vec2.prototype.length = function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vec2.prototype.lengthSq = function () {
+ return (this.x * this.x) + (this.y * this.y);
+ };
+ Vec2.prototype.normalize = function () {
+ var inv = (this.x != 0 || this.y != 0) ? 1 / Math.sqrt(this.x * this.x + this.y * this.y) : 0;
+ this.x *= inv;
+ this.y *= inv;
+ return this;
+ };
+ Vec2.prototype.dot = function (a) {
+ return ((this.x * a.x) + (this.y * a.y));
+ };
+ Vec2.prototype.cross = function (a) {
+ return ((this.x * a.y) - (this.y * a.x));
+ };
+ Vec2.prototype.projectionLength = function (a) {
+ var den = a.dot(a);
+ if(den == 0) {
+ return 0;
+ } else {
+ return Math.abs(this.dot(a) / den);
+ }
+ };
+ Vec2.prototype.angle = function (a) {
+ return Math.atan2(a.x * this.y - a.y * this.x, a.x * this.x + a.y * this.y);
+ };
+ Vec2.prototype.scale = function (x, y) {
+ this.x *= x;
+ this.y *= y || x;
+ return this;
+ };
+ Vec2.prototype.multiplyByScalar = function (scalar) {
+ this.x *= scalar;
+ this.y *= scalar;
+ return this;
+ };
+ Vec2.prototype.multiplyAddByScalar = function (a, scalar) {
+ this.x += a.x * scalar;
+ this.y += a.y * scalar;
+ return this;
+ };
+ Vec2.prototype.divideByScalar = function (scalar) {
+ this.x /= scalar;
+ this.y /= scalar;
+ return this;
+ };
+ Vec2.prototype.reverse = function () {
+ this.x = -this.x;
+ this.y = -this.y;
+ return this;
+ };
+ Vec2.prototype.equals = function (value) {
+ return (this.x == value && this.y == value);
+ };
+ Vec2.prototype.toString = function () {
+ return "[{Vec2 (x=" + this.x + " y=" + this.y + ")}]";
+ };
+ return Vec2;
+ })();
+ Phaser.Vec2 = Vec2;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Vec2Utils = (function () {
+ function Vec2Utils() { }
+ Vec2Utils.add = function add(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x + b.x, a.y + b.y);
+ };
+ Vec2Utils.subtract = function subtract(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x - b.x, a.y - b.y);
+ };
+ Vec2Utils.multiply = function multiply(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x * b.x, a.y * b.y);
+ };
+ Vec2Utils.divide = function divide(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x / b.x, a.y / b.y);
+ };
+ Vec2Utils.scale = function scale(a, s, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x * s, a.y * s);
+ };
+ Vec2Utils.multiplyAdd = function multiplyAdd(a, b, s, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x + b.x * s, a.y + b.y * s);
+ };
+ Vec2Utils.negative = function negative(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(-a.x, -a.y);
+ };
+ Vec2Utils.perp = function perp(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(-a.y, a.x);
+ };
+ Vec2Utils.rperp = function rperp(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.y, -a.x);
+ };
+ Vec2Utils.equals = function equals(a, b) {
+ return a.x == b.x && a.y == b.y;
+ };
+ Vec2Utils.epsilonEquals = function epsilonEquals(a, b, epsilon) {
+ return Math.abs(a.x - b.x) <= epsilon && Math.abs(a.y - b.y) <= epsilon;
+ };
+ Vec2Utils.distance = function distance(a, b) {
+ return Math.sqrt(Vec2Utils.distanceSq(a, b));
+ };
+ Vec2Utils.distanceSq = function distanceSq(a, b) {
+ return ((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y));
+ };
+ Vec2Utils.project = function project(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var amt = a.dot(b) / b.lengthSq();
+ if(amt != 0) {
+ out.setTo(amt * b.x, amt * b.y);
+ }
+ return out;
+ };
+ Vec2Utils.projectUnit = function projectUnit(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var amt = a.dot(b);
+ if(amt != 0) {
+ out.setTo(amt * b.x, amt * b.y);
+ }
+ return out;
+ };
+ Vec2Utils.normalRightHand = function normalRightHand(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.y * -1, a.x);
+ };
+ Vec2Utils.normalize = function normalize(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var m = a.length();
+ if(m != 0) {
+ out.setTo(a.x / m, a.y / m);
+ }
+ return out;
+ };
+ Vec2Utils.dot = function dot(a, b) {
+ return ((a.x * b.x) + (a.y * b.y));
+ };
+ Vec2Utils.cross = function cross(a, b) {
+ return ((a.x * b.y) - (a.y * b.x));
+ };
+ Vec2Utils.angle = function angle(a, b) {
+ return Math.atan2(a.x * b.y - a.y * b.x, a.x * b.x + a.y * b.y);
+ };
+ Vec2Utils.angleSq = function angleSq(a, b) {
+ return a.subtract(b).angle(b.subtract(a));
+ };
+ Vec2Utils.rotateAroundOrigin = function rotateAroundOrigin(a, b, theta, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var x = a.x - b.x;
+ var y = a.y - b.y;
+ return out.setTo(x * Math.cos(theta) - y * Math.sin(theta) + b.x, x * Math.sin(theta) + y * Math.cos(theta) + b.y);
+ };
+ Vec2Utils.rotate = function rotate(a, theta, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ var c = Math.cos(theta);
+ var s = Math.sin(theta);
+ return out.setTo(a.x * c - a.y * s, a.x * s + a.y * c);
+ };
+ Vec2Utils.clone = function clone(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Vec2(); }
+ return out.setTo(a.x, a.y);
+ };
+ return Vec2Utils;
+ })();
+ Phaser.Vec2Utils = Vec2Utils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Mat3 = (function () {
+ function Mat3() {
+ this.data = [
+ 1,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ 0,
+ 0,
+ 1
+ ];
+ }
+ Object.defineProperty(Mat3.prototype, "a00", {
+ get: function () {
+ return this.data[0];
+ },
+ set: function (value) {
+ this.data[0] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a01", {
+ get: function () {
+ return this.data[1];
+ },
+ set: function (value) {
+ this.data[1] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a02", {
+ get: function () {
+ return this.data[2];
+ },
+ set: function (value) {
+ this.data[2] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a10", {
+ get: function () {
+ return this.data[3];
+ },
+ set: function (value) {
+ this.data[3] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a11", {
+ get: function () {
+ return this.data[4];
+ },
+ set: function (value) {
+ this.data[4] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a12", {
+ get: function () {
+ return this.data[5];
+ },
+ set: function (value) {
+ this.data[5] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a20", {
+ get: function () {
+ return this.data[6];
+ },
+ set: function (value) {
+ this.data[6] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a21", {
+ get: function () {
+ return this.data[7];
+ },
+ set: function (value) {
+ this.data[7] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Mat3.prototype, "a22", {
+ get: function () {
+ return this.data[8];
+ },
+ set: function (value) {
+ this.data[8] = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Mat3.prototype.copyFromMat3 = function (source) {
+ this.data[0] = source.data[0];
+ this.data[1] = source.data[1];
+ this.data[2] = source.data[2];
+ this.data[3] = source.data[3];
+ this.data[4] = source.data[4];
+ this.data[5] = source.data[5];
+ this.data[6] = source.data[6];
+ this.data[7] = source.data[7];
+ this.data[8] = source.data[8];
+ return this;
+ };
+ Mat3.prototype.copyFromMat4 = function (source) {
+ this.data[0] = source[0];
+ this.data[1] = source[1];
+ this.data[2] = source[2];
+ this.data[3] = source[4];
+ this.data[4] = source[5];
+ this.data[5] = source[6];
+ this.data[6] = source[8];
+ this.data[7] = source[9];
+ this.data[8] = source[10];
+ return this;
+ };
+ Mat3.prototype.clone = function (out) {
+ if (typeof out === "undefined") { out = new Phaser.Mat3(); }
+ out[0] = this.data[0];
+ out[1] = this.data[1];
+ out[2] = this.data[2];
+ out[3] = this.data[3];
+ out[4] = this.data[4];
+ out[5] = this.data[5];
+ out[6] = this.data[6];
+ out[7] = this.data[7];
+ out[8] = this.data[8];
+ return out;
+ };
+ Mat3.prototype.identity = function () {
+ return this.setTo(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ };
+ Mat3.prototype.translate = function (v) {
+ this.a20 = v.x * this.a00 + v.y * this.a10 + this.a20;
+ this.a21 = v.x * this.a01 + v.y * this.a11 + this.a21;
+ this.a22 = v.x * this.a02 + v.y * this.a12 + this.a22;
+ return this;
+ };
+ Mat3.prototype.setTemps = function () {
+ this._a00 = this.data[0];
+ this._a01 = this.data[1];
+ this._a02 = this.data[2];
+ this._a10 = this.data[3];
+ this._a11 = this.data[4];
+ this._a12 = this.data[5];
+ this._a20 = this.data[6];
+ this._a21 = this.data[7];
+ this._a22 = this.data[8];
+ };
+ Mat3.prototype.rotate = function (rad) {
+ this.setTemps();
+ var s = Phaser.GameMath.sinA[rad];
+ var c = Phaser.GameMath.cosA[rad];
+ this.data[0] = c * this._a00 + s * this._a10;
+ this.data[1] = c * this._a01 + s * this._a10;
+ this.data[2] = c * this._a02 + s * this._a12;
+ this.data[3] = c * this._a10 - s * this._a00;
+ this.data[4] = c * this._a11 - s * this._a01;
+ this.data[5] = c * this._a12 - s * this._a02;
+ return this;
+ };
+ Mat3.prototype.scale = function (v) {
+ this.data[0] = v.x * this.data[0];
+ this.data[1] = v.x * this.data[1];
+ this.data[2] = v.x * this.data[2];
+ this.data[3] = v.y * this.data[3];
+ this.data[4] = v.y * this.data[4];
+ this.data[5] = v.y * this.data[5];
+ return this;
+ };
+ Mat3.prototype.setTo = function (a00, a01, a02, a10, a11, a12, a20, a21, a22) {
+ this.data[0] = a00;
+ this.data[1] = a01;
+ this.data[2] = a02;
+ this.data[3] = a10;
+ this.data[4] = a11;
+ this.data[5] = a12;
+ this.data[6] = a20;
+ this.data[7] = a21;
+ this.data[8] = a22;
+ return this;
+ };
+ Mat3.prototype.toString = function () {
+ return '';
+ };
+ return Mat3;
+ })();
+ Phaser.Mat3 = Mat3;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Mat3Utils = (function () {
+ function Mat3Utils() { }
+ Mat3Utils.transpose = function transpose(source, dest) {
+ if (typeof dest === "undefined") { dest = null; }
+ if(dest === null) {
+ 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 = 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;
+ 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 = 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 = 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 = 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 = {}));
+var __extends = this.__extends || function (d, b) {
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Phaser;
+(function (Phaser) {
+ var QuadTree = (function (_super) {
+ __extends(QuadTree, _super);
+ function QuadTree(manager, x, y, width, height, parent) {
+ if (typeof parent === "undefined") { parent = null; }
+ _super.call(this, x, y, width, height);
+ QuadTree.physics = manager;
+ this._headA = this._tailA = new Phaser.LinkedList();
+ this._headB = this._tailB = new Phaser.LinkedList();
+ if(parent != null) {
+ if(parent._headA.object != null) {
+ this._iterator = parent._headA;
+ while(this._iterator != null) {
+ if(this._tailA.object != null) {
+ this._ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ this._ot.next = this._tailA;
+ }
+ this._tailA.object = this._iterator.object;
+ this._iterator = this._iterator.next;
+ }
+ }
+ if(parent._headB.object != null) {
+ this._iterator = parent._headB;
+ while(this._iterator != null) {
+ if(this._tailB.object != null) {
+ this._ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ this._ot.next = this._tailB;
+ }
+ this._tailB.object = this._iterator.object;
+ this._iterator = this._iterator.next;
+ }
+ }
+ } else {
+ QuadTree._min = (this.width + this.height) / (2 * QuadTree.divisions);
+ }
+ this._canSubdivide = (this.width > QuadTree._min) || (this.height > QuadTree._min);
+ this._northWestTree = null;
+ this._northEastTree = null;
+ this._southEastTree = null;
+ this._southWestTree = null;
+ this._leftEdge = this.x;
+ this._rightEdge = this.x + this.width;
+ this._halfWidth = this.width / 2;
+ this._midpointX = this._leftEdge + this._halfWidth;
+ this._topEdge = this.y;
+ this._bottomEdge = this.y + this.height;
+ this._halfHeight = this.height / 2;
+ this._midpointY = this._topEdge + this._halfHeight;
+ }
+ QuadTree.A_LIST = 0;
+ QuadTree.B_LIST = 1;
+ QuadTree.prototype.destroy = function () {
+ this._tailA.destroy();
+ this._tailB.destroy();
+ this._headA.destroy();
+ this._headB.destroy();
+ this._tailA = null;
+ this._tailB = null;
+ this._headA = null;
+ this._headB = null;
+ if(this._northWestTree != null) {
+ this._northWestTree.destroy();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.destroy();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.destroy();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.destroy();
+ }
+ this._northWestTree = null;
+ this._northEastTree = null;
+ this._southEastTree = null;
+ this._southWestTree = null;
+ QuadTree._object = null;
+ QuadTree._processingCallback = null;
+ QuadTree._notifyCallback = null;
+ };
+ QuadTree.prototype.load = function (objectOrGroup1, objectOrGroup2, notifyCallback, processCallback, context) {
+ if (typeof objectOrGroup2 === "undefined") { objectOrGroup2 = null; }
+ if (typeof notifyCallback === "undefined") { notifyCallback = null; }
+ if (typeof processCallback === "undefined") { processCallback = null; }
+ if (typeof context === "undefined") { context = null; }
+ this.add(objectOrGroup1, QuadTree.A_LIST);
+ if(objectOrGroup2 != null) {
+ this.add(objectOrGroup2, QuadTree.B_LIST);
+ QuadTree._useBothLists = true;
+ } else {
+ QuadTree._useBothLists = false;
+ }
+ QuadTree._notifyCallback = notifyCallback;
+ QuadTree._processingCallback = processCallback;
+ QuadTree._callbackContext = context;
+ };
+ QuadTree.prototype.add = function (objectOrGroup, list) {
+ QuadTree._list = list;
+ if(objectOrGroup.type == Phaser.Types.GROUP) {
+ this._i = 0;
+ this._members = objectOrGroup['members'];
+ this._l = objectOrGroup['length'];
+ while(this._i < this._l) {
+ this._basic = this._members[this._i++];
+ if(this._basic != null && this._basic.exists) {
+ if(this._basic.type == Phaser.Types.GROUP) {
+ this.add(this._basic, list);
+ } else {
+ QuadTree._object = this._basic;
+ if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
+ this.addObject();
+ }
+ }
+ }
+ }
+ } else {
+ QuadTree._object = objectOrGroup;
+ if(QuadTree._object.exists && QuadTree._object.body.allowCollisions) {
+ this.addObject();
+ }
+ }
+ };
+ QuadTree.prototype.addObject = function () {
+ if(!this._canSubdivide || ((this._leftEdge >= QuadTree._object.body.bounds.x) && (this._rightEdge <= QuadTree._object.body.bounds.right) && (this._topEdge >= QuadTree._object.body.bounds.y) && (this._bottomEdge <= QuadTree._object.body.bounds.bottom))) {
+ this.addToList();
+ return;
+ }
+ if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) {
+ if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ return;
+ }
+ if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ return;
+ }
+ }
+ if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) {
+ if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ return;
+ }
+ if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ return;
+ }
+ }
+ if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
+ if(this._northWestTree == null) {
+ this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northWestTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) {
+ if(this._northEastTree == null) {
+ this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this);
+ }
+ this._northEastTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
+ if(this._southEastTree == null) {
+ this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southEastTree.addObject();
+ }
+ if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) {
+ if(this._southWestTree == null) {
+ this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this);
+ }
+ this._southWestTree.addObject();
+ }
+ };
+ QuadTree.prototype.addToList = function () {
+ if(QuadTree._list == QuadTree.A_LIST) {
+ if(this._tailA.object != null) {
+ this._ot = this._tailA;
+ this._tailA = new Phaser.LinkedList();
+ this._ot.next = this._tailA;
+ }
+ this._tailA.object = QuadTree._object;
+ } else {
+ if(this._tailB.object != null) {
+ this._ot = this._tailB;
+ this._tailB = new Phaser.LinkedList();
+ this._ot.next = this._tailB;
+ }
+ this._tailB.object = QuadTree._object;
+ }
+ if(!this._canSubdivide) {
+ return;
+ }
+ if(this._northWestTree != null) {
+ this._northWestTree.addToList();
+ }
+ if(this._northEastTree != null) {
+ this._northEastTree.addToList();
+ }
+ if(this._southEastTree != null) {
+ this._southEastTree.addToList();
+ }
+ if(this._southWestTree != null) {
+ this._southWestTree.addToList();
+ }
+ };
+ QuadTree.prototype.execute = function () {
+ this._overlapProcessed = false;
+ if(this._headA.object != null) {
+ this._iterator = this._headA;
+ while(this._iterator != null) {
+ QuadTree._object = this._iterator.object;
+ if(QuadTree._useBothLists) {
+ QuadTree._iterator = this._headB;
+ } else {
+ QuadTree._iterator = this._iterator.next;
+ }
+ if(QuadTree._object.exists && (QuadTree._object.body.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode()) {
+ this._overlapProcessed = true;
+ }
+ this._iterator = this._iterator.next;
+ }
+ }
+ if((this._northWestTree != null) && this._northWestTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._northEastTree != null) && this._northEastTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._southEastTree != null) && this._southEastTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ if((this._southWestTree != null) && this._southWestTree.execute()) {
+ this._overlapProcessed = true;
+ }
+ return this._overlapProcessed;
+ };
+ QuadTree.prototype.overlapNode = function () {
+ this._overlapProcessed = false;
+ while(QuadTree._iterator != null) {
+ if(!QuadTree._object.exists || (QuadTree._object.body.allowCollisions <= 0)) {
+ break;
+ }
+ this._checkObject = QuadTree._iterator.object;
+ if((QuadTree._object === this._checkObject) || !this._checkObject.exists || (this._checkObject.body.allowCollisions <= 0)) {
+ QuadTree._iterator = QuadTree._iterator.next;
+ continue;
+ }
+ QuadTree._iterator = QuadTree._iterator.next;
+ }
+ return this._overlapProcessed;
+ };
+ return QuadTree;
+ })(Phaser.Rectangle);
+ Phaser.QuadTree = QuadTree;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var LinkedList = (function () {
+ function LinkedList() {
+ this.object = null;
+ this.next = null;
+ }
+ LinkedList.prototype.destroy = function () {
+ this.object = null;
+ if(this.next != null) {
+ this.next.destroy();
+ }
+ this.next = null;
+ };
+ return LinkedList;
+ })();
+ Phaser.LinkedList = LinkedList;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var RandomDataGenerator = (function () {
+ function RandomDataGenerator(seeds) {
+ if (typeof seeds === "undefined") { seeds = []; }
+ this.c = 1;
+ this.sow(seeds);
+ }
+ RandomDataGenerator.prototype.uint32 = function () {
+ return this.rnd.apply(this) * 0x100000000;
+ };
+ RandomDataGenerator.prototype.fract32 = function () {
+ return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;
+ };
+ RandomDataGenerator.prototype.rnd = function () {
+ var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10;
+ this.c = t | 0;
+ this.s0 = this.s1;
+ this.s1 = this.s2;
+ this.s2 = t - this.c;
+ return this.s2;
+ };
+ RandomDataGenerator.prototype.hash = function (data) {
+ var h, i, n;
+ n = 0xefc8249d;
+ data = data.toString();
+ for(i = 0; i < data.length; i++) {
+ n += data.charCodeAt(i);
+ h = 0.02519603282416938 * n;
+ n = h >>> 0;
+ h -= n;
+ h *= n;
+ n = h >>> 0;
+ h -= n;
+ n += h * 0x100000000;
+ }
+ return (n >>> 0) * 2.3283064365386963e-10;
+ };
+ RandomDataGenerator.prototype.sow = function (seeds) {
+ if (typeof seeds === "undefined") { seeds = []; }
+ this.s0 = this.hash(' ');
+ this.s1 = this.hash(this.s0);
+ this.s2 = this.hash(this.s1);
+ var seed;
+ for(var i = 0; seed = seeds[i++]; ) {
+ this.s0 -= this.hash(seed);
+ this.s0 += ~~(this.s0 < 0);
+ this.s1 -= this.hash(seed);
+ this.s1 += ~~(this.s1 < 0);
+ this.s2 -= this.hash(seed);
+ this.s2 += ~~(this.s2 < 0);
+ }
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "integer", {
+ get: function () {
+ return this.uint32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "frac", {
+ get: function () {
+ return this.fract32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "real", {
+ get: function () {
+ return this.uint32() + this.fract32();
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RandomDataGenerator.prototype.integerInRange = function (min, max) {
+ return Math.floor(this.realInRange(min, max));
+ };
+ RandomDataGenerator.prototype.realInRange = function (min, max) {
+ min = min || 0;
+ max = max || 0;
+ return this.frac * (max - min) + min;
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "normal", {
+ get: function () {
+ return 1 - 2 * this.frac;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(RandomDataGenerator.prototype, "uuid", {
+ get: function () {
+ var a, b;
+ for(b = a = ''; a++ < 36; b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-') {
+ ;
+ }
+ return b;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ RandomDataGenerator.prototype.pick = function (array) {
+ return array[this.integerInRange(0, array.length)];
+ };
+ RandomDataGenerator.prototype.weightedPick = function (array) {
+ return array[~~(Math.pow(this.frac, 2) * array.length)];
+ };
+ RandomDataGenerator.prototype.timestamp = function (min, max) {
+ if (typeof min === "undefined") { min = 946684800000; }
+ if (typeof max === "undefined") { max = 1577862000000; }
+ return this.realInRange(min, max);
+ };
+ Object.defineProperty(RandomDataGenerator.prototype, "angle", {
+ get: function () {
+ return this.integerInRange(-180, 180);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return RandomDataGenerator;
+ })();
+ Phaser.RandomDataGenerator = RandomDataGenerator;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Plugin = (function () {
+ function Plugin(game, parent) {
+ this.game = game;
+ this.parent = parent;
+ this.active = false;
+ this.visible = false;
+ this.hasPreUpdate = false;
+ this.hasUpdate = false;
+ this.hasPostUpdate = false;
+ this.hasPreRender = false;
+ this.hasRender = false;
+ this.hasPostRender = false;
+ }
+ Plugin.prototype.preUpdate = function () {
+ };
+ Plugin.prototype.update = function () {
+ };
+ Plugin.prototype.postUpdate = function () {
+ };
+ Plugin.prototype.preRender = function () {
+ };
+ Plugin.prototype.render = function () {
+ };
+ Plugin.prototype.postRender = function () {
+ };
+ Plugin.prototype.destroy = function () {
+ this.game = null;
+ this.parent = null;
+ this.active = false;
+ this.visible = false;
+ };
+ return Plugin;
+ })();
+ Phaser.Plugin = Plugin;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var PluginManager = (function () {
+ function PluginManager(game, parent) {
+ this.game = game;
+ this._parent = parent;
+ this.plugins = [];
+ }
+ PluginManager.prototype.add = function (plugin) {
+ var result = false;
+ if(typeof plugin === 'function') {
+ plugin = new plugin(this.game, this._parent);
+ } else {
+ plugin.game = this.game;
+ plugin.parent = this._parent;
+ }
+ if(typeof plugin['preUpdate'] === 'function') {
+ plugin.hasPreUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['update'] === 'function') {
+ plugin.hasUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['postUpdate'] === 'function') {
+ plugin.hasPostUpdate = true;
+ result = true;
+ }
+ if(typeof plugin['preRender'] === 'function') {
+ plugin.hasPreRender = true;
+ result = true;
+ }
+ if(typeof plugin['render'] === 'function') {
+ plugin.hasRender = true;
+ result = true;
+ }
+ if(typeof plugin['postRender'] === 'function') {
+ plugin.hasPostRender = true;
+ result = true;
+ }
+ if(result == true) {
+ if(plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) {
+ plugin.active = true;
+ }
+ if(plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender) {
+ plugin.visible = true;
+ }
+ this._pluginsLength = this.plugins.push(plugin);
+ return plugin;
+ } else {
+ return null;
+ }
+ };
+ PluginManager.prototype.remove = function (plugin) {
+ this._pluginsLength--;
+ };
+ PluginManager.prototype.preUpdate = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) {
+ this.plugins[this._p].preUpdate();
+ }
+ }
+ };
+ PluginManager.prototype.update = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasUpdate) {
+ this.plugins[this._p].update();
+ }
+ }
+ };
+ PluginManager.prototype.postUpdate = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) {
+ this.plugins[this._p].postUpdate();
+ }
+ }
+ };
+ PluginManager.prototype.preRender = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) {
+ this.plugins[this._p].preRender();
+ }
+ }
+ };
+ PluginManager.prototype.render = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasRender) {
+ this.plugins[this._p].render();
+ }
+ }
+ };
+ PluginManager.prototype.postRender = function () {
+ for(this._p = 0; this._p < this._pluginsLength; this._p++) {
+ if(this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) {
+ this.plugins[this._p].postRender();
+ }
+ }
+ };
+ PluginManager.prototype.destroy = function () {
+ this.plugins.length = 0;
+ this._pluginsLength = 0;
+ this.game = null;
+ this._parent = null;
+ };
+ return PluginManager;
+ })();
+ Phaser.PluginManager = PluginManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Signal = (function () {
+ function Signal() {
+ this._bindings = [];
+ this._prevParams = null;
+ this.memorize = false;
+ this._shouldPropagate = true;
+ this.active = true;
+ }
+ Signal.VERSION = '1.0.0';
+ Signal.prototype.validateListener = function (listener, fnName) {
+ if(typeof listener !== 'function') {
+ throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName));
+ }
+ };
+ Signal.prototype._registerListener = function (listener, isOnce, listenerContext, priority) {
+ var prevIndex = this._indexOfListener(listener, listenerContext);
+ var binding;
+ if(prevIndex !== -1) {
+ binding = this._bindings[prevIndex];
+ if(binding.isOnce() !== isOnce) {
+ throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.');
+ }
+ } else {
+ binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
+ this._addBinding(binding);
+ }
+ if(this.memorize && this._prevParams) {
+ binding.execute(this._prevParams);
+ }
+ return binding;
+ };
+ Signal.prototype._addBinding = function (binding) {
+ var n = this._bindings.length;
+ do {
+ --n;
+ }while(this._bindings[n] && binding.priority <= this._bindings[n].priority);
+ this._bindings.splice(n + 1, 0, binding);
+ };
+ Signal.prototype._indexOfListener = function (listener, context) {
+ var n = this._bindings.length;
+ var cur;
+ while(n--) {
+ cur = this._bindings[n];
+ if(cur.getListener() === listener && cur.context === context) {
+ return n;
+ }
+ }
+ return -1;
+ };
+ Signal.prototype.has = function (listener, context) {
+ if (typeof context === "undefined") { context = null; }
+ return this._indexOfListener(listener, context) !== -1;
+ };
+ Signal.prototype.add = function (listener, listenerContext, priority) {
+ if (typeof listenerContext === "undefined") { listenerContext = null; }
+ if (typeof priority === "undefined") { priority = 0; }
+ this.validateListener(listener, 'add');
+ return this._registerListener(listener, false, listenerContext, priority);
+ };
+ Signal.prototype.addOnce = function (listener, listenerContext, priority) {
+ if (typeof listenerContext === "undefined") { listenerContext = null; }
+ if (typeof priority === "undefined") { priority = 0; }
+ this.validateListener(listener, 'addOnce');
+ return this._registerListener(listener, true, listenerContext, priority);
+ };
+ Signal.prototype.remove = function (listener, context) {
+ if (typeof context === "undefined") { context = null; }
+ this.validateListener(listener, 'remove');
+ var i = this._indexOfListener(listener, context);
+ if(i !== -1) {
+ this._bindings[i]._destroy();
+ this._bindings.splice(i, 1);
+ }
+ return listener;
+ };
+ Signal.prototype.removeAll = function () {
+ if(this._bindings) {
+ var n = this._bindings.length;
+ while(n--) {
+ this._bindings[n]._destroy();
+ }
+ this._bindings.length = 0;
+ }
+ };
+ Signal.prototype.getNumListeners = function () {
+ return this._bindings.length;
+ };
+ Signal.prototype.halt = function () {
+ this._shouldPropagate = false;
+ };
+ Signal.prototype.dispatch = function () {
+ var paramsArr = [];
+ for (var _i = 0; _i < (arguments.length - 0); _i++) {
+ paramsArr[_i] = arguments[_i + 0];
+ }
+ if(!this.active) {
+ return;
+ }
+ var n = this._bindings.length;
+ var bindings;
+ if(this.memorize) {
+ this._prevParams = paramsArr;
+ }
+ if(!n) {
+ return;
+ }
+ bindings = this._bindings.slice(0);
+ this._shouldPropagate = true;
+ do {
+ n--;
+ }while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
+ };
+ Signal.prototype.forget = function () {
+ this._prevParams = null;
+ };
+ Signal.prototype.dispose = function () {
+ this.removeAll();
+ delete this._bindings;
+ delete this._prevParams;
+ };
+ Signal.prototype.toString = function () {
+ return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']';
+ };
+ return Signal;
+ })();
+ Phaser.Signal = Signal;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var SignalBinding = (function () {
+ function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
+ if (typeof priority === "undefined") { priority = 0; }
+ this.active = true;
+ this.params = null;
+ this._listener = listener;
+ this._isOnce = isOnce;
+ this.context = listenerContext;
+ this._signal = signal;
+ this.priority = priority || 0;
+ }
+ SignalBinding.prototype.execute = function (paramsArr) {
+ var handlerReturn;
+ var params;
+ if(this.active && !!this._listener) {
+ params = this.params ? this.params.concat(paramsArr) : paramsArr;
+ handlerReturn = this._listener.apply(this.context, params);
+ if(this._isOnce) {
+ this.detach();
+ }
+ }
+ return handlerReturn;
+ };
+ SignalBinding.prototype.detach = function () {
+ return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
+ };
+ SignalBinding.prototype.isBound = function () {
+ return (!!this._signal && !!this._listener);
+ };
+ SignalBinding.prototype.isOnce = function () {
+ return this._isOnce;
+ };
+ SignalBinding.prototype.getListener = function () {
+ return this._listener;
+ };
+ SignalBinding.prototype.getSignal = function () {
+ return this._signal;
+ };
+ SignalBinding.prototype._destroy = function () {
+ delete this._signal;
+ delete this._listener;
+ delete this.context;
+ };
+ SignalBinding.prototype.toString = function () {
+ return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']';
+ };
+ return SignalBinding;
+ })();
+ Phaser.SignalBinding = SignalBinding;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Group = (function () {
+ function Group(game, maxSize) {
+ if (typeof maxSize === "undefined") { maxSize = 0; }
+ this._sortIndex = '';
+ this._zCounter = 0;
+ this.ID = -1;
+ this.z = -1;
+ this.group = null;
+ this.modified = false;
+ this.game = game;
+ this.type = Phaser.Types.GROUP;
+ this.active = true;
+ this.exists = true;
+ this.visible = true;
+ this.members = [];
+ this.length = 0;
+ this._maxSize = maxSize;
+ this._marker = 0;
+ this._sortIndex = null;
+ this.ID = this.game.world.getNextGroupID();
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this.texture.opaque = false;
+ }
+ Group.prototype.getNextZIndex = function () {
+ return this._zCounter++;
+ };
+ Group.prototype.destroy = function () {
+ if(this.members != null) {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ this._member.destroy();
+ }
+ }
+ this.members.length = 0;
+ }
+ this._sortIndex = null;
+ };
+ Group.prototype.update = function () {
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.active) {
+ if(this._member.type != Phaser.Types.GROUP) {
+ this._member.preUpdate();
+ }
+ this._member.update();
+ }
+ }
+ };
+ Group.prototype.postUpdate = function () {
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.active) {
+ this._member.postUpdate();
+ }
+ }
+ };
+ Group.prototype.render = function (camera) {
+ if(camera.isHidden(this) == true) {
+ return;
+ }
+ this.game.renderer.groupRenderer.preRender(camera, this);
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) {
+ if(this._member.type == Phaser.Types.GROUP) {
+ this._member.render(camera);
+ } else {
+ this.game.renderer.renderGameObject(camera, this._member);
+ }
+ }
+ }
+ this.game.renderer.groupRenderer.postRender(camera, this);
+ };
+ Group.prototype.directRender = function (camera) {
+ this.game.renderer.groupRenderer.preRender(camera, this);
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists) {
+ if(this._member.type == Phaser.Types.GROUP) {
+ this._member.directRender(camera);
+ } else {
+ this.game.renderer.renderGameObject(this._member);
+ }
+ }
+ }
+ this.game.renderer.groupRenderer.postRender(camera, this);
+ };
+ Object.defineProperty(Group.prototype, "maxSize", {
+ get: function () {
+ return this._maxSize;
+ },
+ set: function (size) {
+ this._maxSize = size;
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ if(this._maxSize == 0 || this.members == null || (this._maxSize >= this.members.length)) {
+ return;
+ }
+ this._i = this._maxSize;
+ this._length = this.members.length;
+ while(this._i < this._length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ this._member.destroy();
+ }
+ }
+ this.length = this.members.length = this._maxSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Group.prototype.add = function (object) {
+ if(object.group && (object.group.ID == this.ID || (object.type == Phaser.Types.GROUP && object.ID == this.ID))) {
+ return object;
+ }
+ this._i = 0;
+ this._length = this.members.length;
+ while(this._i < this._length) {
+ if(this.members[this._i] == null) {
+ this.members[this._i] = object;
+ this.setObjectIDs(object);
+ if(this._i >= this.length) {
+ this.length = this._i + 1;
+ }
+ return object;
+ }
+ this._i++;
+ }
+ if(this._maxSize > 0) {
+ if(this.members.length >= this._maxSize) {
+ return object;
+ } else if(this.members.length * 2 <= this._maxSize) {
+ this.members.length *= 2;
+ } else {
+ this.members.length = this._maxSize;
+ }
+ } else {
+ this.members.length *= 2;
+ }
+ this.members[this._i] = object;
+ this.length = this._i + 1;
+ this.setObjectIDs(object);
+ return object;
+ };
+ Group.prototype.addNewSprite = function (x, y, key, frame) {
+ if (typeof key === "undefined") { key = ''; }
+ if (typeof frame === "undefined") { frame = null; }
+ return this.add(new Phaser.Sprite(this.game, x, y, key, frame));
+ };
+ Group.prototype.setObjectIDs = function (object, zIndex) {
+ if (typeof zIndex === "undefined") { zIndex = -1; }
+ if(object.group !== null) {
+ object.group.remove(object);
+ }
+ object.group = this;
+ if(zIndex == -1) {
+ zIndex = this.getNextZIndex();
+ }
+ object.z = zIndex;
+ if(object['events']) {
+ object['events'].onAddedToGroup.dispatch(object, this, object.z);
+ }
+ };
+ Group.prototype.recycle = function (objectClass) {
+ if (typeof objectClass === "undefined") { objectClass = null; }
+ if(this._maxSize > 0) {
+ if(this.length < this._maxSize) {
+ if(objectClass == null) {
+ return null;
+ }
+ return this.add(new objectClass(this.game));
+ } else {
+ this._member = this.members[this._marker++];
+ if(this._marker >= this._maxSize) {
+ this._marker = 0;
+ }
+ return this._member;
+ }
+ } else {
+ this._member = this.getFirstAvailable(objectClass);
+ if(this._member != null) {
+ return this._member;
+ }
+ if(objectClass == null) {
+ return null;
+ }
+ return this.add(new objectClass(this.game));
+ }
+ };
+ Group.prototype.remove = function (object, splice) {
+ if (typeof splice === "undefined") { splice = false; }
+ this._i = this.members.indexOf(object);
+ if(this._i < 0 || (this._i >= this.members.length)) {
+ return null;
+ }
+ if(splice) {
+ this.members.splice(this._i, 1);
+ this.length--;
+ } else {
+ this.members[this._i] = null;
+ }
+ if(object['events']) {
+ object['events'].onRemovedFromGroup.dispatch(object, this);
+ }
+ object.group = null;
+ object.z = -1;
+ return object;
+ };
+ Group.prototype.replace = function (oldObject, newObject) {
+ this._i = this.members.indexOf(oldObject);
+ if(this._i < 0 || (this._i >= this.members.length)) {
+ return null;
+ }
+ this.setObjectIDs(newObject, this.members[this._i].z);
+ this.remove(this.members[this._i]);
+ this.members[this._i] = newObject;
+ return newObject;
+ };
+ Group.prototype.swap = function (child1, child2, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(child1.group.ID != this.ID || child2.group.ID != this.ID || child1 === child2) {
+ return false;
+ }
+ var tempZ = child1.z;
+ child1.z = child2.z;
+ child2.z = tempZ;
+ if(sort) {
+ this.sort();
+ }
+ return true;
+ };
+ Group.prototype.bringToTop = function (child) {
+ var oldZ = child.z;
+ if(!child || child.group == null || child.group.ID != this.ID) {
+ return false;
+ }
+ 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;
+ }
+ }
+ if(child.z == topZ) {
+ return false;
+ }
+ child.z = topZ + 1;
+ this.sort();
+ for(var i = 0; i < this.length; i++) {
+ if(this.members[i]) {
+ this.members[i].z = i;
+ }
+ }
+ return true;
+ };
+ Group.prototype.sort = function (index, order) {
+ if (typeof index === "undefined") { index = 'z'; }
+ if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
+ var _this = this;
+ this._sortIndex = index;
+ this._sortOrder = order;
+ this.members.sort(function (a, b) {
+ return _this.sortHandler(a, b);
+ });
+ };
+ Group.prototype.sortHandler = function (obj1, obj2) {
+ if(!obj1 || !obj2) {
+ return 0;
+ }
+ if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ Group.prototype.setAll = function (variableName, value, recurse) {
+ if (typeof recurse === "undefined") { recurse = true; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recurse && this._member.type == Phaser.Types.GROUP) {
+ this._member.setAll(variableName, value, recurse);
+ } else {
+ this._member[variableName] = value;
+ }
+ }
+ }
+ };
+ Group.prototype.callAll = function (functionName, recurse) {
+ if (typeof recurse === "undefined") { recurse = true; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recurse && this._member.type == Phaser.Types.GROUP) {
+ this._member.callAll(functionName, recurse);
+ } else {
+ this._member[functionName]();
+ }
+ }
+ }
+ };
+ Group.prototype.forEach = function (callback, recursive) {
+ if (typeof recursive === "undefined") { recursive = false; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(recursive && this._member.type == Phaser.Types.GROUP) {
+ this._member.forEach(callback, true);
+ } else {
+ callback.call(this, this._member);
+ }
+ }
+ }
+ };
+ Group.prototype.forEachAlive = function (context, callback, recursive) {
+ if (typeof recursive === "undefined") { recursive = false; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.alive) {
+ if(recursive && this._member.type == Phaser.Types.GROUP) {
+ this._member.forEachAlive(context, callback, true);
+ } else {
+ callback.call(context, this._member);
+ }
+ }
+ }
+ };
+ Group.prototype.getFirstAvailable = function (objectClass) {
+ if (typeof objectClass === "undefined") { objectClass = null; }
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && !this._member.exists && ((objectClass == null) || (typeof this._member === objectClass))) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstNull = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ if(this.members[this._i] == null) {
+ return this._i;
+ } else {
+ this._i++;
+ }
+ }
+ return -1;
+ };
+ Group.prototype.getFirstExtant = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null && this._member.exists) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstAlive = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && this._member.exists && this._member.alive) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.getFirstDead = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && !this._member.alive) {
+ return this._member;
+ }
+ }
+ return null;
+ };
+ Group.prototype.countLiving = function () {
+ this._count = -1;
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(this._count < 0) {
+ this._count = 0;
+ }
+ if(this._member.exists && this._member.alive) {
+ this._count++;
+ }
+ }
+ }
+ return this._count;
+ };
+ Group.prototype.countDead = function () {
+ this._count = -1;
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if(this._member != null) {
+ if(this._count < 0) {
+ this._count = 0;
+ }
+ if(!this._member.alive) {
+ this._count++;
+ }
+ }
+ }
+ return this._count;
+ };
+ Group.prototype.getRandom = function (startIndex, length) {
+ if (typeof startIndex === "undefined") { startIndex = 0; }
+ if (typeof length === "undefined") { length = 0; }
+ if(length == 0) {
+ length = this.length;
+ }
+ return this.game.math.getRandom(this.members, startIndex, length);
+ };
+ Group.prototype.clear = function () {
+ this.length = this.members.length = 0;
+ };
+ Group.prototype.kill = function () {
+ this._i = 0;
+ while(this._i < this.length) {
+ this._member = this.members[this._i++];
+ if((this._member != null) && this._member.exists) {
+ this._member.kill();
+ }
+ }
+ };
+ return Group;
+ })();
+ Phaser.Group = Group;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Camera = (function () {
+ function Camera(game, id, x, y, width, height) {
+ this._target = null;
+ this.worldBounds = null;
+ this.modified = false;
+ this.deadzone = null;
+ this.visible = true;
+ this.z = -1;
+ this.game = game;
+ this.ID = id;
+ this.z = id;
+ width = this.game.math.clamp(width, this.game.stage.width, 1);
+ height = this.game.math.clamp(height, this.game.stage.height, 1);
+ this.worldView = new Phaser.Rectangle(0, 0, width, height);
+ this.screenView = new Phaser.Rectangle(x, y, width, height);
+ this.plugins = new Phaser.PluginManager(this.game, this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this._canvas = document.createElement('canvas');
+ this._canvas.width = width;
+ this._canvas.height = height;
+ this._renderLocal = true;
+ this.texture.canvas = this._canvas;
+ this.texture.context = this.texture.canvas.getContext('2d');
+ this.texture.backgroundColor = this.game.stage.backgroundColor;
+ this.scale = this.transform.scale;
+ this.alpha = this.texture.alpha;
+ this.origin = this.transform.origin;
+ this.crop = this.texture.crop;
+ }
+ Object.defineProperty(Camera.prototype, "alpha", {
+ get: function () {
+ return this.texture.alpha;
+ },
+ set: function (value) {
+ this.texture.alpha = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "directToStage", {
+ set: function (value) {
+ if(value) {
+ this._renderLocal = false;
+ this.texture.canvas = this.game.stage.canvas;
+ Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
+ } else {
+ this._renderLocal = true;
+ this.texture.canvas = this._canvas;
+ Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
+ }
+ this.texture.context = this.texture.canvas.getContext('2d');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Camera.prototype.hide = function (object) {
+ object.texture.hideFromCamera(this);
+ };
+ Camera.prototype.isHidden = function (object) {
+ return object.texture.isHidden(this);
+ };
+ Camera.prototype.show = function (object) {
+ object.texture.showToCamera(this);
+ };
+ Camera.prototype.follow = function (target, style) {
+ if (typeof style === "undefined") { style = Phaser.Types.CAMERA_FOLLOW_LOCKON; }
+ this._target = target;
+ var helper;
+ switch(style) {
+ case Phaser.Types.CAMERA_FOLLOW_PLATFORMER:
+ var w = this.width / 8;
+ var h = this.height / 3;
+ this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_TOPDOWN:
+ helper = Math.max(this.width, this.height) / 4;
+ this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT:
+ helper = Math.max(this.width, this.height) / 8;
+ this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
+ break;
+ case Phaser.Types.CAMERA_FOLLOW_LOCKON:
+ default:
+ this.deadzone = null;
+ break;
+ }
+ };
+ Camera.prototype.focusOnXY = function (x, y) {
+ x += (x > 0) ? 0.0000001 : -0.0000001;
+ y += (y > 0) ? 0.0000001 : -0.0000001;
+ this.worldView.x = Math.round(x - this.worldView.halfWidth);
+ this.worldView.y = Math.round(y - this.worldView.halfHeight);
+ };
+ Camera.prototype.focusOn = function (point) {
+ point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
+ point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
+ this.worldView.x = Math.round(point.x - this.worldView.halfWidth);
+ this.worldView.y = Math.round(point.y - this.worldView.halfHeight);
+ };
+ Camera.prototype.setBounds = function (x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ if(this.worldBounds == null) {
+ this.worldBounds = new Phaser.Rectangle();
+ }
+ this.worldBounds.setTo(x, y, width, height);
+ this.worldView.x = x;
+ this.worldView.y = y;
+ this.update();
+ };
+ Camera.prototype.update = function () {
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ this.plugins.preUpdate();
+ if(this._target !== null) {
+ if(this.deadzone == null) {
+ this.focusOnXY(this._target.x, this._target.y);
+ } else {
+ var edge;
+ var targetX = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
+ var targetY = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
+ edge = targetX - this.deadzone.x;
+ if(this.worldView.x > edge) {
+ this.worldView.x = edge;
+ }
+ edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
+ if(this.worldView.x < edge) {
+ this.worldView.x = edge;
+ }
+ edge = targetY - this.deadzone.y;
+ if(this.worldView.y > edge) {
+ this.worldView.y = edge;
+ }
+ edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
+ if(this.worldView.y < edge) {
+ this.worldView.y = edge;
+ }
+ }
+ }
+ if(this.worldBounds !== null) {
+ if(this.worldView.x < this.worldBounds.left) {
+ this.worldView.x = this.worldBounds.left;
+ }
+ if(this.worldView.x > this.worldBounds.right - this.width) {
+ this.worldView.x = (this.worldBounds.right - this.width) + 1;
+ }
+ if(this.worldView.y < this.worldBounds.top) {
+ this.worldView.y = this.worldBounds.top;
+ }
+ if(this.worldView.y > this.worldBounds.bottom - this.height) {
+ this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
+ }
+ }
+ this.worldView.floor();
+ this.plugins.update();
+ };
+ Camera.prototype.postUpdate = function () {
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ if(this.worldBounds !== null) {
+ if(this.worldView.x < this.worldBounds.left) {
+ this.worldView.x = this.worldBounds.left;
+ }
+ if(this.worldView.x > this.worldBounds.right - this.width) {
+ this.worldView.x = this.worldBounds.right - this.width;
+ }
+ if(this.worldView.y < this.worldBounds.top) {
+ this.worldView.y = this.worldBounds.top;
+ }
+ if(this.worldView.y > this.worldBounds.bottom - this.height) {
+ this.worldView.y = this.worldBounds.bottom - this.height;
+ }
+ }
+ this.worldView.floor();
+ this.plugins.postUpdate();
+ };
+ Camera.prototype.destroy = function () {
+ this.game.world.cameras.removeCamera(this.ID);
+ this.plugins.destroy();
+ };
+ Object.defineProperty(Camera.prototype, "x", {
+ get: function () {
+ return this.worldView.x;
+ },
+ set: function (value) {
+ this.worldView.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "y", {
+ get: function () {
+ return this.worldView.y;
+ },
+ set: function (value) {
+ this.worldView.y = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "width", {
+ get: function () {
+ return this.screenView.width;
+ },
+ set: function (value) {
+ this.screenView.width = value;
+ this.worldView.width = value;
+ if(value !== this.texture.canvas.width) {
+ this.texture.canvas.width = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "height", {
+ get: function () {
+ return this.screenView.height;
+ },
+ set: function (value) {
+ this.screenView.height = value;
+ this.worldView.height = value;
+ if(value !== this.texture.canvas.height) {
+ this.texture.canvas.height = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Camera.prototype.setPosition = function (x, y) {
+ this.screenView.x = x;
+ this.screenView.y = y;
+ };
+ Camera.prototype.setSize = function (width, height) {
+ this.screenView.width = width * this.transform.scale.x;
+ this.screenView.height = height * this.transform.scale.y;
+ this.worldView.width = width;
+ this.worldView.height = height;
+ if(width !== this.texture.canvas.width) {
+ this.texture.canvas.width = width;
+ }
+ if(height !== this.texture.canvas.height) {
+ this.texture.canvas.height = height;
+ }
+ };
+ Object.defineProperty(Camera.prototype, "rotation", {
+ get: function () {
+ return this.transform.rotation;
+ },
+ set: function (value) {
+ this.transform.rotation = this.game.math.wrap(value, 360, 0);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Camera;
+ })();
+ Phaser.Camera = Camera;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var CameraManager = (function () {
+ function CameraManager(game, x, y, width, height) {
+ this._sortIndex = '';
+ this.game = game;
+ this._cameras = [];
+ this._cameraLength = 0;
+ this.defaultCamera = this.addCamera(x, y, width, height);
+ this.defaultCamera.directToStage = true;
+ this.current = this.defaultCamera;
+ }
+ CameraManager.prototype.getAll = function () {
+ return this._cameras;
+ };
+ CameraManager.prototype.update = function () {
+ for(var i = 0; i < this._cameras.length; i++) {
+ this._cameras[i].update();
+ }
+ };
+ CameraManager.prototype.postUpdate = function () {
+ for(var i = 0; i < this._cameras.length; i++) {
+ this._cameras[i].postUpdate();
+ }
+ };
+ CameraManager.prototype.addCamera = function (x, y, width, height) {
+ var newCam = new Phaser.Camera(this.game, this._cameraLength, x, y, width, height);
+ this._cameraLength = this._cameras.push(newCam);
+ return newCam;
+ };
+ CameraManager.prototype.removeCamera = function (id) {
+ for(var c = 0; c < this._cameras.length; c++) {
+ if(this._cameras[c].ID == id) {
+ if(this.current.ID === this._cameras[c].ID) {
+ this.current = null;
+ }
+ this._cameras.splice(c, 1);
+ return true;
+ }
+ }
+ return false;
+ };
+ CameraManager.prototype.swap = function (camera1, camera2, sort) {
+ if (typeof sort === "undefined") { sort = true; }
+ if(camera1.ID == camera2.ID) {
+ return false;
+ }
+ var tempZ = camera1.z;
+ camera1.z = camera2.z;
+ camera2.z = tempZ;
+ if(sort) {
+ this.sort();
+ }
+ return true;
+ };
+ CameraManager.prototype.getCameraUnderPoint = function (x, y) {
+ for(var c = this._cameraLength - 1; c >= 0; c--) {
+ if(this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) {
+ return this._cameras[c];
+ }
+ }
+ return null;
+ };
+ CameraManager.prototype.sort = function (index, order) {
+ if (typeof index === "undefined") { index = 'z'; }
+ if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
+ var _this = this;
+ this._sortIndex = index;
+ this._sortOrder = order;
+ this._cameras.sort(function (a, b) {
+ return _this.sortHandler(a, b);
+ });
+ };
+ CameraManager.prototype.sortHandler = function (obj1, obj2) {
+ if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
+ return this._sortOrder;
+ } else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
+ return -this._sortOrder;
+ }
+ return 0;
+ };
+ CameraManager.prototype.destroy = function () {
+ this._cameras.length = 0;
+ this.current = this.addCamera(0, 0, this.game.stage.width, this.game.stage.height);
+ };
+ return CameraManager;
+ })();
+ Phaser.CameraManager = CameraManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Display) {
+ var CSS3Filters = (function () {
+ function CSS3Filters(parent) {
+ this._blur = 0;
+ this._grayscale = 0;
+ this._sepia = 0;
+ this._brightness = 0;
+ this._contrast = 0;
+ this._hueRotate = 0;
+ this._invert = 0;
+ this._opacity = 0;
+ this._saturate = 0;
+ this.parent = parent;
+ }
+ CSS3Filters.prototype.setFilter = function (local, prefix, value, unit) {
+ this[local] = value;
+ if(this.parent) {
+ this.parent.style['-webkit-filter'] = prefix + '(' + value + unit + ')';
+ }
+ };
+ Object.defineProperty(CSS3Filters.prototype, "blur", {
+ get: function () {
+ return this._blur;
+ },
+ set: function (radius) {
+ this.setFilter('_blur', 'blur', radius, 'px');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "grayscale", {
+ get: function () {
+ return this._grayscale;
+ },
+ set: function (amount) {
+ this.setFilter('_grayscale', 'grayscale', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "sepia", {
+ get: function () {
+ return this._sepia;
+ },
+ set: function (amount) {
+ this.setFilter('_sepia', 'sepia', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "brightness", {
+ get: function () {
+ return this._brightness;
+ },
+ set: function (amount) {
+ this.setFilter('_brightness', 'brightness', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "contrast", {
+ get: function () {
+ return this._contrast;
+ },
+ set: function (amount) {
+ this.setFilter('_contrast', 'contrast', amount, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "hueRotate", {
+ get: function () {
+ return this._hueRotate;
+ },
+ set: function (angle) {
+ this.setFilter('_hueRotate', 'hue-rotate', angle, 'deg');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "invert", {
+ get: function () {
+ return this._invert;
+ },
+ set: function (value) {
+ this.setFilter('_invert', 'invert', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "opacity", {
+ get: function () {
+ return this._opacity;
+ },
+ set: function (value) {
+ this.setFilter('_opacity', 'opacity', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(CSS3Filters.prototype, "saturate", {
+ get: function () {
+ return this._saturate;
+ },
+ set: function (value) {
+ this.setFilter('_saturate', 'saturate', value, '%');
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return CSS3Filters;
+ })();
+ Display.CSS3Filters = CSS3Filters;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Display) {
+ var DynamicTexture = (function () {
+ function DynamicTexture(game, width, height) {
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this.globalCompositeOperation = null;
+ this.game = game;
+ this.type = Phaser.Types.DYNAMICTEXTURE;
+ this.canvas = document.createElement('canvas');
+ this.canvas.width = width;
+ this.canvas.height = height;
+ this.context = this.canvas.getContext('2d');
+ this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
+ this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ }
+ DynamicTexture.prototype.getPixel = function (x, y) {
+ var imageData = this.context.getImageData(x, y, 1, 1);
+ return Phaser.ColorUtils.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ DynamicTexture.prototype.getPixel32 = function (x, y) {
+ var imageData = this.context.getImageData(x, y, 1, 1);
+ return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
+ };
+ DynamicTexture.prototype.getPixels = function (rect) {
+ return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
+ };
+ DynamicTexture.prototype.setPixel = function (x, y, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(x, y, 1, 1);
+ };
+ DynamicTexture.prototype.setPixel32 = function (x, y, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(x, y, 1, 1);
+ };
+ DynamicTexture.prototype.setPixels = function (rect, input) {
+ this.context.putImageData(input, rect.x, rect.y);
+ };
+ DynamicTexture.prototype.fillRect = function (rect, color) {
+ this.context.fillStyle = color;
+ this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
+ DynamicTexture.prototype.pasteImage = function (key, frame, destX, destY, destWidth, destHeight) {
+ if (typeof frame === "undefined") { frame = -1; }
+ if (typeof destX === "undefined") { destX = 0; }
+ if (typeof destY === "undefined") { destY = 0; }
+ if (typeof destWidth === "undefined") { destWidth = null; }
+ if (typeof destHeight === "undefined") { destHeight = null; }
+ var texture = null;
+ var frameData;
+ this._sx = 0;
+ this._sy = 0;
+ this._dx = destX;
+ this._dy = destY;
+ if(frame > -1) {
+ } else {
+ texture = this.game.cache.getImage(key);
+ this._sw = texture.width;
+ this._sh = texture.height;
+ this._dw = texture.width;
+ this._dh = texture.height;
+ }
+ if(destWidth !== null) {
+ this._dw = destWidth;
+ }
+ if(destHeight !== null) {
+ this._dh = destHeight;
+ }
+ if(texture != null) {
+ this.context.drawImage(texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ }
+ };
+ DynamicTexture.prototype.copyPixels = function (sourceTexture, sourceRect, destPoint) {
+ if(Phaser.RectangleUtils.equals(sourceRect, this.bounds) == true) {
+ this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
+ } else {
+ this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
+ }
+ };
+ DynamicTexture.prototype.add = function (sprite) {
+ sprite.texture.canvas = this.canvas;
+ sprite.texture.context = this.context;
+ };
+ DynamicTexture.prototype.assignCanvasToGameObjects = function (objects) {
+ for(var i = 0; i < objects.length; i++) {
+ if(objects[i].texture) {
+ objects[i].texture.canvas = this.canvas;
+ objects[i].texture.context = this.context;
+ }
+ }
+ };
+ DynamicTexture.prototype.clear = function () {
+ this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
+ };
+ DynamicTexture.prototype.render = function (x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if(this.globalCompositeOperation) {
+ this.game.stage.context.save();
+ this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
+ }
+ this.game.stage.context.drawImage(this.canvas, x, y);
+ if(this.globalCompositeOperation) {
+ this.game.stage.context.restore();
+ }
+ };
+ Object.defineProperty(DynamicTexture.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(DynamicTexture.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return DynamicTexture;
+ })();
+ Display.DynamicTexture = DynamicTexture;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Display) {
+ var Texture = (function () {
+ function Texture(parent) {
+ this.imageTexture = null;
+ this.dynamicTexture = null;
+ this.loaded = false;
+ this.opaque = false;
+ this.backgroundColor = 'rgb(255,255,255)';
+ this.globalCompositeOperation = null;
+ this.renderRotation = true;
+ this.flippedX = false;
+ this.flippedY = false;
+ this.isDynamic = false;
+ this.game = parent.game;
+ this.parent = parent;
+ this.canvas = parent.game.stage.canvas;
+ this.context = parent.game.stage.context;
+ this.alpha = 1;
+ this.flippedX = false;
+ this.flippedY = false;
+ this._width = 16;
+ this._height = 16;
+ this.cameraBlacklist = [];
+ this._blacklist = 0;
+ }
+ Texture.prototype.hideFromCamera = function (camera) {
+ if(this.isHidden(camera) == false) {
+ this.cameraBlacklist.push(camera.ID);
+ this._blacklist++;
+ }
+ };
+ Texture.prototype.isHidden = function (camera) {
+ if(this._blacklist && this.cameraBlacklist.indexOf(camera.ID) !== -1) {
+ return true;
+ }
+ return false;
+ };
+ Texture.prototype.showToCamera = function (camera) {
+ if(this.isHidden(camera)) {
+ this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
+ this._blacklist--;
+ }
+ };
+ Texture.prototype.setTo = function (image, dynamic) {
+ if (typeof image === "undefined") { image = null; }
+ if (typeof dynamic === "undefined") { dynamic = null; }
+ if(dynamic) {
+ this.isDynamic = true;
+ this.dynamicTexture = dynamic;
+ this.texture = this.dynamicTexture.canvas;
+ } else {
+ this.isDynamic = false;
+ this.imageTexture = image;
+ this.texture = this.imageTexture;
+ this._width = image.width;
+ this._height = image.height;
+ }
+ this.loaded = true;
+ return this.parent;
+ };
+ Texture.prototype.loadImage = function (key, clearAnimations, updateBody) {
+ if (typeof clearAnimations === "undefined") { clearAnimations = true; }
+ if (typeof updateBody === "undefined") { updateBody = true; }
+ if(clearAnimations && this.parent['animations'] && this.parent['animations'].frameData !== null) {
+ this.parent.animations.destroy();
+ }
+ if(this.game.cache.getImage(key) !== null) {
+ this.setTo(this.game.cache.getImage(key), null);
+ this.cacheKey = key;
+ if(this.game.cache.isSpriteSheet(key) && this.parent['animations']) {
+ this.parent.animations.loadFrameData(this.parent.game.cache.getFrameData(key));
+ } else {
+ if(updateBody && this.parent['body']) {
+ this.parent.body.bounds.width = this.width;
+ this.parent.body.bounds.height = this.height;
+ }
+ }
+ }
+ };
+ Texture.prototype.loadDynamicTexture = function (texture) {
+ if(this.parent.animations.frameData !== null) {
+ this.parent.animations.destroy();
+ }
+ this.setTo(null, texture);
+ this.parent.texture.width = this.width;
+ this.parent.texture.height = this.height;
+ };
+ Object.defineProperty(Texture.prototype, "width", {
+ get: function () {
+ if(this.isDynamic) {
+ return this.dynamicTexture.width;
+ } else {
+ return this._width;
+ }
+ },
+ set: function (value) {
+ this._width = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Texture.prototype, "height", {
+ get: function () {
+ if(this.isDynamic) {
+ return this.dynamicTexture.height;
+ } else {
+ return this._height;
+ }
+ },
+ set: function (value) {
+ this._height = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Texture;
+ })();
+ Display.Texture = Texture;
+ })(Phaser.Display || (Phaser.Display = {}));
+ var Display = Phaser.Display;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Back = (function () {
+ function Back() { }
+ Back.In = function In(k) {
+ var s = 1.70158;
+ return k * k * ((s + 1) * k - s);
+ };
+ Back.Out = function Out(k) {
+ var s = 1.70158;
+ return --k * k * ((s + 1) * k + s) + 1;
+ };
+ Back.InOut = function InOut(k) {
+ var s = 1.70158 * 1.525;
+ if((k *= 2) < 1) {
+ return 0.5 * (k * k * ((s + 1) * k - s));
+ }
+ return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
+ };
+ return Back;
+ })();
+ Easing.Back = Back;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Bounce = (function () {
+ function Bounce() { }
+ Bounce.In = function In(k) {
+ return 1 - Phaser.Easing.Bounce.Out(1 - k);
+ };
+ Bounce.Out = function Out(k) {
+ if(k < (1 / 2.75)) {
+ return 7.5625 * k * k;
+ } else if(k < (2 / 2.75)) {
+ return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
+ } else if(k < (2.5 / 2.75)) {
+ return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
+ } else {
+ return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
+ }
+ };
+ Bounce.InOut = function InOut(k) {
+ if(k < 0.5) {
+ return Phaser.Easing.Bounce.In(k * 2) * 0.5;
+ }
+ return Phaser.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
+ };
+ return Bounce;
+ })();
+ Easing.Bounce = Bounce;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Circular = (function () {
+ function Circular() { }
+ Circular.In = function In(k) {
+ return 1 - Math.sqrt(1 - k * k);
+ };
+ Circular.Out = function Out(k) {
+ return Math.sqrt(1 - (--k * k));
+ };
+ Circular.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return -0.5 * (Math.sqrt(1 - k * k) - 1);
+ }
+ return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
+ };
+ return Circular;
+ })();
+ Easing.Circular = Circular;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Cubic = (function () {
+ function Cubic() { }
+ Cubic.In = function In(k) {
+ return k * k * k;
+ };
+ Cubic.Out = function Out(k) {
+ return --k * k * k + 1;
+ };
+ Cubic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k;
+ }
+ return 0.5 * ((k -= 2) * k * k + 2);
+ };
+ return Cubic;
+ })();
+ Easing.Cubic = Cubic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Elastic = (function () {
+ function Elastic() { }
+ Elastic.In = function In(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
+ };
+ Elastic.Out = function Out(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
+ };
+ Elastic.InOut = function InOut(k) {
+ var s, a = 0.1, p = 0.4;
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if(!a || a < 1) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p * Math.asin(1 / a) / (2 * Math.PI);
+ }
+ if((k *= 2) < 1) {
+ return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
+ }
+ return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
+ };
+ return Elastic;
+ })();
+ Easing.Elastic = Elastic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Exponential = (function () {
+ function Exponential() { }
+ Exponential.In = function In(k) {
+ return k === 0 ? 0 : Math.pow(1024, k - 1);
+ };
+ Exponential.Out = function Out(k) {
+ return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
+ };
+ Exponential.InOut = function InOut(k) {
+ if(k === 0) {
+ return 0;
+ }
+ if(k === 1) {
+ return 1;
+ }
+ if((k *= 2) < 1) {
+ return 0.5 * Math.pow(1024, k - 1);
+ }
+ return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
+ };
+ return Exponential;
+ })();
+ Easing.Exponential = Exponential;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Linear = (function () {
+ function Linear() { }
+ Linear.None = function None(k) {
+ return k;
+ };
+ return Linear;
+ })();
+ Easing.Linear = Linear;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Quadratic = (function () {
+ function Quadratic() { }
+ Quadratic.In = function In(k) {
+ return k * k;
+ };
+ Quadratic.Out = function Out(k) {
+ return k * (2 - k);
+ };
+ Quadratic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k;
+ }
+ return -0.5 * (--k * (k - 2) - 1);
+ };
+ return Quadratic;
+ })();
+ Easing.Quadratic = Quadratic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Quartic = (function () {
+ function Quartic() { }
+ Quartic.In = function In(k) {
+ return k * k * k * k;
+ };
+ Quartic.Out = function Out(k) {
+ return 1 - (--k * k * k * k);
+ };
+ Quartic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k * k;
+ }
+ return -0.5 * ((k -= 2) * k * k * k - 2);
+ };
+ return Quartic;
+ })();
+ Easing.Quartic = Quartic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Quintic = (function () {
+ function Quintic() { }
+ Quintic.In = function In(k) {
+ return k * k * k * k * k;
+ };
+ Quintic.Out = function Out(k) {
+ return --k * k * k * k * k + 1;
+ };
+ Quintic.InOut = function InOut(k) {
+ if((k *= 2) < 1) {
+ return 0.5 * k * k * k * k * k;
+ }
+ return 0.5 * ((k -= 2) * k * k * k * k + 2);
+ };
+ return Quintic;
+ })();
+ Easing.Quintic = Quintic;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Easing) {
+ var Sinusoidal = (function () {
+ function Sinusoidal() { }
+ Sinusoidal.In = function In(k) {
+ return 1 - Math.cos(k * Math.PI / 2);
+ };
+ Sinusoidal.Out = function Out(k) {
+ return Math.sin(k * Math.PI / 2);
+ };
+ Sinusoidal.InOut = function InOut(k) {
+ return 0.5 * (1 - Math.cos(Math.PI * k));
+ };
+ return Sinusoidal;
+ })();
+ Easing.Sinusoidal = Sinusoidal;
+ })(Phaser.Easing || (Phaser.Easing = {}));
+ var Easing = Phaser.Easing;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Tween = (function () {
+ function Tween(object, game) {
+ this._object = null;
+ this._pausedTime = 0;
+ this._valuesStart = {
+ };
+ this._valuesEnd = {
+ };
+ this._duration = 1000;
+ this._delayTime = 0;
+ this._startTime = null;
+ this._loop = false;
+ this._yoyo = false;
+ this._yoyoCount = 0;
+ this._chainedTweens = [];
+ this.isRunning = false;
+ this._object = object;
+ this.game = game;
+ this._manager = this.game.tweens;
+ this._interpolationFunction = this.game.math.linearInterpolation;
+ this._easingFunction = Phaser.Easing.Linear.None;
+ this._chainedTweens = [];
+ this.onStart = new Phaser.Signal();
+ this.onUpdate = new Phaser.Signal();
+ this.onComplete = new Phaser.Signal();
+ }
+ Tween.prototype.to = function (properties, duration, ease, autoStart, delay, loop, yoyo) {
+ if (typeof duration === "undefined") { duration = 1000; }
+ if (typeof ease === "undefined") { ease = null; }
+ if (typeof autoStart === "undefined") { autoStart = false; }
+ if (typeof delay === "undefined") { delay = 0; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof yoyo === "undefined") { yoyo = false; }
+ this._duration = duration;
+ this._valuesEnd = properties;
+ if(ease !== null) {
+ this._easingFunction = ease;
+ }
+ if(delay > 0) {
+ this._delayTime = delay;
+ }
+ this._loop = loop;
+ this._yoyo = yoyo;
+ this._yoyoCount = 0;
+ if(autoStart === true) {
+ return this.start();
+ } else {
+ return this;
+ }
+ };
+ Tween.prototype.loop = function (value) {
+ this._loop = value;
+ return this;
+ };
+ Tween.prototype.yoyo = function (value) {
+ this._yoyo = value;
+ this._yoyoCount = 0;
+ return this;
+ };
+ Tween.prototype.start = function (looped) {
+ if (typeof looped === "undefined") { looped = false; }
+ if(this.game === null || this._object === null) {
+ return;
+ }
+ if(looped == false) {
+ this._manager.add(this);
+ this.onStart.dispatch(this._object);
+ }
+ this._startTime = this.game.time.now + this._delayTime;
+ this.isRunning = true;
+ for(var property in this._valuesEnd) {
+ if(this._object[property] === null || !(property in this._object)) {
+ throw Error('Phaser.Tween interpolation of null value of non-existing property');
+ continue;
+ }
+ if(this._valuesEnd[property] instanceof Array) {
+ if(this._valuesEnd[property].length === 0) {
+ continue;
+ }
+ this._valuesEnd[property] = [
+ this._object[property]
+ ].concat(this._valuesEnd[property]);
+ }
+ if(looped == false) {
+ this._valuesStart[property] = this._object[property];
+ }
+ }
+ return this;
+ };
+ Tween.prototype.reverse = function () {
+ var tempObj = {
+ };
+ for(var property in this._valuesStart) {
+ tempObj[property] = this._valuesStart[property];
+ this._valuesStart[property] = this._valuesEnd[property];
+ this._valuesEnd[property] = tempObj[property];
+ }
+ this._yoyoCount++;
+ return this.start(true);
+ };
+ Tween.prototype.reset = function () {
+ for(var property in this._valuesStart) {
+ this._object[property] = this._valuesStart[property];
+ }
+ return this.start(true);
+ };
+ Tween.prototype.clear = function () {
+ this._chainedTweens = [];
+ this.onStart.removeAll();
+ this.onUpdate.removeAll();
+ this.onComplete.removeAll();
+ return this;
+ };
+ Tween.prototype.stop = function () {
+ if(this._manager !== null) {
+ this._manager.remove(this);
+ }
+ this.isRunning = false;
+ this.onComplete.dispose();
+ return this;
+ };
+ Object.defineProperty(Tween.prototype, "parent", {
+ set: function (value) {
+ this.game = value;
+ this._manager = this.game.tweens;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "delay", {
+ get: function () {
+ return this._delayTime;
+ },
+ set: function (amount) {
+ this._delayTime = amount;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "easing", {
+ get: function () {
+ return this._easingFunction;
+ },
+ set: function (easing) {
+ this._easingFunction = easing;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tween.prototype, "interpolation", {
+ get: function () {
+ return this._interpolationFunction;
+ },
+ set: function (interpolation) {
+ this._interpolationFunction = interpolation;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Tween.prototype.chain = function (tween) {
+ this._chainedTweens.push(tween);
+ return this;
+ };
+ Tween.prototype.pause = function () {
+ this._paused = true;
+ };
+ Tween.prototype.resume = function () {
+ this._paused = false;
+ this._startTime += this.game.time.pauseDuration;
+ };
+ Tween.prototype.update = function (time) {
+ if(this._paused || time < this._startTime) {
+ return true;
+ }
+ this._tempElapsed = (time - this._startTime) / this._duration;
+ this._tempElapsed = this._tempElapsed > 1 ? 1 : this._tempElapsed;
+ this._tempValue = this._easingFunction(this._tempElapsed);
+ for(var property in this._valuesStart) {
+ if(this._valuesEnd[property] instanceof Array) {
+ this._object[property] = this._interpolationFunction(this._valuesEnd[property], this._tempValue);
+ } else {
+ this._object[property] = this._valuesStart[property] + (this._valuesEnd[property] - this._valuesStart[property]) * this._tempValue;
+ }
+ }
+ this.onUpdate.dispatch(this._object, this._tempValue);
+ if(this._tempElapsed == 1) {
+ if(this._yoyo) {
+ if(this._yoyoCount == 0) {
+ this.reverse();
+ return true;
+ } else {
+ if(this._loop == false) {
+ this.onComplete.dispatch(this._object);
+ for(var i = 0; i < this._chainedTweens.length; i++) {
+ this._chainedTweens[i].start();
+ }
+ return false;
+ } else {
+ this._yoyoCount = 0;
+ this.reverse();
+ return true;
+ }
+ }
+ }
+ if(this._loop) {
+ this._yoyoCount = 0;
+ this.reset();
+ return true;
+ } else {
+ this.onComplete.dispatch(this._object);
+ for(var i = 0; i < this._chainedTweens.length; i++) {
+ this._chainedTweens[i].start();
+ }
+ if(this._chainedTweens.length == 0) {
+ this.isRunning = false;
+ }
+ return false;
+ }
+ }
+ return true;
+ };
+ return Tween;
+ })();
+ Phaser.Tween = Tween;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var TweenManager = (function () {
+ function TweenManager(game) {
+ this.game = game;
+ this._tweens = [];
+ this.game.onPause.add(this.pauseAll, this);
+ this.game.onResume.add(this.resumeAll, this);
+ }
+ TweenManager.prototype.getAll = function () {
+ return this._tweens;
+ };
+ TweenManager.prototype.removeAll = function () {
+ this._tweens.length = 0;
+ };
+ TweenManager.prototype.create = function (object, localReference) {
+ if (typeof localReference === "undefined") { localReference = false; }
+ if(localReference) {
+ object['tween'] = new Phaser.Tween(object, this.game);
+ return object['tween'];
+ } else {
+ return new Phaser.Tween(object, this.game);
+ }
+ };
+ TweenManager.prototype.add = function (tween) {
+ tween.parent = this.game;
+ this._tweens.push(tween);
+ return tween;
+ };
+ TweenManager.prototype.remove = function (tween) {
+ var i = this._tweens.indexOf(tween);
+ if(i !== -1) {
+ this._tweens.splice(i, 1);
+ }
+ };
+ TweenManager.prototype.update = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ if(this._tweens[i].update(this.game.time.now)) {
+ i++;
+ } else {
+ this._tweens.splice(i, 1);
+ numTweens--;
+ }
+ }
+ return true;
+ };
+ TweenManager.prototype.pauseAll = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ this._tweens[i].pause();
+ i++;
+ }
+ };
+ TweenManager.prototype.resumeAll = function () {
+ if(this._tweens.length === 0) {
+ return false;
+ }
+ var i = 0;
+ var numTweens = this._tweens.length;
+ while(i < numTweens) {
+ this._tweens[i].resume();
+ i++;
+ }
+ };
+ return TweenManager;
+ })();
+ Phaser.TweenManager = TweenManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var TimeManager = (function () {
+ function TimeManager(game) {
+ this.elapsed = 0;
+ this.physicsElapsed = 0;
+ this.time = 0;
+ this.pausedTime = 0;
+ this.now = 0;
+ this.delta = 0;
+ this.fps = 0;
+ this.fpsMin = 1000;
+ this.fpsMax = 0;
+ this.msMin = 1000;
+ this.msMax = 0;
+ this.frames = 0;
+ this._timeLastSecond = 0;
+ this.pauseDuration = 0;
+ this._pauseStarted = 0;
+ this.game = game;
+ this._started = 0;
+ this._timeLastSecond = this._started;
+ this.time = this._started;
+ this.game.onPause.add(this.gamePaused, this);
+ this.game.onResume.add(this.gameResumed, this);
+ }
+ Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", {
+ get: function () {
+ return (this.now - this._started) * 0.001;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TimeManager.prototype.update = function (raf) {
+ this.now = raf;
+ this.delta = this.now - this.time;
+ this.msMin = Math.min(this.msMin, this.delta);
+ this.msMax = Math.max(this.msMax, this.delta);
+ this.frames++;
+ if(this.now > this._timeLastSecond + 1000) {
+ this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
+ this.fpsMin = Math.min(this.fpsMin, this.fps);
+ this.fpsMax = Math.max(this.fpsMax, this.fps);
+ this._timeLastSecond = this.now;
+ this.frames = 0;
+ }
+ this.time = this.now;
+ this.physicsElapsed = 1.0 * (16.66 / 1000);
+ if(this.game.paused) {
+ this.pausedTime = this.now - this._pauseStarted;
+ }
+ };
+ TimeManager.prototype.gamePaused = function () {
+ this._pauseStarted = this.now;
+ };
+ TimeManager.prototype.gameResumed = function () {
+ this.pauseDuration = this.pausedTime;
+ };
+ TimeManager.prototype.elapsedSince = function (since) {
+ return this.now - since;
+ };
+ TimeManager.prototype.elapsedSecondsSince = function (since) {
+ return (this.now - since) * 0.001;
+ };
+ TimeManager.prototype.reset = function () {
+ this._started = this.now;
+ };
+ return TimeManager;
+ })();
+ Phaser.TimeManager = TimeManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Net = (function () {
+ function Net(game) {
+ this.game = game;
+ }
+ Net.prototype.checkDomainName = function (domain) {
+ return window.location.hostname.indexOf(domain) !== -1;
+ };
+ Net.prototype.updateQueryString = function (key, value, redirect, url) {
+ if (typeof redirect === "undefined") { redirect = false; }
+ if (typeof url === "undefined") { url = ''; }
+ if(url == '') {
+ url = window.location.href;
+ }
+ var output = '';
+ var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
+ if(re.test(url)) {
+ if(typeof value !== 'undefined' && value !== null) {
+ output = url.replace(re, '$1' + key + "=" + value + '$2$3');
+ } else {
+ output = url.replace(re, '$1$3').replace(/(&|\?)$/, '');
+ }
+ } else {
+ if(typeof value !== 'undefined' && value !== null) {
+ var separator = url.indexOf('?') !== -1 ? '&' : '?';
+ var hash = url.split('#');
+ url = hash[0] + separator + key + '=' + value;
+ if(hash[1]) {
+ url += '#' + hash[1];
+ }
+ output = url;
+ } else {
+ output = url;
+ }
+ }
+ if(redirect) {
+ window.location.href = output;
+ } else {
+ return output;
+ }
+ };
+ Net.prototype.getQueryString = function (parameter) {
+ if (typeof parameter === "undefined") { parameter = ''; }
+ var output = {
+ };
+ var keyValues = location.search.substring(1).split('&');
+ for(var i in keyValues) {
+ var key = keyValues[i].split('=');
+ if(key.length > 1) {
+ if(parameter && parameter == this.decodeURI(key[0])) {
+ return this.decodeURI(key[1]);
+ } else {
+ output[this.decodeURI(key[0])] = this.decodeURI(key[1]);
+ }
+ }
+ }
+ return output;
+ };
+ Net.prototype.decodeURI = function (value) {
+ return decodeURIComponent(value.replace(/\+/g, " "));
+ };
+ return Net;
+ })();
+ Phaser.Net = Net;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Keyboard = (function () {
+ function Keyboard(game) {
+ this._keys = {
+ };
+ this._capture = {
+ };
+ this.disabled = false;
+ this.game = game;
+ }
+ Keyboard.prototype.start = function () {
+ var _this = this;
+ this._onKeyDown = function (event) {
+ return _this.onKeyDown(event);
+ };
+ this._onKeyUp = function (event) {
+ return _this.onKeyUp(event);
+ };
+ document.body.addEventListener('keydown', this._onKeyDown, false);
+ document.body.addEventListener('keyup', this._onKeyUp, false);
+ };
+ Keyboard.prototype.stop = function () {
+ document.body.removeEventListener('keydown', this._onKeyDown);
+ document.body.removeEventListener('keyup', this._onKeyUp);
+ };
+ Keyboard.prototype.addKeyCapture = function (keycode) {
+ if(typeof keycode === 'object') {
+ for(var i = 0; i < keycode.length; i++) {
+ this._capture[keycode[i]] = true;
+ }
+ } else {
+ this._capture[keycode] = true;
+ }
+ };
+ Keyboard.prototype.removeKeyCapture = function (keycode) {
+ delete this._capture[keycode];
+ };
+ Keyboard.prototype.clearCaptures = function () {
+ this._capture = {
+ };
+ };
+ Keyboard.prototype.onKeyDown = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ if(this._capture[event.keyCode]) {
+ event.preventDefault();
+ }
+ if(!this._keys[event.keyCode]) {
+ this._keys[event.keyCode] = {
+ isDown: true,
+ timeDown: this.game.time.now,
+ timeUp: 0
+ };
+ } else {
+ this._keys[event.keyCode].isDown = true;
+ this._keys[event.keyCode].timeDown = this.game.time.now;
+ }
+ };
+ Keyboard.prototype.onKeyUp = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ if(this._capture[event.keyCode]) {
+ event.preventDefault();
+ }
+ if(!this._keys[event.keyCode]) {
+ this._keys[event.keyCode] = {
+ isDown: false,
+ timeDown: 0,
+ timeUp: this.game.time.now
+ };
+ } else {
+ this._keys[event.keyCode].isDown = false;
+ this._keys[event.keyCode].timeUp = this.game.time.now;
+ }
+ };
+ Keyboard.prototype.reset = function () {
+ for(var key in this._keys) {
+ this._keys[key].isDown = false;
+ }
+ };
+ Keyboard.prototype.justPressed = function (keycode, duration) {
+ if (typeof duration === "undefined") { duration = 250; }
+ if(this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.prototype.justReleased = function (keycode, duration) {
+ if (typeof duration === "undefined") { duration = 250; }
+ if(this._keys[keycode] && this._keys[keycode].isDown === false && (this.game.time.now - this._keys[keycode].timeUp < duration)) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.prototype.isDown = function (keycode) {
+ if(this._keys[keycode]) {
+ return this._keys[keycode].isDown;
+ } else {
+ return false;
+ }
+ };
+ Keyboard.A = "A".charCodeAt(0);
+ Keyboard.B = "B".charCodeAt(0);
+ Keyboard.C = "C".charCodeAt(0);
+ Keyboard.D = "D".charCodeAt(0);
+ Keyboard.E = "E".charCodeAt(0);
+ Keyboard.F = "F".charCodeAt(0);
+ Keyboard.G = "G".charCodeAt(0);
+ Keyboard.H = "H".charCodeAt(0);
+ Keyboard.I = "I".charCodeAt(0);
+ Keyboard.J = "J".charCodeAt(0);
+ Keyboard.K = "K".charCodeAt(0);
+ Keyboard.L = "L".charCodeAt(0);
+ Keyboard.M = "M".charCodeAt(0);
+ Keyboard.N = "N".charCodeAt(0);
+ Keyboard.O = "O".charCodeAt(0);
+ Keyboard.P = "P".charCodeAt(0);
+ Keyboard.Q = "Q".charCodeAt(0);
+ Keyboard.R = "R".charCodeAt(0);
+ Keyboard.S = "S".charCodeAt(0);
+ Keyboard.T = "T".charCodeAt(0);
+ Keyboard.U = "U".charCodeAt(0);
+ Keyboard.V = "V".charCodeAt(0);
+ Keyboard.W = "W".charCodeAt(0);
+ Keyboard.X = "X".charCodeAt(0);
+ Keyboard.Y = "Y".charCodeAt(0);
+ Keyboard.Z = "Z".charCodeAt(0);
+ Keyboard.ZERO = "0".charCodeAt(0);
+ Keyboard.ONE = "1".charCodeAt(0);
+ Keyboard.TWO = "2".charCodeAt(0);
+ Keyboard.THREE = "3".charCodeAt(0);
+ Keyboard.FOUR = "4".charCodeAt(0);
+ Keyboard.FIVE = "5".charCodeAt(0);
+ Keyboard.SIX = "6".charCodeAt(0);
+ Keyboard.SEVEN = "7".charCodeAt(0);
+ Keyboard.EIGHT = "8".charCodeAt(0);
+ Keyboard.NINE = "9".charCodeAt(0);
+ Keyboard.NUMPAD_0 = 96;
+ Keyboard.NUMPAD_1 = 97;
+ Keyboard.NUMPAD_2 = 98;
+ Keyboard.NUMPAD_3 = 99;
+ Keyboard.NUMPAD_4 = 100;
+ Keyboard.NUMPAD_5 = 101;
+ Keyboard.NUMPAD_6 = 102;
+ Keyboard.NUMPAD_7 = 103;
+ Keyboard.NUMPAD_8 = 104;
+ Keyboard.NUMPAD_9 = 105;
+ Keyboard.NUMPAD_MULTIPLY = 106;
+ Keyboard.NUMPAD_ADD = 107;
+ Keyboard.NUMPAD_ENTER = 108;
+ Keyboard.NUMPAD_SUBTRACT = 109;
+ Keyboard.NUMPAD_DECIMAL = 110;
+ Keyboard.NUMPAD_DIVIDE = 111;
+ Keyboard.F1 = 112;
+ Keyboard.F2 = 113;
+ Keyboard.F3 = 114;
+ Keyboard.F4 = 115;
+ Keyboard.F5 = 116;
+ Keyboard.F6 = 117;
+ Keyboard.F7 = 118;
+ Keyboard.F8 = 119;
+ Keyboard.F9 = 120;
+ Keyboard.F10 = 121;
+ Keyboard.F11 = 122;
+ Keyboard.F12 = 123;
+ Keyboard.F13 = 124;
+ Keyboard.F14 = 125;
+ Keyboard.F15 = 126;
+ Keyboard.COLON = 186;
+ Keyboard.EQUALS = 187;
+ Keyboard.UNDERSCORE = 189;
+ Keyboard.QUESTION_MARK = 191;
+ Keyboard.TILDE = 192;
+ Keyboard.OPEN_BRACKET = 219;
+ Keyboard.BACKWARD_SLASH = 220;
+ Keyboard.CLOSED_BRACKET = 221;
+ Keyboard.QUOTES = 222;
+ Keyboard.BACKSPACE = 8;
+ Keyboard.TAB = 9;
+ Keyboard.CLEAR = 12;
+ Keyboard.ENTER = 13;
+ Keyboard.SHIFT = 16;
+ Keyboard.CONTROL = 17;
+ Keyboard.ALT = 18;
+ Keyboard.CAPS_LOCK = 20;
+ Keyboard.ESC = 27;
+ Keyboard.SPACEBAR = 32;
+ Keyboard.PAGE_UP = 33;
+ Keyboard.PAGE_DOWN = 34;
+ Keyboard.END = 35;
+ Keyboard.HOME = 36;
+ Keyboard.LEFT = 37;
+ Keyboard.UP = 38;
+ Keyboard.RIGHT = 39;
+ Keyboard.DOWN = 40;
+ Keyboard.INSERT = 45;
+ Keyboard.DELETE = 46;
+ Keyboard.HELP = 47;
+ Keyboard.NUM_LOCK = 144;
+ return Keyboard;
+ })();
+ Phaser.Keyboard = Keyboard;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Mouse = (function () {
+ function Mouse(game) {
+ this.disabled = false;
+ this.mouseDownCallback = null;
+ this.mouseMoveCallback = null;
+ this.mouseUpCallback = null;
+ this.game = game;
+ this.callbackContext = this.game;
+ }
+ Mouse.LEFT_BUTTON = 0;
+ Mouse.MIDDLE_BUTTON = 1;
+ Mouse.RIGHT_BUTTON = 2;
+ Mouse.prototype.start = function () {
+ var _this = this;
+ if(this.game.device.android && this.game.device.chrome == false) {
+ return;
+ }
+ this._onMouseDown = function (event) {
+ return _this.onMouseDown(event);
+ };
+ this._onMouseMove = function (event) {
+ return _this.onMouseMove(event);
+ };
+ this._onMouseUp = function (event) {
+ return _this.onMouseUp(event);
+ };
+ this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
+ this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
+ this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
+ };
+ Mouse.prototype.onMouseDown = function (event) {
+ if(this.mouseDownCallback) {
+ this.mouseDownCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.start(event);
+ };
+ Mouse.prototype.onMouseMove = function (event) {
+ if(this.mouseMoveCallback) {
+ this.mouseMoveCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.move(event);
+ };
+ Mouse.prototype.onMouseUp = function (event) {
+ if(this.mouseUpCallback) {
+ this.mouseUpCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event['identifier'] = 0;
+ this.game.input.mousePointer.stop(event);
+ };
+ Mouse.prototype.stop = function () {
+ this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown);
+ this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove);
+ this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp);
+ };
+ return Mouse;
+ })();
+ Phaser.Mouse = Mouse;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var MSPointer = (function () {
+ function MSPointer(game) {
+ this.disabled = false;
+ this.game = game;
+ }
+ MSPointer.prototype.start = function () {
+ var _this = this;
+ if(this.game.device.mspointer == true) {
+ this._onMSPointerDown = function (event) {
+ return _this.onPointerDown(event);
+ };
+ this._onMSPointerMove = function (event) {
+ return _this.onPointerMove(event);
+ };
+ this._onMSPointerUp = function (event) {
+ return _this.onPointerUp(event);
+ };
+ this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
+ this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
+ this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
+ }
+ };
+ MSPointer.prototype.onPointerDown = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.startPointer(event);
+ };
+ MSPointer.prototype.onPointerMove = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.updatePointer(event);
+ };
+ MSPointer.prototype.onPointerUp = function (event) {
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ event.identifier = event.pointerId;
+ this.game.input.stopPointer(event);
+ };
+ MSPointer.prototype.stop = function () {
+ if(this.game.device.mspointer == true) {
+ this.game.stage.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
+ this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
+ this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
+ }
+ };
+ return MSPointer;
+ })();
+ Phaser.MSPointer = MSPointer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Touch = (function () {
+ function Touch(game) {
+ this.disabled = false;
+ this.touchStartCallback = null;
+ this.touchMoveCallback = null;
+ this.touchEndCallback = null;
+ this.touchEnterCallback = null;
+ this.touchLeaveCallback = null;
+ this.touchCancelCallback = null;
+ this.game = game;
+ this.callbackContext = this.game;
+ }
+ Touch.prototype.start = function () {
+ var _this = this;
+ if(this.game.device.touch) {
+ this._onTouchStart = function (event) {
+ return _this.onTouchStart(event);
+ };
+ this._onTouchMove = function (event) {
+ return _this.onTouchMove(event);
+ };
+ this._onTouchEnd = function (event) {
+ return _this.onTouchEnd(event);
+ };
+ this._onTouchEnter = function (event) {
+ return _this.onTouchEnter(event);
+ };
+ this._onTouchLeave = function (event) {
+ return _this.onTouchLeave(event);
+ };
+ this._onTouchCancel = function (event) {
+ return _this.onTouchCancel(event);
+ };
+ this._documentTouchMove = function (event) {
+ return _this.consumeTouchMove(event);
+ };
+ this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false);
+ this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false);
+ this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false);
+ this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false);
+ this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false);
+ this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
+ document.addEventListener('touchmove', this._documentTouchMove, false);
+ }
+ };
+ Touch.prototype.consumeTouchMove = function (event) {
+ event.preventDefault();
+ };
+ Touch.prototype.onTouchStart = function (event) {
+ if(this.touchStartCallback) {
+ this.touchStartCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.startPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchCancel = function (event) {
+ if(this.touchCancelCallback) {
+ this.touchCancelCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.stopPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchEnter = function (event) {
+ if(this.touchEnterCallback) {
+ this.touchEnterCallback.call(this.callbackContext, event);
+ }
+ if(this.game.input.disabled || this.disabled) {
+ return;
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ }
+ };
+ Touch.prototype.onTouchLeave = function (event) {
+ if(this.touchLeaveCallback) {
+ this.touchLeaveCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ }
+ };
+ Touch.prototype.onTouchMove = function (event) {
+ if(this.touchMoveCallback) {
+ this.touchMoveCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.updatePointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.onTouchEnd = function (event) {
+ if(this.touchEndCallback) {
+ this.touchEndCallback.call(this.callbackContext, event);
+ }
+ event.preventDefault();
+ for(var i = 0; i < event.changedTouches.length; i++) {
+ this.game.input.stopPointer(event.changedTouches[i]);
+ }
+ };
+ Touch.prototype.stop = function () {
+ if(this.game.device.touch) {
+ this.game.stage.canvas.removeEventListener('touchstart', this._onTouchStart);
+ this.game.stage.canvas.removeEventListener('touchmove', this._onTouchMove);
+ this.game.stage.canvas.removeEventListener('touchend', this._onTouchEnd);
+ this.game.stage.canvas.removeEventListener('touchenter', this._onTouchEnter);
+ this.game.stage.canvas.removeEventListener('touchleave', this._onTouchLeave);
+ this.game.stage.canvas.removeEventListener('touchcancel', this._onTouchCancel);
+ document.removeEventListener('touchmove', this._documentTouchMove);
+ }
+ };
+ return Touch;
+ })();
+ Phaser.Touch = Touch;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Pointer = (function () {
+ function Pointer(game, id) {
+ this._holdSent = false;
+ this._history = [];
+ this._nextDrop = 0;
+ this._stateReset = false;
+ this.positionDown = null;
+ this.position = null;
+ this.circle = null;
+ this.withinGame = false;
+ this.clientX = -1;
+ this.clientY = -1;
+ this.pageX = -1;
+ this.pageY = -1;
+ this.screenX = -1;
+ this.screenY = -1;
+ this.x = -1;
+ this.y = -1;
+ this.isMouse = false;
+ this.isDown = false;
+ this.isUp = true;
+ this.timeDown = 0;
+ this.timeUp = 0;
+ this.previousTapTime = 0;
+ this.totalTouches = 0;
+ this.msSinceLastClick = Number.MAX_VALUE;
+ this.targetObject = null;
+ this.camera = null;
+ this.game = game;
+ this.id = id;
+ this.active = false;
+ this.position = new Phaser.Vec2();
+ this.positionDown = new Phaser.Vec2();
+ this.circle = new Phaser.Circle(0, 0, 44);
+ if(id == 0) {
+ this.isMouse = true;
+ }
+ }
+ Object.defineProperty(Pointer.prototype, "duration", {
+ get: function () {
+ if(this.isUp) {
+ return -1;
+ }
+ return this.game.time.now - this.timeDown;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Pointer.prototype, "worldX", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Pointer.prototype, "worldY", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Pointer.prototype.start = function (event) {
+ this.identifier = event.identifier;
+ this.target = event.target;
+ if(event.button) {
+ this.button = event.button;
+ }
+ if(this.game.paused == true && this.game.stage.scale.incorrectOrientation == false) {
+ this.game.stage.resumeGame();
+ return this;
+ }
+ this._history.length = 0;
+ this.active = true;
+ this.withinGame = true;
+ this.isDown = true;
+ this.isUp = false;
+ this.msSinceLastClick = this.game.time.now - this.timeDown;
+ this.timeDown = this.game.time.now;
+ this._holdSent = false;
+ this.move(event);
+ this.positionDown.setTo(this.x, this.y);
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.x = this.x;
+ this.game.input.y = this.y;
+ this.game.input.position.setTo(this.x, this.y);
+ this.game.input.onDown.dispatch(this);
+ this.game.input.resetSpeed(this.x, this.y);
+ }
+ this._stateReset = false;
+ this.totalTouches++;
+ if(this.isMouse == false) {
+ this.game.input.currentPointers++;
+ }
+ if(this.targetObject !== null) {
+ this.targetObject.input._touchedHandler(this);
+ }
+ return this;
+ };
+ Pointer.prototype.update = function () {
+ if(this.active) {
+ if(this._holdSent == false && this.duration >= this.game.input.holdRate) {
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.onHold.dispatch(this);
+ }
+ this._holdSent = true;
+ }
+ if(this.game.input.recordPointerHistory && this.game.time.now >= this._nextDrop) {
+ this._nextDrop = this.game.time.now + this.game.input.recordRate;
+ this._history.push({
+ x: this.position.x,
+ y: this.position.y
+ });
+ if(this._history.length > this.game.input.recordLimit) {
+ this._history.shift();
+ }
+ }
+ this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y);
+ }
+ };
+ Pointer.prototype.move = function (event) {
+ if(this.game.input.pollLocked) {
+ return;
+ }
+ if(event.button) {
+ this.button = event.button;
+ }
+ this.clientX = event.clientX;
+ this.clientY = event.clientY;
+ this.pageX = event.pageX;
+ this.pageY = event.pageY;
+ this.screenX = event.screenX;
+ this.screenY = event.screenY;
+ this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
+ this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
+ this.position.setTo(this.x, this.y);
+ this.circle.x = this.x;
+ this.circle.y = this.y;
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.activePointer = this;
+ this.game.input.x = this.x;
+ this.game.input.y = this.y;
+ this.game.input.position.setTo(this.game.input.x, this.game.input.y);
+ this.game.input.circle.x = this.game.input.x;
+ this.game.input.circle.y = this.game.input.y;
+ }
+ if(this.game.paused) {
+ return this;
+ }
+ if(this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true) {
+ if(this.targetObject.input.update(this) == false) {
+ this.targetObject = null;
+ }
+ return this;
+ }
+ this._highestRenderOrderID = -1;
+ this._highestRenderObject = -1;
+ this._highestInputPriorityID = -1;
+ for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
+ if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) {
+ if(this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID)) {
+ this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID;
+ this._highestRenderObject = i;
+ this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID;
+ }
+ }
+ }
+ if(this._highestRenderObject == -1) {
+ if(this.targetObject !== null) {
+ this.targetObject.input._pointerOutHandler(this);
+ this.targetObject = null;
+ }
+ } else {
+ if(this.targetObject == null) {
+ this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
+ this.targetObject.input._pointerOverHandler(this);
+ } else {
+ if(this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) {
+ if(this.targetObject.input.update(this) == false) {
+ this.targetObject = null;
+ }
+ } else {
+ this.targetObject.input._pointerOutHandler(this);
+ this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
+ this.targetObject.input._pointerOverHandler(this);
+ }
+ }
+ }
+ return this;
+ };
+ Pointer.prototype.leave = function (event) {
+ this.withinGame = false;
+ this.move(event);
+ };
+ Pointer.prototype.stop = function (event) {
+ if(this._stateReset) {
+ event.preventDefault();
+ return;
+ }
+ this.timeUp = this.game.time.now;
+ if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
+ this.game.input.onUp.dispatch(this);
+ if(this.duration >= 0 && this.duration <= this.game.input.tapRate) {
+ if(this.timeUp - this.previousTapTime < this.game.input.doubleTapRate) {
+ this.game.input.onTap.dispatch(this, true);
+ } else {
+ this.game.input.onTap.dispatch(this, false);
+ }
+ this.previousTapTime = this.timeUp;
+ }
+ }
+ if(this.id > 0) {
+ this.active = false;
+ }
+ this.withinGame = false;
+ this.isDown = false;
+ this.isUp = true;
+ if(this.isMouse == false) {
+ this.game.input.currentPointers--;
+ }
+ for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
+ if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) {
+ this.game.input.inputObjects[i].input._releasedHandler(this);
+ }
+ }
+ if(this.targetObject) {
+ this.targetObject.input._releasedHandler(this);
+ }
+ this.targetObject = null;
+ return this;
+ };
+ Pointer.prototype.justPressed = function (duration) {
+ if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; }
+ if(this.isDown === true && (this.timeDown + duration) > this.game.time.now) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Pointer.prototype.justReleased = function (duration) {
+ if (typeof duration === "undefined") { duration = this.game.input.justReleasedRate; }
+ if(this.isUp === true && (this.timeUp + duration) > this.game.time.now) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Pointer.prototype.reset = function () {
+ if(this.isMouse == false) {
+ this.active = false;
+ }
+ this.identifier = null;
+ this.isDown = false;
+ this.isUp = true;
+ this.totalTouches = 0;
+ this._holdSent = false;
+ this._history.length = 0;
+ this._stateReset = true;
+ if(this.targetObject && this.targetObject.input) {
+ this.targetObject.input._releasedHandler(this);
+ }
+ this.targetObject = null;
+ };
+ Pointer.prototype.toString = function () {
+ return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
+ };
+ return Pointer;
+ })();
+ Phaser.Pointer = Pointer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var InputHandler = (function () {
+ function InputHandler(parent) {
+ this.priorityID = 0;
+ this.indexID = 0;
+ this.isDragged = false;
+ this.dragPixelPerfect = false;
+ this.allowHorizontalDrag = true;
+ this.allowVerticalDrag = true;
+ this.bringToTop = false;
+ this.snapOnDrag = false;
+ this.snapOnRelease = false;
+ this.snapX = 0;
+ this.snapY = 0;
+ this.draggable = false;
+ this.boundsRect = null;
+ this.boundsSprite = null;
+ this.consumePointerEvent = false;
+ this.game = parent.game;
+ this._parent = parent;
+ this.enabled = false;
+ }
+ InputHandler.prototype.pointerX = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].x;
+ };
+ InputHandler.prototype.pointerY = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].y;
+ };
+ InputHandler.prototype.pointerDown = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isDown;
+ };
+ InputHandler.prototype.pointerUp = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isUp;
+ };
+ InputHandler.prototype.pointerTimeDown = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeDown;
+ };
+ InputHandler.prototype.pointerTimeUp = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeUp;
+ };
+ InputHandler.prototype.pointerOver = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isOver;
+ };
+ InputHandler.prototype.pointerOut = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isOut;
+ };
+ InputHandler.prototype.pointerTimeOver = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeOver;
+ };
+ InputHandler.prototype.pointerTimeOut = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].timeOut;
+ };
+ InputHandler.prototype.pointerDragged = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ return this._pointerData[pointer].isDragged;
+ };
+ InputHandler.prototype.start = function (priority, checkBody, useHandCursor) {
+ if (typeof priority === "undefined") { priority = 0; }
+ if (typeof checkBody === "undefined") { checkBody = false; }
+ if (typeof useHandCursor === "undefined") { useHandCursor = false; }
+ if(this.enabled == false) {
+ this.checkBody = checkBody;
+ this.useHandCursor = useHandCursor;
+ this.priorityID = priority;
+ this._pointerData = [];
+ for(var i = 0; i < 10; i++) {
+ this._pointerData.push({
+ id: i,
+ x: 0,
+ y: 0,
+ isDown: false,
+ isUp: false,
+ isOver: false,
+ isOut: false,
+ timeOver: 0,
+ timeOut: 0,
+ timeDown: 0,
+ timeUp: 0,
+ downDuration: 0,
+ isDragged: false
+ });
+ }
+ this.snapOffset = new Phaser.Point();
+ this.enabled = true;
+ this.game.input.addGameObject(this._parent);
+ if(this._parent.events.onInputOver == null) {
+ this._parent.events.onInputOver = new Phaser.Signal();
+ this._parent.events.onInputOut = new Phaser.Signal();
+ this._parent.events.onInputDown = new Phaser.Signal();
+ this._parent.events.onInputUp = new Phaser.Signal();
+ this._parent.events.onDragStart = new Phaser.Signal();
+ this._parent.events.onDragStop = new Phaser.Signal();
+ }
+ }
+ return this._parent;
+ };
+ InputHandler.prototype.reset = function () {
+ this.enabled = false;
+ for(var i = 0; i < 10; i++) {
+ this._pointerData[i] = {
+ id: i,
+ x: 0,
+ y: 0,
+ isDown: false,
+ isUp: false,
+ isOver: false,
+ isOut: false,
+ timeOver: 0,
+ timeOut: 0,
+ timeDown: 0,
+ timeUp: 0,
+ downDuration: 0,
+ isDragged: false
+ };
+ }
+ };
+ InputHandler.prototype.stop = function () {
+ if(this.enabled == false) {
+ return;
+ } else {
+ this.enabled = false;
+ this.game.input.removeGameObject(this.indexID);
+ }
+ };
+ InputHandler.prototype.destroy = function () {
+ if(this.enabled) {
+ this.enabled = false;
+ this.game.input.removeGameObject(this.indexID);
+ }
+ };
+ InputHandler.prototype.checkPointerOver = function (pointer) {
+ if(this.enabled == false || this._parent.visible == false) {
+ return false;
+ } else {
+ return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
+ }
+ };
+ InputHandler.prototype.update = function (pointer) {
+ if(this.enabled == false || this._parent.visible == false) {
+ this._pointerOutHandler(pointer);
+ return false;
+ }
+ if(this.draggable && this._draggedPointerID == pointer.id) {
+ return this.updateDrag(pointer);
+ } else if(this._pointerData[pointer.id].isOver == true) {
+ if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
+ this._pointerData[pointer.id].x = pointer.x - this._parent.x;
+ this._pointerData[pointer.id].y = pointer.y - this._parent.y;
+ return true;
+ } else {
+ this._pointerOutHandler(pointer);
+ return false;
+ }
+ }
+ };
+ InputHandler.prototype._pointerOverHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isOver == false) {
+ this._pointerData[pointer.id].isOver = true;
+ this._pointerData[pointer.id].isOut = false;
+ this._pointerData[pointer.id].timeOver = this.game.time.now;
+ this._pointerData[pointer.id].x = pointer.x - this._parent.x;
+ this._pointerData[pointer.id].y = pointer.y - this._parent.y;
+ if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
+ this.game.stage.canvas.style.cursor = "pointer";
+ }
+ this._parent.events.onInputOver.dispatch(this._parent, pointer);
+ }
+ };
+ InputHandler.prototype._pointerOutHandler = function (pointer) {
+ this._pointerData[pointer.id].isOver = false;
+ this._pointerData[pointer.id].isOut = true;
+ this._pointerData[pointer.id].timeOut = this.game.time.now;
+ if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
+ this.game.stage.canvas.style.cursor = "default";
+ }
+ this._parent.events.onInputOut.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype._touchedHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) {
+ this._pointerData[pointer.id].isDown = true;
+ this._pointerData[pointer.id].isUp = false;
+ this._pointerData[pointer.id].timeDown = this.game.time.now;
+ this._parent.events.onInputDown.dispatch(this._parent, pointer);
+ if(this.draggable && this.isDragged == false) {
+ this.startDrag(pointer);
+ }
+ if(this.bringToTop) {
+ this._parent.bringToTop();
+ }
+ }
+ return this.consumePointerEvent;
+ };
+ InputHandler.prototype._releasedHandler = function (pointer) {
+ if(this._pointerData[pointer.id].isDown && pointer.isUp) {
+ this._pointerData[pointer.id].isDown = false;
+ this._pointerData[pointer.id].isUp = true;
+ this._pointerData[pointer.id].timeUp = this.game.time.now;
+ this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
+ if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
+ this._parent.events.onInputUp.dispatch(this._parent, pointer);
+ } else {
+ if(this.useHandCursor) {
+ this.game.stage.canvas.style.cursor = "default";
+ }
+ }
+ if(this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
+ this.stopDrag(pointer);
+ }
+ }
+ };
+ InputHandler.prototype.updateDrag = function (pointer) {
+ if(pointer.isUp) {
+ this.stopDrag(pointer);
+ return false;
+ }
+ if(this.allowHorizontalDrag) {
+ this._parent.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
+ }
+ if(this.allowVerticalDrag) {
+ this._parent.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
+ }
+ if(this.boundsRect) {
+ this.checkBoundsRect();
+ }
+ if(this.boundsSprite) {
+ this.checkBoundsSprite();
+ }
+ if(this.snapOnDrag) {
+ this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
+ this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
+ }
+ return true;
+ };
+ InputHandler.prototype.justOver = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay);
+ };
+ InputHandler.prototype.justOut = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay));
+ };
+ InputHandler.prototype.justPressed = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay);
+ };
+ InputHandler.prototype.justReleased = function (pointer, delay) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if (typeof delay === "undefined") { delay = 500; }
+ return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay));
+ };
+ InputHandler.prototype.overDuration = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if(this._pointerData[pointer].isOver) {
+ return this.game.time.now - this._pointerData[pointer].timeOver;
+ }
+ return -1;
+ };
+ InputHandler.prototype.downDuration = function (pointer) {
+ if (typeof pointer === "undefined") { pointer = 0; }
+ if(this._pointerData[pointer].isDown) {
+ return this.game.time.now - this._pointerData[pointer].timeDown;
+ }
+ return -1;
+ };
+ InputHandler.prototype.enableDrag = function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
+ if (typeof lockCenter === "undefined") { lockCenter = false; }
+ if (typeof bringToTop === "undefined") { bringToTop = false; }
+ if (typeof pixelPerfect === "undefined") { pixelPerfect = false; }
+ if (typeof alphaThreshold === "undefined") { alphaThreshold = 255; }
+ if (typeof boundsRect === "undefined") { boundsRect = null; }
+ if (typeof boundsSprite === "undefined") { boundsSprite = null; }
+ this._dragPoint = new Phaser.Point();
+ this.draggable = true;
+ this.bringToTop = bringToTop;
+ this.dragOffset = new Phaser.Point();
+ this.dragFromCenter = lockCenter;
+ this.dragPixelPerfect = pixelPerfect;
+ this.dragPixelPerfectAlpha = alphaThreshold;
+ if(boundsRect) {
+ this.boundsRect = boundsRect;
+ }
+ if(boundsSprite) {
+ this.boundsSprite = boundsSprite;
+ }
+ };
+ InputHandler.prototype.disableDrag = function () {
+ if(this._pointerData) {
+ for(var i = 0; i < 10; i++) {
+ this._pointerData[i].isDragged = false;
+ }
+ }
+ this.draggable = false;
+ this.isDragged = false;
+ this._draggedPointerID = -1;
+ };
+ InputHandler.prototype.startDrag = function (pointer) {
+ this.isDragged = true;
+ this._draggedPointerID = pointer.id;
+ this._pointerData[pointer.id].isDragged = true;
+ if(this.dragFromCenter) {
+ this._parent.transform.centerOn(pointer.worldX, pointer.worldY);
+ this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
+ } else {
+ this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
+ }
+ this.updateDrag(pointer);
+ if(this.bringToTop) {
+ this._parent.bringToTop();
+ }
+ this._parent.events.onDragStart.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype.stopDrag = function (pointer) {
+ this.isDragged = false;
+ this._draggedPointerID = -1;
+ this._pointerData[pointer.id].isDragged = false;
+ if(this.snapOnRelease) {
+ this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
+ this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
+ }
+ this._parent.events.onDragStop.dispatch(this._parent, pointer);
+ this._parent.events.onInputUp.dispatch(this._parent, pointer);
+ };
+ InputHandler.prototype.setDragLock = function (allowHorizontal, allowVertical) {
+ if (typeof allowHorizontal === "undefined") { allowHorizontal = true; }
+ if (typeof allowVertical === "undefined") { allowVertical = true; }
+ this.allowHorizontalDrag = allowHorizontal;
+ this.allowVerticalDrag = allowVertical;
+ };
+ InputHandler.prototype.enableSnap = function (snapX, snapY, onDrag, onRelease) {
+ if (typeof onDrag === "undefined") { onDrag = true; }
+ if (typeof onRelease === "undefined") { onRelease = false; }
+ this.snapOnDrag = onDrag;
+ this.snapOnRelease = onRelease;
+ this.snapX = snapX;
+ this.snapY = snapY;
+ };
+ InputHandler.prototype.disableSnap = function () {
+ this.snapOnDrag = false;
+ this.snapOnRelease = false;
+ };
+ InputHandler.prototype.checkBoundsRect = function () {
+ if(this._parent.x < this.boundsRect.left) {
+ this._parent.x = this.boundsRect.x;
+ } else if((this._parent.x + this._parent.width) > this.boundsRect.right) {
+ this._parent.x = this.boundsRect.right - this._parent.width;
+ }
+ if(this._parent.y < this.boundsRect.top) {
+ this._parent.y = this.boundsRect.top;
+ } else if((this._parent.y + this._parent.height) > this.boundsRect.bottom) {
+ this._parent.y = this.boundsRect.bottom - this._parent.height;
+ }
+ };
+ InputHandler.prototype.checkBoundsSprite = function () {
+ if(this._parent.x < this.boundsSprite.x) {
+ this._parent.x = this.boundsSprite.x;
+ } else if((this._parent.x + this._parent.width) > (this.boundsSprite.x + this.boundsSprite.width)) {
+ this._parent.x = (this.boundsSprite.x + this.boundsSprite.width) - this._parent.width;
+ }
+ if(this._parent.y < this.boundsSprite.y) {
+ this._parent.y = this.boundsSprite.y;
+ } else if((this._parent.y + this._parent.height) > (this.boundsSprite.y + this.boundsSprite.height)) {
+ this._parent.y = (this.boundsSprite.y + this.boundsSprite.height) - this._parent.height;
+ }
+ };
+ return InputHandler;
+ })();
+ Components.InputHandler = InputHandler;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var InputManager = (function () {
+ function InputManager(game) {
+ this.pollRate = 0;
+ this._pollCounter = 0;
+ this._oldPosition = null;
+ this._x = 0;
+ this._y = 0;
+ this.disabled = false;
+ this.multiInputOverride = InputManager.MOUSE_TOUCH_COMBINE;
+ this.position = null;
+ this.speed = null;
+ this.circle = null;
+ this.scale = null;
+ this.maxPointers = 10;
+ this.currentPointers = 0;
+ this.tapRate = 200;
+ this.doubleTapRate = 300;
+ this.holdRate = 2000;
+ this.justPressedRate = 200;
+ this.justReleasedRate = 200;
+ this.recordPointerHistory = false;
+ this.recordRate = 100;
+ this.recordLimit = 100;
+ this.pointer3 = null;
+ this.pointer4 = null;
+ this.pointer5 = null;
+ this.pointer6 = null;
+ this.pointer7 = null;
+ this.pointer8 = null;
+ this.pointer9 = null;
+ this.pointer10 = null;
+ this.activePointer = null;
+ this.inputObjects = [];
+ this.totalTrackedObjects = 0;
+ this.game = game;
+ this.mousePointer = new Phaser.Pointer(this.game, 0);
+ this.pointer1 = new Phaser.Pointer(this.game, 1);
+ this.pointer2 = new Phaser.Pointer(this.game, 2);
+ this.mouse = new Phaser.Mouse(this.game);
+ this.keyboard = new Phaser.Keyboard(this.game);
+ this.touch = new Phaser.Touch(this.game);
+ this.mspointer = new Phaser.MSPointer(this.game);
+ this.onDown = new Phaser.Signal();
+ this.onUp = new Phaser.Signal();
+ this.onTap = new Phaser.Signal();
+ this.onHold = new Phaser.Signal();
+ this.scale = new Phaser.Vec2(1, 1);
+ this.speed = new Phaser.Vec2();
+ this.position = new Phaser.Vec2();
+ this._oldPosition = new Phaser.Vec2();
+ this.circle = new Phaser.Circle(0, 0, 44);
+ this.activePointer = this.mousePointer;
+ this.currentPointers = 0;
+ this.hitCanvas = document.createElement('canvas');
+ this.hitCanvas.width = 1;
+ this.hitCanvas.height = 1;
+ this.hitContext = this.hitCanvas.getContext('2d');
+ }
+ InputManager.MOUSE_OVERRIDES_TOUCH = 0;
+ InputManager.TOUCH_OVERRIDES_MOUSE = 1;
+ InputManager.MOUSE_TOUCH_COMBINE = 2;
+ Object.defineProperty(InputManager.prototype, "camera", {
+ get: function () {
+ return this.activePointer.camera;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "x", {
+ get: function () {
+ return this._x;
+ },
+ set: function (value) {
+ this._x = Math.floor(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "y", {
+ get: function () {
+ return this._y;
+ },
+ set: function (value) {
+ this._y = Math.floor(value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.addPointer = function () {
+ var next = 0;
+ for(var i = 10; i > 0; i--) {
+ if(this['pointer' + i] === null) {
+ next = i;
+ }
+ }
+ if(next == 0) {
+ throw new Error("You can only have 10 Pointer objects");
+ return null;
+ } else {
+ this['pointer' + next] = new Phaser.Pointer(this.game, next);
+ return this['pointer' + next];
+ }
+ };
+ InputManager.prototype.boot = function () {
+ this.mouse.start();
+ this.keyboard.start();
+ this.touch.start();
+ this.mspointer.start();
+ this.mousePointer.active = true;
+ };
+ InputManager.prototype.addGameObject = function (object) {
+ for(var i = 0; i < this.inputObjects.length; i++) {
+ if(this.inputObjects[i] == null) {
+ this.inputObjects[i] = object;
+ object.input.indexID = i;
+ this.totalTrackedObjects++;
+ return;
+ }
+ }
+ object.input.indexID = this.inputObjects.length;
+ this.inputObjects.push(object);
+ this.totalTrackedObjects++;
+ };
+ InputManager.prototype.removeGameObject = function (index) {
+ if(this.inputObjects[index]) {
+ this.inputObjects[index] = null;
+ }
+ };
+ Object.defineProperty(InputManager.prototype, "pollLocked", {
+ get: function () {
+ return (this.pollRate > 0 && this._pollCounter < this.pollRate);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.update = function () {
+ if(this.pollRate > 0 && this._pollCounter < this.pollRate) {
+ this._pollCounter++;
+ return;
+ }
+ this.speed.x = this.position.x - this._oldPosition.x;
+ this.speed.y = this.position.y - this._oldPosition.y;
+ this._oldPosition.copyFrom(this.position);
+ this.mousePointer.update();
+ this.pointer1.update();
+ this.pointer2.update();
+ if(this.pointer3) {
+ this.pointer3.update();
+ }
+ if(this.pointer4) {
+ this.pointer4.update();
+ }
+ if(this.pointer5) {
+ this.pointer5.update();
+ }
+ if(this.pointer6) {
+ this.pointer6.update();
+ }
+ if(this.pointer7) {
+ this.pointer7.update();
+ }
+ if(this.pointer8) {
+ this.pointer8.update();
+ }
+ if(this.pointer9) {
+ this.pointer9.update();
+ }
+ if(this.pointer10) {
+ this.pointer10.update();
+ }
+ this._pollCounter = 0;
+ };
+ InputManager.prototype.reset = function (hard) {
+ if (typeof hard === "undefined") { hard = false; }
+ this.keyboard.reset();
+ this.mousePointer.reset();
+ for(var i = 1; i <= 10; i++) {
+ if(this['pointer' + i]) {
+ this['pointer' + i].reset();
+ }
+ }
+ this.currentPointers = 0;
+ this.game.stage.canvas.style.cursor = "default";
+ if(hard == true) {
+ this.onDown.dispose();
+ this.onUp.dispose();
+ this.onTap.dispose();
+ this.onHold.dispose();
+ this.onDown = new Phaser.Signal();
+ this.onUp = new Phaser.Signal();
+ this.onTap = new Phaser.Signal();
+ this.onHold = new Phaser.Signal();
+ for(var i = 0; i < this.totalTrackedObjects; i++) {
+ if(this.inputObjects[i] && this.inputObjects[i].input) {
+ this.inputObjects[i].input.reset();
+ }
+ }
+ this.inputObjects.length = 0;
+ this.totalTrackedObjects = 0;
+ }
+ this._pollCounter = 0;
+ };
+ InputManager.prototype.resetSpeed = function (x, y) {
+ this._oldPosition.setTo(x, y);
+ this.speed.setTo(0, 0);
+ };
+ Object.defineProperty(InputManager.prototype, "totalInactivePointers", {
+ get: function () {
+ return 10 - this.currentPointers;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "totalActivePointers", {
+ get: function () {
+ this.currentPointers = 0;
+ for(var i = 1; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active) {
+ this.currentPointers++;
+ }
+ }
+ return this.currentPointers;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.startPointer = function (event) {
+ if(this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) {
+ return null;
+ }
+ if(this.pointer1.active == false) {
+ return this.pointer1.start(event);
+ } else if(this.pointer2.active == false) {
+ return this.pointer2.start(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active == false) {
+ return this['pointer' + i].start(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.updatePointer = function (event) {
+ if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
+ return this.pointer1.move(event);
+ } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
+ return this.pointer2.move(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
+ return this['pointer' + i].move(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.stopPointer = function (event) {
+ if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
+ return this.pointer1.stop(event);
+ } else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
+ return this.pointer2.stop(event);
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
+ return this['pointer' + i].stop(event);
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.getPointer = function (state) {
+ if (typeof state === "undefined") { state = false; }
+ if(this.pointer1.active == state) {
+ return this.pointer1;
+ } else if(this.pointer2.active == state) {
+ return this.pointer2;
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].active == state) {
+ return this['pointer' + i];
+ }
+ }
+ }
+ return null;
+ };
+ InputManager.prototype.getPointerFromIdentifier = function (identifier) {
+ if(this.pointer1.identifier == identifier) {
+ return this.pointer1;
+ } else if(this.pointer2.identifier == identifier) {
+ return this.pointer2;
+ } else {
+ for(var i = 3; i <= 10; i++) {
+ if(this['pointer' + i] && this['pointer' + i].identifier == identifier) {
+ return this['pointer' + i];
+ }
+ }
+ }
+ return null;
+ };
+ Object.defineProperty(InputManager.prototype, "worldX", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(InputManager.prototype, "worldY", {
+ get: function () {
+ if(this.camera) {
+ return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
+ }
+ return null;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ InputManager.prototype.getDistance = function (pointer1, pointer2) {
+ return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position);
+ };
+ InputManager.prototype.getAngle = function (pointer1, pointer2) {
+ return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
+ };
+ InputManager.prototype.pixelPerfectCheck = function (sprite, pointer, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ this.hitContext.clearRect(0, 0, 1, 1);
+ return true;
+ };
+ return InputManager;
+ })();
+ Phaser.InputManager = InputManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Device = (function () {
+ function Device() {
+ this.patchAndroidClearRectBug = false;
+ this.desktop = false;
+ this.iOS = false;
+ this.android = false;
+ this.chromeOS = false;
+ this.linux = false;
+ this.macOS = false;
+ this.windows = false;
+ this.canvas = false;
+ this.file = false;
+ this.fileSystem = false;
+ this.localStorage = false;
+ this.webGL = false;
+ this.worker = false;
+ this.touch = false;
+ this.mspointer = false;
+ this.css3D = false;
+ this.arora = false;
+ this.chrome = false;
+ this.epiphany = false;
+ this.firefox = false;
+ this.ie = false;
+ this.ieVersion = 0;
+ this.mobileSafari = false;
+ this.midori = false;
+ this.opera = false;
+ this.safari = false;
+ this.webApp = false;
+ this.audioData = false;
+ this.webAudio = false;
+ this.ogg = false;
+ this.opus = false;
+ this.mp3 = false;
+ this.wav = false;
+ this.m4a = false;
+ this.webm = false;
+ this.iPhone = false;
+ this.iPhone4 = false;
+ this.iPad = false;
+ this.pixelRatio = 0;
+ this._checkAudio();
+ this._checkBrowser();
+ this._checkCSS3D();
+ this._checkDevice();
+ this._checkFeatures();
+ this._checkOS();
+ }
+ Device.prototype._checkOS = function () {
+ var ua = navigator.userAgent;
+ if(/Android/.test(ua)) {
+ this.android = true;
+ } else if(/CrOS/.test(ua)) {
+ this.chromeOS = true;
+ } else if(/iP[ao]d|iPhone/i.test(ua)) {
+ this.iOS = true;
+ } else if(/Linux/.test(ua)) {
+ this.linux = true;
+ } else if(/Mac OS/.test(ua)) {
+ this.macOS = true;
+ } else if(/Windows/.test(ua)) {
+ this.windows = true;
+ }
+ if(this.windows || this.macOS || this.linux) {
+ this.desktop = true;
+ }
+ };
+ Device.prototype._checkFeatures = function () {
+ this.canvas = !!window['CanvasRenderingContext2D'];
+ try {
+ this.localStorage = !!localStorage.getItem;
+ } catch (error) {
+ this.localStorage = false;
+ }
+ this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
+ this.fileSystem = !!window['requestFileSystem'];
+ this.webGL = !!window['WebGLRenderingContext'];
+ this.worker = !!window['Worker'];
+ if('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
+ this.touch = true;
+ }
+ if(window.navigator.msPointerEnabled) {
+ this.mspointer = true;
+ }
+ };
+ Device.prototype._checkBrowser = function () {
+ var ua = navigator.userAgent;
+ if(/Arora/.test(ua)) {
+ this.arora = true;
+ } else if(/Chrome/.test(ua)) {
+ this.chrome = true;
+ } else if(/Epiphany/.test(ua)) {
+ this.epiphany = true;
+ } else if(/Firefox/.test(ua)) {
+ this.firefox = true;
+ } else if(/Mobile Safari/.test(ua)) {
+ this.mobileSafari = true;
+ } else if(/MSIE (\d+\.\d+);/.test(ua)) {
+ this.ie = true;
+ this.ieVersion = parseInt(RegExp.$1);
+ } else if(/Midori/.test(ua)) {
+ this.midori = true;
+ } else if(/Opera/.test(ua)) {
+ this.opera = true;
+ } else if(/Safari/.test(ua)) {
+ this.safari = true;
+ }
+ if(navigator['standalone']) {
+ this.webApp = true;
+ }
+ };
+ Device.prototype.canPlayAudio = function (type) {
+ if(type == 'mp3' && this.mp3) {
+ return true;
+ } else if(type == 'ogg' && (this.ogg || this.opus)) {
+ return true;
+ } else if(type == 'm4a' && this.m4a) {
+ return true;
+ } else if(type == 'wav' && this.wav) {
+ return true;
+ } else if(type == 'webm' && this.webm) {
+ return true;
+ }
+ return false;
+ };
+ Device.prototype._checkAudio = function () {
+ this.audioData = !!(window['Audio']);
+ this.webAudio = !!(window['webkitAudioContext'] || window['AudioContext']);
+ var audioElement = document.createElement('audio');
+ var result = false;
+ try {
+ if(result = !!audioElement.canPlayType) {
+ if(audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
+ this.ogg = true;
+ }
+ if(audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '')) {
+ this.opus = true;
+ }
+ if(audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
+ this.mp3 = true;
+ }
+ if(audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
+ this.wav = true;
+ }
+ if(audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
+ this.m4a = true;
+ }
+ if(audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
+ this.webm = true;
+ }
+ }
+ } catch (e) {
+ }
+ };
+ Device.prototype._checkDevice = function () {
+ this.pixelRatio = window['devicePixelRatio'] || 1;
+ this.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
+ this.iPhone4 = (this.pixelRatio == 2 && this.iPhone);
+ this.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
+ };
+ Device.prototype._checkCSS3D = function () {
+ var el = document.createElement('p');
+ var has3d;
+ var transforms = {
+ 'webkitTransform': '-webkit-transform',
+ 'OTransform': '-o-transform',
+ 'msTransform': '-ms-transform',
+ 'MozTransform': '-moz-transform',
+ 'transform': 'transform'
+ };
+ document.body.insertBefore(el, null);
+ for(var t in transforms) {
+ if(el.style[t] !== undefined) {
+ el.style[t] = "translate3d(1px,1px,1px)";
+ has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
+ }
+ }
+ document.body.removeChild(el);
+ this.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
+ };
+ Device.prototype.isConsoleOpen = function () {
+ if(window.console && window.console['firebug']) {
+ return true;
+ }
+ if(window.console) {
+ console.profile();
+ console.profileEnd();
+ if(console.clear) {
+ console.clear();
+ }
+ return console['profiles'].length > 0;
+ }
+ return false;
+ };
+ return Device;
+ })();
+ Phaser.Device = Device;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var RequestAnimationFrame = (function () {
+ function RequestAnimationFrame(game, callback) {
+ this._isSetTimeOut = false;
+ this.isRunning = false;
+ this.game = game;
+ this.callback = callback;
+ var vendors = [
+ 'ms',
+ 'moz',
+ 'webkit',
+ 'o'
+ ];
+ for(var x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
+ window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
+ window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
+ }
+ this.start();
+ }
+ RequestAnimationFrame.prototype.isUsingSetTimeOut = function () {
+ return this._isSetTimeOut;
+ };
+ RequestAnimationFrame.prototype.isUsingRAF = function () {
+ return this._isSetTimeOut === true;
+ };
+ RequestAnimationFrame.prototype.start = function (callback) {
+ if (typeof callback === "undefined") { callback = null; }
+ var _this = this;
+ if(callback) {
+ this.callback = callback;
+ }
+ if(!window.requestAnimationFrame) {
+ this._isSetTimeOut = true;
+ this._onLoop = function () {
+ return _this.SetTimeoutUpdate();
+ };
+ this._timeOutID = window.setTimeout(this._onLoop, 0);
+ } else {
+ this._isSetTimeOut = false;
+ this._onLoop = function () {
+ return _this.RAFUpdate(0);
+ };
+ window.requestAnimationFrame(this._onLoop);
+ }
+ this.isRunning = true;
+ };
+ RequestAnimationFrame.prototype.stop = function () {
+ if(this._isSetTimeOut) {
+ clearTimeout(this._timeOutID);
+ } else {
+ window.cancelAnimationFrame;
+ }
+ this.isRunning = false;
+ };
+ RequestAnimationFrame.prototype.RAFUpdate = function (time) {
+ var _this = this;
+ this.game.time.update(time);
+ if(this.callback) {
+ this.callback.call(this.game);
+ }
+ this._onLoop = function (time) {
+ return _this.RAFUpdate(time);
+ };
+ window.requestAnimationFrame(this._onLoop);
+ };
+ RequestAnimationFrame.prototype.SetTimeoutUpdate = function () {
+ var _this = this;
+ this.game.time.update(Date.now());
+ this._onLoop = function () {
+ return _this.SetTimeoutUpdate();
+ };
+ this._timeOutID = window.setTimeout(this._onLoop, 16);
+ if(this.callback) {
+ this.callback.call(this.game);
+ }
+ };
+ return RequestAnimationFrame;
+ })();
+ Phaser.RequestAnimationFrame = RequestAnimationFrame;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var StageScaleMode = (function () {
+ function StageScaleMode(game, width, height) {
+ var _this = this;
+ this._startHeight = 0;
+ this.forceLandscape = false;
+ this.forcePortrait = false;
+ this.incorrectOrientation = false;
+ this.pageAlignHorizontally = false;
+ this.pageAlignVeritcally = false;
+ this.minWidth = null;
+ this.maxWidth = null;
+ this.minHeight = null;
+ this.maxHeight = null;
+ this.width = 0;
+ this.height = 0;
+ this.maxIterations = 10;
+ this.game = game;
+ this.enterLandscape = new Phaser.Signal();
+ this.enterPortrait = new Phaser.Signal();
+ if(window['orientation']) {
+ this.orientation = window['orientation'];
+ } else {
+ if(window.outerWidth > window.outerHeight) {
+ this.orientation = 90;
+ } else {
+ this.orientation = 0;
+ }
+ }
+ this.scaleFactor = new Phaser.Vec2(1, 1);
+ this.aspectRatio = 0;
+ this.minWidth = width;
+ this.minHeight = height;
+ this.maxWidth = width;
+ this.maxHeight = height;
+ window.addEventListener('orientationchange', function (event) {
+ return _this.checkOrientation(event);
+ }, false);
+ window.addEventListener('resize', function (event) {
+ return _this.checkResize(event);
+ }, false);
+ }
+ StageScaleMode.EXACT_FIT = 0;
+ StageScaleMode.NO_SCALE = 1;
+ StageScaleMode.SHOW_ALL = 2;
+ Object.defineProperty(StageScaleMode.prototype, "isFullScreen", {
+ get: function () {
+ if(document['fullscreenElement'] === null || document['mozFullScreenElement'] === null || document['webkitFullscreenElement'] === null) {
+ return false;
+ }
+ return true;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ StageScaleMode.prototype.startFullScreen = function () {
+ if(this.isFullScreen) {
+ return;
+ }
+ var element = this.game.stage.canvas;
+ if(element['requestFullScreen']) {
+ element['requestFullScreen']();
+ } else if(element['mozRequestFullScreen']) {
+ element['mozRequestFullScreen']();
+ } else if(element['webkitRequestFullScreen']) {
+ element['webkitRequestFullScreen']();
+ }
+ };
+ StageScaleMode.prototype.stopFullScreen = function () {
+ if(document['cancelFullScreen']) {
+ document['cancelFullScreen']();
+ } else if(document['mozCancelFullScreen']) {
+ document['mozCancelFullScreen']();
+ } else if(document['webkitCancelFullScreen']) {
+ document['webkitCancelFullScreen']();
+ }
+ };
+ StageScaleMode.prototype.update = function () {
+ if(this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height)) {
+ this.refresh();
+ }
+ if(this.forceLandscape || this.forcePortrait) {
+ this.checkOrientationState();
+ }
+ };
+ StageScaleMode.prototype.checkOrientationState = function () {
+ if(this.incorrectOrientation) {
+ if((this.forceLandscape && window.innerWidth > window.innerHeight) || (this.forcePortrait && window.innerHeight > window.innerWidth)) {
+ this.game.paused = false;
+ this.incorrectOrientation = false;
+ this.refresh();
+ }
+ } else {
+ if((this.forceLandscape && window.innerWidth < window.innerHeight) || (this.forcePortrait && window.innerHeight < window.innerWidth)) {
+ this.game.paused = true;
+ this.incorrectOrientation = true;
+ this.refresh();
+ }
+ }
+ };
+ Object.defineProperty(StageScaleMode.prototype, "isPortrait", {
+ get: function () {
+ return this.orientation == 0 || this.orientation == 180;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(StageScaleMode.prototype, "isLandscape", {
+ get: function () {
+ return this.orientation === 90 || this.orientation === -90;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ StageScaleMode.prototype.checkOrientation = function (event) {
+ this.orientation = window['orientation'];
+ if(this.isLandscape) {
+ this.enterLandscape.dispatch(this.orientation, true, false);
+ } else {
+ this.enterPortrait.dispatch(this.orientation, false, true);
+ }
+ if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
+ this.refresh();
+ }
+ };
+ StageScaleMode.prototype.checkResize = function (event) {
+ if(window.outerWidth > window.outerHeight) {
+ this.orientation = 90;
+ } else {
+ this.orientation = 0;
+ }
+ if(this.isLandscape) {
+ this.enterLandscape.dispatch(this.orientation, true, false);
+ } else {
+ this.enterPortrait.dispatch(this.orientation, false, true);
+ }
+ if(this.game.stage.scaleMode !== StageScaleMode.NO_SCALE) {
+ this.refresh();
+ }
+ };
+ StageScaleMode.prototype.refresh = function () {
+ var _this = this;
+ if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
+ document.documentElement['style'].minHeight = '2000px';
+ this._startHeight = window.innerHeight;
+ if(this.game.device.android && this.game.device.chrome == false) {
+ window.scrollTo(0, 1);
+ } else {
+ window.scrollTo(0, 0);
+ }
+ }
+ if(this._check == null && this.maxIterations > 0) {
+ this._iterations = this.maxIterations;
+ this._check = window.setInterval(function () {
+ return _this.setScreenSize();
+ }, 10);
+ this.setScreenSize();
+ }
+ };
+ StageScaleMode.prototype.setScreenSize = function (force) {
+ if (typeof force === "undefined") { force = false; }
+ if(this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) {
+ if(this.game.device.android && this.game.device.chrome == false) {
+ window.scrollTo(0, 1);
+ } else {
+ window.scrollTo(0, 0);
+ }
+ }
+ this._iterations--;
+ if(force || window.innerHeight > this._startHeight || this._iterations < 0) {
+ document.documentElement['style'].minHeight = window.innerHeight + 'px';
+ if(this.incorrectOrientation == true) {
+ this.setMaximum();
+ } else if(this.game.stage.scaleMode == StageScaleMode.EXACT_FIT) {
+ this.setExactFit();
+ } else if(this.game.stage.scaleMode == StageScaleMode.SHOW_ALL) {
+ this.setShowAll();
+ }
+ this.setSize();
+ clearInterval(this._check);
+ this._check = null;
+ }
+ };
+ StageScaleMode.prototype.setSize = function () {
+ if(this.incorrectOrientation == false) {
+ if(this.maxWidth && this.width > this.maxWidth) {
+ this.width = this.maxWidth;
+ }
+ if(this.maxHeight && this.height > this.maxHeight) {
+ this.height = this.maxHeight;
+ }
+ if(this.minWidth && this.width < this.minWidth) {
+ this.width = this.minWidth;
+ }
+ if(this.minHeight && this.height < this.minHeight) {
+ this.height = this.minHeight;
+ }
+ }
+ this.game.stage.canvas.style.width = this.width + 'px';
+ this.game.stage.canvas.style.height = this.height + 'px';
+ this.game.input.scale.setTo(this.game.stage.width / this.width, this.game.stage.height / this.height);
+ if(this.pageAlignHorizontally) {
+ if(this.width < window.innerWidth && this.incorrectOrientation == false) {
+ this.game.stage.canvas.style.marginLeft = Math.round((window.innerWidth - this.width) / 2) + 'px';
+ } else {
+ this.game.stage.canvas.style.marginLeft = '0px';
+ }
+ }
+ if(this.pageAlignVeritcally) {
+ if(this.height < window.innerHeight && this.incorrectOrientation == false) {
+ this.game.stage.canvas.style.marginTop = Math.round((window.innerHeight - this.height) / 2) + 'px';
+ } else {
+ this.game.stage.canvas.style.marginTop = '0px';
+ }
+ }
+ this.game.stage.getOffset(this.game.stage.canvas);
+ this.aspectRatio = this.width / this.height;
+ this.scaleFactor.x = this.game.stage.width / this.width;
+ this.scaleFactor.y = this.game.stage.height / this.height;
+ };
+ StageScaleMode.prototype.setMaximum = function () {
+ this.width = window.innerWidth;
+ this.height = window.innerHeight;
+ };
+ StageScaleMode.prototype.setShowAll = function () {
+ var multiplier = Math.min((window.innerHeight / this.game.stage.height), (window.innerWidth / this.game.stage.width));
+ this.width = Math.round(this.game.stage.width * multiplier);
+ this.height = Math.round(this.game.stage.height * multiplier);
+ };
+ StageScaleMode.prototype.setExactFit = function () {
+ if(this.maxWidth && window.innerWidth > this.maxWidth) {
+ this.width = this.maxWidth;
+ } else {
+ this.width = window.innerWidth;
+ }
+ if(this.maxHeight && window.innerHeight > this.maxHeight) {
+ this.height = this.maxHeight;
+ } else {
+ this.height = window.innerHeight;
+ }
+ };
+ return StageScaleMode;
+ })();
+ Phaser.StageScaleMode = StageScaleMode;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var BootScreen = (function () {
+ function BootScreen(game) {
+ this._logoData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGgAAAAZCAYAAADdYmvFAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAstJREFUeNrsWlFuwjAMbavdZGcAcRm4AXzvCPuGG8BlEJxhZ+l4TJ48z3actGGthqUI1MaO/V6cmIT2/fW10eTt46NvKshtvDZlG31yfOL9a/ldU6x4IZ0GQs0gS217enMkJYr5ixXkYrFoVqtV1kDn8/n+KfXw/Hq9Nin7h8MhScB2u3Xtav2ivsNWrh7XLcWMYqA4eUZ1kj0MAifHJEeKFojWzyIH+rL/0Cwif2AX9nN1oQOgrTg8XcTFx+ScdEOJ4WBxXQ1EjRyrn0cOzzQLzFyQSQcgw/5Qkkr0JVEQpNIdhL4vm4DL5fLulNTHcy6Uxl4/6iMLiePx2KzX6/v30+n0aynUlrnSeNq2/VN9bgM4dFPdNPmsJnIg/PuQbJmLdFN3UNu0SzbyJ0GOWJVWZE/QMkY+owrqXxGEdZA37BVyX6lJTipT6J1lf7fbqc+xh8nYeIvikatP+PGW0nEJ4jOydHYOIcfKnmgWoZDQSIIeio4Sf1IthYWskCO4vqQ6lFYjl8tl9L1H67PZbMz3VO3t93uVXHofmUjReLyMwHi5eCb3ICwJj5ZU9nCg+SzUgPYyif+2epTk4pkkyDp+eXTlZu2BkUybEkklePZfK9lPuTnc07vbmt1bYulHBeNQgx18SsH4ni/cV2rSLtqNDNUH2JQ2SsXS57Y9PHlfumkwCdICt5rnkNdPjpMiIEWgRlAJSdF4SvCQMWj+VyfI0h8D/EgWSYKiJKXi8VrOhJUxaFiFCOKKUJAtR78k9eX4USLHXqLGXOIiWUT4Vj9JiP4W0io3VDz8AJXblNWQrOimLjIGy/9uLICH6mrVmFbxEFHauzmc0fGJJmPg/v+6D0oB7N2bj0FsNHtSWTQniWTR931QlHXvasDTHXLjqY0/1/8hSDxACD+lAGH8dKQbQk5N3TFtzDmLWutvV0+pL5FVoHvCNG35FGAAayS4KUoKC9QAAAAASUVORK5CYII=";
+ this._color1 = {
+ r: 20,
+ g: 20,
+ b: 20
+ };
+ this._color2 = {
+ r: 200,
+ g: 200,
+ b: 200
+ };
+ this._fade = null;
+ this.game = game;
+ this._logo = new Image();
+ this._logo.src = this._logoData;
+ }
+ BootScreen.prototype.update = function () {
+ if(this._fade == null) {
+ this.colorCycle();
+ }
+ this._color1.r = Math.round(this._color1.r);
+ this._color1.g = Math.round(this._color1.g);
+ this._color1.b = Math.round(this._color1.b);
+ this._color2.r = Math.round(this._color2.r);
+ this._color2.g = Math.round(this._color2.g);
+ this._color2.b = Math.round(this._color2.b);
+ };
+ BootScreen.prototype.render = function () {
+ var grd = this.game.stage.context.createLinearGradient(0, 0, 0, this.game.stage.height);
+ grd.addColorStop(0, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
+ grd.addColorStop(0.5, 'rgb(' + this._color2.r + ', ' + this._color2.g + ', ' + this._color2.b + ')');
+ grd.addColorStop(1, 'rgb(' + this._color1.r + ', ' + this._color1.g + ', ' + this._color1.b + ')');
+ this.game.stage.context.fillStyle = grd;
+ this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
+ this.game.stage.context.shadowOffsetX = 0;
+ this.game.stage.context.shadowOffsetY = 0;
+ if(this._logo) {
+ this.game.stage.context.drawImage(this._logo, 32, 32);
+ }
+ this.game.stage.context.shadowColor = 'rgb(0,0,0)';
+ this.game.stage.context.shadowOffsetX = 1;
+ this.game.stage.context.shadowOffsetY = 1;
+ this.game.stage.context.shadowBlur = 0;
+ this.game.stage.context.fillStyle = 'rgb(255,255,255)';
+ this.game.stage.context.font = 'bold 18px Arial';
+ this.game.stage.context.textBaseline = 'top';
+ this.game.stage.context.fillText(Phaser.VERSION, 32, 64 + 32);
+ this.game.stage.context.fillText('Game Size: ' + this.game.stage.width + ' x ' + this.game.stage.height, 32, 64 + 64);
+ this.game.stage.context.fillText('www.photonstorm.com', 32, 64 + 96);
+ this.game.stage.context.font = '16px Arial';
+ this.game.stage.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 64 + 160);
+ this.game.stage.context.fillText('functions in the Game constructor or use Game.switchState()', 32, 64 + 184);
+ };
+ BootScreen.prototype.colorCycle = function () {
+ this._fade = this.game.add.tween(this._color2);
+ this._fade.to({
+ r: Math.random() * 250,
+ g: Math.random() * 250,
+ b: Math.random() * 250
+ }, 3000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.colorCycle, this);
+ this._fade.start();
+ };
+ return BootScreen;
+ })();
+ Phaser.BootScreen = BootScreen;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var OrientationScreen = (function () {
+ function OrientationScreen(game) {
+ this._showOnLandscape = false;
+ this._showOnPortrait = false;
+ this.game = game;
+ }
+ OrientationScreen.prototype.enable = function (onLandscape, onPortrait, imageKey) {
+ this._showOnLandscape = onLandscape;
+ this._showOnPortrait = onPortrait;
+ this.landscapeImage = this.game.cache.getImage(imageKey);
+ this.portraitImage = this.game.cache.getImage(imageKey);
+ };
+ OrientationScreen.prototype.update = function () {
+ };
+ OrientationScreen.prototype.render = function () {
+ if(this._showOnLandscape) {
+ this.game.stage.context.drawImage(this.landscapeImage, 0, 0, this.landscapeImage.width, this.landscapeImage.height, 0, 0, this.game.stage.width, this.game.stage.height);
+ } else if(this._showOnPortrait) {
+ this.game.stage.context.drawImage(this.portraitImage, 0, 0, this.portraitImage.width, this.portraitImage.height, 0, 0, this.game.stage.width, this.game.stage.height);
+ }
+ };
+ return OrientationScreen;
+ })();
+ Phaser.OrientationScreen = OrientationScreen;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var PauseScreen = (function () {
+ function PauseScreen(game, width, height) {
+ this.game = game;
+ this._canvas = document.createElement('canvas');
+ this._canvas.width = width;
+ this._canvas.height = height;
+ this._context = this._canvas.getContext('2d');
+ }
+ PauseScreen.prototype.onPaused = function () {
+ this._context.clearRect(0, 0, this._canvas.width, this._canvas.height);
+ this._context.drawImage(this.game.stage.canvas, 0, 0);
+ this._color = {
+ r: 255,
+ g: 255,
+ b: 255
+ };
+ this.fadeOut();
+ };
+ PauseScreen.prototype.onResume = function () {
+ this._fade.stop();
+ this.game.tweens.remove(this._fade);
+ };
+ PauseScreen.prototype.update = function () {
+ this._color.r = Math.round(this._color.r);
+ this._color.g = Math.round(this._color.g);
+ this._color.b = Math.round(this._color.b);
+ };
+ PauseScreen.prototype.render = function () {
+ this.game.stage.context.drawImage(this._canvas, 0, 0);
+ this.game.stage.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
+ this.game.stage.context.fillRect(0, 0, this.game.stage.width, this.game.stage.height);
+ var arrowWidth = Math.round(this.game.stage.width / 2);
+ var arrowHeight = Math.round(this.game.stage.height / 2);
+ var sx = this.game.stage.centerX - arrowWidth / 2;
+ var sy = this.game.stage.centerY - arrowHeight / 2;
+ this.game.stage.context.beginPath();
+ this.game.stage.context.moveTo(sx, sy);
+ this.game.stage.context.lineTo(sx, sy + arrowHeight);
+ this.game.stage.context.lineTo(sx + arrowWidth, this.game.stage.centerY);
+ this.game.stage.context.fillStyle = 'rgba(' + this._color.r + ', ' + this._color.g + ', ' + this._color.b + ', 0.8)';
+ this.game.stage.context.fill();
+ this.game.stage.context.closePath();
+ };
+ PauseScreen.prototype.fadeOut = function () {
+ this._fade = this.game.add.tween(this._color);
+ this._fade.to({
+ r: 50,
+ g: 50,
+ b: 50
+ }, 1000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.fadeIn, this);
+ this._fade.start();
+ };
+ PauseScreen.prototype.fadeIn = function () {
+ this._fade = this.game.add.tween(this._color);
+ this._fade.to({
+ r: 255,
+ g: 255,
+ b: 255
+ }, 1000, Phaser.Easing.Linear.None);
+ this._fade.onComplete.add(this.fadeOut, this);
+ this._fade.start();
+ };
+ return PauseScreen;
+ })();
+ Phaser.PauseScreen = PauseScreen;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var SoundManager = (function () {
+ function SoundManager(game) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = false;
+ this.noAudio = false;
+ this.context = null;
+ this._muted = false;
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.onSoundDecode = new Phaser.Signal();
+ this.game = game;
+ this._volume = 1;
+ this._muted = false;
+ this._sounds = [];
+ if(this.game.device.iOS && this.game.device.webAudio == false) {
+ this.channels = 1;
+ }
+ if(this.game.device.iOS || (window['PhaserGlobal'] && window['PhaserGlobal'].fakeiOSTouchLock)) {
+ this.game.input.touch.callbackContext = this;
+ this.game.input.touch.touchStartCallback = this.unlock;
+ this.game.input.mouse.callbackContext = this;
+ this.game.input.mouse.mouseDownCallback = this.unlock;
+ this.touchLocked = true;
+ } else {
+ this.touchLocked = false;
+ }
+ if(window['PhaserGlobal']) {
+ if(window['PhaserGlobal'].disableAudio == true) {
+ this.usingWebAudio = false;
+ this.noAudio = true;
+ return;
+ }
+ if(window['PhaserGlobal'].disableWebAudio == true) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = true;
+ this.noAudio = false;
+ return;
+ }
+ }
+ this.usingWebAudio = true;
+ this.noAudio = false;
+ if(!!window['AudioContext']) {
+ this.context = new window['AudioContext']();
+ } else if(!!window['webkitAudioContext']) {
+ this.context = new window['webkitAudioContext']();
+ } else if(!!window['Audio']) {
+ this.usingWebAudio = false;
+ this.usingAudioTag = true;
+ } else {
+ this.usingWebAudio = false;
+ this.noAudio = true;
+ }
+ if(this.context !== null) {
+ if(typeof this.context.createGain === 'undefined') {
+ this.masterGain = this.context.createGainNode();
+ } else {
+ this.masterGain = this.context.createGain();
+ }
+ this.masterGain.gain.value = 1;
+ this.masterGain.connect(this.context.destination);
+ }
+ }
+ SoundManager.prototype.unlock = function () {
+ if(this.touchLocked == false) {
+ return;
+ }
+ if(this.game.device.webAudio && (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == false)) {
+ var buffer = this.context.createBuffer(1, 1, 22050);
+ this._unlockSource = this.context.createBufferSource();
+ this._unlockSource.buffer = buffer;
+ this._unlockSource.connect(this.context.destination);
+ this._unlockSource.noteOn(0);
+ } else {
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.game.input.touch.callbackContext = null;
+ this.game.input.touch.touchStartCallback = null;
+ this.game.input.mouse.callbackContext = null;
+ this.game.input.mouse.mouseDownCallback = null;
+ }
+ };
+ Object.defineProperty(SoundManager.prototype, "mute", {
+ get: function () {
+ return this._muted;
+ },
+ set: function (value) {
+ if(value) {
+ if(this._muted) {
+ return;
+ }
+ this._muted = true;
+ if(this.usingWebAudio) {
+ this._muteVolume = this.masterGain.gain.value;
+ this.masterGain.gain.value = 0;
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].mute = true;
+ }
+ }
+ } else {
+ if(this._muted == false) {
+ return;
+ }
+ this._muted = false;
+ if(this.usingWebAudio) {
+ this.masterGain.gain.value = this._muteVolume;
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].mute = false;
+ }
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(SoundManager.prototype, "volume", {
+ get: function () {
+ if(this.usingWebAudio) {
+ return this.masterGain.gain.value;
+ } else {
+ return this._volume;
+ }
+ },
+ set: function (value) {
+ value = this.game.math.clamp(value, 1, 0);
+ this._volume = value;
+ if(this.usingWebAudio) {
+ this.masterGain.gain.value = value;
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i].usingAudioTag) {
+ this._sounds[i].volume = this._sounds[i].volume * value;
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ SoundManager.prototype.stopAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].stop();
+ }
+ }
+ };
+ SoundManager.prototype.pauseAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].pause();
+ }
+ }
+ };
+ SoundManager.prototype.resumeAll = function () {
+ for(var i = 0; i < this._sounds.length; i++) {
+ if(this._sounds[i]) {
+ this._sounds[i].resume();
+ }
+ }
+ };
+ SoundManager.prototype.decode = function (key, sound) {
+ if (typeof sound === "undefined") { sound = null; }
+ var soundData = this.game.cache.getSoundData(key);
+ if(soundData) {
+ if(this.game.cache.isSoundDecoded(key) === false) {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+ var that = this;
+ this.context.decodeAudioData(soundData, function (buffer) {
+ that.game.cache.decodedSound(key, buffer);
+ if(sound) {
+ that.onSoundDecode.dispatch(sound);
+ }
+ });
+ }
+ }
+ };
+ SoundManager.prototype.update = function () {
+ if(this.touchLocked) {
+ if(this.game.device.webAudio && this._unlockSource !== null) {
+ if((this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
+ this.touchLocked = false;
+ this._unlockSource = null;
+ this.game.input.touch.callbackContext = null;
+ this.game.input.touch.touchStartCallback = null;
+ }
+ }
+ }
+ for(var i = 0; i < this._sounds.length; i++) {
+ this._sounds[i].update();
+ }
+ };
+ SoundManager.prototype.add = function (key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ var sound = new Phaser.Sound(this.game, key, volume, loop);
+ this._sounds.push(sound);
+ return sound;
+ };
+ return SoundManager;
+ })();
+ Phaser.SoundManager = SoundManager;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Sound = (function () {
+ function Sound(game, key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.context = null;
+ this._buffer = null;
+ this._muted = false;
+ this.usingWebAudio = false;
+ this.usingAudioTag = false;
+ this.name = '';
+ this.autoplay = false;
+ this.totalDuration = 0;
+ this.startTime = 0;
+ this.currentTime = 0;
+ this.duration = 0;
+ this.stopTime = 0;
+ this.paused = false;
+ this.loop = false;
+ this.isPlaying = false;
+ this.currentMarker = '';
+ this.pendingPlayback = false;
+ this.override = false;
+ this.game = game;
+ this.usingWebAudio = this.game.sound.usingWebAudio;
+ this.usingAudioTag = this.game.sound.usingAudioTag;
+ this.key = key;
+ if(this.usingWebAudio) {
+ this.context = this.game.sound.context;
+ this.masterGainNode = this.game.sound.masterGain;
+ if(typeof this.context.createGain === 'undefined') {
+ this.gainNode = this.context.createGainNode();
+ } else {
+ this.gainNode = this.context.createGain();
+ }
+ this.gainNode.gain.value = volume * this.game.sound.volume;
+ this.gainNode.connect(this.masterGainNode);
+ } else {
+ if(this.game.cache.getSound(key) && this.game.cache.getSound(key).locked == false) {
+ this._sound = this.game.cache.getSoundData(key);
+ this.totalDuration = this._sound.duration;
+ } else {
+ this.game.cache.onSoundUnlock.add(this.soundHasUnlocked, this);
+ }
+ }
+ this._volume = volume;
+ this.loop = loop;
+ this.markers = {
+ };
+ this.onDecoded = new Phaser.Signal();
+ this.onPlay = new Phaser.Signal();
+ this.onPause = new Phaser.Signal();
+ this.onResume = new Phaser.Signal();
+ this.onLoop = new Phaser.Signal();
+ this.onStop = new Phaser.Signal();
+ this.onMute = new Phaser.Signal();
+ this.onMarkerComplete = new Phaser.Signal();
+ }
+ Sound.prototype.soundHasUnlocked = function (key) {
+ if(key == this.key) {
+ this._sound = this.game.cache.getSoundData(this.key);
+ this.totalDuration = this._sound.duration;
+ }
+ };
+ Object.defineProperty(Sound.prototype, "isDecoding", {
+ get: function () {
+ return this.game.cache.getSound(this.key).isDecoding;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sound.prototype, "isDecoded", {
+ get: function () {
+ return this.game.cache.isSoundDecoded(this.key);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sound.prototype.addMarker = function (name, start, stop, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.markers[name] = {
+ name: name,
+ start: start,
+ stop: stop,
+ volume: volume,
+ duration: stop - start,
+ loop: loop
+ };
+ };
+ Sound.prototype.removeMarker = function (name) {
+ delete this.markers[name];
+ };
+ Sound.prototype.update = function () {
+ if(this.pendingPlayback && this.game.cache.isSoundReady(this.key)) {
+ this.pendingPlayback = false;
+ this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
+ }
+ if(this.isPlaying) {
+ this.currentTime = this.game.time.now - this.startTime;
+ if(this.currentTime >= this.duration) {
+ if(this.usingWebAudio) {
+ if(this.loop) {
+ this.onLoop.dispatch(this);
+ if(this.currentMarker == '') {
+ this.currentTime = 0;
+ this.startTime = this.game.time.now;
+ } else {
+ this.play(this.currentMarker, 0, this.volume, true, true);
+ }
+ } else {
+ this.stop();
+ }
+ } else {
+ if(this.loop) {
+ this.onLoop.dispatch(this);
+ this.play(this.currentMarker, 0, this.volume, true, true);
+ } else {
+ this.stop();
+ }
+ }
+ }
+ }
+ };
+ Sound.prototype.play = function (marker, position, volume, loop, forceRestart) {
+ if (typeof marker === "undefined") { marker = ''; }
+ if (typeof position === "undefined") { position = 0; }
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof forceRestart === "undefined") { forceRestart = false; }
+ if(this.isPlaying == true && forceRestart == false && this.override == false) {
+ return;
+ }
+ if(this.isPlaying && this.override) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.stop === 'undefined') {
+ this._sound.noteOff(0);
+ } else {
+ this._sound.stop(0);
+ }
+ } else if(this.usingAudioTag) {
+ this._sound.pause();
+ this._sound.currentTime = 0;
+ }
+ }
+ this.currentMarker = marker;
+ if(marker !== '' && this.markers[marker]) {
+ this.position = this.markers[marker].start;
+ this.volume = this.markers[marker].volume;
+ this.loop = this.markers[marker].loop;
+ this.duration = this.markers[marker].duration * 1000;
+ this._tempMarker = marker;
+ this._tempPosition = this.position;
+ this._tempVolume = this.volume;
+ this._tempLoop = this.loop;
+ } else {
+ this.position = position;
+ this.volume = volume;
+ this.loop = loop;
+ this.duration = 0;
+ this._tempMarker = marker;
+ this._tempPosition = position;
+ this._tempVolume = volume;
+ this._tempLoop = loop;
+ }
+ if(this.usingWebAudio) {
+ if(this.game.cache.isSoundDecoded(this.key)) {
+ if(this._buffer == null) {
+ this._buffer = this.game.cache.getSoundData(this.key);
+ }
+ this._sound = this.context.createBufferSource();
+ this._sound.buffer = this._buffer;
+ this._sound.connect(this.gainNode);
+ this.totalDuration = this._sound.buffer.duration;
+ if(this.duration == 0) {
+ this.duration = this.totalDuration * 1000;
+ }
+ if(this.loop && marker == '') {
+ this._sound.loop = true;
+ }
+ if(typeof this._sound.start === 'undefined') {
+ this._sound.noteGrainOn(0, this.position, this.duration / 1000);
+ } else {
+ this._sound.start(0, this.position, this.duration / 1000);
+ }
+ this.isPlaying = true;
+ this.startTime = this.game.time.now;
+ this.currentTime = 0;
+ this.stopTime = this.startTime + this.duration;
+ this.onPlay.dispatch(this);
+ } else {
+ this.pendingPlayback = true;
+ if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false) {
+ this.game.sound.decode(this.key, this);
+ }
+ }
+ } else {
+ if(this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).locked) {
+ this.game.cache.reloadSound(this.key);
+ this.pendingPlayback = true;
+ } else {
+ if(this._sound && this._sound.readyState == 4) {
+ if(this.duration == 0) {
+ this.duration = this.totalDuration * 1000;
+ }
+ this._sound.currentTime = this.position;
+ this._sound.muted = this._muted;
+ if(this._muted) {
+ this._sound.volume = 0;
+ } else {
+ this._sound.volume = this._volume;
+ }
+ this._sound.play();
+ this.isPlaying = true;
+ this.startTime = this.game.time.now;
+ this.currentTime = 0;
+ this.stopTime = this.startTime + this.duration;
+ this.onPlay.dispatch(this);
+ } else {
+ this.pendingPlayback = true;
+ }
+ }
+ }
+ };
+ Sound.prototype.restart = function (marker, position, volume, loop) {
+ if (typeof marker === "undefined") { marker = ''; }
+ if (typeof position === "undefined") { position = 0; }
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ this.play(marker, position, volume, loop, true);
+ };
+ Sound.prototype.pause = function () {
+ if(this.isPlaying && this._sound) {
+ this.stop();
+ this.isPlaying = false;
+ this.paused = true;
+ this.onPause.dispatch(this);
+ }
+ };
+ Sound.prototype.resume = function () {
+ if(this.paused && this._sound) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.start === 'undefined') {
+ this._sound.noteGrainOn(0, this.position, this.duration);
+ } else {
+ this._sound.start(0, this.position, this.duration);
+ }
+ } else {
+ this._sound.play();
+ }
+ this.isPlaying = true;
+ this.paused = false;
+ this.onResume.dispatch(this);
+ }
+ };
+ Sound.prototype.stop = function () {
+ if(this.isPlaying && this._sound) {
+ if(this.usingWebAudio) {
+ if(typeof this._sound.stop === 'undefined') {
+ this._sound.noteOff(0);
+ } else {
+ this._sound.stop(0);
+ }
+ } else if(this.usingAudioTag) {
+ this._sound.pause();
+ this._sound.currentTime = 0;
+ }
+ }
+ this.isPlaying = false;
+ var prevMarker = this.currentMarker;
+ this.currentMarker = '';
+ this.onStop.dispatch(this, prevMarker);
+ };
+ Object.defineProperty(Sound.prototype, "mute", {
+ get: function () {
+ return this._muted;
+ },
+ set: function (value) {
+ if(value) {
+ this._muted = true;
+ if(this.usingWebAudio) {
+ this._muteVolume = this.gainNode.gain.value;
+ this.gainNode.gain.value = 0;
+ } else if(this.usingAudioTag && this._sound) {
+ this._muteVolume = this._sound.volume;
+ this._sound.volume = 0;
+ }
+ } else {
+ this._muted = false;
+ if(this.usingWebAudio) {
+ this.gainNode.gain.value = this._muteVolume;
+ } else if(this.usingAudioTag && this._sound) {
+ this._sound.volume = this._muteVolume;
+ }
+ }
+ this.onMute.dispatch(this);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sound.prototype, "volume", {
+ get: function () {
+ return this._volume;
+ },
+ set: function (value) {
+ this._volume = value;
+ if(this.usingWebAudio) {
+ this.gainNode.gain.value = value;
+ } else if(this.usingAudioTag && this._sound) {
+ this._sound.volume = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Sound;
+ })();
+ Phaser.Sound = Sound;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Animation = (function () {
+ function Animation(game, parent, frameData, name, frames, delay, looped) {
+ this.game = game;
+ this._parent = parent;
+ this._frames = frames;
+ this._frameData = frameData;
+ this.name = name;
+ this.delay = 1000 / delay;
+ this.looped = looped;
+ this.isFinished = false;
+ this.isPlaying = false;
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ }
+ Object.defineProperty(Animation.prototype, "frameTotal", {
+ get: function () {
+ return this._frames.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Animation.prototype, "frame", {
+ get: function () {
+ if(this.currentFrame !== null) {
+ return this.currentFrame.index;
+ } else {
+ return this._frameIndex;
+ }
+ },
+ set: function (value) {
+ this.currentFrame = this._frameData.getFrame(value);
+ if(this.currentFrame !== null) {
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ this._frameIndex = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Animation.prototype.play = function (frameRate, loop) {
+ if (typeof frameRate === "undefined") { frameRate = null; }
+ if (typeof loop === "undefined") { loop = false; }
+ if(frameRate !== null) {
+ this.delay = 1000 / frameRate;
+ }
+ this.looped = loop;
+ this.isPlaying = true;
+ this.isFinished = false;
+ this._timeLastFrame = this.game.time.now;
+ this._timeNextFrame = this.game.time.now + this.delay;
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ this._parent.events.onAnimationStart.dispatch(this._parent, this);
+ return this;
+ };
+ Animation.prototype.restart = function () {
+ this.isPlaying = true;
+ this.isFinished = false;
+ this._timeLastFrame = this.game.time.now;
+ this._timeNextFrame = this.game.time.now + this.delay;
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ };
+ Animation.prototype.stop = function () {
+ this.isPlaying = false;
+ this.isFinished = true;
+ };
+ Animation.prototype.update = function () {
+ if(this.isPlaying == true && this.game.time.now >= this._timeNextFrame) {
+ this._frameIndex++;
+ if(this._frameIndex == this._frames.length) {
+ if(this.looped) {
+ this._frameIndex = 0;
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ this._parent.events.onAnimationLoop.dispatch(this._parent, this);
+ } else {
+ this.onComplete();
+ }
+ } else {
+ this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
+ }
+ this._timeLastFrame = this.game.time.now;
+ this._timeNextFrame = this.game.time.now + this.delay;
+ return true;
+ }
+ return false;
+ };
+ Animation.prototype.destroy = function () {
+ this.game = null;
+ this._parent = null;
+ this._frames = null;
+ this._frameData = null;
+ this.currentFrame = null;
+ this.isPlaying = false;
+ };
+ Animation.prototype.onComplete = function () {
+ this.isPlaying = false;
+ this.isFinished = true;
+ this._parent.events.onAnimationComplete.dispatch(this._parent, this);
+ };
+ return Animation;
+ })();
+ Phaser.Animation = Animation;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var AnimationManager = (function () {
+ function AnimationManager(parent) {
+ this._frameData = null;
+ this.autoUpdateBounds = true;
+ this.currentFrame = null;
+ this._parent = parent;
+ this.game = parent.game;
+ this._anims = {
+ };
+ }
+ AnimationManager.prototype.loadFrameData = function (frameData) {
+ this._frameData = frameData;
+ this.frame = 0;
+ };
+ AnimationManager.prototype.add = function (name, frames, frameRate, loop, useNumericIndex) {
+ if (typeof frames === "undefined") { frames = null; }
+ if (typeof frameRate === "undefined") { frameRate = 60; }
+ if (typeof loop === "undefined") { loop = false; }
+ if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
+ if(this._frameData == null) {
+ return;
+ }
+ if(this._parent.events.onAnimationStart == null) {
+ this._parent.events.onAnimationStart = new Phaser.Signal();
+ this._parent.events.onAnimationComplete = new Phaser.Signal();
+ this._parent.events.onAnimationLoop = new Phaser.Signal();
+ }
+ if(frames == null) {
+ frames = this._frameData.getFrameIndexes();
+ } else {
+ if(this.validateFrames(frames, useNumericIndex) == false) {
+ throw Error('Invalid frames given to Animation ' + name);
+ return;
+ }
+ }
+ if(useNumericIndex == false) {
+ frames = this._frameData.getFrameIndexesByName(frames);
+ }
+ this._anims[name] = new Phaser.Animation(this.game, this._parent, this._frameData, name, frames, frameRate, loop);
+ this.currentAnim = this._anims[name];
+ this.currentFrame = this.currentAnim.currentFrame;
+ return this._anims[name];
+ };
+ AnimationManager.prototype.validateFrames = function (frames, useNumericIndex) {
+ for(var i = 0; i < frames.length; i++) {
+ if(useNumericIndex == true) {
+ if(frames[i] > this._frameData.total) {
+ return false;
+ }
+ } else {
+ if(this._frameData.checkFrameName(frames[i]) == false) {
+ return false;
+ }
+ }
+ }
+ return true;
+ };
+ AnimationManager.prototype.play = function (name, frameRate, loop) {
+ if (typeof frameRate === "undefined") { frameRate = null; }
+ if (typeof loop === "undefined") { loop = false; }
+ if(this._anims[name]) {
+ if(this.currentAnim == this._anims[name]) {
+ if(this.currentAnim.isPlaying == false) {
+ return this.currentAnim.play(frameRate, loop);
+ }
+ } else {
+ this.currentAnim = this._anims[name];
+ return this.currentAnim.play(frameRate, loop);
+ }
+ }
+ };
+ AnimationManager.prototype.stop = function (name) {
+ if(this._anims[name]) {
+ this.currentAnim = this._anims[name];
+ this.currentAnim.stop();
+ }
+ };
+ AnimationManager.prototype.update = function () {
+ if(this.currentAnim && this.currentAnim.update() == true) {
+ this.currentFrame = this.currentAnim.currentFrame;
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ }
+ };
+ Object.defineProperty(AnimationManager.prototype, "frameData", {
+ get: function () {
+ return this._frameData;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(AnimationManager.prototype, "frameTotal", {
+ get: function () {
+ if(this._frameData) {
+ return this._frameData.total;
+ } else {
+ return -1;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(AnimationManager.prototype, "frame", {
+ get: function () {
+ return this._frameIndex;
+ },
+ set: function (value) {
+ if(this._frameData && this._frameData.getFrame(value) !== null) {
+ this.currentFrame = this._frameData.getFrame(value);
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ if(this.autoUpdateBounds && this._parent['body']) {
+ this._parent.body.bounds.width = this.currentFrame.width;
+ this._parent.body.bounds.height = this.currentFrame.height;
+ }
+ this._frameIndex = value;
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(AnimationManager.prototype, "frameName", {
+ get: function () {
+ return this.currentFrame.name;
+ },
+ set: function (value) {
+ if(this._frameData && this._frameData.getFrameByName(value)) {
+ this.currentFrame = this._frameData.getFrameByName(value);
+ this._parent.texture.width = this.currentFrame.width;
+ this._parent.texture.height = this.currentFrame.height;
+ this._frameIndex = this.currentFrame.index;
+ } else {
+ throw new Error("Cannot set frameName: " + value);
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ AnimationManager.prototype.destroy = function () {
+ this._anims = {
+ };
+ this._frameData = null;
+ this._frameIndex = 0;
+ this.currentAnim = null;
+ this.currentFrame = null;
+ };
+ return AnimationManager;
+ })();
+ Components.AnimationManager = AnimationManager;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Frame = (function () {
+ function Frame(x, y, width, height, name) {
+ this.name = '';
+ this.rotated = false;
+ this.rotationDirection = 'cw';
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.name = name;
+ this.rotated = false;
+ this.trimmed = false;
+ }
+ Frame.prototype.setRotation = function (rotated, rotationDirection) {
+ };
+ Frame.prototype.setTrim = function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
+ this.trimmed = trimmed;
+ if(trimmed) {
+ this.width = actualWidth;
+ this.height = actualHeight;
+ this.sourceSizeW = actualWidth;
+ this.sourceSizeH = actualHeight;
+ this.spriteSourceSizeX = destX;
+ this.spriteSourceSizeY = destY;
+ this.spriteSourceSizeW = destWidth;
+ this.spriteSourceSizeH = destHeight;
+ }
+ };
+ return Frame;
+ })();
+ Phaser.Frame = Frame;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var FrameData = (function () {
+ function FrameData() {
+ this._frames = [];
+ this._frameNames = [];
+ }
+ Object.defineProperty(FrameData.prototype, "total", {
+ get: function () {
+ return this._frames.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ FrameData.prototype.addFrame = function (frame) {
+ frame.index = this._frames.length;
+ this._frames.push(frame);
+ if(frame.name !== '') {
+ this._frameNames[frame.name] = frame.index;
+ }
+ return frame;
+ };
+ FrameData.prototype.getFrame = function (index) {
+ if(this._frames[index]) {
+ return this._frames[index];
+ }
+ return null;
+ };
+ FrameData.prototype.getFrameByName = function (name) {
+ if(this._frameNames[name] !== '') {
+ return this._frames[this._frameNames[name]];
+ }
+ return null;
+ };
+ FrameData.prototype.checkFrameName = function (name) {
+ if(this._frameNames[name] == null) {
+ return false;
+ }
+ return true;
+ };
+ FrameData.prototype.getFrameRange = function (start, end, output) {
+ if (typeof output === "undefined") { output = []; }
+ for(var i = start; i <= end; i++) {
+ output.push(this._frames[i]);
+ }
+ return output;
+ };
+ FrameData.prototype.getFrameIndexes = function (output) {
+ if (typeof output === "undefined") { output = []; }
+ output.length = 0;
+ for(var i = 0; i < this._frames.length; i++) {
+ output.push(i);
+ }
+ return output;
+ };
+ FrameData.prototype.getFrameIndexesByName = function (input) {
+ var output = [];
+ for(var i = 0; i < input.length; i++) {
+ if(this.getFrameByName(input[i])) {
+ output.push(this.getFrameByName(input[i]).index);
+ }
+ }
+ return output;
+ };
+ FrameData.prototype.getAllFrames = function () {
+ return this._frames;
+ };
+ FrameData.prototype.getFrames = function (range) {
+ var output = [];
+ for(var i = 0; i < range.length; i++) {
+ output.push(this._frames[i]);
+ }
+ return output;
+ };
+ return FrameData;
+ })();
+ Phaser.FrameData = FrameData;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Cache = (function () {
+ function Cache(game) {
+ this.onSoundUnlock = new Phaser.Signal();
+ this.game = game;
+ this._canvases = {
+ };
+ this._images = {
+ };
+ this._sounds = {
+ };
+ this._text = {
+ };
+ }
+ Cache.prototype.addCanvas = function (key, canvas, context) {
+ this._canvases[key] = {
+ canvas: canvas,
+ context: context
+ };
+ };
+ Cache.prototype.addSpriteSheet = function (key, url, data, frameWidth, frameHeight, frameMax) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: true,
+ frameWidth: frameWidth,
+ frameHeight: frameHeight
+ };
+ this._images[key].frameData = Phaser.AnimationLoader.parseSpriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
+ };
+ Cache.prototype.addTextureAtlas = function (key, url, data, atlasData, format) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: true
+ };
+ if(format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ this._images[key].frameData = Phaser.AnimationLoader.parseJSONData(this.game, atlasData);
+ } else if(format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING) {
+ this._images[key].frameData = Phaser.AnimationLoader.parseXMLData(this.game, atlasData, format);
+ }
+ };
+ Cache.prototype.addImage = function (key, url, data) {
+ this._images[key] = {
+ url: url,
+ data: data,
+ spriteSheet: false
+ };
+ };
+ Cache.prototype.addSound = function (key, url, data, webAudio, audioTag) {
+ if (typeof webAudio === "undefined") { webAudio = true; }
+ if (typeof audioTag === "undefined") { audioTag = false; }
+ var locked = this.game.sound.touchLocked;
+ var decoded = false;
+ if(audioTag) {
+ decoded = true;
+ }
+ this._sounds[key] = {
+ url: url,
+ data: data,
+ locked: locked,
+ isDecoding: false,
+ decoded: decoded,
+ webAudio: webAudio,
+ audioTag: audioTag
+ };
+ };
+ Cache.prototype.reloadSound = function (key) {
+ var _this = this;
+ if(this._sounds[key]) {
+ this._sounds[key].data.src = this._sounds[key].url;
+ this._sounds[key].data.addEventListener('canplaythrough', function () {
+ return _this.reloadSoundComplete(key);
+ }, false);
+ this._sounds[key].data.load();
+ }
+ };
+ Cache.prototype.reloadSoundComplete = function (key) {
+ if(this._sounds[key]) {
+ this._sounds[key].locked = false;
+ this.onSoundUnlock.dispatch(key);
+ }
+ };
+ Cache.prototype.updateSound = function (key, property, value) {
+ if(this._sounds[key]) {
+ this._sounds[key][property] = value;
+ }
+ };
+ Cache.prototype.decodedSound = function (key, data) {
+ this._sounds[key].data = data;
+ this._sounds[key].decoded = true;
+ this._sounds[key].isDecoding = false;
+ };
+ Cache.prototype.addText = function (key, url, data) {
+ this._text[key] = {
+ url: url,
+ data: data
+ };
+ };
+ Cache.prototype.getCanvas = function (key) {
+ if(this._canvases[key]) {
+ return this._canvases[key].canvas;
+ }
+ return null;
+ };
+ Cache.prototype.getImage = function (key) {
+ if(this._images[key]) {
+ return this._images[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.getFrameData = function (key) {
+ if(this._images[key] && this._images[key].spriteSheet == true) {
+ return this._images[key].frameData;
+ }
+ return null;
+ };
+ Cache.prototype.getSound = function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key];
+ }
+ return null;
+ };
+ Cache.prototype.getSoundData = function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.isSoundDecoded = function (key) {
+ if(this._sounds[key]) {
+ return this._sounds[key].decoded;
+ }
+ };
+ Cache.prototype.isSoundReady = function (key) {
+ if(this._sounds[key] && this._sounds[key].decoded == true && this._sounds[key].locked == false) {
+ return true;
+ }
+ return false;
+ };
+ Cache.prototype.isSpriteSheet = function (key) {
+ if(this._images[key]) {
+ return this._images[key].spriteSheet;
+ }
+ };
+ Cache.prototype.getText = function (key) {
+ if(this._text[key]) {
+ return this._text[key].data;
+ }
+ return null;
+ };
+ Cache.prototype.getImageKeys = function () {
+ var output = [];
+ for(var item in this._images) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.getSoundKeys = function () {
+ var output = [];
+ for(var item in this._sounds) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.getTextKeys = function () {
+ var output = [];
+ for(var item in this._text) {
+ output.push(item);
+ }
+ return output;
+ };
+ Cache.prototype.removeCanvas = function (key) {
+ delete this._canvases[key];
+ };
+ Cache.prototype.removeImage = function (key) {
+ delete this._images[key];
+ };
+ Cache.prototype.removeSound = function (key) {
+ delete this._sounds[key];
+ };
+ Cache.prototype.removeText = function (key) {
+ delete this._text[key];
+ };
+ Cache.prototype.destroy = function () {
+ for(var item in this._canvases) {
+ delete this._canvases[item['key']];
+ }
+ for(var item in this._images) {
+ delete this._images[item['key']];
+ }
+ for(var item in this._sounds) {
+ delete this._sounds[item['key']];
+ }
+ for(var item in this._text) {
+ delete this._text[item['key']];
+ }
+ };
+ return Cache;
+ })();
+ Phaser.Cache = Cache;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Loader = (function () {
+ function Loader(game) {
+ this.crossOrigin = '';
+ this.baseURL = '';
+ this.game = game;
+ this._keys = [];
+ this._fileList = {
+ };
+ this._xhr = new XMLHttpRequest();
+ this._queueSize = 0;
+ this.isLoading = false;
+ this.onFileComplete = new Phaser.Signal();
+ this.onFileError = new Phaser.Signal();
+ this.onLoadStart = new Phaser.Signal();
+ this.onLoadComplete = new Phaser.Signal();
+ }
+ Loader.TEXTURE_ATLAS_JSON_ARRAY = 0;
+ Loader.TEXTURE_ATLAS_JSON_HASH = 1;
+ Loader.TEXTURE_ATLAS_XML_STARLING = 2;
+ Loader.prototype.reset = function () {
+ this._queueSize = 0;
+ this.isLoading = false;
+ };
+ Object.defineProperty(Loader.prototype, "queueSize", {
+ get: function () {
+ return this._queueSize;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Loader.prototype.image = function (key, url, overwrite) {
+ if (typeof overwrite === "undefined") { overwrite = false; }
+ if(overwrite == true || this.checkKeyExists(key) == false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'image',
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.spritesheet = function (key, url, frameWidth, frameHeight, frameMax) {
+ if (typeof frameMax === "undefined") { frameMax = -1; }
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'spritesheet',
+ key: key,
+ url: url,
+ data: null,
+ frameWidth: frameWidth,
+ frameHeight: frameHeight,
+ frameMax: frameMax,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.atlas = function (key, textureURL, atlasURL, atlasData, format) {
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ if (typeof format === "undefined") { format = Loader.TEXTURE_ATLAS_JSON_ARRAY; }
+ if(this.checkKeyExists(key) === false) {
+ if(atlasURL !== null) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ atlasURL: atlasURL,
+ data: null,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ } else {
+ if(format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ if(typeof atlasData === 'string') {
+ atlasData = JSON.parse(atlasData);
+ }
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ data: null,
+ atlasURL: null,
+ atlasData: atlasData,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ } else if(format == Loader.TEXTURE_ATLAS_XML_STARLING) {
+ if(typeof atlasData === 'string') {
+ var xml;
+ try {
+ if(window['DOMParser']) {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ } else {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ } catch (e) {
+ xml = undefined;
+ }
+ if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
+ throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
+ } else {
+ atlasData = xml;
+ }
+ }
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'textureatlas',
+ key: key,
+ url: textureURL,
+ data: null,
+ atlasURL: null,
+ atlasData: atlasData,
+ format: format,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ }
+ }
+ };
+ Loader.prototype.audio = function (key, urls, autoDecode) {
+ if (typeof autoDecode === "undefined") { autoDecode = true; }
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'audio',
+ key: key,
+ url: urls,
+ data: null,
+ buffer: null,
+ error: false,
+ loaded: false,
+ autoDecode: autoDecode
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.text = function (key, url) {
+ if(this.checkKeyExists(key) === false) {
+ this._queueSize++;
+ this._fileList[key] = {
+ type: 'text',
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+ this._keys.push(key);
+ }
+ };
+ Loader.prototype.removeFile = function (key) {
+ delete this._fileList[key];
+ };
+ Loader.prototype.removeAll = function () {
+ this._fileList = {
+ };
+ };
+ Loader.prototype.start = function () {
+ if(this.isLoading) {
+ return;
+ }
+ this.progress = 0;
+ this.hasLoaded = false;
+ this.isLoading = true;
+ this.onLoadStart.dispatch(this.queueSize);
+ if(this._keys.length > 0) {
+ this._progressChunk = 100 / this._keys.length;
+ this.loadFile();
+ } else {
+ this.progress = 100;
+ this.hasLoaded = true;
+ this.onLoadComplete.dispatch();
+ }
+ };
+ Loader.prototype.loadFile = function () {
+ var _this = this;
+ var file = this._fileList[this._keys.pop()];
+ switch(file.type) {
+ case 'image':
+ case 'spritesheet':
+ case 'textureatlas':
+ file.data = new Image();
+ file.data.name = file.key;
+ file.data.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.crossOrigin = this.crossOrigin;
+ file.data.src = this.baseURL + file.url;
+ break;
+ case 'audio':
+ file.url = this.getAudioURL(file.url);
+ if(file.url !== null) {
+ if(this.game.sound.usingWebAudio) {
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "arraybuffer";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ } else if(this.game.sound.usingAudioTag) {
+ if(this.game.sound.touchLocked) {
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ this.fileComplete(file.key);
+ } else {
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
+ file.data.load();
+ }
+ }
+ }
+ break;
+ case 'text':
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "text";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ break;
+ }
+ };
+ Loader.prototype.getAudioURL = function (urls) {
+ var extension;
+ for(var i = 0; i < urls.length; i++) {
+ extension = urls[i].toLowerCase();
+ extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
+ if(this.game.device.canPlayAudio(extension)) {
+ return urls[i];
+ }
+ }
+ return null;
+ };
+ Loader.prototype.fileError = function (key) {
+ this._fileList[key].loaded = true;
+ this._fileList[key].error = true;
+ this.onFileError.dispatch(key);
+ throw new Error("Phaser.Loader error loading file: " + key);
+ this.nextFile(key, false);
+ };
+ Loader.prototype.fileComplete = function (key) {
+ var _this = this;
+ if(!this._fileList[key]) {
+ throw new Error('Phaser.Loader fileComplete invalid key ' + key);
+ return;
+ }
+ this._fileList[key].loaded = true;
+ var file = this._fileList[key];
+ var loadNext = true;
+ switch(file.type) {
+ case 'image':
+ this.game.cache.addImage(file.key, file.url, file.data);
+ break;
+ case 'spritesheet':
+ this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax);
+ break;
+ case 'textureatlas':
+ if(file.atlasURL == null) {
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
+ } else {
+ loadNext = false;
+ this._xhr.open("GET", this.baseURL + file.atlasURL, true);
+ this._xhr.responseType = "text";
+ if(file.format == Loader.TEXTURE_ATLAS_JSON_ARRAY) {
+ this._xhr.onload = function () {
+ return _this.jsonLoadComplete(file.key);
+ };
+ } else if(file.format == Loader.TEXTURE_ATLAS_XML_STARLING) {
+ this._xhr.onload = function () {
+ return _this.xmlLoadComplete(file.key);
+ };
+ }
+ this._xhr.onerror = function () {
+ return _this.dataLoadError(file.key);
+ };
+ this._xhr.send();
+ }
+ break;
+ case 'audio':
+ if(this.game.sound.usingWebAudio) {
+ file.data = this._xhr.response;
+ this.game.cache.addSound(file.key, file.url, file.data, true, false);
+ if(file.autoDecode) {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+ var that = this;
+ var key = file.key;
+ this.game.sound.context.decodeAudioData(file.data, function (buffer) {
+ if(buffer) {
+ that.game.cache.decodedSound(key, buffer);
+ }
+ });
+ }
+ } else {
+ file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete);
+ this.game.cache.addSound(file.key, file.url, file.data, false, true);
+ }
+ break;
+ case 'text':
+ file.data = this._xhr.response;
+ this.game.cache.addText(file.key, file.url, file.data);
+ break;
+ }
+ if(loadNext) {
+ this.nextFile(key, true);
+ }
+ };
+ Loader.prototype.jsonLoadComplete = function (key) {
+ var data = JSON.parse(this._xhr.response);
+ var file = this._fileList[key];
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.dataLoadError = function (key) {
+ var file = this._fileList[key];
+ file.error = true;
+ throw new Error("Phaser.Loader dataLoadError: " + key);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.xmlLoadComplete = function (key) {
+ var atlasData = this._xhr.response;
+ var xml;
+ try {
+ if(window['DOMParser']) {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ } else {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ } catch (e) {
+ xml = undefined;
+ }
+ if(!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
+ throw new Error("Phaser.Loader. Invalid XML given");
+ }
+ var file = this._fileList[key];
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
+ this.nextFile(key, true);
+ };
+ Loader.prototype.nextFile = function (previousKey, success) {
+ this.progress = Math.round(this.progress + this._progressChunk);
+ if(this.progress > 100) {
+ this.progress = 100;
+ }
+ this.onFileComplete.dispatch(this.progress, previousKey, success, this._queueSize - this._keys.length, this._queueSize);
+ if(this._keys.length > 0) {
+ this.loadFile();
+ } else {
+ this.hasLoaded = true;
+ this.isLoading = false;
+ this.removeAll();
+ this.onLoadComplete.dispatch();
+ }
+ };
+ Loader.prototype.checkKeyExists = function (key) {
+ if(this._fileList[key]) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ return Loader;
+ })();
+ Phaser.Loader = Loader;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var AnimationLoader = (function () {
+ function AnimationLoader() { }
+ AnimationLoader.parseSpriteSheet = function parseSpriteSheet(game, key, frameWidth, frameHeight, frameMax) {
+ var img = game.cache.getImage(key);
+ if(img == null) {
+ return null;
+ }
+ var width = img.width;
+ var height = img.height;
+ var row = Math.round(width / frameWidth);
+ var column = Math.round(height / frameHeight);
+ var total = row * column;
+ if(frameMax !== -1) {
+ total = frameMax;
+ }
+ if(width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
+ throw new Error("AnimationLoader.parseSpriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
+ return null;
+ }
+ var data = new Phaser.FrameData();
+ var x = 0;
+ var y = 0;
+ for(var i = 0; i < total; i++) {
+ data.addFrame(new Phaser.Frame(x, y, frameWidth, frameHeight, ''));
+ x += frameWidth;
+ if(x === width) {
+ x = 0;
+ y += frameHeight;
+ }
+ }
+ return data;
+ };
+ AnimationLoader.parseJSONData = function parseJSONData(game, json) {
+ if(!json['frames']) {
+ console.log(json);
+ throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
+ }
+ var data = new Phaser.FrameData();
+ var frames = json['frames'];
+ var newFrame;
+ for(var i = 0; i < frames.length; i++) {
+ newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
+ newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
+ }
+ return data;
+ };
+ AnimationLoader.parseXMLData = function parseXMLData(game, xml, format) {
+ if(!xml.getElementsByTagName('TextureAtlas')) {
+ throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing tag");
+ }
+ var data = new Phaser.FrameData();
+ var frames = xml.getElementsByTagName('SubTexture');
+ var newFrame;
+ for(var i = 0; i < frames.length; i++) {
+ var frame = frames[i].attributes;
+ newFrame = data.addFrame(new Phaser.Frame(frame.x.nodeValue, frame.y.nodeValue, frame.width.nodeValue, frame.height.nodeValue, frame.name.nodeValue));
+ if(frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0') {
+ newFrame.setTrim(true, frame.width.nodeValue, frame.height.nodeValue, Math.abs(frame.frameX.nodeValue), Math.abs(frame.frameY.nodeValue), frame.frameWidth.nodeValue, frame.frameHeight.nodeValue);
+ }
+ }
+ return data;
+ };
+ return AnimationLoader;
+ })();
+ Phaser.AnimationLoader = AnimationLoader;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Tile = (function () {
+ function Tile(game, tilemap, index, width, height) {
+ this.mass = 1.0;
+ this.collideLeft = false;
+ this.collideRight = false;
+ this.collideUp = false;
+ this.collideDown = false;
+ this.separateX = true;
+ this.separateY = true;
+ this.game = game;
+ this.tilemap = tilemap;
+ this.index = index;
+ this.width = width;
+ this.height = height;
+ this.allowCollisions = Phaser.Types.NONE;
+ }
+ Tile.prototype.destroy = function () {
+ this.tilemap = null;
+ };
+ Tile.prototype.setCollision = function (collision, resetCollisions, separateX, separateY) {
+ if(resetCollisions) {
+ this.resetCollision();
+ }
+ this.separateX = separateX;
+ this.separateY = separateY;
+ this.allowCollisions = collision;
+ if(collision & Phaser.Types.ANY) {
+ this.collideLeft = true;
+ this.collideRight = true;
+ this.collideUp = true;
+ this.collideDown = true;
+ return;
+ }
+ if(collision & Phaser.Types.LEFT || collision & Phaser.Types.WALL) {
+ this.collideLeft = true;
+ }
+ if(collision & Phaser.Types.RIGHT || collision & Phaser.Types.WALL) {
+ this.collideRight = true;
+ }
+ if(collision & Phaser.Types.UP || collision & Phaser.Types.CEILING) {
+ this.collideUp = true;
+ }
+ if(collision & Phaser.Types.DOWN || collision & Phaser.Types.CEILING) {
+ this.collideDown = true;
+ }
+ };
+ Tile.prototype.resetCollision = function () {
+ this.allowCollisions = Phaser.Types.NONE;
+ this.collideLeft = false;
+ this.collideRight = false;
+ this.collideUp = false;
+ this.collideDown = false;
+ };
+ Tile.prototype.toString = function () {
+ return "[{Tile (index=" + this.index + " collisions=" + this.allowCollisions + " width=" + this.width + " height=" + this.height + ")}]";
+ };
+ return Tile;
+ })();
+ Phaser.Tile = Tile;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Tilemap = (function () {
+ function Tilemap(game, key, mapData, format, resizeWorld, tileWidth, tileHeight) {
+ if (typeof resizeWorld === "undefined") { resizeWorld = true; }
+ if (typeof tileWidth === "undefined") { tileWidth = 0; }
+ if (typeof tileHeight === "undefined") { tileHeight = 0; }
+ this.z = -1;
+ this.renderOrderID = 0;
+ this.collisionCallback = null;
+ this.game = game;
+ this.type = Phaser.Types.TILEMAP;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ this.tiles = [];
+ this.layers = [];
+ this.mapFormat = format;
+ switch(format) {
+ case Tilemap.FORMAT_CSV:
+ this.parseCSV(game.cache.getText(mapData), key, tileWidth, tileHeight);
+ break;
+ case Tilemap.FORMAT_TILED_JSON:
+ this.parseTiledJSON(game.cache.getText(mapData), key);
+ break;
+ }
+ if(this.currentLayer && resizeWorld) {
+ this.game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
+ }
+ }
+ Tilemap.FORMAT_CSV = 0;
+ Tilemap.FORMAT_TILED_JSON = 1;
+ Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) {
+ var layer = new Phaser.TilemapLayer(this, 0, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
+ data = data.trim();
+ var rows = data.split("\n");
+ for(var i = 0; i < rows.length; i++) {
+ var column = rows[i].split(",");
+ if(column.length > 0) {
+ layer.addColumn(column);
+ }
+ }
+ layer.updateBounds();
+ var tileQuantity = layer.parseTileOffsets();
+ this.currentLayer = layer;
+ this.collisionLayer = layer;
+ this.layers.push(layer);
+ this.generateTiles(tileQuantity);
+ };
+ Tilemap.prototype.parseTiledJSON = function (data, key) {
+ data = data.trim();
+ var json = JSON.parse(data);
+ for(var i = 0; i < json.layers.length; i++) {
+ var layer = new Phaser.TilemapLayer(this, i, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
+ if(!json.layers[i].data) {
+ continue;
+ }
+ layer.alpha = json.layers[i].opacity;
+ layer.visible = json.layers[i].visible;
+ layer.tileMargin = json.tilesets[0].margin;
+ layer.tileSpacing = json.tilesets[0].spacing;
+ var c = 0;
+ var row;
+ for(var t = 0; t < json.layers[i].data.length; t++) {
+ if(c == 0) {
+ row = [];
+ }
+ row.push(json.layers[i].data[t]);
+ c++;
+ if(c == json.layers[i].width) {
+ layer.addColumn(row);
+ c = 0;
+ }
+ }
+ layer.updateBounds();
+ var tileQuantity = layer.parseTileOffsets();
+ this.currentLayer = layer;
+ this.collisionLayer = layer;
+ this.layers.push(layer);
+ }
+ this.generateTiles(tileQuantity);
+ };
+ Tilemap.prototype.generateTiles = function (qty) {
+ for(var i = 0; i < qty; i++) {
+ this.tiles.push(new Phaser.Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
+ }
+ };
+ Object.defineProperty(Tilemap.prototype, "widthInPixels", {
+ get: function () {
+ return this.currentLayer.widthInPixels;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Tilemap.prototype, "heightInPixels", {
+ get: function () {
+ return this.currentLayer.heightInPixels;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Tilemap.prototype.setCollisionCallback = function (context, callback) {
+ this.collisionCallbackContext = context;
+ this.collisionCallback = callback;
+ };
+ Tilemap.prototype.setCollisionRange = function (start, end, collision, resetCollisions, separateX, separateY) {
+ if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
+ if (typeof resetCollisions === "undefined") { resetCollisions = false; }
+ if (typeof separateX === "undefined") { separateX = true; }
+ if (typeof separateY === "undefined") { separateY = true; }
+ for(var i = start; i < end; i++) {
+ this.tiles[i].setCollision(collision, resetCollisions, separateX, separateY);
+ }
+ };
+ Tilemap.prototype.setCollisionByIndex = function (values, collision, resetCollisions, separateX, separateY) {
+ if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
+ if (typeof resetCollisions === "undefined") { resetCollisions = false; }
+ if (typeof separateX === "undefined") { separateX = true; }
+ if (typeof separateY === "undefined") { separateY = true; }
+ for(var i = 0; i < values.length; i++) {
+ this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
+ }
+ };
+ Tilemap.prototype.getTileByIndex = function (value) {
+ if(this.tiles[value]) {
+ return this.tiles[value];
+ }
+ return null;
+ };
+ Tilemap.prototype.getTile = function (x, y, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileIndex(x, y)];
+ };
+ Tilemap.prototype.getTileFromWorldXY = function (x, y, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
+ };
+ Tilemap.prototype.getTileFromInputXY = function (layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.worldX, this.game.input.worldY)];
+ };
+ Tilemap.prototype.getTileOverlaps = function (object) {
+ return this.currentLayer.getTileOverlaps(object);
+ };
+ Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
+ if (typeof objectOrGroup === "undefined") { objectOrGroup = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof context === "undefined") { context = null; }
+ if(callback !== null && context !== null) {
+ this.collisionCallback = callback;
+ this.collisionCallbackContext = context;
+ }
+ if(objectOrGroup == null) {
+ objectOrGroup = this.game.world.group;
+ }
+ if(objectOrGroup.isGroup == false) {
+ this.collideGameObject(objectOrGroup);
+ } else {
+ objectOrGroup.forEachAlive(this, this.collideGameObject, true);
+ }
+ };
+ Tilemap.prototype.collideGameObject = function (object) {
+ if(object.body.type == Phaser.Types.BODY_DYNAMIC && object.exists == true && object.body.allowCollisions != Phaser.Types.NONE) {
+ this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
+ if(this.collisionCallback !== null && this._tempCollisionData.length > 0) {
+ this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ };
+ Tilemap.prototype.putTile = function (x, y, index, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer.ID; }
+ this.layers[layer].putTile(x, y, index);
+ };
+ Tilemap.prototype.destroy = function () {
+ this.texture = null;
+ this.transform = null;
+ this.tiles.length = 0;
+ this.layers.length = 0;
+ };
+ return Tilemap;
+ })();
+ Phaser.Tilemap = Tilemap;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var TilemapLayer = (function () {
+ function TilemapLayer(parent, id, key, mapFormat, name, tileWidth, tileHeight) {
+ this.exists = true;
+ this.visible = true;
+ this.widthInTiles = 0;
+ this.heightInTiles = 0;
+ this.widthInPixels = 0;
+ this.heightInPixels = 0;
+ this.tileMargin = 0;
+ this.tileSpacing = 0;
+ this.parent = parent;
+ this.game = parent.game;
+ this.ID = id;
+ this.name = name;
+ this.mapFormat = mapFormat;
+ this.tileWidth = tileWidth;
+ this.tileHeight = tileHeight;
+ this.boundsInTiles = new Phaser.Rectangle();
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ if(key !== null) {
+ this.texture.loadImage(key, false);
+ } else {
+ this.texture.opaque = true;
+ }
+ this.alpha = this.texture.alpha;
+ this.mapData = [];
+ this._tempTileBlock = [];
+ }
+ TilemapLayer.prototype.putTileWorldXY = function (x, y, index) {
+ 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;
+ }
+ }
+ };
+ TilemapLayer.prototype.putTile = function (x, y, index) {
+ if(y >= 0 && y < this.mapData.length) {
+ if(x >= 0 && x < this.mapData[y].length) {
+ this.mapData[y][x] = index;
+ }
+ }
+ };
+ TilemapLayer.prototype.swapTile = function (tileA, tileB, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ if (typeof height === "undefined") { height = this.heightInTiles; }
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ if(this._tempTileBlock[r].tile.index == tileA) {
+ this._tempTileBlock[r].newIndex = true;
+ }
+ if(this._tempTileBlock[r].tile.index == tileB) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileA;
+ }
+ }
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ if(this._tempTileBlock[r].newIndex == true) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
+ }
+ }
+ };
+ TilemapLayer.prototype.fillTile = function (index, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ 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] = index;
+ }
+ };
+ TilemapLayer.prototype.randomiseTiles = function (tiles, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ 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);
+ }
+ };
+ TilemapLayer.prototype.replaceTile = function (tileA, tileB, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = this.widthInTiles; }
+ if (typeof height === "undefined") { height = this.heightInTiles; }
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ if(this._tempTileBlock[r].tile.index == tileA) {
+ this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
+ }
+ }
+ };
+ TilemapLayer.prototype.getTileBlock = function (x, y, width, height) {
+ var output = [];
+ this.getTempBlock(x, y, width, height);
+ for(var r = 0; r < this._tempTileBlock.length; r++) {
+ output.push({
+ x: this._tempTileBlock[r].x,
+ y: this._tempTileBlock[r].y,
+ tile: this._tempTileBlock[r].tile
+ });
+ }
+ return output;
+ };
+ TilemapLayer.prototype.getTileFromWorldXY = function (x, y) {
+ 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 = function (object) {
+ if(object.body.bounds.x < 0 || object.body.bounds.x > this.widthInPixels || object.body.bounds.y < 0 || object.body.bounds.bottom > this.heightInPixels) {
+ return;
+ }
+ 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._tempBlockResults = [];
+ this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
+ return this._tempBlockResults;
+ };
+ TilemapLayer.prototype.getTempBlock = function (x, y, width, height, collisionOnly) {
+ if (typeof collisionOnly === "undefined") { collisionOnly = false; }
+ if(x < 0) {
+ x = 0;
+ }
+ if(y < 0) {
+ y = 0;
+ }
+ if(width > this.widthInTiles) {
+ width = this.widthInTiles;
+ }
+ if(height > this.heightInTiles) {
+ height = this.heightInTiles;
+ }
+ this._tempTileBlock = [];
+ for(var ty = y; ty < y + height; ty++) {
+ for(var tx = x; tx < x + width; tx++) {
+ if(collisionOnly) {
+ 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]]
+ });
+ }
+ } else {
+ if(this.mapData[ty] && this.mapData[ty][tx]) {
+ this._tempTileBlock.push({
+ x: tx,
+ y: ty,
+ tile: this.parent.tiles[this.mapData[ty][tx]]
+ });
+ }
+ }
+ }
+ }
+ };
+ TilemapLayer.prototype.getTileIndex = function (x, y) {
+ if(y >= 0 && y < this.mapData.length) {
+ if(x >= 0 && x < this.mapData[y].length) {
+ return this.mapData[y][x];
+ }
+ }
+ return null;
+ };
+ TilemapLayer.prototype.addColumn = function (column) {
+ var data = [];
+ for(var c = 0; c < column.length; c++) {
+ data[c] = parseInt(column[c]);
+ }
+ if(this.widthInTiles == 0) {
+ this.widthInTiles = data.length;
+ this.widthInPixels = this.widthInTiles * this.tileWidth;
+ }
+ this.mapData.push(data);
+ this.heightInTiles++;
+ this.heightInPixels += this.tileHeight;
+ };
+ TilemapLayer.prototype.updateBounds = function () {
+ this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
+ };
+ TilemapLayer.prototype.parseTileOffsets = function () {
+ this.tileOffsets = [];
+ var i = 0;
+ if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) {
+ 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] = {
+ x: tx,
+ y: ty
+ };
+ i++;
+ }
+ }
+ return this.tileOffsets.length;
+ };
+ return TilemapLayer;
+ })();
+ Phaser.TilemapLayer = TilemapLayer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var PhysicsManager = (function () {
+ function PhysicsManager(game) {
+ this._length = 0;
+ this.grav = 0.2;
+ this.drag = 1;
+ this.bounce = 0.3;
+ this.friction = 0.05;
+ this.min_f = 0;
+ this.max_f = 1;
+ this.min_b = 0;
+ this.max_b = 1;
+ this.min_g = 0;
+ this.max_g = 1;
+ this.xmin = 0;
+ this.xmax = 800;
+ this.ymin = 0;
+ this.ymax = 600;
+ this.objrad = 24;
+ this.tilerad = 24 * 2;
+ this.objspeed = 0.2;
+ this.maxspeed = 20;
+ this.game = game;
+ }
+ PhysicsManager.prototype.update = function () {
+ };
+ PhysicsManager.prototype.updateMotion = function (body) {
+ this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
+ body.angularVelocity += this._velocityDelta;
+ body.sprite.transform.rotation += body.angularVelocity * this.game.time.physicsElapsed;
+ body.angularVelocity += this._velocityDelta;
+ this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
+ body.velocity.x += this._velocityDelta;
+ this._delta = body.velocity.x * this.game.time.physicsElapsed;
+ body.aabb.pos.x += this._delta;
+ body.deltaX = this._delta;
+ this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
+ body.velocity.y += this._velocityDelta;
+ this._delta = body.velocity.y * this.game.time.physicsElapsed;
+ body.aabb.pos.y += this._delta;
+ body.deltaY = this._delta;
+ body.aabb.integrateVerlet();
+ };
+ PhysicsManager.prototype.computeVelocity = function (velocity, gravity, acceleration, drag, max) {
+ if (typeof gravity === "undefined") { gravity = 0; }
+ if (typeof acceleration === "undefined") { acceleration = 0; }
+ if (typeof drag === "undefined") { drag = 0; }
+ if (typeof max === "undefined") { max = 10000; }
+ if(acceleration !== 0) {
+ velocity += (acceleration + gravity) * this.game.time.elapsed;
+ } else if(drag !== 0) {
+ this._drag = drag * this.game.time.elapsed;
+ if(velocity - this._drag > 0) {
+ velocity = velocity - this._drag;
+ } else if(velocity + this._drag < 0) {
+ velocity += this._drag;
+ } else {
+ velocity = 0;
+ }
+ velocity += gravity;
+ }
+ if((velocity != 0) && (max != 10000)) {
+ if(velocity > max) {
+ velocity = max;
+ } else if(velocity < -max) {
+ velocity = -max;
+ }
+ }
+ return velocity;
+ };
+ return PhysicsManager;
+ })();
+ Physics.PhysicsManager = PhysicsManager;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var Body = (function () {
+ function Body(sprite, type) {
+ this.angularVelocity = 0;
+ this.angularAcceleration = 0;
+ this.angularDrag = 0;
+ this.maxAngular = 10000;
+ this.deltaX = 0;
+ this.deltaY = 0;
+ this.sprite = sprite;
+ this.game = sprite.game;
+ this.type = type;
+ this.aabb = new Phaser.Physics.AABB(sprite.game, sprite.x, sprite.y, sprite.width, sprite.height);
+ this.velocity = new Phaser.Vec2();
+ this.acceleration = new Phaser.Vec2();
+ this.drag = new Phaser.Vec2();
+ this.gravity = new Phaser.Vec2();
+ this.maxVelocity = new Phaser.Vec2(10000, 10000);
+ this.angularVelocity = 0;
+ this.angularAcceleration = 0;
+ this.angularDrag = 0;
+ this.maxAngular = 10000;
+ this.allowCollisions = Phaser.Types.ANY;
+ }
+ return Body;
+ })();
+ Physics.Body = Body;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var AABB = (function () {
+ function AABB(game, x, y, width, height) {
+ this.type = 0;
+ this.game = game;
+ this.pos = new Phaser.Vec2(x, y);
+ this.oldpos = new Phaser.Vec2(x, y);
+ this.width = Math.abs(width);
+ this.height = Math.abs(height);
+ this.aabbTileProjections = {
+ };
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.AABB22Deg.CollideS;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.AABB22Deg.CollideB;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.AABB45Deg.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.AABB67Deg.CollideS;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.AABB67Deg.CollideB;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.AABBConcave.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.AABBConvex.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.AABBFull.Collide;
+ this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.AABBHalf.Collide;
+ }
+ AABB.COL_NONE = 0;
+ AABB.COL_AXIS = 1;
+ AABB.COL_OTHER = 2;
+ AABB.prototype.integrateVerlet = function () {
+ var d = 0;
+ var g = 0;
+ var px = this.pos.x;
+ var py = this.pos.y;
+ var ox = this.oldpos.x;
+ var oy = this.oldpos.y;
+ this.oldpos.x = this.pos.x;
+ this.oldpos.y = this.pos.y;
+ this.pos.x += (d * px) - (d * ox);
+ this.pos.y += (d * py) - (d * oy) + g;
+ };
+ AABB.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ var vx = this.pos.x - this.oldpos.x;
+ var vy = this.pos.y - this.oldpos.y;
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = vx - nx;
+ var ty = vy - ny;
+ this.pos.x += px;
+ this.pos.y += py;
+ this.oldpos.x += px;
+ this.oldpos.y += py;
+ if(dp < 0) {
+ var b = 1 + 0.5;
+ var f = 0.05;
+ var fx = tx * f;
+ var fy = ty * f;
+ this.oldpos.x += (nx * b) + fx;
+ this.oldpos.y += (ny * b) + fy;
+ }
+ };
+ AABB.prototype.collideAABBVsTile = function (tile) {
+ var pos = this.pos;
+ var c = tile;
+ var tx = c.pos.x;
+ var ty = c.pos.y;
+ var txw = c.xw;
+ var tyw = c.yw;
+ var dx = pos.x - tx;
+ var px = (txw + this.width) - Math.abs(dx);
+ if(0 < px) {
+ var dy = pos.y - ty;
+ var py = (tyw + this.height) - Math.abs(dy);
+ if(0 < py) {
+ if(px < py) {
+ if(dx < 0) {
+ px *= -1;
+ py = 0;
+ } else {
+ py = 0;
+ }
+ } else {
+ if(dy < 0) {
+ px = 0;
+ py *= -1;
+ } else {
+ px = 0;
+ }
+ }
+ this.resolveBoxTile(px, py, this, c);
+ }
+ }
+ };
+ AABB.prototype.collideAABBVsWorldBounds = function () {
+ var p = this.pos;
+ var xw = this.width;
+ var yw = this.height;
+ var XMIN = 0;
+ var XMAX = 800;
+ var YMIN = 0;
+ var YMAX = 600;
+ var dx = XMIN - (p.x - xw);
+ if(0 < dx) {
+ this.reportCollisionVsWorld(dx, 0, 1, 0, null);
+ } else {
+ dx = (p.x + xw) - XMAX;
+ if(0 < dx) {
+ this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ var dy = YMIN - (p.y - yw);
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, dy, 0, 1, null);
+ } else {
+ dy = (p.y + yw) - YMAX;
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ AABB.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.strokeRect(this.pos.x - this.width, this.pos.y - this.height, this.width * 2, this.height * 2);
+ context.stroke();
+ context.closePath();
+ context.fillStyle = 'rgb(0,255,0)';
+ context.fillRect(this.pos.x, this.pos.y, 2, 2);
+ };
+ AABB.prototype.resolveBoxTile = function (x, y, box, t) {
+ if(0 < t.ID) {
+ return this.aabbTileProjections[t.CTYPE](x, y, box, t);
+ } else {
+ return false;
+ }
+ };
+ return AABB;
+ })();
+ Physics.AABB = AABB;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var Circle = (function () {
+ function Circle(game, x, y, radius) {
+ this.type = 1;
+ this.game = game;
+ this.pos = new Phaser.Vec2(x, y);
+ this.oldpos = new Phaser.Vec2(x, y);
+ this.radius = radius;
+ this.circleTileProjections = {
+ };
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.Circle22Deg.CollideS;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.Circle22Deg.CollideB;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.Circle45Deg.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.Circle67Deg.CollideS;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.Circle67Deg.CollideB;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.CircleConcave.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.CircleConvex.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.CircleFull.Collide;
+ this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.CircleHalf.Collide;
+ }
+ Circle.COL_NONE = 0;
+ Circle.COL_AXIS = 1;
+ Circle.COL_OTHER = 2;
+ Circle.prototype.integrateVerlet = function () {
+ var d = 1;
+ var g = 0.2;
+ var p = this.pos;
+ var o = this.oldpos;
+ var px;
+ var py;
+ var ox = o.x;
+ var oy = o.y;
+ o.x = px = p.x;
+ o.y = py = p.y;
+ p.x += (d * px) - (d * ox);
+ p.y += (d * py) - (d * oy) + g;
+ };
+ Circle.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
+ if (typeof obj === "undefined") { obj = null; }
+ var p = this.pos;
+ var o = this.oldpos;
+ var vx = p.x - o.x;
+ var vy = p.y - o.y;
+ var dp = (vx * dx + vy * dy);
+ var nx = dp * dx;
+ var ny = dp * dy;
+ var tx = vx - nx;
+ var ty = vy - ny;
+ var b, bx, by, f, fx, fy;
+ if(dp < 0) {
+ f = 0.05;
+ fx = tx * f;
+ fy = ty * f;
+ b = 1 + 0.3;
+ bx = (nx * b);
+ by = (ny * b);
+ } else {
+ bx = by = fx = fy = 0;
+ }
+ p.x += px;
+ p.y += py;
+ o.x += px + bx + fx;
+ o.y += py + by + fy;
+ };
+ Circle.prototype.collideCircleVsWorldBounds = function () {
+ var p = this.pos;
+ var r = this.radius;
+ var XMIN = 0;
+ var XMAX = 800;
+ var YMIN = 0;
+ var YMAX = 600;
+ var dx = XMIN - (p.x - r);
+ if(0 < dx) {
+ this.reportCollisionVsWorld(dx, 0, 1, 0, null);
+ } else {
+ dx = (p.x + r) - XMAX;
+ if(0 < dx) {
+ this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
+ }
+ }
+ var dy = YMIN - (p.y - r);
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, dy, 0, 1, null);
+ } else {
+ dy = (p.y + r) - YMAX;
+ if(0 < dy) {
+ this.reportCollisionVsWorld(0, -dy, 0, -1, null);
+ }
+ }
+ };
+ Circle.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(0,255,0)';
+ context.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2);
+ context.stroke();
+ context.closePath();
+ if(this.oH == 1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x - this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ } else if(this.oH == -1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x + this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ }
+ if(this.oV == 1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y - this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y - this.radius);
+ context.stroke();
+ context.closePath();
+ } else if(this.oV == -1) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,0,0)';
+ context.moveTo(this.pos.x - this.radius, this.pos.y + this.radius);
+ context.lineTo(this.pos.x + this.radius, this.pos.y + this.radius);
+ context.stroke();
+ context.closePath();
+ }
+ };
+ Circle.prototype.collideCircleVsTile = function (tile) {
+ var pos = this.pos;
+ var r = this.radius;
+ var c = tile;
+ var tx = c.pos.x;
+ var ty = c.pos.y;
+ var txw = c.xw;
+ var tyw = c.yw;
+ var dx = pos.x - tx;
+ var px = (txw + r) - Math.abs(dx);
+ if(0 < px) {
+ var dy = pos.y - ty;
+ var py = (tyw + r) - Math.abs(dy);
+ if(0 < py) {
+ this.oH = 0;
+ this.oV = 0;
+ if(dx < -txw) {
+ this.oH = -1;
+ } else if(txw < dx) {
+ this.oH = 1;
+ }
+ if(dy < -tyw) {
+ this.oV = -1;
+ } else if(tyw < dy) {
+ this.oV = 1;
+ }
+ this.resolveCircleTile(px, py, this.oH, this.oV, this, c);
+ }
+ }
+ };
+ Circle.prototype.resolveCircleTile = function (x, y, oH, oV, obj, t) {
+ if(0 < t.ID) {
+ return this.circleTileProjections[t.CTYPE](x, y, oH, oV, obj, t);
+ } else {
+ console.log("resolveCircleTile() was called with an empty (or unknown) tile!: ID=" + t.ID + " (" + t.i + "," + t.j + ")");
+ return false;
+ }
+ };
+ return Circle;
+ })();
+ Physics.Circle = Circle;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ var TileMapCell = (function () {
+ function TileMapCell(game, x, y, xw, yw) {
+ this.game = game;
+ this.ID = TileMapCell.TID_EMPTY;
+ this.CTYPE = TileMapCell.CTYPE_EMPTY;
+ this.pos = new Phaser.Vec2(x, y);
+ this.xw = xw;
+ this.yw = yw;
+ this.minx = this.pos.x - this.xw;
+ this.maxx = this.pos.x + this.xw;
+ this.miny = this.pos.y - this.yw;
+ this.maxy = this.pos.y + this.yw;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ }
+ TileMapCell.TID_EMPTY = 0;
+ TileMapCell.TID_FULL = 1;
+ TileMapCell.TID_45DEGpn = 2;
+ TileMapCell.TID_45DEGnn = 3;
+ TileMapCell.TID_45DEGnp = 4;
+ TileMapCell.TID_45DEGpp = 5;
+ TileMapCell.TID_CONCAVEpn = 6;
+ TileMapCell.TID_CONCAVEnn = 7;
+ TileMapCell.TID_CONCAVEnp = 8;
+ TileMapCell.TID_CONCAVEpp = 9;
+ TileMapCell.TID_CONVEXpn = 10;
+ TileMapCell.TID_CONVEXnn = 11;
+ TileMapCell.TID_CONVEXnp = 12;
+ TileMapCell.TID_CONVEXpp = 13;
+ TileMapCell.TID_22DEGpnS = 14;
+ TileMapCell.TID_22DEGnnS = 15;
+ TileMapCell.TID_22DEGnpS = 16;
+ TileMapCell.TID_22DEGppS = 17;
+ TileMapCell.TID_22DEGpnB = 18;
+ TileMapCell.TID_22DEGnnB = 19;
+ TileMapCell.TID_22DEGnpB = 20;
+ TileMapCell.TID_22DEGppB = 21;
+ TileMapCell.TID_67DEGpnS = 22;
+ TileMapCell.TID_67DEGnnS = 23;
+ TileMapCell.TID_67DEGnpS = 24;
+ TileMapCell.TID_67DEGppS = 25;
+ TileMapCell.TID_67DEGpnB = 26;
+ TileMapCell.TID_67DEGnnB = 27;
+ TileMapCell.TID_67DEGnpB = 28;
+ TileMapCell.TID_67DEGppB = 29;
+ TileMapCell.TID_HALFd = 30;
+ TileMapCell.TID_HALFr = 31;
+ TileMapCell.TID_HALFu = 32;
+ TileMapCell.TID_HALFl = 33;
+ TileMapCell.CTYPE_EMPTY = 0;
+ TileMapCell.CTYPE_FULL = 1;
+ TileMapCell.CTYPE_45DEG = 2;
+ TileMapCell.CTYPE_CONCAVE = 6;
+ TileMapCell.CTYPE_CONVEX = 10;
+ TileMapCell.CTYPE_22DEGs = 14;
+ TileMapCell.CTYPE_22DEGb = 18;
+ TileMapCell.CTYPE_67DEGs = 22;
+ TileMapCell.CTYPE_67DEGb = 26;
+ TileMapCell.CTYPE_HALF = 30;
+ TileMapCell.prototype.SetState = function (ID) {
+ if(ID == TileMapCell.TID_EMPTY) {
+ this.Clear();
+ } else {
+ this.ID = ID;
+ this.UpdateType();
+ }
+ return this;
+ };
+ TileMapCell.prototype.Clear = function () {
+ this.ID = TileMapCell.TID_EMPTY;
+ this.UpdateType();
+ };
+ TileMapCell.prototype.render = function (context) {
+ context.beginPath();
+ context.strokeStyle = 'rgb(255,255,0)';
+ context.strokeRect(this.minx, this.miny, this.xw * 2, this.yw * 2);
+ context.strokeRect(this.pos.x, this.pos.y, 2, 2);
+ context.closePath();
+ };
+ TileMapCell.prototype.UpdateType = function () {
+ if(0 < this.ID) {
+ if(this.ID < TileMapCell.CTYPE_45DEG) {
+ this.CTYPE = TileMapCell.CTYPE_FULL;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID < TileMapCell.CTYPE_CONCAVE) {
+ this.CTYPE = TileMapCell.CTYPE_45DEG;
+ if(this.ID == TileMapCell.TID_45DEGpn) {
+ console.log('set tile as 45deg pn');
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else if(this.ID == TileMapCell.TID_45DEGnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else if(this.ID == TileMapCell.TID_45DEGnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else if(this.ID == TileMapCell.TID_45DEGpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = this.signx / Math.SQRT2;
+ this.sy = this.signy / Math.SQRT2;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_CONVEX) {
+ this.CTYPE = TileMapCell.CTYPE_CONCAVE;
+ if(this.ID == TileMapCell.TID_CONCAVEpn) {
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONCAVEpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_22DEGs) {
+ this.CTYPE = TileMapCell.CTYPE_CONVEX;
+ if(this.ID == TileMapCell.TID_CONVEXpn) {
+ this.signx = 1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXnn) {
+ this.signx = -1;
+ this.signy = -1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXnp) {
+ this.signx = -1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else if(this.ID == TileMapCell.TID_CONVEXpp) {
+ this.signx = 1;
+ this.signy = 1;
+ this.sx = 0;
+ this.sy = 0;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_22DEGb) {
+ this.CTYPE = TileMapCell.CTYPE_22DEGs;
+ if(this.ID == TileMapCell.TID_22DEGpnS) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnnS) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnpS) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGppS) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_67DEGs) {
+ this.CTYPE = TileMapCell.CTYPE_22DEGb;
+ if(this.ID == TileMapCell.TID_22DEGpnB) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnnB) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGnpB) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else if(this.ID == TileMapCell.TID_22DEGppB) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 1) / slen;
+ this.sy = (this.signy * 2) / slen;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_67DEGb) {
+ this.CTYPE = TileMapCell.CTYPE_67DEGs;
+ if(this.ID == TileMapCell.TID_67DEGpnS) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnnS) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnpS) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGppS) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else {
+ return false;
+ }
+ } else if(this.ID < TileMapCell.CTYPE_HALF) {
+ this.CTYPE = TileMapCell.CTYPE_67DEGb;
+ if(this.ID == TileMapCell.TID_67DEGpnB) {
+ this.signx = 1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnnB) {
+ this.signx = -1;
+ this.signy = -1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGnpB) {
+ this.signx = -1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else if(this.ID == TileMapCell.TID_67DEGppB) {
+ this.signx = 1;
+ this.signy = 1;
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ this.sx = (this.signx * 2) / slen;
+ this.sy = (this.signy * 1) / slen;
+ } else {
+ return false;
+ }
+ } else {
+ this.CTYPE = TileMapCell.CTYPE_HALF;
+ if(this.ID == TileMapCell.TID_HALFd) {
+ this.signx = 0;
+ this.signy = -1;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFu) {
+ this.signx = 0;
+ this.signy = 1;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFl) {
+ this.signx = 1;
+ this.signy = 0;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else if(this.ID == TileMapCell.TID_HALFr) {
+ this.signx = -1;
+ this.signy = 0;
+ this.sx = this.signx;
+ this.sy = this.signy;
+ } else {
+ return false;
+ }
+ }
+ } else {
+ this.CTYPE = TileMapCell.CTYPE_EMPTY;
+ this.signx = 0;
+ this.signy = 0;
+ this.sx = 0;
+ this.sy = 0;
+ }
+ };
+ return TileMapCell;
+ })();
+ Physics.TileMapCell = TileMapCell;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABB22Deg = (function () {
+ function AABB22Deg() { }
+ AABB22Deg.CollideS = function CollideS(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var py = obj.pos.y - (signy * obj.height);
+ var penY = t.pos.y - py;
+ if(0 < (penY * signy)) {
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ var aY = Math.abs(penY);
+ if(lenP < lenN) {
+ if(aY < lenP) {
+ obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ }
+ } else {
+ if(aY < lenN) {
+ obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ AABB22Deg.CollideB = function CollideB(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB22Deg;
+ })();
+ Projection.AABB22Deg = AABB22Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABB45Deg = (function () {
+ function AABB45Deg() { }
+ AABB45Deg.Collide = function Collide(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - t.pos.x;
+ var oy = (obj.pos.y - (signy * obj.height)) - t.pos.y;
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB45Deg;
+ })();
+ Projection.AABB45Deg = AABB45Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABB67Deg = (function () {
+ function AABB67Deg() { }
+ AABB67Deg.CollideS = function CollideS(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var px = obj.pos.x - (signx * obj.width);
+ var penX = t.pos.x - px;
+ if(0 < (penX * signx)) {
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y + (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ var aX = Math.abs(penX);
+ if(lenP < lenN) {
+ if(aX < lenP) {
+ obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ }
+ } else {
+ if(aX < lenN) {
+ obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ AABB67Deg.CollideB = function CollideB(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
+ var sx = t.sx;
+ var sy = t.sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABB67Deg;
+ })();
+ Projection.AABB67Deg = AABB67Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBConcave = (function () {
+ function AABBConcave() { }
+ AABBConcave.Collide = function Collide(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (t.pos.x + (signx * t.xw)) - (obj.pos.x - (signx * obj.width));
+ var oy = (t.pos.y + (signy * t.yw)) - (obj.pos.y - (signy * obj.height));
+ var twid = t.xw * 2;
+ var rad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = len - rad;
+ if(0 < pen) {
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBConcave;
+ })();
+ Projection.AABBConcave = AABBConcave;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBConvex = (function () {
+ function AABBConvex() { }
+ AABBConvex.Collide = function Collide(x, y, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var ox = (obj.pos.x - (signx * obj.width)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (signy * obj.height)) - (t.pos.y - (signy * t.yw));
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var twid = t.xw * 2;
+ var rad = Math.sqrt(twid * twid + 0);
+ var pen = rad - len;
+ if(((signx * ox) < 0) || ((signy * oy) < 0)) {
+ var lenP = Math.sqrt(x * x + y * y);
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBConvex;
+ })();
+ Projection.AABBConvex = AABBConvex;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBFull = (function () {
+ function AABBFull() { }
+ AABBFull.Collide = function Collide(x, y, obj, t) {
+ var l = Math.sqrt(x * x + y * y);
+ obj.reportCollisionVsWorld(x, y, x / l, y / l, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ };
+ return AABBFull;
+ })();
+ Projection.AABBFull = AABBFull;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var AABBHalf = (function () {
+ function AABBHalf() { }
+ AABBHalf.Collide = function Collide(x, y, obj, t) {
+ var sx = t.signx;
+ var sy = t.signy;
+ var ox = (obj.pos.x - (sx * obj.width)) - t.pos.x;
+ var oy = (obj.pos.y - (sy * obj.height)) - t.pos.y;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.AABB.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy, t);
+ return Phaser.Physics.AABB.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.AABB.COL_NONE;
+ };
+ return AABBHalf;
+ })();
+ Projection.AABBHalf = AABBHalf;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var Circle22Deg = (function () {
+ function Circle22Deg() { }
+ Circle22Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ if(0 < (signy * oV)) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ var sx = t.sx;
+ var sy = t.sy;
+ var r = obj.radius;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - t.pos.y;
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = r - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ ox -= r * sx;
+ oy -= r * sy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP;
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ var vx = t.pos.x - (signx * t.xw);
+ var vy = t.pos.y;
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ if((dy * signy) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x + (oH * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ Circle22Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(oH == 0) {
+ if(oV == 0) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP;
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y + (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - (t.pos.x + (signx * t.xw));
+ var oy = obj.pos.y - t.pos.y;
+ if((oy * signy) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ sx = (signx * 1) / slen;
+ sy = (signy * 2) / slen;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x - (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y + (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle22Deg;
+ })();
+ Projection.Circle22Deg = Circle22Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var Circle45Deg = (function () {
+ function Circle45Deg() { }
+ Circle45Deg.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = (obj.pos.x - (sx * obj.radius)) - t.pos.x;
+ var oy = (obj.pos.y - (sy * obj.radius)) - t.pos.y;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y + (oV * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var sx = t.sx;
+ var sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x + (oH * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle45Deg;
+ })();
+ Projection.Circle45Deg = Circle45Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var Circle67Deg = (function () {
+ function Circle67Deg() { }
+ Circle67Deg.CollideS = function CollideS(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(0 < (signx * oH)) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = obj.pos.x - t.pos.x;
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = r - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ ox -= r * sx;
+ oy -= r * sy;
+ var dp = (ox * sx) + (oy * sy);
+ var lenP;
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ var vx = t.pos.x;
+ var vy = t.pos.y - (signy * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ if((dx * signx) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y + (oV * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ Circle67Deg.CollideB = function CollideB(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var sx;
+ var sy;
+ if(oH == 0) {
+ if(oV == 0) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ var lenP;
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - t.pos.x;
+ var oy = obj.pos.y - (t.pos.y + (signy * t.yw));
+ if((ox * signx) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ sx = t.sx;
+ sy = t.sy;
+ var perp = (ox * -sy) + (oy * sx);
+ if(0 < (perp * signx * signy)) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, sx, sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var slen = Math.sqrt(2 * 2 + 1 * 1);
+ var sx = (signx * 2) / slen;
+ var sy = (signy * 1) / slen;
+ var ox = obj.pos.x - (t.pos.x + (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var perp = (ox * -sy) + (oy * sx);
+ if((perp * signx * signy) < 0) {
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var dp = (ox * sx) + (oy * sy);
+ var pen = obj.radius - Math.abs(dp);
+ if(0 < pen) {
+ obj.reportCollisionVsWorld(sx * pen, sy * pen, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ sx = t.sx;
+ sy = t.sy;
+ var r = obj.radius;
+ var ox = (obj.pos.x - (sx * r)) - (t.pos.x + (signx * t.xw));
+ var oy = (obj.pos.y - (sy * r)) - (t.pos.y - (signy * t.yw));
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ obj.reportCollisionVsWorld(-sx * dp, -sy * dp, t.sx, t.sy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return Circle67Deg;
+ })();
+ Projection.Circle67Deg = Circle67Deg;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleConcave = (function () {
+ function CircleConcave() { }
+ CircleConcave.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ var ox = (t.pos.x + (signx * t.xw)) - obj.pos.x;
+ var oy = (t.pos.y + (signy * t.yw)) - obj.pos.y;
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (len + obj.radius) - trad;
+ if(0 < pen) {
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ return Phaser.Physics.Circle.COL_NONE;
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x - (signx * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = 0;
+ dy = oV;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y - (signy * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH;
+ dy = 0;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleConcave;
+ })();
+ Projection.CircleConcave = CircleConcave;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleConvex = (function () {
+ function CircleConvex() { }
+ CircleConvex.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var lenP;
+ if(oH == 0) {
+ if(oV == 0) {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ if(x < y) {
+ lenP = x;
+ y = 0;
+ if((obj.pos.x - t.pos.x) < 0) {
+ x *= -1;
+ }
+ } else {
+ lenP = y;
+ x = 0;
+ if((obj.pos.y - t.pos.y) < 0) {
+ y *= -1;
+ }
+ }
+ if(lenP < pen) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if((signy * oV) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ } else if(oV == 0) {
+ if((signx * oH) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if(0 < ((signx * oH) + (signy * oV))) {
+ var ox = obj.pos.x - (t.pos.x - (signx * t.xw));
+ var oy = obj.pos.y - (t.pos.y - (signy * t.yw));
+ var twid = t.xw * 2;
+ var trad = Math.sqrt(twid * twid + 0);
+ var len = Math.sqrt(ox * ox + oy * oy);
+ var pen = (trad + obj.radius) - len;
+ if(0 < pen) {
+ ox /= len;
+ oy /= len;
+ obj.reportCollisionVsWorld(ox * pen, oy * pen, ox, oy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleConvex;
+ })();
+ Projection.CircleConvex = CircleConvex;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleFull = (function () {
+ function CircleFull() { }
+ CircleFull.Collide = function Collide(x, y, oH, oV, obj, t) {
+ if(oH == 0) {
+ if(oV == 0) {
+ if(x < y) {
+ var dx = obj.pos.x - t.pos.x;
+ if(dx < 0) {
+ obj.reportCollisionVsWorld(-x, 0, -1, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(x, 0, 1, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else {
+ var dy = obj.pos.y - t.pos.y;
+ if(dy < 0) {
+ obj.reportCollisionVsWorld(0, -y, 0, -1, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(0, y, 0, 1, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else if(oV == 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleFull;
+ })();
+ Projection.CircleFull = CircleFull;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Physics) {
+ (function (Projection) {
+ var CircleHalf = (function () {
+ function CircleHalf() { }
+ CircleHalf.Collide = function Collide(x, y, oH, oV, obj, t) {
+ var signx = t.signx;
+ var signy = t.signy;
+ var celldp = (oH * signx + oV * signy);
+ if(0 < celldp) {
+ return Phaser.Physics.Circle.COL_NONE;
+ } else if(oH == 0) {
+ if(oV == 0) {
+ var r = obj.radius;
+ var ox = (obj.pos.x - (signx * r)) - t.pos.x;
+ var oy = (obj.pos.y - (signy * r)) - t.pos.y;
+ var sx = signx;
+ var sy = signy;
+ var dp = (ox * sx) + (oy * sy);
+ if(dp < 0) {
+ sx *= -dp;
+ sy *= -dp;
+ var lenN = Math.sqrt(sx * sx + sy * sy);
+ var lenP = Math.sqrt(x * x + y * y);
+ if(lenP < lenN) {
+ obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ obj.reportCollisionVsWorld(sx, sy, t.signx, t.signy);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ if(celldp == 0) {
+ var r = obj.radius;
+ var dx = obj.pos.x - t.pos.x;
+ if((dx * signx) < 0) {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var dy = obj.pos.y - (t.pos.y + oV * t.yw);
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = signx / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(0, y * oV, 0, oV, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ }
+ } else if(oV == 0) {
+ if(celldp == 0) {
+ var r = obj.radius;
+ var dy = obj.pos.y - t.pos.y;
+ if((dy * signy) < 0) {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ } else {
+ var dx = obj.pos.x - (t.pos.x + oH * t.xw);
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = signx / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ } else {
+ obj.reportCollisionVsWorld(x * oH, 0, oH, 0, t);
+ return Phaser.Physics.Circle.COL_AXIS;
+ }
+ } else {
+ var vx = t.pos.x + (oH * t.xw);
+ var vy = t.pos.y + (oV * t.yw);
+ var dx = obj.pos.x - vx;
+ var dy = obj.pos.y - vy;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var pen = obj.radius - len;
+ if(0 < pen) {
+ if(len == 0) {
+ dx = oH / Math.SQRT2;
+ dy = oV / Math.SQRT2;
+ } else {
+ dx /= len;
+ dy /= len;
+ }
+ obj.reportCollisionVsWorld(dx * pen, dy * pen, dx, dy, t);
+ return Phaser.Physics.Circle.COL_OTHER;
+ }
+ }
+ return Phaser.Physics.Circle.COL_NONE;
+ };
+ return CircleHalf;
+ })();
+ Projection.CircleHalf = CircleHalf;
+ })(Physics.Projection || (Physics.Projection = {}));
+ var Projection = Physics.Projection;
+ })(Phaser.Physics || (Phaser.Physics = {}));
+ var Physics = Phaser.Physics;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var Events = (function () {
+ function Events(parent) {
+ this.game = parent.game;
+ this._parent = parent;
+ this.onAddedToGroup = new Phaser.Signal();
+ this.onRemovedFromGroup = new Phaser.Signal();
+ this.onKilled = new Phaser.Signal();
+ this.onRevived = new Phaser.Signal();
+ this.onOutOfBounds = new Phaser.Signal();
+ }
+ return Events;
+ })();
+ Components.Events = Events;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Sprite = (function () {
+ function Sprite(game, x, y, key, frame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof frame === "undefined") { frame = null; }
+ this.modified = false;
+ this.x = 0;
+ this.y = 0;
+ this.z = -1;
+ this.renderOrderID = 0;
+ this.game = game;
+ this.type = Phaser.Types.SPRITE;
+ this.exists = true;
+ this.active = true;
+ this.visible = true;
+ this.alive = true;
+ this.x = x;
+ this.y = y;
+ this.z = -1;
+ this.group = null;
+ this.name = '';
+ this.events = new Phaser.Components.Events(this);
+ this.animations = new Phaser.Components.AnimationManager(this);
+ this.input = new Phaser.Components.InputHandler(this);
+ this.texture = new Phaser.Display.Texture(this);
+ this.transform = new Phaser.Components.TransformManager(this);
+ if(key !== null) {
+ this.texture.loadImage(key, false);
+ } else {
+ this.texture.opaque = true;
+ }
+ if(frame !== null) {
+ if(typeof frame == 'string') {
+ this.frameName = frame;
+ } else {
+ this.frame = frame;
+ }
+ }
+ this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
+ this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
+ this.transform.setCache();
+ this.body = new Phaser.Physics.Body(this, 0);
+ this.outOfBounds = false;
+ this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
+ this.scale = this.transform.scale;
+ this.alpha = this.texture.alpha;
+ this.origin = this.transform.origin;
+ this.crop = this.texture.crop;
+ }
+ Object.defineProperty(Sprite.prototype, "rotation", {
+ get: function () {
+ return this.transform.rotation;
+ },
+ set: function (value) {
+ this.transform.rotation = this.game.math.wrap(value, 360, 0);
+ if(this.body) {
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sprite.prototype.bringToTop = function () {
+ if(this.group) {
+ this.group.bringToTop(this);
+ }
+ };
+ Object.defineProperty(Sprite.prototype, "alpha", {
+ get: function () {
+ return this.texture.alpha;
+ },
+ set: function (value) {
+ this.texture.alpha = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "frame", {
+ get: function () {
+ return this.animations.frame;
+ },
+ set: function (value) {
+ this.animations.frame = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "frameName", {
+ get: function () {
+ return this.animations.frameName;
+ },
+ set: function (value) {
+ this.animations.frameName = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "width", {
+ get: function () {
+ return this.texture.width * this.transform.scale.x;
+ },
+ set: function (value) {
+ this.transform.scale.x = value / this.texture.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Sprite.prototype, "height", {
+ get: function () {
+ return this.texture.height * this.transform.scale.y;
+ },
+ set: function (value) {
+ this.transform.scale.y = value / this.texture.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Sprite.prototype.preUpdate = function () {
+ this.transform.update();
+ if(this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0) {
+ this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
+ } else {
+ this.worldView.x = this.x - (this.width * this.transform.origin.x);
+ }
+ if(this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0) {
+ this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
+ } else {
+ this.worldView.y = this.y - (this.height * this.transform.origin.y);
+ }
+ this.worldView.width = this.width;
+ this.worldView.height = this.height;
+ if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
+ this.modified = true;
+ }
+ };
+ Sprite.prototype.update = function () {
+ };
+ Sprite.prototype.postUpdate = function () {
+ this.animations.update();
+ this.checkBounds();
+ if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
+ this.modified = false;
+ }
+ };
+ Sprite.prototype.checkBounds = function () {
+ if(Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds)) {
+ this.outOfBounds = false;
+ } else {
+ if(this.outOfBounds == false) {
+ this.events.onOutOfBounds.dispatch(this);
+ }
+ this.outOfBounds = true;
+ if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL) {
+ this.kill();
+ } else if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY) {
+ this.destroy();
+ }
+ }
+ };
+ Sprite.prototype.destroy = function () {
+ this.input.destroy();
+ };
+ Sprite.prototype.kill = function (removeFromGroup) {
+ if (typeof removeFromGroup === "undefined") { removeFromGroup = false; }
+ this.alive = false;
+ this.exists = false;
+ if(removeFromGroup && this.group) {
+ }
+ this.events.onKilled.dispatch(this);
+ };
+ Sprite.prototype.revive = function () {
+ this.alive = true;
+ this.exists = true;
+ this.events.onRevived.dispatch(this);
+ };
+ return Sprite;
+ })();
+ Phaser.Sprite = Sprite;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Components) {
+ var TransformManager = (function () {
+ function TransformManager(parent) {
+ this._dirty = false;
+ this.rotationOffset = 0;
+ this.rotation = 0;
+ this.game = parent.game;
+ this.parent = parent;
+ this.local = new Phaser.Mat3();
+ this.scrollFactor = new Phaser.Vec2(1, 1);
+ this.origin = new Phaser.Vec2();
+ this.scale = new Phaser.Vec2(1, 1);
+ this.skew = new Phaser.Vec2();
+ this.center = new Phaser.Point();
+ this.upperLeft = new Phaser.Point();
+ this.upperRight = new Phaser.Point();
+ this.bottomLeft = new Phaser.Point();
+ this.bottomRight = new Phaser.Point();
+ this._pos = new Phaser.Point();
+ this._scale = new Phaser.Point();
+ this._size = new Phaser.Point();
+ this._halfSize = new Phaser.Point();
+ this._offset = new Phaser.Point();
+ this._origin = new Phaser.Point();
+ this._sc = new Phaser.Point();
+ this._scA = new Phaser.Point();
+ }
+ Object.defineProperty(TransformManager.prototype, "distance", {
+ get: function () {
+ return this._distance;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "angleToCenter", {
+ get: function () {
+ return this._angle;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "offsetX", {
+ get: function () {
+ return this._offset.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "offsetY", {
+ get: function () {
+ return this._offset.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "halfWidth", {
+ get: function () {
+ return this._halfSize.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "halfHeight", {
+ get: function () {
+ return this._halfSize.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "sin", {
+ get: function () {
+ return this._sc.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(TransformManager.prototype, "cos", {
+ get: function () {
+ return this._sc.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ TransformManager.prototype.centerOn = function (x, y) {
+ this.parent.x = x + (this.parent.x - this.center.x);
+ this.parent.y = y + (this.parent.y - this.center.y);
+ };
+ TransformManager.prototype.setCache = function () {
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this._halfSize.x = this.parent.width / 2;
+ this._halfSize.y = this.parent.height / 2;
+ this._offset.x = this.origin.x * this.parent.width;
+ this._offset.y = this.origin.y * this.parent.height;
+ this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
+ this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
+ this._size.x = this.parent.width;
+ this._size.y = this.parent.height;
+ this._origin.x = this.origin.x;
+ this._origin.y = this.origin.y;
+ this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._prevRotation = this.rotation;
+ if(this.parent.texture && this.parent.texture.renderRotation) {
+ this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ } else {
+ this._sc.x = 0;
+ this._sc.y = 1;
+ }
+ this.center.x = this.parent.x + this._distance * this._scA.y;
+ this.center.y = this.parent.y + this._distance * this._scA.x;
+ this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this._flippedX = this.parent.texture.flippedX;
+ this._flippedY = this.parent.texture.flippedY;
+ };
+ TransformManager.prototype.update = function () {
+ this._dirty = false;
+ if(this.parent.width !== this._size.x || this.parent.height !== this._size.y || this.origin.x !== this._origin.x || this.origin.y !== this._origin.y) {
+ this._halfSize.x = this.parent.width / 2;
+ this._halfSize.y = this.parent.height / 2;
+ this._offset.x = this.origin.x * this.parent.width;
+ this._offset.y = this.origin.y * this.parent.height;
+ this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
+ this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
+ this._size.x = this.parent.width;
+ this._size.y = this.parent.height;
+ this._origin.x = this.origin.x;
+ this._origin.y = this.origin.y;
+ this._dirty = true;
+ }
+ if(this.rotation != this._prevRotation || this._dirty) {
+ this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
+ if(this.parent.texture.renderRotation) {
+ this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
+ } else {
+ this._sc.x = 0;
+ this._sc.y = 1;
+ }
+ this._prevRotation = this.rotation;
+ this._dirty = true;
+ }
+ if(this._dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y) {
+ this.center.x = this.parent.x + this._distance * this._scA.y;
+ this.center.y = this.parent.y + this._distance * this._scA.x;
+ this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
+ this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
+ this._pos.x = this.parent.x;
+ this._pos.y = this.parent.y;
+ this.local.data[2] = this.parent.x;
+ this.local.data[5] = this.parent.y;
+ }
+ if(this._dirty || this._flippedX != this.parent.texture.flippedX) {
+ this._flippedX = this.parent.texture.flippedX;
+ if(this._flippedX) {
+ this.local.data[0] = this._sc.y * -this.scale.x;
+ this.local.data[3] = (this._sc.x * -this.scale.x) + this.skew.x;
+ } else {
+ this.local.data[0] = this._sc.y * this.scale.x;
+ this.local.data[3] = (this._sc.x * this.scale.x) + this.skew.x;
+ }
+ }
+ if(this._dirty || this._flippedY != this.parent.texture.flippedY) {
+ this._flippedY = this.parent.texture.flippedY;
+ if(this._flippedY) {
+ this.local.data[4] = this._sc.y * -this.scale.y;
+ this.local.data[1] = -(this._sc.x * -this.scale.y) + this.skew.y;
+ } else {
+ this.local.data[4] = this._sc.y * this.scale.y;
+ this.local.data[1] = -(this._sc.x * this.scale.y) + this.skew.y;
+ }
+ }
+ };
+ return TransformManager;
+ })();
+ Components.TransformManager = TransformManager;
+ })(Phaser.Components || (Phaser.Components = {}));
+ var Components = Phaser.Components;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var ScrollRegion = (function () {
+ function ScrollRegion(x, y, width, height, speedX, speedY) {
+ this._anchorWidth = 0;
+ this._anchorHeight = 0;
+ this._inverseWidth = 0;
+ this._inverseHeight = 0;
+ this.visible = true;
+ this._A = new Phaser.Rectangle(x, y, width, height);
+ this._B = new Phaser.Rectangle(x, y, width, height);
+ this._C = new Phaser.Rectangle(x, y, width, height);
+ this._D = new Phaser.Rectangle(x, y, width, height);
+ this._scroll = new Phaser.Vec2();
+ this._bounds = new Phaser.Rectangle(x, y, width, height);
+ this.scrollSpeed = new Phaser.Vec2(speedX, speedY);
+ }
+ ScrollRegion.prototype.update = function (delta) {
+ this._scroll.x += this.scrollSpeed.x;
+ this._scroll.y += this.scrollSpeed.y;
+ if(this._scroll.x > this._bounds.right) {
+ this._scroll.x = this._bounds.x;
+ }
+ if(this._scroll.x < this._bounds.x) {
+ this._scroll.x = this._bounds.right;
+ }
+ if(this._scroll.y > this._bounds.bottom) {
+ this._scroll.y = this._bounds.y;
+ }
+ if(this._scroll.y < this._bounds.y) {
+ this._scroll.y = this._bounds.bottom;
+ }
+ this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
+ this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
+ if(this._anchorWidth > this._bounds.width) {
+ this._anchorWidth = this._bounds.width;
+ }
+ if(this._anchorHeight > this._bounds.height) {
+ this._anchorHeight = this._bounds.height;
+ }
+ this._inverseWidth = this._bounds.width - this._anchorWidth;
+ this._inverseHeight = this._bounds.height - this._anchorHeight;
+ this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
+ this._B.y = this._scroll.y;
+ this._B.width = this._inverseWidth;
+ this._B.height = this._anchorHeight;
+ this._C.x = this._scroll.x;
+ this._C.width = this._anchorWidth;
+ this._C.height = this._inverseHeight;
+ this._D.width = this._inverseWidth;
+ this._D.height = this._inverseHeight;
+ };
+ ScrollRegion.prototype.render = function (context, texture, dx, dy, dw, dh) {
+ if(this.visible == false) {
+ return;
+ }
+ this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
+ this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
+ this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
+ this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
+ };
+ ScrollRegion.prototype.crop = function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
+ offsetX += destX;
+ offsetY += destY;
+ if(srcW > (destX + destW) - offsetX) {
+ srcW = (destX + destW) - offsetX;
+ }
+ if(srcH > (destY + destH) - offsetY) {
+ srcH = (destY + destH) - offsetY;
+ }
+ srcX = Math.floor(srcX);
+ srcY = Math.floor(srcY);
+ srcW = Math.floor(srcW);
+ srcH = Math.floor(srcH);
+ offsetX = Math.floor(offsetX + this._bounds.x);
+ offsetY = Math.floor(offsetY + this._bounds.y);
+ if(srcW > 0 && srcH > 0) {
+ context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
+ }
+ };
+ return ScrollRegion;
+ })();
+ Phaser.ScrollRegion = ScrollRegion;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var ScrollZone = (function (_super) {
+ __extends(ScrollZone, _super);
+ function ScrollZone(game, key, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ _super.call(this, game, x, y, key);
+ this.type = Phaser.Types.SCROLLZONE;
+ this.regions = [];
+ if(this.texture.loaded) {
+ if(width > this.width || height > this.height) {
+ this.createRepeatingTexture(width, height);
+ this.width = width;
+ this.height = height;
+ }
+ this.addRegion(0, 0, this.width, this.height);
+ if((width < this.width || height < this.height) && width !== 0 && height !== 0) {
+ this.width = width;
+ this.height = height;
+ }
+ }
+ }
+ ScrollZone.prototype.addRegion = function (x, y, width, height, speedX, speedY) {
+ if (typeof speedX === "undefined") { speedX = 0; }
+ if (typeof speedY === "undefined") { speedY = 0; }
+ if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
+ throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
+ return null;
+ }
+ this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
+ this.regions.push(this.currentRegion);
+ return this.currentRegion;
+ };
+ ScrollZone.prototype.setSpeed = function (x, y) {
+ if(this.currentRegion) {
+ this.currentRegion.scrollSpeed.setTo(x, y);
+ }
+ return this;
+ };
+ ScrollZone.prototype.update = function () {
+ for(var i = 0; i < this.regions.length; i++) {
+ this.regions[i].update(this.game.time.delta);
+ }
+ };
+ ScrollZone.prototype.createRepeatingTexture = function (regionWidth, regionHeight) {
+ var tileWidth = Math.ceil(this.width / regionWidth) * regionWidth;
+ var tileHeight = Math.ceil(this.height / regionHeight) * regionHeight;
+ var dt = new Phaser.Display.DynamicTexture(this.game, tileWidth, tileHeight);
+ dt.context.rect(0, 0, tileWidth, tileHeight);
+ dt.context.fillStyle = dt.context.createPattern(this.texture.imageTexture, "repeat");
+ dt.context.fill();
+ this.texture.loadDynamicTexture(dt);
+ };
+ return ScrollZone;
+ })(Phaser.Sprite);
+ Phaser.ScrollZone = ScrollZone;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var GameObjectFactory = (function () {
+ function GameObjectFactory(game) {
+ this.game = game;
+ this._world = this.game.world;
+ }
+ GameObjectFactory.prototype.camera = function (x, y, width, height) {
+ return this._world.cameras.addCamera(x, y, width, height);
+ };
+ GameObjectFactory.prototype.button = function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof callbackContext === "undefined") { callbackContext = null; }
+ if (typeof overFrame === "undefined") { overFrame = null; }
+ if (typeof outFrame === "undefined") { outFrame = null; }
+ if (typeof downFrame === "undefined") { downFrame = null; }
+ return this._world.group.add(new Phaser.UI.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
+ };
+ GameObjectFactory.prototype.sprite = function (x, y, key, frame) {
+ if (typeof key === "undefined") { key = ''; }
+ if (typeof frame === "undefined") { frame = null; }
+ return this._world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
+ };
+ GameObjectFactory.prototype.audio = function (key, volume, loop) {
+ if (typeof volume === "undefined") { volume = 1; }
+ if (typeof loop === "undefined") { loop = false; }
+ return this.game.sound.add(key, volume, loop);
+ };
+ GameObjectFactory.prototype.circle = function (x, y, radius) {
+ return new Phaser.Physics.Circle(this.game, x, y, radius);
+ };
+ GameObjectFactory.prototype.aabb = function (x, y, width, height) {
+ return new Phaser.Physics.AABB(this.game, x, y, Math.floor(width / 2), Math.floor(height / 2));
+ };
+ GameObjectFactory.prototype.cell = function (x, y, width, height, state) {
+ if (typeof state === "undefined") { state = Phaser.Physics.TileMapCell.TID_FULL; }
+ return new Phaser.Physics.TileMapCell(this.game, x, y, width, height).SetState(state);
+ };
+ GameObjectFactory.prototype.dynamicTexture = function (width, height) {
+ return new Phaser.Display.DynamicTexture(this.game, width, height);
+ };
+ GameObjectFactory.prototype.group = function (maxSize) {
+ if (typeof maxSize === "undefined") { maxSize = 0; }
+ return this._world.group.add(new Phaser.Group(this.game, maxSize));
+ };
+ GameObjectFactory.prototype.scrollZone = function (key, x, y, width, height) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof width === "undefined") { width = 0; }
+ if (typeof height === "undefined") { height = 0; }
+ return this._world.group.add(new Phaser.ScrollZone(this.game, key, x, y, width, height));
+ };
+ GameObjectFactory.prototype.tilemap = function (key, mapData, format, resizeWorld, tileWidth, tileHeight) {
+ if (typeof resizeWorld === "undefined") { resizeWorld = true; }
+ if (typeof tileWidth === "undefined") { tileWidth = 0; }
+ if (typeof tileHeight === "undefined") { tileHeight = 0; }
+ return this._world.group.add(new Phaser.Tilemap(this.game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
+ };
+ GameObjectFactory.prototype.tween = function (obj, localReference) {
+ if (typeof localReference === "undefined") { localReference = false; }
+ return this.game.tweens.create(obj, localReference);
+ };
+ GameObjectFactory.prototype.existingSprite = function (sprite) {
+ return this._world.group.add(sprite);
+ };
+ GameObjectFactory.prototype.existingGroup = function (group) {
+ return this._world.group.add(group);
+ };
+ GameObjectFactory.prototype.existingButton = function (button) {
+ return this._world.group.add(button);
+ };
+ GameObjectFactory.prototype.existingScrollZone = function (scrollZone) {
+ return this._world.group.add(scrollZone);
+ };
+ GameObjectFactory.prototype.existingTilemap = function (tilemap) {
+ return this._world.group.add(tilemap);
+ };
+ GameObjectFactory.prototype.existingTween = function (tween) {
+ return this.game.tweens.add(tween);
+ };
+ return GameObjectFactory;
+ })();
+ Phaser.GameObjectFactory = GameObjectFactory;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (UI) {
+ var Button = (function (_super) {
+ __extends(Button, _super);
+ function Button(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ if (typeof key === "undefined") { key = null; }
+ if (typeof callback === "undefined") { callback = null; }
+ if (typeof callbackContext === "undefined") { callbackContext = null; }
+ if (typeof overFrame === "undefined") { overFrame = null; }
+ if (typeof outFrame === "undefined") { outFrame = null; }
+ if (typeof downFrame === "undefined") { downFrame = null; }
+ _super.call(this, game, x, y, key, outFrame);
+ this._onOverFrameName = null;
+ this._onOutFrameName = null;
+ this._onDownFrameName = null;
+ this._onUpFrameName = null;
+ this._onOverFrameID = null;
+ this._onOutFrameID = null;
+ this._onDownFrameID = null;
+ this._onUpFrameID = null;
+ this.type = Phaser.Types.BUTTON;
+ if(typeof overFrame == 'string') {
+ this._onOverFrameName = overFrame;
+ } else {
+ this._onOverFrameID = overFrame;
+ }
+ if(typeof outFrame == 'string') {
+ this._onOutFrameName = outFrame;
+ this._onUpFrameName = outFrame;
+ } else {
+ this._onOutFrameID = outFrame;
+ this._onUpFrameID = outFrame;
+ }
+ if(typeof downFrame == 'string') {
+ this._onDownFrameName = downFrame;
+ } else {
+ this._onDownFrameID = downFrame;
+ }
+ this.onInputOver = new Phaser.Signal();
+ this.onInputOut = new Phaser.Signal();
+ this.onInputDown = new Phaser.Signal();
+ this.onInputUp = new Phaser.Signal();
+ if(callback) {
+ this.onInputUp.add(callback, callbackContext);
+ }
+ this.input.start(0, false, true);
+ this.events.onInputOver.add(this.onInputOverHandler, this);
+ this.events.onInputOut.add(this.onInputOutHandler, this);
+ this.events.onInputDown.add(this.onInputDownHandler, this);
+ this.events.onInputUp.add(this.onInputUpHandler, this);
+ }
+ Button.prototype.onInputOverHandler = function (pointer) {
+ if(this._onOverFrameName != null) {
+ this.frameName = this._onOverFrameName;
+ } else if(this._onOverFrameID != null) {
+ this.frame = this._onOverFrameID;
+ }
+ if(this.onInputOver) {
+ this.onInputOver.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputOutHandler = function (pointer) {
+ if(this._onOutFrameName != null) {
+ this.frameName = this._onOutFrameName;
+ } else if(this._onOutFrameID != null) {
+ this.frame = this._onOutFrameID;
+ }
+ if(this.onInputOut) {
+ this.onInputOut.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputDownHandler = function (pointer) {
+ if(this._onDownFrameName != null) {
+ this.frameName = this._onDownFrameName;
+ } else if(this._onDownFrameID != null) {
+ this.frame = this._onDownFrameID;
+ }
+ if(this.onInputDown) {
+ this.onInputDown.dispatch(this, pointer);
+ }
+ };
+ Button.prototype.onInputUpHandler = function (pointer) {
+ if(this._onUpFrameName != null) {
+ this.frameName = this._onUpFrameName;
+ } else if(this._onUpFrameID != null) {
+ this.frame = this._onUpFrameID;
+ }
+ if(this.onInputUp) {
+ this.onInputUp.dispatch(this, pointer);
+ }
+ };
+ Object.defineProperty(Button.prototype, "priorityID", {
+ get: function () {
+ return this.input.priorityID;
+ },
+ set: function (value) {
+ this.input.priorityID = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Button.prototype, "useHandCursor", {
+ get: function () {
+ return this.input.useHandCursor;
+ },
+ set: function (value) {
+ this.input.useHandCursor = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Button;
+ })(Phaser.Sprite);
+ UI.Button = Button;
+ })(Phaser.UI || (Phaser.UI = {}));
+ var UI = Phaser.UI;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var CanvasUtils = (function () {
+ function CanvasUtils() { }
+ CanvasUtils.getAspectRatio = function getAspectRatio(canvas) {
+ return canvas.width / canvas.height;
+ };
+ CanvasUtils.setBackgroundColor = function setBackgroundColor(canvas, color) {
+ if (typeof color === "undefined") { color = 'rgb(0,0,0)'; }
+ canvas.style.backgroundColor = color;
+ return canvas;
+ };
+ CanvasUtils.setTouchAction = function setTouchAction(canvas, value) {
+ if (typeof value === "undefined") { value = 'none'; }
+ canvas.style.msTouchAction = value;
+ canvas.style['ms-touch-action'] = value;
+ canvas.style['touch-action'] = value;
+ return canvas;
+ };
+ CanvasUtils.addToDOM = function addToDOM(canvas, parent, overflowHidden) {
+ if (typeof parent === "undefined") { parent = ''; }
+ if (typeof overflowHidden === "undefined") { overflowHidden = true; }
+ if((parent !== '' || parent !== null) && document.getElementById(parent)) {
+ document.getElementById(parent).appendChild(canvas);
+ if(overflowHidden) {
+ document.getElementById(parent).style.overflow = 'hidden';
+ }
+ } else {
+ document.body.appendChild(canvas);
+ }
+ return canvas;
+ };
+ CanvasUtils.setTransform = function setTransform(context, translateX, translateY, scaleX, scaleY, skewX, skewY) {
+ context.setTransform(scaleX, skewX, skewY, scaleY, translateX, translateY);
+ return context;
+ };
+ CanvasUtils.setSmoothingEnabled = function setSmoothingEnabled(context, value) {
+ context['imageSmoothingEnabled'] = value;
+ context['mozImageSmoothingEnabled'] = value;
+ context['oImageSmoothingEnabled'] = value;
+ context['webkitImageSmoothingEnabled'] = value;
+ context['msImageSmoothingEnabled'] = value;
+ return context;
+ };
+ CanvasUtils.setImageRenderingCrisp = function setImageRenderingCrisp(canvas) {
+ canvas.style['image-rendering'] = 'crisp-edges';
+ canvas.style['image-rendering'] = '-moz-crisp-edges';
+ canvas.style['image-rendering'] = '-webkit-optimize-contrast';
+ canvas.style.msInterpolationMode = 'nearest-neighbor';
+ return canvas;
+ };
+ CanvasUtils.setImageRenderingBicubic = function setImageRenderingBicubic(canvas) {
+ canvas.style['image-rendering'] = 'auto';
+ canvas.style.msInterpolationMode = 'bicubic';
+ return canvas;
+ };
+ return CanvasUtils;
+ })();
+ Phaser.CanvasUtils = CanvasUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var CircleUtils = (function () {
+ function CircleUtils() { }
+ CircleUtils.clone = function clone(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Circle(); }
+ return out.setTo(a.x, a.y, a.diameter);
+ };
+ CircleUtils.contains = function contains(a, x, y) {
+ if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
+ var dx = (a.x - x) * (a.x - x);
+ var dy = (a.y - y) * (a.y - y);
+ return (dx + dy) <= (a.radius * a.radius);
+ }
+ return false;
+ };
+ CircleUtils.containsPoint = function containsPoint(a, point) {
+ return CircleUtils.contains(a, point.x, point.y);
+ };
+ CircleUtils.containsCircle = function containsCircle(a, b) {
+ return true;
+ };
+ CircleUtils.distanceBetween = function distanceBetween(a, target, round) {
+ if (typeof round === "undefined") { round = false; }
+ var dx = a.x - target.x;
+ var dy = a.y - target.y;
+ if(round === true) {
+ return Math.round(Math.sqrt(dx * dx + dy * dy));
+ } else {
+ return Math.sqrt(dx * dx + dy * dy);
+ }
+ };
+ CircleUtils.equals = function equals(a, b) {
+ return (a.x == b.x && a.y == b.y && a.diameter == b.diameter);
+ };
+ CircleUtils.intersects = function intersects(a, b) {
+ return (Phaser.CircleUtils.distanceBetween(a, b) <= (a.radius + b.radius));
+ };
+ CircleUtils.circumferencePoint = function circumferencePoint(a, angle, asDegrees, out) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ if(asDegrees === true) {
+ angle = angle * Phaser.GameMath.DEG_TO_RAD;
+ }
+ return out.setTo(a.x + a.radius * Math.cos(angle), a.y + a.radius * Math.sin(angle));
+ };
+ CircleUtils.intersectsRectangle = function intersectsRectangle(c, r) {
+ var cx = Math.abs(c.x - r.x - r.halfWidth);
+ var xDist = r.halfWidth + c.radius;
+ if(cx > xDist) {
+ return false;
+ }
+ var cy = Math.abs(c.y - r.y - r.halfHeight);
+ var yDist = r.halfHeight + c.radius;
+ if(cy > yDist) {
+ return false;
+ }
+ if(cx <= r.halfWidth || cy <= r.halfHeight) {
+ return true;
+ }
+ var xCornerDist = cx - r.halfWidth;
+ var yCornerDist = cy - r.halfHeight;
+ var xCornerDistSq = xCornerDist * xCornerDist;
+ var yCornerDistSq = yCornerDist * yCornerDist;
+ var maxCornerDistSq = c.radius * c.radius;
+ return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
+ };
+ return CircleUtils;
+ })();
+ Phaser.CircleUtils = CircleUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var ColorUtils = (function () {
+ function ColorUtils() { }
+ ColorUtils.getColor32 = function getColor32(alpha, red, green, blue) {
+ return alpha << 24 | red << 16 | green << 8 | blue;
+ };
+ ColorUtils.getColor = function getColor(red, green, blue) {
+ return red << 16 | green << 8 | blue;
+ };
+ ColorUtils.getHSVColorWheel = function getHSVColorWheel(alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var colors = [];
+ for(var c = 0; c <= 359; c++) {
+ colors[c] = Phaser.ColorUtils.getWebRGB(Phaser.ColorUtils.HSVtoRGB(c, 1.0, 1.0, alpha));
+ }
+ return colors;
+ };
+ ColorUtils.hexToRGB = function hexToRGB(h) {
+ var hex16 = (h.charAt(0) == "#") ? h.substring(1, 7) : h;
+ var r = parseInt(hex16.substring(0, 2), 16);
+ var g = parseInt(hex16.substring(2, 4), 16);
+ var b = parseInt(hex16.substring(4, 6), 16);
+ return {
+ r: r,
+ g: g,
+ b: b
+ };
+ };
+ ColorUtils.getComplementHarmony = function getComplementHarmony(color) {
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
+ return Phaser.ColorUtils.HSVtoRGB(opposite, 1.0, 1.0);
+ };
+ ColorUtils.getAnalogousHarmony = function getAnalogousHarmony(color, threshold) {
+ if (typeof threshold === "undefined") { threshold = 30; }
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ if(threshold > 359 || threshold < 0) {
+ throw Error("Color Warning: Invalid threshold given to getAnalogousHarmony()");
+ }
+ var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 359 - threshold, 359);
+ var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, threshold, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(warmer, 1.0, 1.0),
+ color3: Phaser.ColorUtils.HSVtoRGB(colder, 1.0, 1.0),
+ hue1: hsv.hue,
+ hue2: warmer,
+ hue3: colder
+ };
+ };
+ ColorUtils.getSplitComplementHarmony = function getSplitComplementHarmony(color, threshold) {
+ if (typeof threshold === "undefined") { threshold = 30; }
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ if(threshold >= 359 || threshold <= 0) {
+ throw Error("Phaser.ColorUtils Warning: Invalid threshold given to getSplitComplementHarmony()");
+ }
+ var opposite = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
+ var warmer = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite - threshold, 359);
+ var colder = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, opposite + threshold, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(warmer, hsv.saturation, hsv.value),
+ color3: Phaser.ColorUtils.HSVtoRGB(colder, hsv.saturation, hsv.value),
+ hue1: hsv.hue,
+ hue2: warmer,
+ hue3: colder
+ };
+ };
+ ColorUtils.getTriadicHarmony = function getTriadicHarmony(color) {
+ var hsv = Phaser.ColorUtils.RGBtoHSV(color);
+ var triadic1 = Phaser.ColorUtils.game.math.wrapValue(hsv.hue, 120, 359);
+ var triadic2 = Phaser.ColorUtils.game.math.wrapValue(triadic1, 120, 359);
+ return {
+ color1: color,
+ color2: Phaser.ColorUtils.HSVtoRGB(triadic1, 1.0, 1.0),
+ color3: Phaser.ColorUtils.HSVtoRGB(triadic2, 1.0, 1.0)
+ };
+ };
+ ColorUtils.getColorInfo = function getColorInfo(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ var hsl = Phaser.ColorUtils.RGBtoHSV(color);
+ var result = Phaser.ColorUtils.RGBtoHexstring(color) + "\n";
+ result = result.concat("Alpha: " + argb.alpha + " Red: " + argb.red + " Green: " + argb.green + " Blue: " + argb.blue) + "\n";
+ result = result.concat("Hue: " + hsl.hue + " Saturation: " + hsl.saturation + " Lightnes: " + hsl.lightness);
+ return result;
+ };
+ ColorUtils.RGBtoHexstring = function RGBtoHexstring(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ return "0x" + Phaser.ColorUtils.colorToHexstring(argb.alpha) + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
+ };
+ ColorUtils.RGBtoWebstring = function RGBtoWebstring(color) {
+ var argb = Phaser.ColorUtils.getRGB(color);
+ return "#" + Phaser.ColorUtils.colorToHexstring(argb.red) + Phaser.ColorUtils.colorToHexstring(argb.green) + Phaser.ColorUtils.colorToHexstring(argb.blue);
+ };
+ ColorUtils.colorToHexstring = function colorToHexstring(color) {
+ var digits = "0123456789ABCDEF";
+ var lsd = color % 16;
+ var msd = (color - lsd) / 16;
+ var hexified = digits.charAt(msd) + digits.charAt(lsd);
+ return hexified;
+ };
+ ColorUtils.HSVtoRGB = function HSVtoRGB(h, s, v, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var result;
+ if(s == 0.0) {
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, v * 255, v * 255);
+ } else {
+ h = h / 60.0;
+ var f = h - Math.floor(h);
+ var p = v * (1.0 - s);
+ var q = v * (1.0 - s * f);
+ var t = v * (1.0 - s * (1.0 - f));
+ switch(Math.floor(h)) {
+ case 0:
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, t * 255, p * 255);
+ break;
+ case 1:
+ result = Phaser.ColorUtils.getColor32(alpha, q * 255, v * 255, p * 255);
+ break;
+ case 2:
+ result = Phaser.ColorUtils.getColor32(alpha, p * 255, v * 255, t * 255);
+ break;
+ case 3:
+ result = Phaser.ColorUtils.getColor32(alpha, p * 255, q * 255, v * 255);
+ break;
+ case 4:
+ result = Phaser.ColorUtils.getColor32(alpha, t * 255, p * 255, v * 255);
+ break;
+ case 5:
+ result = Phaser.ColorUtils.getColor32(alpha, v * 255, p * 255, q * 255);
+ break;
+ default:
+ throw new Error("Phaser.ColorUtils.HSVtoRGB : Unknown color");
+ }
+ }
+ return result;
+ };
+ ColorUtils.RGBtoHSV = function RGBtoHSV(color) {
+ var rgb = Phaser.ColorUtils.getRGB(color);
+ var red = rgb.red / 255;
+ var green = rgb.green / 255;
+ var blue = rgb.blue / 255;
+ var min = Math.min(red, green, blue);
+ var max = Math.max(red, green, blue);
+ var delta = max - min;
+ var lightness = (max + min) / 2;
+ var hue;
+ var saturation;
+ if(delta == 0) {
+ hue = 0;
+ saturation = 0;
+ } else {
+ if(lightness < 0.5) {
+ saturation = delta / (max + min);
+ } else {
+ saturation = delta / (2 - max - min);
+ }
+ var delta_r = (((max - red) / 6) + (delta / 2)) / delta;
+ var delta_g = (((max - green) / 6) + (delta / 2)) / delta;
+ var delta_b = (((max - blue) / 6) + (delta / 2)) / delta;
+ if(red == max) {
+ hue = delta_b - delta_g;
+ } else if(green == max) {
+ hue = (1 / 3) + delta_r - delta_b;
+ } else if(blue == max) {
+ hue = (2 / 3) + delta_g - delta_r;
+ }
+ if(hue < 0) {
+ hue += 1;
+ }
+ if(hue > 1) {
+ hue -= 1;
+ }
+ }
+ hue *= 360;
+ hue = Math.round(hue);
+ return {
+ hue: hue,
+ saturation: saturation,
+ lightness: lightness,
+ value: lightness
+ };
+ };
+ ColorUtils.interpolateColor = function interpolateColor(color1, color2, steps, currentStep, alpha) {
+ if (typeof alpha === "undefined") { alpha = 255; }
+ var src1 = Phaser.ColorUtils.getRGB(color1);
+ var src2 = Phaser.ColorUtils.getRGB(color2);
+ var r = (((src2.red - src1.red) * currentStep) / steps) + src1.red;
+ var g = (((src2.green - src1.green) * currentStep) / steps) + src1.green;
+ var b = (((src2.blue - src1.blue) * currentStep) / steps) + src1.blue;
+ return Phaser.ColorUtils.getColor32(alpha, r, g, b);
+ };
+ ColorUtils.interpolateColorWithRGB = function interpolateColorWithRGB(color, r, g, b, steps, currentStep) {
+ var src = Phaser.ColorUtils.getRGB(color);
+ var or = (((r - src.red) * currentStep) / steps) + src.red;
+ var og = (((g - src.green) * currentStep) / steps) + src.green;
+ var ob = (((b - src.blue) * currentStep) / steps) + src.blue;
+ return Phaser.ColorUtils.getColor(or, og, ob);
+ };
+ ColorUtils.interpolateRGB = function interpolateRGB(r1, g1, b1, r2, g2, b2, steps, currentStep) {
+ var r = (((r2 - r1) * currentStep) / steps) + r1;
+ var g = (((g2 - g1) * currentStep) / steps) + g1;
+ var b = (((b2 - b1) * currentStep) / steps) + b1;
+ return Phaser.ColorUtils.getColor(r, g, b);
+ };
+ ColorUtils.getRandomColor = function getRandomColor(min, max, alpha) {
+ if (typeof min === "undefined") { min = 0; }
+ if (typeof max === "undefined") { max = 255; }
+ if (typeof alpha === "undefined") { alpha = 255; }
+ if(max > 255) {
+ return Phaser.ColorUtils.getColor(255, 255, 255);
+ }
+ if(min > max) {
+ return Phaser.ColorUtils.getColor(255, 255, 255);
+ }
+ var red = min + Math.round(Math.random() * (max - min));
+ var green = min + Math.round(Math.random() * (max - min));
+ var blue = min + Math.round(Math.random() * (max - min));
+ return Phaser.ColorUtils.getColor32(alpha, red, green, blue);
+ };
+ ColorUtils.getRGB = function getRGB(color) {
+ return {
+ alpha: color >>> 24,
+ red: color >> 16 & 0xFF,
+ green: color >> 8 & 0xFF,
+ blue: color & 0xFF
+ };
+ };
+ ColorUtils.getWebRGB = function getWebRGB(color) {
+ var alpha = (color >>> 24) / 255;
+ var red = color >> 16 & 0xFF;
+ var green = color >> 8 & 0xFF;
+ var blue = color & 0xFF;
+ return 'rgba(' + red.toString() + ',' + green.toString() + ',' + blue.toString() + ',' + alpha.toString() + ')';
+ };
+ ColorUtils.getAlpha = function getAlpha(color) {
+ return color >>> 24;
+ };
+ ColorUtils.getAlphaFloat = function getAlphaFloat(color) {
+ return (color >>> 24) / 255;
+ };
+ ColorUtils.getRed = function getRed(color) {
+ return color >> 16 & 0xFF;
+ };
+ ColorUtils.getGreen = function getGreen(color) {
+ return color >> 8 & 0xFF;
+ };
+ ColorUtils.getBlue = function getBlue(color) {
+ return color & 0xFF;
+ };
+ return ColorUtils;
+ })();
+ Phaser.ColorUtils = ColorUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var PointUtils = (function () {
+ function PointUtils() { }
+ PointUtils.add = function add(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x + b.x, a.y + b.y);
+ };
+ PointUtils.subtract = function subtract(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x - b.x, a.y - b.y);
+ };
+ PointUtils.multiply = function multiply(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x * b.x, a.y * b.y);
+ };
+ PointUtils.divide = function divide(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x / b.x, a.y / b.y);
+ };
+ PointUtils.clamp = function clamp(a, min, max) {
+ Phaser.PointUtils.clampX(a, min, max);
+ Phaser.PointUtils.clampY(a, min, max);
+ return a;
+ };
+ PointUtils.clampX = function clampX(a, min, max) {
+ a.x = Math.max(Math.min(a.x, max), min);
+ return a;
+ };
+ PointUtils.clampY = function clampY(a, min, max) {
+ a.y = Math.max(Math.min(a.y, max), min);
+ return a;
+ };
+ PointUtils.clone = function clone(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Point(); }
+ return output.setTo(a.x, a.y);
+ };
+ PointUtils.distanceBetween = function distanceBetween(a, b, round) {
+ if (typeof round === "undefined") { round = false; }
+ var dx = a.x - b.x;
+ var dy = a.y - b.y;
+ if(round === true) {
+ return Math.round(Math.sqrt(dx * dx + dy * dy));
+ } else {
+ return Math.sqrt(dx * dx + dy * dy);
+ }
+ };
+ PointUtils.equals = function equals(a, b) {
+ return (a.x == b.x && a.y == b.y);
+ };
+ PointUtils.rotate = function rotate(a, x, y, angle, asDegrees, distance) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof distance === "undefined") { distance = null; }
+ if(asDegrees) {
+ angle = angle * Phaser.GameMath.DEG_TO_RAD;
+ }
+ if(distance === null) {
+ distance = Math.sqrt(((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y)));
+ }
+ return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
+ };
+ PointUtils.rotateAroundPoint = function rotateAroundPoint(a, b, angle, asDegrees, distance) {
+ if (typeof asDegrees === "undefined") { asDegrees = false; }
+ if (typeof distance === "undefined") { distance = null; }
+ return Phaser.PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance);
+ };
+ return PointUtils;
+ })();
+ Phaser.PointUtils = PointUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var RectangleUtils = (function () {
+ function RectangleUtils() { }
+ RectangleUtils.getTopLeftAsPoint = function getTopLeftAsPoint(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.x, a.y);
+ };
+ RectangleUtils.getBottomRightAsPoint = function getBottomRightAsPoint(a, out) {
+ if (typeof out === "undefined") { out = new Phaser.Point(); }
+ return out.setTo(a.right, a.bottom);
+ };
+ RectangleUtils.inflate = function inflate(a, dx, dy) {
+ a.x -= dx;
+ a.width += 2 * dx;
+ a.y -= dy;
+ a.height += 2 * dy;
+ return a;
+ };
+ RectangleUtils.inflatePoint = function inflatePoint(a, point) {
+ return Phaser.RectangleUtils.inflate(a, point.x, point.y);
+ };
+ RectangleUtils.size = function size(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Point(); }
+ return output.setTo(a.width, a.height);
+ };
+ RectangleUtils.clone = function clone(a, output) {
+ if (typeof output === "undefined") { output = new Phaser.Rectangle(); }
+ return output.setTo(a.x, a.y, a.width, a.height);
+ };
+ RectangleUtils.contains = function contains(a, x, y) {
+ return (x >= a.x && x <= a.right && y >= a.y && y <= a.bottom);
+ };
+ RectangleUtils.containsPoint = function containsPoint(a, point) {
+ return Phaser.RectangleUtils.contains(a, point.x, point.y);
+ };
+ RectangleUtils.containsRect = function containsRect(a, b) {
+ if(a.volume > b.volume) {
+ return false;
+ }
+ return (a.x >= b.x && a.y >= b.y && a.right <= b.right && a.bottom <= b.bottom);
+ };
+ RectangleUtils.equals = function equals(a, b) {
+ return (a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height);
+ };
+ RectangleUtils.intersection = function intersection(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
+ if(Phaser.RectangleUtils.intersects(a, b)) {
+ out.x = Math.max(a.x, b.x);
+ out.y = Math.max(a.y, b.y);
+ out.width = Math.min(a.right, b.right) - out.x;
+ out.height = Math.min(a.bottom, b.bottom) - out.y;
+ }
+ return out;
+ };
+ RectangleUtils.intersects = function intersects(a, b, tolerance) {
+ if (typeof tolerance === "undefined") { tolerance = 0; }
+ return !(a.left > b.right + tolerance || a.right < b.left - tolerance || a.top > b.bottom + tolerance || a.bottom < b.top - tolerance);
+ };
+ RectangleUtils.intersectsRaw = function intersectsRaw(a, left, right, top, bottom, tolerance) {
+ if (typeof tolerance === "undefined") { tolerance = 0; }
+ return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
+ };
+ RectangleUtils.union = function union(a, b, out) {
+ if (typeof out === "undefined") { out = new Phaser.Rectangle(); }
+ return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom));
+ };
+ return RectangleUtils;
+ })();
+ Phaser.RectangleUtils = RectangleUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var SpriteUtils = (function () {
+ function SpriteUtils() { }
+ SpriteUtils.updateCameraView = function updateCameraView(camera, sprite) {
+ if(sprite.rotation == 0 || sprite.texture.renderRotation == false) {
+ sprite.cameraView.x = Math.floor(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.width * sprite.transform.origin.x));
+ sprite.cameraView.y = Math.floor(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.height * sprite.transform.origin.y));
+ sprite.cameraView.width = sprite.width;
+ sprite.cameraView.height = sprite.height;
+ } else {
+ if(sprite.transform.origin.x == 0.5 && sprite.transform.origin.y == 0.5) {
+ Phaser.SpriteUtils._sin = sprite.transform.sin;
+ Phaser.SpriteUtils._cos = sprite.transform.cos;
+ if(Phaser.SpriteUtils._sin < 0) {
+ Phaser.SpriteUtils._sin = -Phaser.SpriteUtils._sin;
+ }
+ if(Phaser.SpriteUtils._cos < 0) {
+ Phaser.SpriteUtils._cos = -Phaser.SpriteUtils._cos;
+ }
+ sprite.cameraView.width = Math.round(sprite.height * Phaser.SpriteUtils._sin + sprite.width * Phaser.SpriteUtils._cos);
+ sprite.cameraView.height = Math.round(sprite.height * Phaser.SpriteUtils._cos + sprite.width * Phaser.SpriteUtils._sin);
+ sprite.cameraView.x = Math.round(sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x) - (sprite.cameraView.width * sprite.transform.origin.x));
+ sprite.cameraView.y = Math.round(sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y) - (sprite.cameraView.height * sprite.transform.origin.y));
+ } else {
+ sprite.cameraView.x = Math.min(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x);
+ sprite.cameraView.y = Math.min(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y);
+ sprite.cameraView.width = Math.max(sprite.transform.upperLeft.x, sprite.transform.upperRight.x, sprite.transform.bottomLeft.x, sprite.transform.bottomRight.x) - sprite.cameraView.x;
+ sprite.cameraView.height = Math.max(sprite.transform.upperLeft.y, sprite.transform.upperRight.y, sprite.transform.bottomLeft.y, sprite.transform.bottomRight.y) - sprite.cameraView.y;
+ }
+ }
+ return sprite.cameraView;
+ };
+ SpriteUtils.getAsPoints = function getAsPoints(sprite) {
+ var out = [];
+ out.push(new Phaser.Point(sprite.x, sprite.y));
+ out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y));
+ out.push(new Phaser.Point(sprite.x + sprite.width, sprite.y + sprite.height));
+ out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
+ return out;
+ };
+ SpriteUtils.overlapsXY = function overlapsXY(sprite, x, y) {
+ if(sprite.transform.rotation == 0) {
+ return Phaser.RectangleUtils.contains(sprite.worldView, x, y);
+ }
+ if((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0) {
+ return false;
+ }
+ if((x - sprite.transform.upperRight.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperRight.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) > 0) {
+ return false;
+ }
+ if((x - sprite.transform.upperLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) < 0) {
+ return false;
+ }
+ if((x - sprite.transform.bottomLeft.x) * (sprite.transform.bottomLeft.x - sprite.transform.upperLeft.x) + (y - sprite.transform.bottomLeft.y) * (sprite.transform.bottomLeft.y - sprite.transform.upperLeft.y) > 0) {
+ return false;
+ }
+ return true;
+ };
+ SpriteUtils.overlapsPoint = function overlapsPoint(sprite, point) {
+ return Phaser.SpriteUtils.overlapsXY(sprite, point.x, point.y);
+ };
+ SpriteUtils.onScreen = function onScreen(sprite, camera) {
+ if (typeof camera === "undefined") { camera = null; }
+ if(camera == null) {
+ camera = sprite.game.camera;
+ }
+ Phaser.SpriteUtils.getScreenXY(sprite, SpriteUtils._tempPoint, camera);
+ return (Phaser.SpriteUtils._tempPoint.x + sprite.width > 0) && (Phaser.SpriteUtils._tempPoint.x < camera.width) && (Phaser.SpriteUtils._tempPoint.y + sprite.height > 0) && (Phaser.SpriteUtils._tempPoint.y < camera.height);
+ };
+ SpriteUtils.getScreenXY = function getScreenXY(sprite, point, camera) {
+ if (typeof point === "undefined") { point = null; }
+ if (typeof camera === "undefined") { camera = null; }
+ if(point == null) {
+ point = new Phaser.Point();
+ }
+ if(camera == null) {
+ camera = sprite.game.camera;
+ }
+ point.x = sprite.x - camera.x * sprite.transform.scrollFactor.x;
+ point.y = sprite.y - camera.y * sprite.transform.scrollFactor.y;
+ point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
+ point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
+ return point;
+ };
+ SpriteUtils.reset = function reset(sprite, x, y) {
+ sprite.revive();
+ sprite.x = x;
+ sprite.y = y;
+ return sprite;
+ };
+ SpriteUtils.setBounds = function setBounds(x, y, width, height) {
+ };
+ return SpriteUtils;
+ })();
+ Phaser.SpriteUtils = SpriteUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var DebugUtils = (function () {
+ function DebugUtils() { }
+ DebugUtils.font = '14px Courier';
+ DebugUtils.lineHeight = 16;
+ DebugUtils.renderShadow = true;
+ DebugUtils.start = function start(x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.currentX = x;
+ Phaser.DebugUtils.currentY = y;
+ Phaser.DebugUtils.currentColor = color;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.font = Phaser.DebugUtils.font;
+ };
+ DebugUtils.line = function line(text, x, y) {
+ if (typeof x === "undefined") { x = null; }
+ if (typeof y === "undefined") { y = null; }
+ if(x !== null) {
+ Phaser.DebugUtils.currentX = x;
+ }
+ if(y !== null) {
+ Phaser.DebugUtils.currentY = y;
+ }
+ if(Phaser.DebugUtils.renderShadow) {
+ Phaser.DebugUtils.context.fillStyle = 'rgb(0,0,0)';
+ Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX + 1, Phaser.DebugUtils.currentY + 1);
+ Phaser.DebugUtils.context.fillStyle = Phaser.DebugUtils.currentColor;
+ }
+ Phaser.DebugUtils.context.fillText(text, Phaser.DebugUtils.currentX, Phaser.DebugUtils.currentY);
+ Phaser.DebugUtils.currentY += Phaser.DebugUtils.lineHeight;
+ };
+ DebugUtils.renderSpriteCorners = function renderSpriteCorners(sprite, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,0,255)'; }
+ Phaser.DebugUtils.start(0, 0, color);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperLeft.x) + ' y: ' + Math.floor(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.upperRight.x) + ' y: ' + Math.floor(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomLeft.x) + ' y: ' + Math.floor(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y);
+ Phaser.DebugUtils.line('x: ' + Math.floor(sprite.transform.bottomRight.x) + ' y: ' + Math.floor(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y);
+ };
+ DebugUtils.renderSoundInfo = function renderSoundInfo(sound, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked + ' Pending Playback: ' + sound.pendingPlayback);
+ Phaser.DebugUtils.line('Decoded: ' + sound.isDecoded + ' Decoding: ' + sound.isDecoding);
+ Phaser.DebugUtils.line('Total Duration: ' + sound.totalDuration + ' Playing: ' + sound.isPlaying);
+ Phaser.DebugUtils.line('Time: ' + sound.currentTime);
+ Phaser.DebugUtils.line('Volume: ' + sound.volume + ' Muted: ' + sound.mute);
+ Phaser.DebugUtils.line('WebAudio: ' + sound.usingWebAudio + ' Audio: ' + sound.usingAudioTag);
+ if(sound.currentMarker !== '') {
+ Phaser.DebugUtils.line('Marker: ' + sound.currentMarker + ' Duration: ' + sound.duration);
+ Phaser.DebugUtils.line('Start: ' + sound.markers[sound.currentMarker].start + ' Stop: ' + sound.markers[sound.currentMarker].stop);
+ Phaser.DebugUtils.line('Position: ' + sound.position);
+ }
+ };
+ DebugUtils.renderCameraInfo = function renderCameraInfo(camera, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Camera ID: ' + camera.ID + ' (' + camera.screenView.width + ' x ' + camera.screenView.height + ')');
+ Phaser.DebugUtils.line('X: ' + camera.x + ' Y: ' + camera.y + ' Rotation: ' + camera.transform.rotation);
+ Phaser.DebugUtils.line('WorldView X: ' + camera.worldView.x + ' Y: ' + camera.worldView.y + ' W: ' + camera.worldView.width + ' H: ' + camera.worldView.height);
+ Phaser.DebugUtils.line('ScreenView X: ' + camera.screenView.x + ' Y: ' + camera.screenView.y + ' W: ' + camera.screenView.width + ' H: ' + camera.screenView.height);
+ if(camera.worldBounds) {
+ Phaser.DebugUtils.line('Bounds: ' + camera.worldBounds.width + ' x ' + camera.worldBounds.height);
+ }
+ };
+ DebugUtils.renderPointer = function renderPointer(pointer, hideIfUp, downColor, upColor, color) {
+ if (typeof hideIfUp === "undefined") { hideIfUp = false; }
+ if (typeof downColor === "undefined") { downColor = 'rgba(0,255,0,0.5)'; }
+ if (typeof upColor === "undefined") { upColor = 'rgba(255,0,0,0.5)'; }
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ if(hideIfUp == true && pointer.isUp == true) {
+ return;
+ }
+ Phaser.DebugUtils.context.beginPath();
+ Phaser.DebugUtils.context.arc(pointer.x, pointer.y, pointer.circle.radius, 0, Math.PI * 2);
+ if(pointer.active) {
+ Phaser.DebugUtils.context.fillStyle = downColor;
+ } else {
+ Phaser.DebugUtils.context.fillStyle = upColor;
+ }
+ Phaser.DebugUtils.context.fill();
+ Phaser.DebugUtils.context.closePath();
+ Phaser.DebugUtils.context.beginPath();
+ Phaser.DebugUtils.context.moveTo(pointer.positionDown.x, pointer.positionDown.y);
+ Phaser.DebugUtils.context.lineTo(pointer.position.x, pointer.position.y);
+ Phaser.DebugUtils.context.lineWidth = 2;
+ Phaser.DebugUtils.context.stroke();
+ Phaser.DebugUtils.context.closePath();
+ Phaser.DebugUtils.start(pointer.x, pointer.y - 100, color);
+ Phaser.DebugUtils.line('ID: ' + pointer.id + " Active: " + pointer.active);
+ Phaser.DebugUtils.line('World X: ' + pointer.worldX + " World Y: " + pointer.worldY);
+ Phaser.DebugUtils.line('Screen X: ' + pointer.x + " Screen Y: " + pointer.y);
+ Phaser.DebugUtils.line('Duration: ' + pointer.duration + " ms");
+ };
+ DebugUtils.renderSpriteInputInfo = function renderSpriteInputInfo(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')');
+ Phaser.DebugUtils.line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1));
+ Phaser.DebugUtils.line('over: ' + sprite.input.pointerOver() + ' duration: ' + sprite.input.overDuration().toFixed(0));
+ Phaser.DebugUtils.line('down: ' + sprite.input.pointerDown() + ' duration: ' + sprite.input.downDuration().toFixed(0));
+ Phaser.DebugUtils.line('just over: ' + sprite.input.justOver() + ' just out: ' + sprite.input.justOut());
+ };
+ DebugUtils.renderInputInfo = function renderInputInfo(x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ if(Phaser.DebugUtils.game.input.camera) {
+ Phaser.DebugUtils.line('Input - Camera: ' + Phaser.DebugUtils.game.input.camera.ID);
+ } else {
+ Phaser.DebugUtils.line('Input - Camera: null');
+ }
+ Phaser.DebugUtils.line('X: ' + Phaser.DebugUtils.game.input.x + ' Y: ' + Phaser.DebugUtils.game.input.y);
+ Phaser.DebugUtils.line('World X: ' + Phaser.DebugUtils.game.input.worldX + ' World Y: ' + Phaser.DebugUtils.game.input.worldY);
+ Phaser.DebugUtils.line('Scale X: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1) + ' Scale Y: ' + Phaser.DebugUtils.game.input.scale.x.toFixed(1));
+ Phaser.DebugUtils.line('Screen X: ' + Phaser.DebugUtils.game.input.activePointer.screenX + ' Screen Y: ' + Phaser.DebugUtils.game.input.activePointer.screenY);
+ };
+ DebugUtils.renderSpriteWorldView = function renderSpriteWorldView(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite World Coords (' + sprite.width + ' x ' + sprite.height + ')');
+ Phaser.DebugUtils.line('x: ' + sprite.worldView.x + ' y: ' + sprite.worldView.y);
+ Phaser.DebugUtils.line('bottom: ' + sprite.worldView.bottom + ' right: ' + sprite.worldView.right.toFixed(1));
+ };
+ DebugUtils.renderSpriteWorldViewBounds = function renderSpriteWorldViewBounds(sprite, color) {
+ if (typeof color === "undefined") { color = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.renderRectangle(sprite.worldView, color);
+ };
+ DebugUtils.renderSpriteInfo = function renderSpriteInfo(sprite, x, y, color) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ Phaser.DebugUtils.start(x, y, color);
+ Phaser.DebugUtils.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y);
+ Phaser.DebugUtils.line('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
+ Phaser.DebugUtils.line('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right);
+ Phaser.DebugUtils.line('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1));
+ Phaser.DebugUtils.line('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1));
+ Phaser.DebugUtils.line('center x: ' + sprite.transform.center.x + ' y: ' + sprite.transform.center.y);
+ Phaser.DebugUtils.line('cameraView x: ' + sprite.cameraView.x + ' y: ' + sprite.cameraView.y + ' width: ' + sprite.cameraView.width + ' height: ' + sprite.cameraView.height);
+ Phaser.DebugUtils.line('inCamera: ' + Phaser.DebugUtils.game.renderer.spriteRenderer.inCamera(Phaser.DebugUtils.game.camera, sprite));
+ };
+ DebugUtils.renderSpriteBounds = function renderSpriteBounds(sprite, camera, color) {
+ if (typeof camera === "undefined") { camera = null; }
+ if (typeof color === "undefined") { color = 'rgba(0,255,0,0.2)'; }
+ if(camera == null) {
+ camera = Phaser.DebugUtils.game.camera;
+ }
+ var dx = sprite.worldView.x;
+ var dy = sprite.worldView.y;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
+ };
+ DebugUtils.renderPixel = function renderPixel(x, y, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(x, y, 1, 1);
+ };
+ DebugUtils.renderPoint = function renderPoint(point, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,1)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(point.x, point.y, 1, 1);
+ };
+ DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
+ };
+ DebugUtils.renderCircle = function renderCircle(circle, fillStyle) {
+ if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
+ Phaser.DebugUtils.context.fillStyle = fillStyle;
+ Phaser.DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
+ Phaser.DebugUtils.context.fill();
+ };
+ DebugUtils.renderText = function renderText(text, x, y, color, font) {
+ if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
+ if (typeof font === "undefined") { font = '16px Courier'; }
+ Phaser.DebugUtils.context.font = font;
+ Phaser.DebugUtils.context.fillStyle = color;
+ Phaser.DebugUtils.context.fillText(text, x, y);
+ };
+ return DebugUtils;
+ })();
+ Phaser.DebugUtils = DebugUtils;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Headless) {
+ var HeadlessRenderer = (function () {
+ function HeadlessRenderer(game) {
+ this.game = game;
+ }
+ HeadlessRenderer.prototype.render = function () {
+ };
+ HeadlessRenderer.prototype.renderGameObject = function (camera, object) {
+ };
+ return HeadlessRenderer;
+ })();
+ Headless.HeadlessRenderer = HeadlessRenderer;
+ })(Renderer.Headless || (Renderer.Headless = {}));
+ var Headless = Renderer.Headless;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var CameraRenderer = (function () {
+ function CameraRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._tx = 0;
+ this._ty = 0;
+ this._gac = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ CameraRenderer.prototype.preRender = function (camera) {
+ if(camera.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
+ return false;
+ }
+ if(this.game.device.patchAndroidClearRectBug) {
+ camera.texture.context.fillStyle = 'rgb(0,0,0)';
+ camera.texture.context.fillRect(0, 0, camera.width, camera.height);
+ } else {
+ camera.texture.context.clearRect(0, 0, camera.width, camera.height);
+ }
+ if(camera.texture.alpha !== 1 && camera.texture.context.globalAlpha != camera.texture.alpha) {
+ this._ga = camera.texture.context.globalAlpha;
+ camera.texture.context.globalAlpha = camera.texture.alpha;
+ }
+ if(camera.texture.opaque) {
+ camera.texture.context.fillStyle = camera.texture.backgroundColor;
+ camera.texture.context.fillRect(0, 0, camera.width, camera.height);
+ }
+ if(camera.texture.globalCompositeOperation) {
+ camera.texture.context.globalCompositeOperation = camera.texture.globalCompositeOperation;
+ }
+ camera.plugins.preRender();
+ };
+ CameraRenderer.prototype.postRender = function (camera) {
+ if(this._ga > -1) {
+ camera.texture.context.globalAlpha = this._ga;
+ }
+ camera.plugins.postRender();
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = camera.width;
+ this._sh = camera.height;
+ this._fx = camera.transform.scale.x;
+ this._fy = camera.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = camera.screenView.x;
+ this._dy = camera.screenView.y;
+ this._dw = camera.width;
+ this._dh = camera.height;
+ this.game.stage.context.save();
+ if(camera.texture.flippedX) {
+ this._fx = -camera.transform.scale.x;
+ }
+ if(camera.texture.flippedY) {
+ this._fy = -camera.transform.scale.y;
+ }
+ if(camera.modified) {
+ if(camera.transform.rotation !== 0 || camera.transform.rotationOffset !== 0) {
+ this._sin = Math.sin(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
+ this._cos = Math.cos(camera.game.math.degreesToRadians(camera.transform.rotationOffset + camera.transform.rotation));
+ }
+ this.game.stage.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + camera.transform.skew.x, -(this._sin * this._fy) + camera.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
+ this._dx = camera.transform.origin.x * -this._dw;
+ this._dy = camera.transform.origin.y * -this._dh;
+ } else {
+ this._dx -= (this._dw * camera.transform.origin.x);
+ this._dy -= (this._dh * camera.transform.origin.y);
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
+ this.game.stage.context.restore();
+ return false;
+ }
+ this.game.stage.context.drawImage(camera.texture.canvas, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ this.game.stage.context.restore();
+ };
+ return CameraRenderer;
+ })();
+ Canvas.CameraRenderer = CameraRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var GeometryRenderer = (function () {
+ function GeometryRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ GeometryRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) {
+ if (typeof outline === "undefined") { outline = false; }
+ if (typeof fill === "undefined") { fill = true; }
+ if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; }
+ if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; }
+ if (typeof lineWidth === "undefined") { lineWidth = 1; }
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = circle.diameter;
+ this._sh = circle.diameter;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = camera.screenView.x + circle.x - camera.worldView.x;
+ this._dy = camera.screenView.y + circle.y - camera.worldView.y;
+ this._dw = circle.diameter;
+ this._dh = circle.diameter;
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ this.game.stage.saveCanvasValues();
+ context.save();
+ context.lineWidth = lineWidth;
+ context.strokeStyle = lineColor;
+ context.fillStyle = fillColor;
+ context.beginPath();
+ context.arc(this._dx, this._dy, circle.radius, 0, Math.PI * 2);
+ context.closePath();
+ if(outline) {
+ }
+ if(fill) {
+ context.fill();
+ }
+ context.restore();
+ this.game.stage.restoreCanvasValues();
+ return true;
+ };
+ return GeometryRenderer;
+ })();
+ Canvas.GeometryRenderer = GeometryRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var GroupRenderer = (function () {
+ function GroupRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ GroupRenderer.prototype.preRender = function (camera, group) {
+ if(group.visible == false || camera.transform.scale.x == 0 || camera.transform.scale.y == 0 || camera.texture.alpha < 0.1) {
+ return false;
+ }
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = group.texture.width;
+ this._sh = group.texture.height;
+ this._fx = group.transform.scale.x;
+ this._fy = group.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = group.texture.width;
+ this._dh = group.texture.height;
+ if(group.texture.globalCompositeOperation) {
+ group.texture.context.save();
+ group.texture.context.globalCompositeOperation = group.texture.globalCompositeOperation;
+ }
+ if(group.texture.alpha !== 1 && group.texture.context.globalAlpha !== group.texture.alpha) {
+ this._ga = group.texture.context.globalAlpha;
+ group.texture.context.globalAlpha = group.texture.alpha;
+ }
+ if(group.texture.flippedX) {
+ this._fx = -group.transform.scale.x;
+ }
+ if(group.texture.flippedY) {
+ this._fy = -group.transform.scale.y;
+ }
+ if(group.modified) {
+ if(group.transform.rotation !== 0 || group.transform.rotationOffset !== 0) {
+ this._sin = Math.sin(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
+ this._cos = Math.cos(group.game.math.degreesToRadians(group.transform.rotationOffset + group.transform.rotation));
+ }
+ group.texture.context.save();
+ group.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + group.transform.skew.x, -(this._sin * this._fy) + group.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
+ this._dx = -group.transform.origin.x;
+ this._dy = -group.transform.origin.y;
+ } else {
+ if(!group.transform.origin.equals(0)) {
+ this._dx -= group.transform.origin.x;
+ this._dy -= group.transform.origin.y;
+ }
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(group.texture.opaque) {
+ group.texture.context.fillStyle = group.texture.backgroundColor;
+ group.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
+ }
+ if(group.texture.loaded) {
+ group.texture.context.drawImage(group.texture.texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ }
+ return true;
+ };
+ GroupRenderer.prototype.postRender = function (camera, group) {
+ if(group.modified || group.texture.globalCompositeOperation) {
+ group.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ group.texture.context.globalAlpha = this._ga;
+ }
+ };
+ return GroupRenderer;
+ })();
+ Canvas.GroupRenderer = GroupRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var ScrollZoneRenderer = (function () {
+ function ScrollZoneRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._fx = 1;
+ this._fy = 1;
+ this._sin = 0;
+ this._cos = 1;
+ this.game = game;
+ }
+ ScrollZoneRenderer.prototype.inCamera = function (camera, scrollZone) {
+ if(scrollZone.transform.scrollFactor.equals(0)) {
+ return true;
+ }
+ return true;
+ };
+ ScrollZoneRenderer.prototype.render = function (camera, scrollZone) {
+ if(scrollZone.transform.scale.x == 0 || scrollZone.transform.scale.y == 0 || scrollZone.texture.alpha < 0.1 || this.inCamera(camera, scrollZone) == false) {
+ return false;
+ }
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = scrollZone.width;
+ this._sh = scrollZone.height;
+ this._fx = scrollZone.transform.scale.x;
+ this._fy = scrollZone.transform.scale.y;
+ this._sin = 0;
+ this._cos = 1;
+ this._dx = (camera.screenView.x * scrollZone.transform.scrollFactor.x) + scrollZone.x - (camera.worldView.x * scrollZone.transform.scrollFactor.x);
+ this._dy = (camera.screenView.y * scrollZone.transform.scrollFactor.y) + scrollZone.y - (camera.worldView.y * scrollZone.transform.scrollFactor.y);
+ this._dw = scrollZone.width;
+ this._dh = scrollZone.height;
+ if(scrollZone.texture.alpha !== 1) {
+ this._ga = scrollZone.texture.context.globalAlpha;
+ scrollZone.texture.context.globalAlpha = scrollZone.texture.alpha;
+ }
+ if(scrollZone.texture.flippedX) {
+ this._fx = -scrollZone.transform.scale.x;
+ }
+ if(scrollZone.texture.flippedY) {
+ this._fy = -scrollZone.transform.scale.y;
+ }
+ if(scrollZone.modified) {
+ if(scrollZone.texture.renderRotation == true && (scrollZone.rotation !== 0 || scrollZone.transform.rotationOffset !== 0)) {
+ this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
+ this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.transform.rotationOffset + scrollZone.rotation));
+ }
+ scrollZone.texture.context.save();
+ scrollZone.texture.context.setTransform(this._cos * this._fx, (this._sin * this._fx) + scrollZone.transform.skew.x, -(this._sin * this._fy) + scrollZone.transform.skew.y, this._cos * this._fy, this._dx, this._dy);
+ this._dx = -scrollZone.transform.origin.x;
+ this._dy = -scrollZone.transform.origin.y;
+ } else {
+ if(!scrollZone.transform.origin.equals(0)) {
+ this._dx -= scrollZone.transform.origin.x;
+ this._dy -= scrollZone.transform.origin.y;
+ }
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ for(var i = 0; i < scrollZone.regions.length; i++) {
+ if(scrollZone.texture.isDynamic) {
+ scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
+ } else {
+ scrollZone.regions[i].render(scrollZone.texture.context, scrollZone.texture.texture, this._dx, this._dy, this._dw, this._dh);
+ }
+ }
+ if(scrollZone.modified) {
+ scrollZone.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ scrollZone.texture.context.globalAlpha = this._ga;
+ }
+ this.game.renderer.renderCount++;
+ return true;
+ };
+ return ScrollZoneRenderer;
+ })();
+ Canvas.ScrollZoneRenderer = ScrollZoneRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var SpriteRenderer = (function () {
+ function SpriteRenderer(game) {
+ this._ga = 1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = 0;
+ this._sh = 0;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this.game = game;
+ }
+ SpriteRenderer.prototype.inCamera = function (camera, sprite) {
+ if(sprite.transform.scrollFactor.equals(0)) {
+ return true;
+ }
+ return true;
+ };
+ SpriteRenderer.prototype.render = function (camera, sprite) {
+ Phaser.SpriteUtils.updateCameraView(camera, sprite);
+ if(sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false) {
+ return false;
+ }
+ this._ga = -1;
+ this._sx = 0;
+ this._sy = 0;
+ this._sw = sprite.texture.width;
+ this._sh = sprite.texture.height;
+ this._dx = sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
+ this._dy = sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
+ this._dw = sprite.texture.width;
+ this._dh = sprite.texture.height;
+ if(sprite.animations.currentFrame !== null) {
+ this._sx = sprite.animations.currentFrame.x;
+ this._sy = sprite.animations.currentFrame.y;
+ if(sprite.animations.currentFrame.trimmed) {
+ this._dx += sprite.animations.currentFrame.spriteSourceSizeX;
+ this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
+ this._sw = sprite.animations.currentFrame.spriteSourceSizeW;
+ this._sh = sprite.animations.currentFrame.spriteSourceSizeH;
+ this._dw = sprite.animations.currentFrame.spriteSourceSizeW;
+ this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
+ }
+ }
+ if(sprite.modified) {
+ camera.texture.context.save();
+ camera.texture.context.setTransform(sprite.transform.local.data[0], sprite.transform.local.data[3], sprite.transform.local.data[1], sprite.transform.local.data[4], this._dx, this._dy);
+ this._dx = sprite.transform.origin.x * -this._dw;
+ this._dy = sprite.transform.origin.y * -this._dh;
+ } else {
+ this._dx -= (this._dw * sprite.transform.origin.x);
+ this._dy -= (this._dh * sprite.transform.origin.y);
+ }
+ if(sprite.crop) {
+ this._sx += sprite.crop.x * sprite.transform.scale.x;
+ this._sy += sprite.crop.y * sprite.transform.scale.y;
+ this._sw = sprite.crop.width * sprite.transform.scale.x;
+ this._sh = sprite.crop.height * sprite.transform.scale.y;
+ this._dx += sprite.crop.x * sprite.transform.scale.x;
+ this._dy += sprite.crop.y * sprite.transform.scale.y;
+ this._dw = sprite.crop.width * sprite.transform.scale.x;
+ this._dh = sprite.crop.height * sprite.transform.scale.y;
+ }
+ this._sx = Math.floor(this._sx);
+ this._sy = Math.floor(this._sy);
+ this._sw = Math.floor(this._sw);
+ this._sh = Math.floor(this._sh);
+ this._dx = Math.floor(this._dx);
+ this._dy = Math.floor(this._dy);
+ this._dw = Math.floor(this._dw);
+ this._dh = Math.floor(this._dh);
+ if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
+ return false;
+ }
+ if(sprite.texture.globalCompositeOperation) {
+ camera.texture.context.save();
+ camera.texture.context.globalCompositeOperation = sprite.texture.globalCompositeOperation;
+ }
+ if(sprite.texture.alpha !== 1 && camera.texture.context.globalAlpha != sprite.texture.alpha) {
+ this._ga = sprite.texture.context.globalAlpha;
+ camera.texture.context.globalAlpha = sprite.texture.alpha;
+ }
+ if(sprite.texture.opaque) {
+ camera.texture.context.fillStyle = sprite.texture.backgroundColor;
+ camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
+ }
+ if(sprite.texture.loaded) {
+ camera.texture.context.drawImage(sprite.texture.texture, this._sx, this._sy, this._sw, this._sh, this._dx, this._dy, this._dw, this._dh);
+ }
+ if(sprite.modified || sprite.texture.globalCompositeOperation) {
+ camera.texture.context.restore();
+ }
+ if(this._ga > -1) {
+ camera.texture.context.globalAlpha = this._ga;
+ }
+ sprite.renderOrderID = this.game.renderer.renderCount;
+ this.game.renderer.renderCount++;
+ return true;
+ };
+ return SpriteRenderer;
+ })();
+ Canvas.SpriteRenderer = SpriteRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var TilemapRenderer = (function () {
+ function TilemapRenderer(game) {
+ this._ga = 1;
+ this._dx = 0;
+ this._dy = 0;
+ this._dw = 0;
+ this._dh = 0;
+ this._tx = 0;
+ this._ty = 0;
+ this._tl = 0;
+ this._maxX = 0;
+ this._maxY = 0;
+ this._startX = 0;
+ this._startY = 0;
+ this.game = game;
+ }
+ TilemapRenderer.prototype.render = function (camera, tilemap) {
+ this._tl = tilemap.layers.length;
+ for(var i = 0; i < this._tl; i++) {
+ if(tilemap.layers[i].visible == false || tilemap.layers[i].alpha < 0.1) {
+ continue;
+ }
+ var layer = tilemap.layers[i];
+ this._maxX = this.game.math.ceil(camera.width / layer.tileWidth) + 1;
+ this._maxY = this.game.math.ceil(camera.height / layer.tileHeight) + 1;
+ this._startX = this.game.math.floor(camera.worldView.x / layer.tileWidth);
+ this._startY = this.game.math.floor(camera.worldView.y / layer.tileHeight);
+ 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;
+ }
+ 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;
+ 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 TilemapRenderer;
+ })();
+ Canvas.TilemapRenderer = TilemapRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Renderer) {
+ (function (Canvas) {
+ var CanvasRenderer = (function () {
+ function CanvasRenderer(game) {
+ this._c = 0;
+ this.game = game;
+ this.cameraRenderer = new Phaser.Renderer.Canvas.CameraRenderer(game);
+ this.groupRenderer = new Phaser.Renderer.Canvas.GroupRenderer(game);
+ this.spriteRenderer = new Phaser.Renderer.Canvas.SpriteRenderer(game);
+ this.geometryRenderer = new Phaser.Renderer.Canvas.GeometryRenderer(game);
+ this.scrollZoneRenderer = new Phaser.Renderer.Canvas.ScrollZoneRenderer(game);
+ this.tilemapRenderer = new Phaser.Renderer.Canvas.TilemapRenderer(game);
+ }
+ CanvasRenderer.prototype.render = function () {
+ this._cameraList = this.game.world.getAllCameras();
+ this.renderCount = 0;
+ for(this._c = 0; this._c < this._cameraList.length; this._c++) {
+ if(this._cameraList[this._c].visible) {
+ this.cameraRenderer.preRender(this._cameraList[this._c]);
+ this.game.world.group.render(this._cameraList[this._c]);
+ this.cameraRenderer.postRender(this._cameraList[this._c]);
+ }
+ }
+ this.renderTotal = this.renderCount;
+ };
+ CanvasRenderer.prototype.renderGameObject = function (camera, object) {
+ if(object.type == Phaser.Types.SPRITE || object.type == Phaser.Types.BUTTON) {
+ this.spriteRenderer.render(camera, object);
+ } else if(object.type == Phaser.Types.SCROLLZONE) {
+ this.scrollZoneRenderer.render(camera, object);
+ } else if(object.type == Phaser.Types.TILEMAP) {
+ this.tilemapRenderer.render(camera, object);
+ }
+ };
+ return CanvasRenderer;
+ })();
+ Canvas.CanvasRenderer = CanvasRenderer;
+ })(Renderer.Canvas || (Renderer.Canvas = {}));
+ var Canvas = Renderer.Canvas;
+ })(Phaser.Renderer || (Phaser.Renderer = {}));
+ var Renderer = Phaser.Renderer;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var ParticleManager = (function () {
+ function ParticleManager(proParticleCount, integrationType) {
+ this.PARTICLE_CREATED = 'partilcleCreated';
+ this.PARTICLE_UPDATE = 'partilcleUpdate';
+ this.PARTICLE_SLEEP = 'particleSleep';
+ this.PARTICLE_DEAD = 'partilcleDead';
+ this.PROTON_UPDATE = 'protonUpdate';
+ this.PROTON_UPDATE_AFTER = 'protonUpdateAfter';
+ this.EMITTER_ADDED = 'emitterAdded';
+ this.EMITTER_REMOVED = 'emitterRemoved';
+ this.emitters = [];
+ this.renderers = [];
+ this.time = 0;
+ this.oldTime = 0;
+ this.amendChangeTabsBug = true;
+ this.TextureBuffer = {
+ };
+ this.TextureCanvasBuffer = {
+ };
+ this.proParticleCount = Particles.ParticleUtils.initValue(proParticleCount, ParticleManager.POOL_MAX);
+ this.integrationType = Particles.ParticleUtils.initValue(integrationType, ParticleManager.EULER);
+ this.emitters = [];
+ this.renderers = [];
+ this.time = 0;
+ this.oldTime = 0;
+ ParticleManager.pool = new Phaser.Particles.ParticlePool(proParticleCount);
+ ParticleManager.integrator = new Phaser.Particles.NumericalIntegration(this.integrationType);
+ }
+ ParticleManager.POOL_MAX = 1000;
+ ParticleManager.TIME_STEP = 60;
+ ParticleManager.MEASURE = 100;
+ ParticleManager.EULER = 'euler';
+ ParticleManager.RK2 = 'runge-kutta2';
+ ParticleManager.RK4 = 'runge-kutta4';
+ ParticleManager.VERLET = 'verlet';
+ ParticleManager.prototype.addRender = function (render) {
+ render.proton = this;
+ this.renderers.push(render.proton);
+ };
+ ParticleManager.prototype.addEmitter = function (emitter) {
+ this.emitters.push(emitter);
+ emitter.parent = this;
+ };
+ ParticleManager.prototype.removeEmitter = function (emitter) {
+ var index = this.emitters.indexOf(emitter);
+ this.emitters.splice(index, 1);
+ emitter.parent = null;
+ };
+ ParticleManager.prototype.update = function () {
+ if(!this.oldTime) {
+ this.oldTime = new Date().getTime();
+ }
+ var time = new Date().getTime();
+ this.elapsed = (time - this.oldTime) / 1000;
+ this.oldTime = time;
+ if(this.elapsed > 0) {
+ for(var i = 0; i < this.emitters.length; i++) {
+ this.emitters[i].update(this.elapsed);
+ }
+ }
+ };
+ ParticleManager.prototype.amendChangeTabsBugHandler = function () {
+ if(this.elapsed > .5) {
+ this.oldTime = new Date().getTime();
+ this.elapsed = 0;
+ }
+ };
+ ParticleManager.prototype.getParticleNumber = function () {
+ var total = 0;
+ for(var i = 0; i < this.emitters.length; i++) {
+ total += this.emitters[i].particles.length;
+ }
+ return total;
+ };
+ ParticleManager.prototype.destroy = function () {
+ for(var i = 0; i < this.emitters.length; i++) {
+ this.emitters[i].destory();
+ delete this.emitters[i];
+ }
+ this.emitters = [];
+ this.time = 0;
+ this.oldTime = 0;
+ ParticleManager.pool.release();
+ };
+ return ParticleManager;
+ })();
+ Particles.ParticleManager = ParticleManager;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Particle = (function () {
+ function Particle() {
+ this.life = Infinity;
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.sleep = false;
+ this.target = null;
+ this.sprite = null;
+ this.parent = null;
+ this.mass = 1;
+ this.radius = 10;
+ this.alpha = 1;
+ this.scale = 1;
+ this.rotation = 0;
+ this.color = null;
+ this.easing = Phaser.Easing.Linear.None;
+ this.p = new Phaser.Vec2();
+ this.v = new Phaser.Vec2();
+ this.a = new Phaser.Vec2();
+ this.old = {
+ p: new Phaser.Vec2(),
+ v: new Phaser.Vec2(),
+ a: new Phaser.Vec2()
+ };
+ this.behaviours = [];
+ this.id = 'particle_' + Particle.ID++;
+ this.reset(true);
+ }
+ Particle.ID = 0;
+ Particle.prototype.getDirection = function () {
+ return Math.atan2(this.v.x, -this.v.y) * (180 / Math.PI);
+ };
+ Particle.prototype.reset = function (init) {
+ this.life = Infinity;
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.sleep = false;
+ this.target = null;
+ this.sprite = null;
+ this.parent = null;
+ this.mass = 1;
+ this.radius = 10;
+ this.alpha = 1;
+ this.scale = 1;
+ this.rotation = 0;
+ this.color = null;
+ this.easing = Phaser.Easing.Linear.None;
+ if(init) {
+ this.transform = {
+ };
+ this.p = new Phaser.Vec2();
+ this.v = new Phaser.Vec2();
+ this.a = new Phaser.Vec2();
+ this.old = {
+ p: new Phaser.Vec2(),
+ v: new Phaser.Vec2(),
+ a: new Phaser.Vec2()
+ };
+ this.behaviours = [];
+ } else {
+ Particles.ParticleUtils.destroyObject(this.transform);
+ this.p.setTo(0, 0);
+ this.v.setTo(0, 0);
+ this.a.setTo(0, 0);
+ this.old.p.setTo(0, 0);
+ this.old.v.setTo(0, 0);
+ this.old.a.setTo(0, 0);
+ this.removeAllBehaviours();
+ }
+ this.transform.rgb = {
+ r: 255,
+ g: 255,
+ b: 255
+ };
+ return this;
+ };
+ Particle.prototype.update = function (time, index) {
+ if(!this.sleep) {
+ this.age += time;
+ var length = this.behaviours.length, i;
+ for(i = 0; i < length; i++) {
+ if(this.behaviours[i]) {
+ this.behaviours[i].applyBehaviour(this, time, index);
+ }
+ }
+ }
+ if(this.age >= this.life) {
+ this.destroy();
+ } else {
+ var scale = this.easing(this.age / this.life);
+ this.energy = Math.max(1 - scale, 0);
+ }
+ };
+ Particle.prototype.addBehaviour = function (behaviour) {
+ this.behaviours.push(behaviour);
+ if(behaviour.hasOwnProperty('parents')) {
+ behaviour.parents.push(this);
+ }
+ behaviour.initialize(this);
+ };
+ Particle.prototype.addBehaviours = function (behaviours) {
+ var length = behaviours.length, i;
+ for(i = 0; i < length; i++) {
+ this.addBehaviour(behaviours[i]);
+ }
+ };
+ Particle.prototype.removeBehaviour = function (behaviour) {
+ var index = this.behaviours.indexOf(behaviour);
+ if(index > -1) {
+ var outBehaviour = this.behaviours.splice(index, 1);
+ }
+ };
+ Particle.prototype.removeAllBehaviours = function () {
+ Particles.ParticleUtils.destroyArray(this.behaviours);
+ };
+ Particle.prototype.destroy = function () {
+ this.removeAllBehaviours();
+ this.energy = 0;
+ this.dead = true;
+ this.parent = null;
+ };
+ return Particle;
+ })();
+ Particles.Particle = Particle;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Emitter = (function () {
+ function Emitter(pObj) {
+ this.initializes = [];
+ this.particles = [];
+ this.behaviours = [];
+ this.emitTime = 0;
+ this.emitTotalTimes = -1;
+ this.initializes = [];
+ this.particles = [];
+ this.behaviours = [];
+ this.emitTime = 0;
+ this.emitTotalTimes = -1;
+ this.damping = .006;
+ this.bindEmitter = true;
+ this.rate = new Phaser.Particles.Initializers.Rate(1, .1);
+ this.id = 'emitter_' + Emitter.ID++;
+ }
+ Emitter.ID = 0;
+ Emitter.prototype.emit = function (emitTime, life) {
+ this.emitTime = 0;
+ this.emitTotalTimes = Particles.ParticleUtils.initValue(emitTime, Infinity);
+ if(life == true || life == 'life' || life == 'destroy') {
+ if(emitTime == 'once') {
+ this.life = 1;
+ } else {
+ this.life = this.emitTotalTimes;
+ }
+ } else if(!isNaN(life)) {
+ this.life = life;
+ }
+ this.rate.init();
+ };
+ Emitter.prototype.stopEmit = function () {
+ this.emitTotalTimes = -1;
+ this.emitTime = 0;
+ };
+ Emitter.prototype.removeAllParticles = function () {
+ for(var i = 0; i < this.particles.length; i++) {
+ this.particles[i].dead = true;
+ }
+ };
+ Emitter.prototype.createParticle = function (initialize, behaviour) {
+ if (typeof initialize === "undefined") { initialize = null; }
+ if (typeof behaviour === "undefined") { behaviour = null; }
+ var particle = Particles.ParticleManager.pool.get();
+ this.setupParticle(particle, initialize, behaviour);
+ return particle;
+ };
+ Emitter.prototype.addSelfInitialize = function (pObj) {
+ if(pObj['init']) {
+ pObj.init(this);
+ } else {
+ }
+ };
+ Emitter.prototype.addInitialize = function () {
+ var length = arguments.length, i;
+ for(i = 0; i < length; i++) {
+ this.initializes.push(arguments[i]);
+ }
+ };
+ Emitter.prototype.removeInitialize = function (initializer) {
+ var index = this.initializes.indexOf(initializer);
+ if(index > -1) {
+ this.initializes.splice(index, 1);
+ }
+ };
+ Emitter.prototype.removeInitializers = function () {
+ Particles.ParticleUtils.destroyArray(this.initializes);
+ };
+ Emitter.prototype.addBehaviour = function () {
+ var length = arguments.length, i;
+ for(i = 0; i < length; i++) {
+ this.behaviours.push(arguments[i]);
+ if(arguments[i].hasOwnProperty("parents")) {
+ arguments[i].parents.push(this);
+ }
+ }
+ };
+ Emitter.prototype.removeBehaviour = function (behaviour) {
+ var index = this.behaviours.indexOf(behaviour);
+ if(index > -1) {
+ this.behaviours.splice(index, 1);
+ }
+ };
+ Emitter.prototype.removeAllBehaviours = function () {
+ Particles.ParticleUtils.destroyArray(this.behaviours);
+ };
+ Emitter.prototype.integrate = function (time) {
+ var damping = 1 - this.damping;
+ Particles.ParticleManager.integrator.integrate(this, time, damping);
+ var length = this.particles.length, i;
+ for(i = 0; i < length; i++) {
+ var particle = this.particles[i];
+ particle.update(time, i);
+ Particles.ParticleManager.integrator.integrate(particle, time, damping);
+ }
+ };
+ Emitter.prototype.emitting = function (time) {
+ if(this.emitTotalTimes == 1) {
+ var length = this.rate.getValue(99999), i;
+ for(i = 0; i < length; i++) {
+ this.createParticle();
+ }
+ this.emitTotalTimes = 0;
+ } else if(!isNaN(this.emitTotalTimes)) {
+ this.emitTime += time;
+ if(this.emitTime < this.emitTotalTimes) {
+ var length = this.rate.getValue(time), i;
+ for(i = 0; i < length; i++) {
+ this.createParticle();
+ }
+ }
+ }
+ };
+ Emitter.prototype.update = function (time) {
+ this.age += time;
+ if(this.age >= this.life || this.dead) {
+ this.destroy();
+ }
+ this.emitting(time);
+ this.integrate(time);
+ var particle;
+ var length = this.particles.length, k;
+ for(k = length - 1; k >= 0; k--) {
+ particle = this.particles[k];
+ if(particle.dead) {
+ Particles.ParticleManager.pool.set(particle);
+ this.particles.splice(k, 1);
+ }
+ }
+ };
+ Emitter.prototype.setupParticle = function (particle, initialize, behaviour) {
+ var initializes = this.initializes;
+ var behaviours = this.behaviours;
+ if(initialize) {
+ if(initialize instanceof Array) {
+ initializes = initialize;
+ } else {
+ initializes = [
+ initialize
+ ];
+ }
+ }
+ if(behaviour) {
+ if(behaviour instanceof Array) {
+ behaviours = behaviour;
+ } else {
+ behaviours = [
+ behaviour
+ ];
+ }
+ }
+ particle.addBehaviours(behaviours);
+ particle.parent = this;
+ this.particles.push(particle);
+ };
+ Emitter.prototype.destroy = function () {
+ this.dead = true;
+ this.emitTotalTimes = -1;
+ if(this.particles.length == 0) {
+ this.removeInitializers();
+ this.removeAllBehaviours();
+ if(this.parent) {
+ this.parent.removeEmitter(this);
+ }
+ }
+ };
+ return Emitter;
+ })();
+ Particles.Emitter = Emitter;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var ParticlePool = (function () {
+ function ParticlePool(num, releaseTime) {
+ if (typeof releaseTime === "undefined") { releaseTime = 0; }
+ this.poolList = [];
+ this.timeoutID = 0;
+ this.proParticleCount = Particles.ParticleUtils.initValue(num, 0);
+ this.releaseTime = Particles.ParticleUtils.initValue(releaseTime, -1);
+ this.poolList = [];
+ this.timeoutID = 0;
+ for(var i = 0; i < this.proParticleCount; i++) {
+ this.add();
+ }
+ if(this.releaseTime > 0) {
+ this.timeoutID = setTimeout(this.release, this.releaseTime / 1000);
+ }
+ }
+ ParticlePool.prototype.create = function (newTypeParticleClass) {
+ if (typeof newTypeParticleClass === "undefined") { newTypeParticleClass = null; }
+ if(newTypeParticleClass) {
+ return new newTypeParticleClass();
+ } else {
+ return new Phaser.Particles.Particle();
+ }
+ };
+ ParticlePool.prototype.getCount = function () {
+ return this.poolList.length;
+ };
+ ParticlePool.prototype.add = function () {
+ return this.poolList.push(this.create());
+ };
+ ParticlePool.prototype.get = function () {
+ if(this.poolList.length === 0) {
+ return this.create();
+ } else {
+ return this.poolList.pop().reset();
+ }
+ };
+ ParticlePool.prototype.set = function (particle) {
+ if(this.poolList.length < Particles.ParticleManager.POOL_MAX) {
+ return this.poolList.push(particle);
+ }
+ };
+ ParticlePool.prototype.release = function () {
+ for(var i = 0; i < this.poolList.length; i++) {
+ if(this.poolList[i]['destroy']) {
+ this.poolList[i].destroy();
+ }
+ delete this.poolList[i];
+ }
+ this.poolList = [];
+ };
+ return ParticlePool;
+ })();
+ Particles.ParticlePool = ParticlePool;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var ParticleUtils = (function () {
+ function ParticleUtils() { }
+ ParticleUtils.initValue = function initValue(value, defaults) {
+ var value = (value != null && value != undefined) ? value : defaults;
+ return value;
+ };
+ ParticleUtils.isArray = function isArray(value) {
+ return typeof value === 'object' && value.hasOwnProperty('length');
+ };
+ ParticleUtils.destroyArray = function destroyArray(array) {
+ array.length = 0;
+ };
+ ParticleUtils.destroyObject = function destroyObject(obj) {
+ for(var o in obj) {
+ delete obj[o];
+ }
+ };
+ ParticleUtils.setSpanValue = function setSpanValue(a, b, c) {
+ if (typeof b === "undefined") { b = null; }
+ if (typeof c === "undefined") { c = null; }
+ if(a instanceof Phaser.Particles.Span) {
+ return a;
+ } else {
+ if(!b) {
+ return new Phaser.Particles.Span(a);
+ } else {
+ if(!c) {
+ return new Phaser.Particles.Span(a, b);
+ } else {
+ return new Phaser.Particles.Span(a, b, c);
+ }
+ }
+ }
+ };
+ ParticleUtils.getSpanValue = function getSpanValue(pan) {
+ if(pan instanceof Phaser.Particles.Span) {
+ return pan.getValue();
+ } else {
+ return pan;
+ }
+ };
+ ParticleUtils.randomAToB = function randomAToB(a, b, INT) {
+ if (typeof INT === "undefined") { INT = null; }
+ if(!INT) {
+ return a + Math.random() * (b - a);
+ } else {
+ return Math.floor(Math.random() * (b - a)) + a;
+ }
+ };
+ ParticleUtils.randomFloating = function randomFloating(center, f, INT) {
+ return ParticleUtils.randomAToB(center - f, center + f, INT);
+ };
+ ParticleUtils.randomZone = function randomZone(display) {
+ };
+ ParticleUtils.degreeTransform = function degreeTransform(a) {
+ return a * Math.PI / 180;
+ };
+ ParticleUtils.randomColor = function randomColor() {
+ return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
+ };
+ ParticleUtils.setEasingByName = function setEasingByName(name) {
+ switch(name) {
+ case 'easeLinear':
+ return Phaser.Easing.Linear.None;
+ break;
+ case 'easeInQuad':
+ return Phaser.Easing.Quadratic.In;
+ break;
+ case 'easeOutQuad':
+ return Phaser.Easing.Quadratic.Out;
+ break;
+ case 'easeInOutQuad':
+ return Phaser.Easing.Quadratic.InOut;
+ break;
+ case 'easeInCubic':
+ return Phaser.Easing.Cubic.In;
+ break;
+ case 'easeOutCubic':
+ return Phaser.Easing.Cubic.Out;
+ break;
+ case 'easeInOutCubic':
+ return Phaser.Easing.Cubic.InOut;
+ break;
+ case 'easeInQuart':
+ return Phaser.Easing.Quartic.In;
+ break;
+ case 'easeOutQuart':
+ return Phaser.Easing.Quartic.Out;
+ break;
+ case 'easeInOutQuart':
+ return Phaser.Easing.Quartic.InOut;
+ break;
+ case 'easeInSine':
+ return Phaser.Easing.Sinusoidal.In;
+ break;
+ case 'easeOutSine':
+ return Phaser.Easing.Sinusoidal.Out;
+ break;
+ case 'easeInOutSine':
+ return Phaser.Easing.Sinusoidal.InOut;
+ break;
+ case 'easeInExpo':
+ return Phaser.Easing.Exponential.In;
+ break;
+ case 'easeOutExpo':
+ return Phaser.Easing.Exponential.Out;
+ break;
+ case 'easeInOutExpo':
+ return Phaser.Easing.Exponential.InOut;
+ break;
+ case 'easeInCirc':
+ return Phaser.Easing.Circular.In;
+ break;
+ case 'easeOutCirc':
+ return Phaser.Easing.Circular.Out;
+ break;
+ case 'easeInOutCirc':
+ return Phaser.Easing.Circular.InOut;
+ break;
+ case 'easeInBack':
+ return Phaser.Easing.Back.In;
+ break;
+ case 'easeOutBack':
+ return Phaser.Easing.Back.Out;
+ break;
+ case 'easeInOutBack':
+ return Phaser.Easing.Back.InOut;
+ break;
+ default:
+ return Phaser.Easing.Linear.None;
+ break;
+ }
+ };
+ return ParticleUtils;
+ })();
+ Particles.ParticleUtils = ParticleUtils;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Polar2D = (function () {
+ function Polar2D(r, tha) {
+ this.r = Math.abs(r) || 0;
+ this.tha = tha || 0;
+ }
+ Polar2D.prototype.set = function (r, tha) {
+ this.r = r;
+ this.tha = tha;
+ return this;
+ };
+ Polar2D.prototype.setR = function (r) {
+ this.r = r;
+ return this;
+ };
+ Polar2D.prototype.setTha = function (tha) {
+ this.tha = tha;
+ return this;
+ };
+ Polar2D.prototype.copy = function (p) {
+ this.r = p.r;
+ this.tha = p.tha;
+ return this;
+ };
+ Polar2D.prototype.toVector = function () {
+ return new Phaser.Vec2(this.getX(), this.getY());
+ };
+ Polar2D.prototype.getX = function () {
+ return this.r * Math.sin(this.tha);
+ };
+ Polar2D.prototype.getY = function () {
+ return -this.r * Math.cos(this.tha);
+ };
+ Polar2D.prototype.normalize = function () {
+ this.r = 1;
+ return this;
+ };
+ Polar2D.prototype.equals = function (v) {
+ return ((v.r === this.r) && (v.tha === this.tha));
+ };
+ Polar2D.prototype.toArray = function () {
+ return [
+ this.r,
+ this.tha
+ ];
+ };
+ Polar2D.prototype.clear = function () {
+ this.r = 0.0;
+ this.tha = 0.0;
+ return this;
+ };
+ Polar2D.prototype.clone = function () {
+ return new Polar2D(this.r, this.tha);
+ };
+ return Polar2D;
+ })();
+ Particles.Polar2D = Polar2D;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var Span = (function () {
+ function Span(a, b, center) {
+ if (typeof b === "undefined") { b = null; }
+ if (typeof center === "undefined") { center = null; }
+ this.isArray = false;
+ if(Particles.ParticleUtils.isArray(a)) {
+ this.isArray = true;
+ this.a = a;
+ } else {
+ this.a = Particles.ParticleUtils.initValue(a, 1);
+ this.b = Particles.ParticleUtils.initValue(b, this.a);
+ this.center = Particles.ParticleUtils.initValue(center, false);
+ }
+ }
+ Span.prototype.getValue = function (INT) {
+ if (typeof INT === "undefined") { INT = null; }
+ if(this.isArray) {
+ return this.a[Math.floor(this.a.length * Math.random())];
+ } else {
+ if(!this.center) {
+ return Particles.ParticleUtils.randomAToB(this.a, this.b, INT);
+ } else {
+ return Particles.ParticleUtils.randomFloating(this.a, this.b, INT);
+ }
+ }
+ };
+ Span.getSpan = function getSpan(a, b, center) {
+ return new Span(a, b, center);
+ };
+ return Span;
+ })();
+ Particles.Span = Span;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ var NumericalIntegration = (function () {
+ function NumericalIntegration(type) {
+ this.type = Particles.ParticleUtils.initValue(type, Particles.ParticleManager.EULER);
+ }
+ NumericalIntegration.prototype.integrate = function (particles, time, damping) {
+ this.eulerIntegrate(particles, time, damping);
+ };
+ NumericalIntegration.prototype.eulerIntegrate = function (particle, time, damping) {
+ if(!particle.sleep) {
+ particle.old.p.copy(particle.p);
+ particle.old.v.copy(particle.v);
+ particle.a.multiplyScalar(1 / particle.mass);
+ particle.v.add(particle.a.multiplyScalar(time));
+ particle.p.add(particle.old.v.multiplyScalar(time));
+ if(damping) {
+ particle.v.multiplyScalar(damping);
+ }
+ particle.a.clear();
+ }
+ };
+ return NumericalIntegration;
+ })();
+ Particles.NumericalIntegration = NumericalIntegration;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Behaviours) {
+ var Behaviour = (function () {
+ function Behaviour(life, easing) {
+ this.id = 'Behaviour_' + Behaviour.ID++;
+ this.life = Particles.ParticleUtils.initValue(life, Infinity);
+ this.easing = Particles.ParticleUtils.setEasingByName(easing);
+ this.age = 0;
+ this.energy = 1;
+ this.dead = false;
+ this.parents = [];
+ this.name = 'Behaviour';
+ }
+ Behaviour.prototype.normalizeForce = function (force) {
+ return force.multiplyScalar(Particles.ParticleManager.MEASURE);
+ };
+ Behaviour.prototype.normalizeValue = function (value) {
+ return value * Particles.ParticleManager.MEASURE;
+ };
+ Behaviour.prototype.initialize = function (particle) {
+ };
+ Behaviour.prototype.applyBehaviour = function (particle, time, index) {
+ this.age += time;
+ if(this.age >= this.life || this.dead) {
+ this.energy = 0;
+ this.dead = true;
+ this.destroy();
+ } else {
+ var scale = this.easing(particle.age / particle.life);
+ this.energy = Math.max(1 - scale, 0);
+ }
+ };
+ Behaviour.prototype.destroy = function () {
+ var index;
+ var length = this.parents.length, i;
+ for(i = 0; i < length; i++) {
+ this.parents[i].removeBehaviour(this);
+ }
+ this.parents = [];
+ };
+ return Behaviour;
+ })();
+ Behaviours.Behaviour = Behaviour;
+ })(Particles.Behaviours || (Particles.Behaviours = {}));
+ var Behaviours = Particles.Behaviours;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Behaviours) {
+ var RandomDrift = (function (_super) {
+ __extends(RandomDrift, _super);
+ function RandomDrift(driftX, driftY, delay, life, easing) {
+ _super.call(this, life, easing);
+ this.reset(driftX, driftY, delay);
+ this.time = 0;
+ this.name = "RandomDrift";
+ }
+ RandomDrift.prototype.reset = function (driftX, driftY, delay, life, easing) {
+ if (typeof life === "undefined") { life = null; }
+ if (typeof easing === "undefined") { easing = null; }
+ this.panFoce = new Phaser.Vec2(driftX, driftY);
+ this.panFoce = this.normalizeForce(this.panFoce);
+ this.delay = delay;
+ if(life) {
+ this.life = Particles.ParticleUtils.initValue(life, Infinity);
+ this.easing = Particles.ParticleUtils.initValue(easing, Phaser.Easing.Linear.None);
+ }
+ };
+ RandomDrift.prototype.applyBehaviour = function (particle, time, index) {
+ _super.prototype.applyBehaviour.call(this, particle, time, index);
+ this.time += time;
+ if(this.time >= this.delay) {
+ particle.a.addXY(Particles.ParticleUtils.randomAToB(-this.panFoce.x, this.panFoce.x), Particles.ParticleUtils.randomAToB(-this.panFoce.y, this.panFoce.y));
+ this.time = 0;
+ }
+ };
+ return RandomDrift;
+ })(Behaviours.Behaviour);
+ Behaviours.RandomDrift = RandomDrift;
+ })(Particles.Behaviours || (Particles.Behaviours = {}));
+ var Behaviours = Particles.Behaviours;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Initialize = (function () {
+ function Initialize() { }
+ Initialize.prototype.initialize = function (target) {
+ };
+ Initialize.prototype.reset = function (a, b, c) {
+ };
+ Initialize.prototype.init = function (emitter, particle) {
+ if (typeof particle === "undefined") { particle = null; }
+ if(particle) {
+ this.initialize(particle);
+ } else {
+ this.initialize(emitter);
+ }
+ };
+ return Initialize;
+ })();
+ Initializers.Initialize = Initialize;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Life = (function (_super) {
+ __extends(Life, _super);
+ function Life(a, b, c) {
+ _super.call(this);
+ this.lifePan = Particles.ParticleUtils.setSpanValue(a, b, c);
+ }
+ Life.prototype.initialize = function (target) {
+ if(this.lifePan.a == Infinity) {
+ target.life = Infinity;
+ } else {
+ target.life = this.lifePan.getValue();
+ }
+ };
+ return Life;
+ })(Initializers.Initialize);
+ Initializers.Life = Life;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Mass = (function (_super) {
+ __extends(Mass, _super);
+ function Mass(a, b, c) {
+ _super.call(this);
+ this.massPan = Particles.ParticleUtils.setSpanValue(a, b, c);
+ }
+ Mass.prototype.initialize = function (target) {
+ target.mass = this.massPan.getValue();
+ };
+ return Mass;
+ })(Initializers.Initialize);
+ Initializers.Mass = Mass;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Position = (function (_super) {
+ __extends(Position, _super);
+ function Position(zone) {
+ _super.call(this);
+ if(zone != null && zone != undefined) {
+ this.zone = zone;
+ } else {
+ this.zone = new Phaser.Particles.Zones.PointZone();
+ }
+ }
+ Position.prototype.reset = function (zone) {
+ if(zone != null && zone != undefined) {
+ this.zone = zone;
+ } else {
+ this.zone = new Phaser.Particles.Zones.PointZone();
+ }
+ };
+ Position.prototype.initialize = function (target) {
+ this.zone.getPosition();
+ target.p.x = this.zone.vector.x;
+ target.p.y = this.zone.vector.y;
+ };
+ return Position;
+ })(Initializers.Initialize);
+ Initializers.Position = Position;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Rate = (function (_super) {
+ __extends(Rate, _super);
+ function Rate(numpan, timepan) {
+ _super.call(this);
+ numpan = Particles.ParticleUtils.initValue(numpan, 1);
+ timepan = Particles.ParticleUtils.initValue(timepan, 1);
+ this.numPan = new Phaser.Particles.Span(numpan);
+ this.timePan = new Phaser.Particles.Span(timepan);
+ this.startTime = 0;
+ this.nextTime = 0;
+ this.init();
+ }
+ Rate.prototype.init = function () {
+ this.startTime = 0;
+ this.nextTime = this.timePan.getValue();
+ };
+ Rate.prototype.getValue = function (time) {
+ this.startTime += time;
+ if(this.startTime >= this.nextTime) {
+ this.startTime = 0;
+ this.nextTime = this.timePan.getValue();
+ if(this.numPan.b == 1) {
+ if(this.numPan.getValue(false) > 0.5) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } else {
+ return this.numPan.getValue(true);
+ }
+ }
+ return 0;
+ };
+ return Rate;
+ })(Initializers.Initialize);
+ Initializers.Rate = Rate;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Initializers) {
+ var Velocity = (function (_super) {
+ __extends(Velocity, _super);
+ function Velocity(rpan, thapan, type) {
+ _super.call(this);
+ this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
+ this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
+ this.type = Particles.ParticleUtils.initValue(type, 'vector');
+ }
+ Velocity.prototype.reset = function (rpan, thapan, type) {
+ this.rPan = Particles.ParticleUtils.setSpanValue(rpan);
+ this.thaPan = Particles.ParticleUtils.setSpanValue(thapan);
+ this.type = Particles.ParticleUtils.initValue(type, 'vector');
+ };
+ Velocity.prototype.normalizeVelocity = function (vr) {
+ return vr * Particles.ParticleManager.MEASURE;
+ };
+ Velocity.prototype.initialize = function (target) {
+ if(this.type == 'p' || this.type == 'P' || this.type == 'polar') {
+ var polar2d = new Particles.Polar2D(this.normalizeVelocity(this.rPan.getValue()), this.thaPan.getValue() * Math.PI / 180);
+ target.v.x = polar2d.getX();
+ target.v.y = polar2d.getY();
+ } else {
+ target.v.x = this.normalizeVelocity(this.rPan.getValue());
+ target.v.y = this.normalizeVelocity(this.thaPan.getValue());
+ }
+ };
+ return Velocity;
+ })(Initializers.Initialize);
+ Initializers.Velocity = Velocity;
+ })(Particles.Initializers || (Particles.Initializers = {}));
+ var Initializers = Particles.Initializers;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Zones) {
+ var Zone = (function () {
+ function Zone() {
+ this.vector = new Phaser.Vec2();
+ this.random = 0;
+ this.crossType = "dead";
+ this.alert = true;
+ }
+ return Zone;
+ })();
+ Zones.Zone = Zone;
+ })(Particles.Zones || (Particles.Zones = {}));
+ var Zones = Particles.Zones;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ (function (Particles) {
+ (function (Zones) {
+ var PointZone = (function (_super) {
+ __extends(PointZone, _super);
+ function PointZone(x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
+ _super.call(this);
+ this.x = x;
+ this.y = y;
+ }
+ PointZone.prototype.getPosition = function () {
+ return this.vector.setTo(this.x, this.y);
+ };
+ PointZone.prototype.crossing = function (particle) {
+ if(this.alert) {
+ alert('Sorry PointZone does not support crossing method');
+ this.alert = false;
+ }
+ };
+ return PointZone;
+ })(Zones.Zone);
+ Zones.PointZone = PointZone;
+ })(Particles.Zones || (Particles.Zones = {}));
+ var Zones = Particles.Zones;
+ })(Phaser.Particles || (Phaser.Particles = {}));
+ var Particles = Phaser.Particles;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var World = (function () {
+ function World(game, width, height) {
+ this._groupCounter = 0;
+ this.game = game;
+ this.cameras = new Phaser.CameraManager(this.game, 0, 0, width, height);
+ this.bounds = new Phaser.Rectangle(0, 0, width, height);
+ }
+ World.prototype.getNextGroupID = function () {
+ return this._groupCounter++;
+ };
+ World.prototype.boot = function () {
+ this.group = new Phaser.Group(this.game, 0);
+ };
+ World.prototype.update = function () {
+ this.group.update();
+ this.cameras.update();
+ };
+ World.prototype.postUpdate = function () {
+ this.group.postUpdate();
+ this.cameras.postUpdate();
+ };
+ World.prototype.destroy = function () {
+ this.group.destroy();
+ this.cameras.destroy();
+ };
+ World.prototype.setSize = function (width, height, updateCameraBounds) {
+ if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; }
+ this.bounds.width = width;
+ this.bounds.height = height;
+ if(updateCameraBounds == true) {
+ this.game.camera.setBounds(0, 0, width, height);
+ }
+ };
+ Object.defineProperty(World.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ set: function (value) {
+ this.bounds.width = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ set: function (value) {
+ this.bounds.height = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "centerX", {
+ get: function () {
+ return this.bounds.halfWidth;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "centerY", {
+ get: function () {
+ return this.bounds.halfHeight;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "randomX", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.width);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(World.prototype, "randomY", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.height);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ World.prototype.getAllCameras = function () {
+ return this.cameras.getAll();
+ };
+ return World;
+ })();
+ Phaser.World = World;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Stage = (function () {
+ function Stage(game, parent, width, height) {
+ var _this = this;
+ this._backgroundColor = 'rgb(0,0,0)';
+ this.clear = true;
+ this.disablePauseScreen = false;
+ this.disableBootScreen = false;
+ this.disableVisibilityChange = false;
+ this.game = game;
+ this.canvas = document.createElement('canvas');
+ this.canvas.width = width;
+ this.canvas.height = height;
+ this.context = this.canvas.getContext('2d');
+ Phaser.CanvasUtils.addToDOM(this.canvas, parent, true);
+ Phaser.CanvasUtils.setTouchAction(this.canvas);
+ this.canvas.oncontextmenu = function (event) {
+ event.preventDefault();
+ };
+ this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
+ this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
+ this.scale = new Phaser.StageScaleMode(this.game, width, height);
+ this.getOffset(this.canvas);
+ this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, width, height);
+ this.aspectRatio = width / height;
+ document.addEventListener('visibilitychange', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ document.addEventListener('webkitvisibilitychange', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ document.addEventListener('pagehide', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ document.addEventListener('pageshow', function (event) {
+ return _this.visibilityChange(event);
+ }, false);
+ window.onblur = function (event) {
+ return _this.visibilityChange(event);
+ };
+ window.onfocus = function (event) {
+ return _this.visibilityChange(event);
+ };
+ }
+ Stage.prototype.boot = function () {
+ this.bootScreen = new Phaser.BootScreen(this.game);
+ this.pauseScreen = new Phaser.PauseScreen(this.game, this.width, this.height);
+ this.orientationScreen = new Phaser.OrientationScreen(this.game);
+ this.scale.setScreenSize(true);
+ };
+ Stage.prototype.update = function () {
+ this.scale.update();
+ this.context.setTransform(1, 0, 0, 1, 0, 0);
+ if(this.clear || (this.game.paused && this.disablePauseScreen == false)) {
+ if(this.game.device.patchAndroidClearRectBug) {
+ this.context.fillStyle = this._backgroundColor;
+ this.context.fillRect(0, 0, this.width, this.height);
+ } else {
+ this.context.clearRect(0, 0, this.width, this.height);
+ }
+ }
+ if(this.game.paused && this.scale.incorrectOrientation) {
+ this.orientationScreen.update();
+ this.orientationScreen.render();
+ return;
+ }
+ if(this.game.isRunning == false && this.disableBootScreen == false) {
+ this.bootScreen.update();
+ this.bootScreen.render();
+ }
+ if(this.game.paused && this.disablePauseScreen == false) {
+ this.pauseScreen.update();
+ this.pauseScreen.render();
+ }
+ };
+ Stage.prototype.visibilityChange = function (event) {
+ if(this.disableVisibilityChange) {
+ return;
+ }
+ if(event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) {
+ if(this.game.paused == false) {
+ this.pauseGame();
+ }
+ } else {
+ if(this.game.paused == true) {
+ this.resumeGame();
+ }
+ }
+ };
+ Stage.prototype.enableOrientationCheck = function (forceLandscape, forcePortrait, imageKey) {
+ if (typeof imageKey === "undefined") { imageKey = ''; }
+ this.scale.forceLandscape = forceLandscape;
+ this.scale.forcePortrait = forcePortrait;
+ this.orientationScreen.enable(forceLandscape, forcePortrait, imageKey);
+ if(forceLandscape || forcePortrait) {
+ if((this.scale.isLandscape && forcePortrait) || (this.scale.isPortrait && forceLandscape)) {
+ this.game.paused = true;
+ this.scale.incorrectOrientation = true;
+ } else {
+ this.scale.incorrectOrientation = false;
+ }
+ }
+ };
+ Stage.prototype.pauseGame = function () {
+ this.game.paused = true;
+ if(this.disablePauseScreen == false && this.pauseScreen) {
+ this.pauseScreen.onPaused();
+ }
+ this.saveCanvasValues();
+ };
+ Stage.prototype.resumeGame = function () {
+ if(this.disablePauseScreen == false && this.pauseScreen) {
+ this.pauseScreen.onResume();
+ }
+ this.restoreCanvasValues();
+ this.game.paused = false;
+ };
+ Stage.prototype.getOffset = function (element, populateOffset) {
+ if (typeof populateOffset === "undefined") { populateOffset = true; }
+ var box = element.getBoundingClientRect();
+ var clientTop = element.clientTop || document.body.clientTop || 0;
+ var clientLeft = element.clientLeft || document.body.clientLeft || 0;
+ var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop;
+ var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft;
+ if(populateOffset) {
+ this.offset = new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
+ return this.offset;
+ } else {
+ return new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
+ }
+ };
+ Stage.prototype.saveCanvasValues = function () {
+ this.strokeStyle = this.context.strokeStyle;
+ this.lineWidth = this.context.lineWidth;
+ this.fillStyle = this.context.fillStyle;
+ };
+ Stage.prototype.restoreCanvasValues = function () {
+ this.context.strokeStyle = this.strokeStyle;
+ this.context.lineWidth = this.lineWidth;
+ this.context.fillStyle = this.fillStyle;
+ if(this.game.device.patchAndroidClearRectBug) {
+ this.context.fillStyle = this._backgroundColor;
+ this.context.fillRect(0, 0, this.width, this.height);
+ } else {
+ this.context.clearRect(0, 0, this.width, this.height);
+ }
+ };
+ Object.defineProperty(Stage.prototype, "backgroundColor", {
+ get: function () {
+ return this._backgroundColor;
+ },
+ set: function (color) {
+ this.canvas.style.backgroundColor = color;
+ this._backgroundColor = color;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "x", {
+ get: function () {
+ return this.bounds.x;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "y", {
+ get: function () {
+ return this.bounds.y;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "width", {
+ get: function () {
+ return this.bounds.width;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "height", {
+ get: function () {
+ return this.bounds.height;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "centerX", {
+ get: function () {
+ return this.bounds.halfWidth;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "centerY", {
+ get: function () {
+ return this.bounds.halfHeight;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "randomX", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.width);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Stage.prototype, "randomY", {
+ get: function () {
+ return Math.round(Math.random() * this.bounds.height);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Stage;
+ })();
+ Phaser.Stage = Stage;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var State = (function () {
+ 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.sound = game.sound;
+ this.stage = game.stage;
+ this.time = game.time;
+ this.tweens = game.tweens;
+ this.world = game.world;
+ }
+ State.prototype.init = function () {
+ };
+ State.prototype.create = function () {
+ };
+ State.prototype.update = function () {
+ };
+ State.prototype.render = function () {
+ };
+ State.prototype.paused = function () {
+ };
+ State.prototype.destroy = function () {
+ };
+ return State;
+ })();
+ Phaser.State = State;
+})(Phaser || (Phaser = {}));
+var Phaser;
+(function (Phaser) {
+ var Game = (function () {
+ function Game(callbackContext, parent, width, height, preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
+ if (typeof parent === "undefined") { parent = ''; }
+ if (typeof width === "undefined") { width = 800; }
+ if (typeof height === "undefined") { height = 600; }
+ if (typeof preloadCallback === "undefined") { preloadCallback = null; }
+ if (typeof createCallback === "undefined") { createCallback = null; }
+ if (typeof updateCallback === "undefined") { updateCallback = null; }
+ if (typeof renderCallback === "undefined") { renderCallback = null; }
+ if (typeof destroyCallback === "undefined") { destroyCallback = null; }
+ var _this = this;
+ this._loadComplete = false;
+ this._paused = false;
+ this._pendingState = null;
+ this.state = null;
+ this.onPreloadCallback = null;
+ this.onCreateCallback = null;
+ this.onUpdateCallback = null;
+ this.onRenderCallback = null;
+ this.onPreRenderCallback = null;
+ this.onLoadUpdateCallback = null;
+ this.onLoadRenderCallback = null;
+ this.onPausedCallback = null;
+ this.onDestroyCallback = null;
+ this.isBooted = false;
+ this.isRunning = false;
+ this.id = Phaser.GAMES.push(this) - 1;
+ this.callbackContext = callbackContext;
+ this.onPreloadCallback = preloadCallback;
+ this.onCreateCallback = createCallback;
+ this.onUpdateCallback = updateCallback;
+ this.onRenderCallback = renderCallback;
+ this.onDestroyCallback = destroyCallback;
+ if(document.readyState === 'complete' || document.readyState === 'interactive') {
+ setTimeout(function () {
+ return Phaser.GAMES[_this.id].boot(parent, width, height);
+ });
+ } else {
+ document.addEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot(parent, width, height), false);
+ window.addEventListener('load', Phaser.GAMES[this.id].boot(parent, width, height), false);
+ }
+ }
+ Game.prototype.boot = function (parent, width, height) {
+ var _this = this;
+ if(this.isBooted == true) {
+ return;
+ }
+ if(!document.body) {
+ setTimeout(function () {
+ return Phaser.GAMES[_this.id].boot(parent, width, height);
+ }, 13);
+ } else {
+ document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
+ window.removeEventListener('load', Phaser.GAMES[this.id].boot);
+ this.onPause = new Phaser.Signal();
+ this.onResume = new Phaser.Signal();
+ this.device = new Phaser.Device();
+ this.net = new Phaser.Net(this);
+ this.math = new Phaser.GameMath(this);
+ this.stage = new Phaser.Stage(this, parent, width, height);
+ this.world = new Phaser.World(this, width, height);
+ this.add = new Phaser.GameObjectFactory(this);
+ this.cache = new Phaser.Cache(this);
+ this.load = new Phaser.Loader(this);
+ this.time = new Phaser.TimeManager(this);
+ this.tweens = new Phaser.TweenManager(this);
+ this.input = new Phaser.InputManager(this);
+ this.sound = new Phaser.SoundManager(this);
+ this.rnd = new Phaser.RandomDataGenerator([
+ (Date.now() * Math.random()).toString()
+ ]);
+ this.physics = new Phaser.Physics.PhysicsManager(this);
+ this.plugins = new Phaser.PluginManager(this, this);
+ this.load.onLoadComplete.add(this.loadComplete, this);
+ this.setRenderer(Phaser.Types.RENDERER_CANVAS);
+ this.world.boot();
+ this.stage.boot();
+ this.input.boot();
+ this.isBooted = true;
+ Phaser.DebugUtils.game = this;
+ Phaser.ColorUtils.game = this;
+ Phaser.DebugUtils.context = this.stage.context;
+ if(this.onPreloadCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null) {
+ this._raf = new Phaser.RequestAnimationFrame(this, this.bootLoop);
+ } else {
+ this.isRunning = true;
+ this._loadComplete = false;
+ this._raf = new Phaser.RequestAnimationFrame(this, this.loop);
+ if(this._pendingState) {
+ this.switchState(this._pendingState, false, false);
+ } else {
+ this.startState();
+ }
+ }
+ }
+ };
+ Game.prototype.loadComplete = function () {
+ this._loadComplete = true;
+ this.onCreateCallback.call(this.callbackContext);
+ };
+ Game.prototype.bootLoop = function () {
+ this.tweens.update();
+ this.input.update();
+ this.stage.update();
+ };
+ Game.prototype.pausedLoop = function () {
+ this.tweens.update();
+ this.input.update();
+ this.stage.update();
+ this.sound.update();
+ if(this.onPausedCallback !== null) {
+ this.onPausedCallback.call(this.callbackContext);
+ }
+ };
+ Game.prototype.loop = function () {
+ this.plugins.preUpdate();
+ this.tweens.update();
+ this.input.update();
+ this.stage.update();
+ this.sound.update();
+ this.physics.update();
+ this.world.update();
+ this.plugins.update();
+ if(this._loadComplete && this.onUpdateCallback) {
+ this.onUpdateCallback.call(this.callbackContext);
+ } else if(this._loadComplete == false && this.onLoadUpdateCallback) {
+ this.onLoadUpdateCallback.call(this.callbackContext);
+ }
+ this.world.postUpdate();
+ this.plugins.postUpdate();
+ this.plugins.preRender();
+ if(this._loadComplete && this.onPreRenderCallback) {
+ this.onPreRenderCallback.call(this.callbackContext);
+ }
+ this.renderer.render();
+ this.plugins.render();
+ if(this._loadComplete && this.onRenderCallback) {
+ this.onRenderCallback.call(this.callbackContext);
+ } else if(this._loadComplete == false && this.onLoadRenderCallback) {
+ this.onLoadRenderCallback.call(this.callbackContext);
+ }
+ this.plugins.postRender();
+ };
+ Game.prototype.startState = function () {
+ if(this.onPreloadCallback !== null) {
+ this.load.reset();
+ this.onPreloadCallback.call(this.callbackContext);
+ if(this.load.queueSize == 0) {
+ if(this.onCreateCallback !== null) {
+ this.onCreateCallback.call(this.callbackContext);
+ }
+ this._loadComplete = true;
+ } else {
+ this.load.onLoadComplete.add(this.loadComplete, this);
+ this.load.start();
+ }
+ } else {
+ if(this.onCreateCallback !== null) {
+ this.onCreateCallback.call(this.callbackContext);
+ }
+ this._loadComplete = true;
+ }
+ };
+ Game.prototype.setRenderer = function (renderer) {
+ switch(renderer) {
+ case Phaser.Types.RENDERER_AUTO_DETECT:
+ this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
+ break;
+ case Phaser.Types.RENDERER_AUTO_DETECT:
+ case Phaser.Types.RENDERER_CANVAS:
+ this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
+ break;
+ }
+ };
+ Game.prototype.setCallbacks = function (preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
+ if (typeof preloadCallback === "undefined") { preloadCallback = null; }
+ if (typeof createCallback === "undefined") { createCallback = null; }
+ if (typeof updateCallback === "undefined") { updateCallback = null; }
+ if (typeof renderCallback === "undefined") { renderCallback = null; }
+ if (typeof destroyCallback === "undefined") { destroyCallback = null; }
+ this.onPreloadCallback = preloadCallback;
+ this.onCreateCallback = createCallback;
+ this.onUpdateCallback = updateCallback;
+ this.onRenderCallback = renderCallback;
+ this.onDestroyCallback = destroyCallback;
+ };
+ Game.prototype.switchState = function (state, clearWorld, clearCache) {
+ if (typeof clearWorld === "undefined") { clearWorld = true; }
+ if (typeof clearCache === "undefined") { clearCache = false; }
+ if(this.isBooted == false) {
+ this._pendingState = state;
+ return;
+ }
+ if(this.onDestroyCallback !== null) {
+ this.onDestroyCallback.call(this.callbackContext);
+ }
+ this.input.reset(true);
+ if(typeof state === 'function') {
+ this.state = new state(this);
+ }
+ if(this.state['create'] || this.state['update']) {
+ this.callbackContext = this.state;
+ this.onPreloadCallback = null;
+ this.onLoadRenderCallback = null;
+ this.onLoadUpdateCallback = null;
+ this.onCreateCallback = null;
+ this.onUpdateCallback = null;
+ this.onRenderCallback = null;
+ this.onPreRenderCallback = null;
+ this.onPausedCallback = null;
+ this.onDestroyCallback = null;
+ if(this.state['preload']) {
+ this.onPreloadCallback = this.state['preload'];
+ }
+ if(this.state['loadRender']) {
+ this.onLoadRenderCallback = this.state['loadRender'];
+ }
+ if(this.state['loadUpdate']) {
+ this.onLoadUpdateCallback = this.state['loadUpdate'];
+ }
+ if(this.state['create']) {
+ this.onCreateCallback = this.state['create'];
+ }
+ if(this.state['update']) {
+ this.onUpdateCallback = this.state['update'];
+ }
+ if(this.state['preRender']) {
+ this.onPreRenderCallback = this.state['preRender'];
+ }
+ if(this.state['render']) {
+ this.onRenderCallback = this.state['render'];
+ }
+ if(this.state['paused']) {
+ this.onPausedCallback = this.state['paused'];
+ }
+ if(this.state['destroy']) {
+ this.onDestroyCallback = this.state['destroy'];
+ }
+ if(clearWorld) {
+ this.world.destroy();
+ if(clearCache == true) {
+ this.cache.destroy();
+ }
+ }
+ this._loadComplete = false;
+ this.startState();
+ } else {
+ throw new Error("Invalid State object given. Must contain at least a create or update function.");
+ }
+ };
+ Game.prototype.destroy = function () {
+ this.callbackContext = null;
+ this.onPreloadCallback = null;
+ this.onLoadRenderCallback = null;
+ this.onLoadUpdateCallback = null;
+ this.onCreateCallback = null;
+ this.onUpdateCallback = null;
+ this.onRenderCallback = null;
+ this.onPausedCallback = null;
+ this.onDestroyCallback = null;
+ this.cache = null;
+ this.input = null;
+ this.load = null;
+ this.sound = null;
+ this.stage = null;
+ this.time = null;
+ this.world = null;
+ this.isBooted = false;
+ };
+ Object.defineProperty(Game.prototype, "paused", {
+ get: function () {
+ return this._paused;
+ },
+ set: function (value) {
+ if(value == true && this._paused == false) {
+ this._paused = true;
+ this.onPause.dispatch();
+ this.sound.pauseAll();
+ this._raf.callback = this.pausedLoop;
+ } else if(value == false && this._paused == true) {
+ this._paused = false;
+ this.onResume.dispatch();
+ this.input.reset();
+ this.sound.resumeAll();
+ if(this.isRunning == false) {
+ this._raf.callback = this.bootLoop;
+ } else {
+ this._raf.callback = this.loop;
+ }
+ }
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Game.prototype, "camera", {
+ get: function () {
+ return this.world.cameras.current;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ return Game;
+ })();
+ Phaser.Game = Game;
+})(Phaser || (Phaser = {}));
diff --git a/Tests/assets/mp3/SoundEffects/alien_death1.wav b/examples/assets/audio/SoundEffects/alien_death1.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/alien_death1.wav
rename to examples/assets/audio/SoundEffects/alien_death1.wav
diff --git a/Tests/assets/mp3/SoundEffects/battery.wav b/examples/assets/audio/SoundEffects/battery.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/battery.wav
rename to examples/assets/audio/SoundEffects/battery.wav
diff --git a/Tests/assets/mp3/SoundEffects/boss_hit.wav b/examples/assets/audio/SoundEffects/boss_hit.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/boss_hit.wav
rename to examples/assets/audio/SoundEffects/boss_hit.wav
diff --git a/Tests/assets/mp3/SoundEffects/door_open.wav b/examples/assets/audio/SoundEffects/door_open.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/door_open.wav
rename to examples/assets/audio/SoundEffects/door_open.wav
diff --git a/Tests/assets/mp3/SoundEffects/escape.wav b/examples/assets/audio/SoundEffects/escape.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/escape.wav
rename to examples/assets/audio/SoundEffects/escape.wav
diff --git a/Tests/assets/mp3/SoundEffects/explode1.wav b/examples/assets/audio/SoundEffects/explode1.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/explode1.wav
rename to examples/assets/audio/SoundEffects/explode1.wav
diff --git a/Tests/assets/mp3/SoundEffects/key.wav b/examples/assets/audio/SoundEffects/key.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/key.wav
rename to examples/assets/audio/SoundEffects/key.wav
diff --git a/Tests/assets/mp3/SoundEffects/lazer.wav b/examples/assets/audio/SoundEffects/lazer.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/lazer.wav
rename to examples/assets/audio/SoundEffects/lazer.wav
diff --git a/Tests/assets/mp3/SoundEffects/lazer_wall_off.mp3 b/examples/assets/audio/SoundEffects/lazer_wall_off.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/lazer_wall_off.mp3
rename to examples/assets/audio/SoundEffects/lazer_wall_off.mp3
diff --git a/Tests/assets/mp3/SoundEffects/menu_select.mp3 b/examples/assets/audio/SoundEffects/menu_select.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/menu_select.mp3
rename to examples/assets/audio/SoundEffects/menu_select.mp3
diff --git a/Tests/assets/mp3/SoundEffects/menu_switch.mp3 b/examples/assets/audio/SoundEffects/menu_switch.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/menu_switch.mp3
rename to examples/assets/audio/SoundEffects/menu_switch.mp3
diff --git a/Tests/assets/mp3/SoundEffects/meow1.mp3 b/examples/assets/audio/SoundEffects/meow1.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/meow1.mp3
rename to examples/assets/audio/SoundEffects/meow1.mp3
diff --git a/Tests/assets/mp3/SoundEffects/meow2.mp3 b/examples/assets/audio/SoundEffects/meow2.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/meow2.mp3
rename to examples/assets/audio/SoundEffects/meow2.mp3
diff --git a/Tests/assets/mp3/SoundEffects/need_cells.wav b/examples/assets/audio/SoundEffects/need_cells.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/need_cells.wav
rename to examples/assets/audio/SoundEffects/need_cells.wav
diff --git a/Tests/assets/mp3/SoundEffects/numkey.wav b/examples/assets/audio/SoundEffects/numkey.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/numkey.wav
rename to examples/assets/audio/SoundEffects/numkey.wav
diff --git a/Tests/assets/mp3/SoundEffects/numkey_wrong.wav b/examples/assets/audio/SoundEffects/numkey_wrong.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/numkey_wrong.wav
rename to examples/assets/audio/SoundEffects/numkey_wrong.wav
diff --git a/Tests/assets/mp3/SoundEffects/p-ping.mp3 b/examples/assets/audio/SoundEffects/p-ping.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/p-ping.mp3
rename to examples/assets/audio/SoundEffects/p-ping.mp3
diff --git a/Tests/assets/mp3/SoundEffects/pickup.wav b/examples/assets/audio/SoundEffects/pickup.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/pickup.wav
rename to examples/assets/audio/SoundEffects/pickup.wav
diff --git a/Tests/assets/mp3/SoundEffects/pistol.wav b/examples/assets/audio/SoundEffects/pistol.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/pistol.wav
rename to examples/assets/audio/SoundEffects/pistol.wav
diff --git a/Tests/assets/mp3/SoundEffects/player_death.wav b/examples/assets/audio/SoundEffects/player_death.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/player_death.wav
rename to examples/assets/audio/SoundEffects/player_death.wav
diff --git a/Tests/assets/mp3/SoundEffects/pusher.wav b/examples/assets/audio/SoundEffects/pusher.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/pusher.wav
rename to examples/assets/audio/SoundEffects/pusher.wav
diff --git a/Tests/assets/mp3/SoundEffects/sentry_explode.wav b/examples/assets/audio/SoundEffects/sentry_explode.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/sentry_explode.wav
rename to examples/assets/audio/SoundEffects/sentry_explode.wav
diff --git a/Tests/assets/mp3/SoundEffects/shot1.wav b/examples/assets/audio/SoundEffects/shot1.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/shot1.wav
rename to examples/assets/audio/SoundEffects/shot1.wav
diff --git a/Tests/assets/mp3/SoundEffects/shot2.wav b/examples/assets/audio/SoundEffects/shot2.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/shot2.wav
rename to examples/assets/audio/SoundEffects/shot2.wav
diff --git a/Tests/assets/mp3/SoundEffects/shotgun.wav b/examples/assets/audio/SoundEffects/shotgun.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/shotgun.wav
rename to examples/assets/audio/SoundEffects/shotgun.wav
diff --git a/Tests/assets/mp3/SoundEffects/spaceman.wav b/examples/assets/audio/SoundEffects/spaceman.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/spaceman.wav
rename to examples/assets/audio/SoundEffects/spaceman.wav
diff --git a/Tests/assets/mp3/SoundEffects/squit.wav b/examples/assets/audio/SoundEffects/squit.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/squit.wav
rename to examples/assets/audio/SoundEffects/squit.wav
diff --git a/Tests/assets/mp3/SoundEffects/steps1.mp3 b/examples/assets/audio/SoundEffects/steps1.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/steps1.mp3
rename to examples/assets/audio/SoundEffects/steps1.mp3
diff --git a/Tests/assets/mp3/SoundEffects/steps2.mp3 b/examples/assets/audio/SoundEffects/steps2.mp3
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/steps2.mp3
rename to examples/assets/audio/SoundEffects/steps2.mp3
diff --git a/Tests/assets/mp3/SoundEffects/wall.wav b/examples/assets/audio/SoundEffects/wall.wav
similarity index 100%
rename from Tests/assets/mp3/SoundEffects/wall.wav
rename to examples/assets/audio/SoundEffects/wall.wav
diff --git a/Tests/assets/mp3/bodenstaendig_2000_in_rock_4bit.mp3 b/examples/assets/audio/bodenstaendig_2000_in_rock_4bit.mp3
similarity index 100%
rename from Tests/assets/mp3/bodenstaendig_2000_in_rock_4bit.mp3
rename to examples/assets/audio/bodenstaendig_2000_in_rock_4bit.mp3
diff --git a/Tests/assets/mp3/goaman_intro.mp3 b/examples/assets/audio/goaman_intro.mp3
similarity index 100%
rename from Tests/assets/mp3/goaman_intro.mp3
rename to examples/assets/audio/goaman_intro.mp3
diff --git a/Tests/assets/mp3/oedipus_ark_pandora.mp3 b/examples/assets/audio/oedipus_ark_pandora.mp3
similarity index 100%
rename from Tests/assets/mp3/oedipus_ark_pandora.mp3
rename to examples/assets/audio/oedipus_ark_pandora.mp3
diff --git a/Tests/assets/mp3/oedipus_wizball_highscore.mp3 b/examples/assets/audio/oedipus_wizball_highscore.mp3
similarity index 100%
rename from Tests/assets/mp3/oedipus_wizball_highscore.mp3
rename to examples/assets/audio/oedipus_wizball_highscore.mp3
diff --git a/Tests/assets/mp3/oedipus_wizball_highscore.ogg b/examples/assets/audio/oedipus_wizball_highscore.ogg
similarity index 100%
rename from Tests/assets/mp3/oedipus_wizball_highscore.ogg
rename to examples/assets/audio/oedipus_wizball_highscore.ogg
diff --git a/Tests/assets/mp3/oedipus_wizball_highscore.xmp b/examples/assets/audio/oedipus_wizball_highscore.xmp
similarity index 100%
rename from Tests/assets/mp3/oedipus_wizball_highscore.xmp
rename to examples/assets/audio/oedipus_wizball_highscore.xmp
diff --git a/Tests/assets/mp3/tommy_in_goa.mp3 b/examples/assets/audio/tommy_in_goa.mp3
similarity index 100%
rename from Tests/assets/mp3/tommy_in_goa.mp3
rename to examples/assets/audio/tommy_in_goa.mp3
diff --git a/Tests/assets/buttons/arrow-button.png b/examples/assets/buttons/arrow-button.png
similarity index 100%
rename from Tests/assets/buttons/arrow-button.png
rename to examples/assets/buttons/arrow-button.png
diff --git a/Tests/assets/buttons/baddie-buttons.png b/examples/assets/buttons/baddie-buttons.png
similarity index 100%
rename from Tests/assets/buttons/baddie-buttons.png
rename to examples/assets/buttons/baddie-buttons.png
diff --git a/Tests/assets/buttons/button_sprite_sheet.png b/examples/assets/buttons/button_sprite_sheet.png
similarity index 100%
rename from Tests/assets/buttons/button_sprite_sheet.png
rename to examples/assets/buttons/button_sprite_sheet.png
diff --git a/Tests/assets/buttons/button_texture_atlas.json b/examples/assets/buttons/button_texture_atlas.json
similarity index 100%
rename from Tests/assets/buttons/button_texture_atlas.json
rename to examples/assets/buttons/button_texture_atlas.json
diff --git a/Tests/assets/buttons/button_texture_atlas.png b/examples/assets/buttons/button_texture_atlas.png
similarity index 100%
rename from Tests/assets/buttons/button_texture_atlas.png
rename to examples/assets/buttons/button_texture_atlas.png
diff --git a/Tests/assets/buttons/follow-style-button.png b/examples/assets/buttons/follow-style-button.png
similarity index 100%
rename from Tests/assets/buttons/follow-style-button.png
rename to examples/assets/buttons/follow-style-button.png
diff --git a/Tests/assets/buttons/number-buttons-90x90.png b/examples/assets/buttons/number-buttons-90x90.png
similarity index 100%
rename from Tests/assets/buttons/number-buttons-90x90.png
rename to examples/assets/buttons/number-buttons-90x90.png
diff --git a/Tests/assets/buttons/number-buttons.png b/examples/assets/buttons/number-buttons.png
similarity index 100%
rename from Tests/assets/buttons/number-buttons.png
rename to examples/assets/buttons/number-buttons.png
diff --git a/Tests/assets/buttons/revive-button.png b/examples/assets/buttons/revive-button.png
similarity index 100%
rename from Tests/assets/buttons/revive-button.png
rename to examples/assets/buttons/revive-button.png
diff --git a/Tests/assets/buttons/spacebar.png b/examples/assets/buttons/spacebar.png
similarity index 100%
rename from Tests/assets/buttons/spacebar.png
rename to examples/assets/buttons/spacebar.png
diff --git a/Tests/assets/fonts/032.png b/examples/assets/fonts/032.png
similarity index 100%
rename from Tests/assets/fonts/032.png
rename to examples/assets/fonts/032.png
diff --git a/Tests/assets/fonts/036.png b/examples/assets/fonts/036.png
similarity index 100%
rename from Tests/assets/fonts/036.png
rename to examples/assets/fonts/036.png
diff --git a/Tests/assets/fonts/047.png b/examples/assets/fonts/047.png
similarity index 100%
rename from Tests/assets/fonts/047.png
rename to examples/assets/fonts/047.png
diff --git a/Tests/assets/fonts/070.png b/examples/assets/fonts/070.png
similarity index 100%
rename from Tests/assets/fonts/070.png
rename to examples/assets/fonts/070.png
diff --git a/Tests/assets/fonts/072.png b/examples/assets/fonts/072.png
similarity index 100%
rename from Tests/assets/fonts/072.png
rename to examples/assets/fonts/072.png
diff --git a/Tests/assets/fonts/087.png b/examples/assets/fonts/087.png
similarity index 100%
rename from Tests/assets/fonts/087.png
rename to examples/assets/fonts/087.png
diff --git a/Tests/assets/fonts/110.png b/examples/assets/fonts/110.png
similarity index 100%
rename from Tests/assets/fonts/110.png
rename to examples/assets/fonts/110.png
diff --git a/Tests/assets/fonts/141.png b/examples/assets/fonts/141.png
similarity index 100%
rename from Tests/assets/fonts/141.png
rename to examples/assets/fonts/141.png
diff --git a/Tests/assets/fonts/165.png b/examples/assets/fonts/165.png
similarity index 100%
rename from Tests/assets/fonts/165.png
rename to examples/assets/fonts/165.png
diff --git a/Tests/assets/fonts/16x16-blue-metal.png b/examples/assets/fonts/16x16-blue-metal.png
similarity index 100%
rename from Tests/assets/fonts/16x16-blue-metal.png
rename to examples/assets/fonts/16x16-blue-metal.png
diff --git a/Tests/assets/fonts/16x16-cool-metal.png b/examples/assets/fonts/16x16-cool-metal.png
similarity index 100%
rename from Tests/assets/fonts/16x16-cool-metal.png
rename to examples/assets/fonts/16x16-cool-metal.png
diff --git a/Tests/assets/fonts/171.png b/examples/assets/fonts/171.png
similarity index 100%
rename from Tests/assets/fonts/171.png
rename to examples/assets/fonts/171.png
diff --git a/Tests/assets/fonts/1984-nocooper-tebirod_logo.png b/examples/assets/fonts/1984-nocooper-tebirod_logo.png
similarity index 100%
rename from Tests/assets/fonts/1984-nocooper-tebirod_logo.png
rename to examples/assets/fonts/1984-nocooper-tebirod_logo.png
diff --git a/Tests/assets/fonts/225.png b/examples/assets/fonts/225.png
similarity index 100%
rename from Tests/assets/fonts/225.png
rename to examples/assets/fonts/225.png
diff --git a/Tests/assets/fonts/231.png b/examples/assets/fonts/231.png
similarity index 100%
rename from Tests/assets/fonts/231.png
rename to examples/assets/fonts/231.png
diff --git a/Tests/assets/fonts/260.png b/examples/assets/fonts/260.png
similarity index 100%
rename from Tests/assets/fonts/260.png
rename to examples/assets/fonts/260.png
diff --git a/Tests/assets/fonts/283.png b/examples/assets/fonts/283.png
similarity index 100%
rename from Tests/assets/fonts/283.png
rename to examples/assets/fonts/283.png
diff --git a/Tests/assets/fonts/284.png b/examples/assets/fonts/284.png
similarity index 100%
rename from Tests/assets/fonts/284.png
rename to examples/assets/fonts/284.png
diff --git a/Tests/assets/fonts/297.png b/examples/assets/fonts/297.png
similarity index 100%
rename from Tests/assets/fonts/297.png
rename to examples/assets/fonts/297.png
diff --git a/Tests/assets/fonts/313.png b/examples/assets/fonts/313.png
similarity index 100%
rename from Tests/assets/fonts/313.png
rename to examples/assets/fonts/313.png
diff --git a/Tests/assets/fonts/8x9_golden.png b/examples/assets/fonts/8x9_golden.png
similarity index 100%
rename from Tests/assets/fonts/8x9_golden.png
rename to examples/assets/fonts/8x9_golden.png
diff --git a/Tests/assets/fonts/ACFRESET.png b/examples/assets/fonts/ACFRESET.png
similarity index 100%
rename from Tests/assets/fonts/ACFRESET.png
rename to examples/assets/fonts/ACFRESET.png
diff --git a/Tests/assets/fonts/FONT3.png b/examples/assets/fonts/FONT3.png
similarity index 100%
rename from Tests/assets/fonts/FONT3.png
rename to examples/assets/fonts/FONT3.png
diff --git a/Tests/assets/fonts/KNIGHT3.png b/examples/assets/fonts/KNIGHT3.png
similarity index 100%
rename from Tests/assets/fonts/KNIGHT3.png
rename to examples/assets/fonts/KNIGHT3.png
diff --git a/Tests/assets/fonts/MEGADETH.GIF b/examples/assets/fonts/MEGADETH.GIF
similarity index 100%
rename from Tests/assets/fonts/MEGADETH.GIF
rename to examples/assets/fonts/MEGADETH.GIF
diff --git a/Tests/assets/fonts/MEGAMINI.GIF b/examples/assets/fonts/MEGAMINI.GIF
similarity index 100%
rename from Tests/assets/fonts/MEGAMINI.GIF
rename to examples/assets/fonts/MEGAMINI.GIF
diff --git a/Tests/assets/fonts/PICKPILE.png b/examples/assets/fonts/PICKPILE.png
similarity index 100%
rename from Tests/assets/fonts/PICKPILE.png
rename to examples/assets/fonts/PICKPILE.png
diff --git a/Tests/assets/fonts/STEEL.png b/examples/assets/fonts/STEEL.png
similarity index 100%
rename from Tests/assets/fonts/STEEL.png
rename to examples/assets/fonts/STEEL.png
diff --git a/Tests/assets/fonts/ST_ADM.GIF b/examples/assets/fonts/ST_ADM.GIF
similarity index 100%
rename from Tests/assets/fonts/ST_ADM.GIF
rename to examples/assets/fonts/ST_ADM.GIF
diff --git a/Tests/assets/fonts/WAYNE_3D.png b/examples/assets/fonts/WAYNE_3D.png
similarity index 100%
rename from Tests/assets/fonts/WAYNE_3D.png
rename to examples/assets/fonts/WAYNE_3D.png
diff --git a/Tests/assets/fonts/bluepink_font.png b/examples/assets/fonts/bluepink_font.png
similarity index 100%
rename from Tests/assets/fonts/bluepink_font.png
rename to examples/assets/fonts/bluepink_font.png
diff --git a/Tests/assets/fonts/bubbles_font.png b/examples/assets/fonts/bubbles_font.png
similarity index 100%
rename from Tests/assets/fonts/bubbles_font.png
rename to examples/assets/fonts/bubbles_font.png
diff --git a/Tests/assets/fonts/deltaforce_font.png b/examples/assets/fonts/deltaforce_font.png
similarity index 100%
rename from Tests/assets/fonts/deltaforce_font.png
rename to examples/assets/fonts/deltaforce_font.png
diff --git a/Tests/assets/fonts/digits_font_ilkke.png b/examples/assets/fonts/digits_font_ilkke.png
similarity index 100%
rename from Tests/assets/fonts/digits_font_ilkke.png
rename to examples/assets/fonts/digits_font_ilkke.png
diff --git a/Tests/assets/fonts/gold_font.png b/examples/assets/fonts/gold_font.png
similarity index 100%
rename from Tests/assets/fonts/gold_font.png
rename to examples/assets/fonts/gold_font.png
diff --git a/Tests/assets/fonts/grid_legend_font_aliased.png b/examples/assets/fonts/grid_legend_font_aliased.png
similarity index 100%
rename from Tests/assets/fonts/grid_legend_font_aliased.png
rename to examples/assets/fonts/grid_legend_font_aliased.png
diff --git a/Tests/assets/fonts/grid_legend_font_solid.png b/examples/assets/fonts/grid_legend_font_solid.png
similarity index 100%
rename from Tests/assets/fonts/grid_legend_font_solid.png
rename to examples/assets/fonts/grid_legend_font_solid.png
diff --git a/Tests/assets/fonts/knighthawks_font.png b/examples/assets/fonts/knighthawks_font.png
similarity index 100%
rename from Tests/assets/fonts/knighthawks_font.png
rename to examples/assets/fonts/knighthawks_font.png
diff --git a/Tests/assets/fonts/naos_font.png b/examples/assets/fonts/naos_font.png
similarity index 100%
rename from Tests/assets/fonts/naos_font.png
rename to examples/assets/fonts/naos_font.png
diff --git a/Tests/assets/fonts/robocop_font.png b/examples/assets/fonts/robocop_font.png
similarity index 100%
rename from Tests/assets/fonts/robocop_font.png
rename to examples/assets/fonts/robocop_font.png
diff --git a/Tests/assets/fonts/spaz_font.png b/examples/assets/fonts/spaz_font.png
similarity index 100%
rename from Tests/assets/fonts/spaz_font.png
rename to examples/assets/fonts/spaz_font.png
diff --git a/Tests/assets/fonts/steelpp_font.png b/examples/assets/fonts/steelpp_font.png
similarity index 100%
rename from Tests/assets/fonts/steelpp_font.png
rename to examples/assets/fonts/steelpp_font.png
diff --git a/Tests/assets/fonts/tbj_font.png b/examples/assets/fonts/tbj_font.png
similarity index 100%
rename from Tests/assets/fonts/tbj_font.png
rename to examples/assets/fonts/tbj_font.png
diff --git a/Tests/assets/fonts/tsk_font.png b/examples/assets/fonts/tsk_font.png
similarity index 100%
rename from Tests/assets/fonts/tsk_font.png
rename to examples/assets/fonts/tsk_font.png
diff --git a/Tests/assets/games/f1/car1.png b/examples/assets/games/f1/car1.png
similarity index 100%
rename from Tests/assets/games/f1/car1.png
rename to examples/assets/games/f1/car1.png
diff --git a/Tests/assets/games/f1/track.png b/examples/assets/games/f1/track.png
similarity index 100%
rename from Tests/assets/games/f1/track.png
rename to examples/assets/games/f1/track.png
diff --git a/Tests/assets/maps/catastrophi_level1.csv b/examples/assets/maps/catastrophi_level1.csv
similarity index 100%
rename from Tests/assets/maps/catastrophi_level1.csv
rename to examples/assets/maps/catastrophi_level1.csv
diff --git a/Tests/assets/maps/catastrophi_level2.csv b/examples/assets/maps/catastrophi_level2.csv
similarity index 100%
rename from Tests/assets/maps/catastrophi_level2.csv
rename to examples/assets/maps/catastrophi_level2.csv
diff --git a/Tests/assets/maps/catastrophi_level3.csv b/examples/assets/maps/catastrophi_level3.csv
similarity index 100%
rename from Tests/assets/maps/catastrophi_level3.csv
rename to examples/assets/maps/catastrophi_level3.csv
diff --git a/Tests/assets/maps/compass grid.tmx b/examples/assets/maps/compass grid.tmx
similarity index 100%
rename from Tests/assets/maps/compass grid.tmx
rename to examples/assets/maps/compass grid.tmx
diff --git a/Tests/assets/maps/desert.json b/examples/assets/maps/desert.json
similarity index 100%
rename from Tests/assets/maps/desert.json
rename to examples/assets/maps/desert.json
diff --git a/Tests/assets/maps/desert2.json b/examples/assets/maps/desert2.json
similarity index 100%
rename from Tests/assets/maps/desert2.json
rename to examples/assets/maps/desert2.json
diff --git a/Tests/assets/maps/map draw.tmx b/examples/assets/maps/map draw.tmx
similarity index 100%
rename from Tests/assets/maps/map draw.tmx
rename to examples/assets/maps/map draw.tmx
diff --git a/Tests/assets/maps/mapCSV_Group1_Map1.csv b/examples/assets/maps/mapCSV_Group1_Map1.csv
similarity index 100%
rename from Tests/assets/maps/mapCSV_Group1_Map1.csv
rename to examples/assets/maps/mapCSV_Group1_Map1.csv
diff --git a/Tests/assets/maps/mapCSV_SciFi_Map1.csv b/examples/assets/maps/mapCSV_SciFi_Map1.csv
similarity index 100%
rename from Tests/assets/maps/mapCSV_SciFi_Map1.csv
rename to examples/assets/maps/mapCSV_SciFi_Map1.csv
diff --git a/Tests/assets/maps/mapdraw.json b/examples/assets/maps/mapdraw.json
similarity index 100%
rename from Tests/assets/maps/mapdraw.json
rename to examples/assets/maps/mapdraw.json
diff --git a/Tests/assets/maps/multi-layer-test.json b/examples/assets/maps/multi-layer-test.json
similarity index 100%
rename from Tests/assets/maps/multi-layer-test.json
rename to examples/assets/maps/multi-layer-test.json
diff --git a/Tests/assets/maps/platform-test-1.json b/examples/assets/maps/platform-test-1.json
similarity index 100%
rename from Tests/assets/maps/platform-test-1.json
rename to examples/assets/maps/platform-test-1.json
diff --git a/Tests/assets/maps/platformer_map.csv b/examples/assets/maps/platformer_map.csv
similarity index 100%
rename from Tests/assets/maps/platformer_map.csv
rename to examples/assets/maps/platformer_map.csv
diff --git a/Tests/assets/maps/shmup_level_1_map.csv b/examples/assets/maps/shmup_level_1_map.csv
similarity index 100%
rename from Tests/assets/maps/shmup_level_1_map.csv
rename to examples/assets/maps/shmup_level_1_map.csv
diff --git a/Tests/assets/maps/test.json b/examples/assets/maps/test.json
similarity index 100%
rename from Tests/assets/maps/test.json
rename to examples/assets/maps/test.json
diff --git a/Tests/assets/misc/NSLIDE6A_020.bmp b/examples/assets/misc/NSLIDE6A_020.bmp
similarity index 100%
rename from Tests/assets/misc/NSLIDE6A_020.bmp
rename to examples/assets/misc/NSLIDE6A_020.bmp
diff --git a/Tests/assets/misc/baddie1.png b/examples/assets/misc/baddie1.png
similarity index 100%
rename from Tests/assets/misc/baddie1.png
rename to examples/assets/misc/baddie1.png
diff --git a/Tests/assets/misc/baddie2.png b/examples/assets/misc/baddie2.png
similarity index 100%
rename from Tests/assets/misc/baddie2.png
rename to examples/assets/misc/baddie2.png
diff --git a/Tests/assets/misc/boss1.png b/examples/assets/misc/boss1.png
similarity index 100%
rename from Tests/assets/misc/boss1.png
rename to examples/assets/misc/boss1.png
diff --git a/Tests/assets/misc/bullet0.png b/examples/assets/misc/bullet0.png
similarity index 100%
rename from Tests/assets/misc/bullet0.png
rename to examples/assets/misc/bullet0.png
diff --git a/Tests/assets/misc/bullet1.png b/examples/assets/misc/bullet1.png
similarity index 100%
rename from Tests/assets/misc/bullet1.png
rename to examples/assets/misc/bullet1.png
diff --git a/Tests/assets/misc/bullet2.png b/examples/assets/misc/bullet2.png
similarity index 100%
rename from Tests/assets/misc/bullet2.png
rename to examples/assets/misc/bullet2.png
diff --git a/Tests/assets/misc/ceiling_texture.png b/examples/assets/misc/ceiling_texture.png
similarity index 100%
rename from Tests/assets/misc/ceiling_texture.png
rename to examples/assets/misc/ceiling_texture.png
diff --git a/Tests/assets/misc/enemy-fire-1.png b/examples/assets/misc/enemy-fire-1.png
similarity index 100%
rename from Tests/assets/misc/enemy-fire-1.png
rename to examples/assets/misc/enemy-fire-1.png
diff --git a/Tests/assets/misc/explode1.png b/examples/assets/misc/explode1.png
similarity index 100%
rename from Tests/assets/misc/explode1.png
rename to examples/assets/misc/explode1.png
diff --git a/Tests/assets/misc/map-japan.png b/examples/assets/misc/map-japan.png
similarity index 100%
rename from Tests/assets/misc/map-japan.png
rename to examples/assets/misc/map-japan.png
diff --git a/Tests/assets/misc/map-newyork.png b/examples/assets/misc/map-newyork.png
similarity index 100%
rename from Tests/assets/misc/map-newyork.png
rename to examples/assets/misc/map-newyork.png
diff --git a/Tests/assets/misc/particle_small.png b/examples/assets/misc/particle_small.png
similarity index 100%
rename from Tests/assets/misc/particle_small.png
rename to examples/assets/misc/particle_small.png
diff --git a/Tests/assets/misc/particle_smallest.png b/examples/assets/misc/particle_smallest.png
similarity index 100%
rename from Tests/assets/misc/particle_smallest.png
rename to examples/assets/misc/particle_smallest.png
diff --git a/Tests/assets/misc/plane-shadow.png b/examples/assets/misc/plane-shadow.png
similarity index 100%
rename from Tests/assets/misc/plane-shadow.png
rename to examples/assets/misc/plane-shadow.png
diff --git a/Tests/assets/misc/plane-sheet.png b/examples/assets/misc/plane-sheet.png
similarity index 100%
rename from Tests/assets/misc/plane-sheet.png
rename to examples/assets/misc/plane-sheet.png
diff --git a/Tests/assets/misc/star_particle.png b/examples/assets/misc/star_particle.png
similarity index 100%
rename from Tests/assets/misc/star_particle.png
rename to examples/assets/misc/star_particle.png
diff --git a/Tests/assets/misc/starfield.jpg b/examples/assets/misc/starfield.jpg
similarity index 100%
rename from Tests/assets/misc/starfield.jpg
rename to examples/assets/misc/starfield.jpg
diff --git a/Tests/assets/misc/starfield.png b/examples/assets/misc/starfield.png
similarity index 100%
rename from Tests/assets/misc/starfield.png
rename to examples/assets/misc/starfield.png
diff --git a/Tests/assets/misc/water_texture.jpg b/examples/assets/misc/water_texture.jpg
similarity index 100%
rename from Tests/assets/misc/water_texture.jpg
rename to examples/assets/misc/water_texture.jpg
diff --git a/Tests/assets/pics/1984-nocooper-space.png b/examples/assets/pics/1984-nocooper-space.png
similarity index 100%
rename from Tests/assets/pics/1984-nocooper-space.png
rename to examples/assets/pics/1984-nocooper-space.png
diff --git a/Tests/assets/pics/WARZONE.png b/examples/assets/pics/WARZONE.png
similarity index 100%
rename from Tests/assets/pics/WARZONE.png
rename to examples/assets/pics/WARZONE.png
diff --git a/Tests/assets/pics/acryl_bladerunner.png b/examples/assets/pics/acryl_bladerunner.png
similarity index 100%
rename from Tests/assets/pics/acryl_bladerunner.png
rename to examples/assets/pics/acryl_bladerunner.png
diff --git a/Tests/assets/pics/acryl_bobablast.png b/examples/assets/pics/acryl_bobablast.png
similarity index 100%
rename from Tests/assets/pics/acryl_bobablast.png
rename to examples/assets/pics/acryl_bobablast.png
diff --git a/Tests/assets/pics/agent-t-buggin-acf_logo.png b/examples/assets/pics/agent-t-buggin-acf_logo.png
similarity index 100%
rename from Tests/assets/pics/agent-t-buggin-acf_logo.png
rename to examples/assets/pics/agent-t-buggin-acf_logo.png
diff --git a/Tests/assets/pics/alex-bisleys_horsy_5.png b/examples/assets/pics/alex-bisleys_horsy_5.png
similarity index 100%
rename from Tests/assets/pics/alex-bisleys_horsy_5.png
rename to examples/assets/pics/alex-bisleys_horsy_5.png
diff --git a/Tests/assets/pics/alpha-test.png b/examples/assets/pics/alpha-test.png
similarity index 100%
rename from Tests/assets/pics/alpha-test.png
rename to examples/assets/pics/alpha-test.png
diff --git a/Tests/assets/pics/atari_fujilogo.png b/examples/assets/pics/atari_fujilogo.png
similarity index 100%
rename from Tests/assets/pics/atari_fujilogo.png
rename to examples/assets/pics/atari_fujilogo.png
diff --git a/Tests/assets/pics/auto_scroll_landscape.png b/examples/assets/pics/auto_scroll_landscape.png
similarity index 100%
rename from Tests/assets/pics/auto_scroll_landscape.png
rename to examples/assets/pics/auto_scroll_landscape.png
diff --git a/Tests/assets/pics/aya_touhou_teng_soldier.png b/examples/assets/pics/aya_touhou_teng_soldier.png
similarity index 100%
rename from Tests/assets/pics/aya_touhou_teng_soldier.png
rename to examples/assets/pics/aya_touhou_teng_soldier.png
diff --git a/Tests/assets/pics/cactuar.png b/examples/assets/pics/cactuar.png
similarity index 100%
rename from Tests/assets/pics/cactuar.png
rename to examples/assets/pics/cactuar.png
diff --git a/Tests/assets/pics/cockpit.png b/examples/assets/pics/cockpit.png
similarity index 100%
rename from Tests/assets/pics/cockpit.png
rename to examples/assets/pics/cockpit.png
diff --git a/Tests/assets/pics/color-wheel.png b/examples/assets/pics/color-wheel.png
similarity index 100%
rename from Tests/assets/pics/color-wheel.png
rename to examples/assets/pics/color-wheel.png
diff --git a/Tests/assets/pics/color_wheel_swirl.png b/examples/assets/pics/color_wheel_swirl.png
similarity index 100%
rename from Tests/assets/pics/color_wheel_swirl.png
rename to examples/assets/pics/color_wheel_swirl.png
diff --git a/Tests/assets/pics/coma-zero_gravity.png b/examples/assets/pics/coma-zero_gravity.png
similarity index 100%
rename from Tests/assets/pics/coma-zero_gravity.png
rename to examples/assets/pics/coma-zero_gravity.png
diff --git a/Tests/assets/pics/cougar-face_of_nature.png b/examples/assets/pics/cougar-face_of_nature.png
similarity index 100%
rename from Tests/assets/pics/cougar-face_of_nature.png
rename to examples/assets/pics/cougar-face_of_nature.png
diff --git a/Tests/assets/pics/cougar_dragonsun.png b/examples/assets/pics/cougar_dragonsun.png
similarity index 100%
rename from Tests/assets/pics/cougar_dragonsun.png
rename to examples/assets/pics/cougar_dragonsun.png
diff --git a/Tests/assets/pics/destop-rewarding.png b/examples/assets/pics/destop-rewarding.png
similarity index 100%
rename from Tests/assets/pics/destop-rewarding.png
rename to examples/assets/pics/destop-rewarding.png
diff --git a/Tests/assets/pics/destop-unknown.png b/examples/assets/pics/destop-unknown.png
similarity index 100%
rename from Tests/assets/pics/destop-unknown.png
rename to examples/assets/pics/destop-unknown.png
diff --git a/Tests/assets/pics/devilstar_demo_download_disk.png b/examples/assets/pics/devilstar_demo_download_disk.png
similarity index 100%
rename from Tests/assets/pics/devilstar_demo_download_disk.png
rename to examples/assets/pics/devilstar_demo_download_disk.png
diff --git a/Tests/assets/pics/dr_ick.png b/examples/assets/pics/dr_ick.png
similarity index 100%
rename from Tests/assets/pics/dr_ick.png
rename to examples/assets/pics/dr_ick.png
diff --git a/Tests/assets/pics/dragonwiz.png b/examples/assets/pics/dragonwiz.png
similarity index 100%
rename from Tests/assets/pics/dragonwiz.png
rename to examples/assets/pics/dragonwiz.png
diff --git a/Tests/assets/pics/fof_background.png b/examples/assets/pics/fof_background.png
similarity index 100%
rename from Tests/assets/pics/fof_background.png
rename to examples/assets/pics/fof_background.png
diff --git a/Tests/assets/pics/game14_angel_dawn.png b/examples/assets/pics/game14_angel_dawn.png
similarity index 100%
rename from Tests/assets/pics/game14_angel_dawn.png
rename to examples/assets/pics/game14_angel_dawn.png
diff --git a/Tests/assets/pics/havoc-plastic_surgery.png b/examples/assets/pics/havoc-plastic_surgery.png
similarity index 100%
rename from Tests/assets/pics/havoc-plastic_surgery.png
rename to examples/assets/pics/havoc-plastic_surgery.png
diff --git a/Tests/assets/pics/hotshot-chaos_in_tokyo.png b/examples/assets/pics/hotshot-chaos_in_tokyo.png
similarity index 100%
rename from Tests/assets/pics/hotshot-chaos_in_tokyo.png
rename to examples/assets/pics/hotshot-chaos_in_tokyo.png
diff --git a/Tests/assets/pics/jim_sachs_time_crystal.png b/examples/assets/pics/jim_sachs_time_crystal.png
similarity index 100%
rename from Tests/assets/pics/jim_sachs_time_crystal.png
rename to examples/assets/pics/jim_sachs_time_crystal.png
diff --git a/Tests/assets/pics/kris-jovo.jpg b/examples/assets/pics/kris-jovo.jpg
similarity index 100%
rename from Tests/assets/pics/kris-jovo.jpg
rename to examples/assets/pics/kris-jovo.jpg
diff --git a/Tests/assets/pics/ladycop.png b/examples/assets/pics/ladycop.png
similarity index 100%
rename from Tests/assets/pics/ladycop.png
rename to examples/assets/pics/ladycop.png
diff --git a/Tests/assets/pics/lance-overdose-loader_eye.png b/examples/assets/pics/lance-overdose-loader_eye.png
similarity index 100%
rename from Tests/assets/pics/lance-overdose-loader_eye.png
rename to examples/assets/pics/lance-overdose-loader_eye.png
diff --git a/Tests/assets/pics/large-color-wheel.png b/examples/assets/pics/large-color-wheel.png
similarity index 100%
rename from Tests/assets/pics/large-color-wheel.png
rename to examples/assets/pics/large-color-wheel.png
diff --git a/Tests/assets/pics/lazur_skkaay3.png b/examples/assets/pics/lazur_skkaay3.png
similarity index 100%
rename from Tests/assets/pics/lazur_skkaay3.png
rename to examples/assets/pics/lazur_skkaay3.png
diff --git a/Tests/assets/pics/louie-inga.png b/examples/assets/pics/louie-inga.png
similarity index 100%
rename from Tests/assets/pics/louie-inga.png
rename to examples/assets/pics/louie-inga.png
diff --git a/Tests/assets/pics/mack_golden_girl.png b/examples/assets/pics/mack_golden_girl.png
similarity index 100%
rename from Tests/assets/pics/mack_golden_girl.png
rename to examples/assets/pics/mack_golden_girl.png
diff --git a/Tests/assets/pics/mask-test.png b/examples/assets/pics/mask-test.png
similarity index 100%
rename from Tests/assets/pics/mask-test.png
rename to examples/assets/pics/mask-test.png
diff --git a/Tests/assets/pics/mask-test2.png b/examples/assets/pics/mask-test2.png
similarity index 100%
rename from Tests/assets/pics/mask-test2.png
rename to examples/assets/pics/mask-test2.png
diff --git a/Tests/assets/pics/nanoha_taiken_blue.png b/examples/assets/pics/nanoha_taiken_blue.png
similarity index 100%
rename from Tests/assets/pics/nanoha_taiken_blue.png
rename to examples/assets/pics/nanoha_taiken_blue.png
diff --git a/Tests/assets/pics/nanoha_taiken_pink.png b/examples/assets/pics/nanoha_taiken_pink.png
similarity index 100%
rename from Tests/assets/pics/nanoha_taiken_pink.png
rename to examples/assets/pics/nanoha_taiken_pink.png
diff --git a/Tests/assets/pics/nanoha_taiken_purple.png b/examples/assets/pics/nanoha_taiken_purple.png
similarity index 100%
rename from Tests/assets/pics/nanoha_taiken_purple.png
rename to examples/assets/pics/nanoha_taiken_purple.png
diff --git a/Tests/assets/pics/ninja-masters2.png b/examples/assets/pics/ninja-masters2.png
similarity index 100%
rename from Tests/assets/pics/ninja-masters2.png
rename to examples/assets/pics/ninja-masters2.png
diff --git a/Tests/assets/pics/nslide_snot.png b/examples/assets/pics/nslide_snot.png
similarity index 100%
rename from Tests/assets/pics/nslide_snot.png
rename to examples/assets/pics/nslide_snot.png
diff --git a/Tests/assets/pics/pigchampagne.png b/examples/assets/pics/pigchampagne.png
similarity index 100%
rename from Tests/assets/pics/pigchampagne.png
rename to examples/assets/pics/pigchampagne.png
diff --git a/Tests/assets/pics/platformer_backdrop.png b/examples/assets/pics/platformer_backdrop.png
similarity index 100%
rename from Tests/assets/pics/platformer_backdrop.png
rename to examples/assets/pics/platformer_backdrop.png
diff --git a/Tests/assets/pics/profil-sad_plush.png b/examples/assets/pics/profil-sad_plush.png
similarity index 100%
rename from Tests/assets/pics/profil-sad_plush.png
rename to examples/assets/pics/profil-sad_plush.png
diff --git a/Tests/assets/pics/questar.png b/examples/assets/pics/questar.png
similarity index 100%
rename from Tests/assets/pics/questar.png
rename to examples/assets/pics/questar.png
diff --git a/Tests/assets/pics/ra_einstein.png b/examples/assets/pics/ra_einstein.png
similarity index 100%
rename from Tests/assets/pics/ra_einstein.png
rename to examples/assets/pics/ra_einstein.png
diff --git a/Tests/assets/pics/remember-me.jpg b/examples/assets/pics/remember-me.jpg
similarity index 100%
rename from Tests/assets/pics/remember-me.jpg
rename to examples/assets/pics/remember-me.jpg
diff --git a/Tests/assets/pics/scrollframe.png b/examples/assets/pics/scrollframe.png
similarity index 100%
rename from Tests/assets/pics/scrollframe.png
rename to examples/assets/pics/scrollframe.png
diff --git a/Tests/assets/pics/seven_seas_andromeda_fairfax.png b/examples/assets/pics/seven_seas_andromeda_fairfax.png
similarity index 100%
rename from Tests/assets/pics/seven_seas_andromeda_fairfax.png
rename to examples/assets/pics/seven_seas_andromeda_fairfax.png
diff --git a/Tests/assets/pics/shadow_of_the_beast2_karamoon.png b/examples/assets/pics/shadow_of_the_beast2_karamoon.png
similarity index 100%
rename from Tests/assets/pics/shadow_of_the_beast2_karamoon.png
rename to examples/assets/pics/shadow_of_the_beast2_karamoon.png
diff --git a/Tests/assets/pics/shadow_of_the_beast2_other_world.png b/examples/assets/pics/shadow_of_the_beast2_other_world.png
similarity index 100%
rename from Tests/assets/pics/shadow_of_the_beast2_other_world.png
rename to examples/assets/pics/shadow_of_the_beast2_other_world.png
diff --git a/Tests/assets/pics/shmup_hud.png b/examples/assets/pics/shmup_hud.png
similarity index 100%
rename from Tests/assets/pics/shmup_hud.png
rename to examples/assets/pics/shmup_hud.png
diff --git a/Tests/assets/pics/shocktroopers_angel.png b/examples/assets/pics/shocktroopers_angel.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_angel.png
rename to examples/assets/pics/shocktroopers_angel.png
diff --git a/Tests/assets/pics/shocktroopers_angel2.png b/examples/assets/pics/shocktroopers_angel2.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_angel2.png
rename to examples/assets/pics/shocktroopers_angel2.png
diff --git a/Tests/assets/pics/shocktroopers_leon.png b/examples/assets/pics/shocktroopers_leon.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_leon.png
rename to examples/assets/pics/shocktroopers_leon.png
diff --git a/Tests/assets/pics/shocktroopers_leon2.png b/examples/assets/pics/shocktroopers_leon2.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_leon2.png
rename to examples/assets/pics/shocktroopers_leon2.png
diff --git a/Tests/assets/pics/shocktroopers_lulu.png b/examples/assets/pics/shocktroopers_lulu.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_lulu.png
rename to examples/assets/pics/shocktroopers_lulu.png
diff --git a/Tests/assets/pics/shocktroopers_lulu2.png b/examples/assets/pics/shocktroopers_lulu2.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_lulu2.png
rename to examples/assets/pics/shocktroopers_lulu2.png
diff --git a/Tests/assets/pics/shocktroopers_toy.png b/examples/assets/pics/shocktroopers_toy.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_toy.png
rename to examples/assets/pics/shocktroopers_toy.png
diff --git a/Tests/assets/pics/shocktroopers_toy2.png b/examples/assets/pics/shocktroopers_toy2.png
similarity index 100%
rename from Tests/assets/pics/shocktroopers_toy2.png
rename to examples/assets/pics/shocktroopers_toy2.png
diff --git a/Tests/assets/pics/slayer-sorry_im_the_beast.png b/examples/assets/pics/slayer-sorry_im_the_beast.png
similarity index 100%
rename from Tests/assets/pics/slayer-sorry_im_the_beast.png
rename to examples/assets/pics/slayer-sorry_im_the_beast.png
diff --git a/Tests/assets/pics/spaceship.png b/examples/assets/pics/spaceship.png
similarity index 100%
rename from Tests/assets/pics/spaceship.png
rename to examples/assets/pics/spaceship.png
diff --git a/Tests/assets/pics/spaz-bitch-beatnick.png b/examples/assets/pics/spaz-bitch-beatnick.png
similarity index 100%
rename from Tests/assets/pics/spaz-bitch-beatnick.png
rename to examples/assets/pics/spaz-bitch-beatnick.png
diff --git a/Tests/assets/pics/spaz-oh_crikey-komische_sackratten_von_der_hohle.png b/examples/assets/pics/spaz-oh_crikey-komische_sackratten_von_der_hohle.png
similarity index 100%
rename from Tests/assets/pics/spaz-oh_crikey-komische_sackratten_von_der_hohle.png
rename to examples/assets/pics/spaz-oh_crikey-komische_sackratten_von_der_hohle.png
diff --git a/Tests/assets/pics/spyro.png b/examples/assets/pics/spyro.png
similarity index 100%
rename from Tests/assets/pics/spyro.png
rename to examples/assets/pics/spyro.png
diff --git a/Tests/assets/pics/supercars_parsec.png b/examples/assets/pics/supercars_parsec.png
similarity index 100%
rename from Tests/assets/pics/supercars_parsec.png
rename to examples/assets/pics/supercars_parsec.png
diff --git a/Tests/assets/pics/texturepacker_test.json b/examples/assets/pics/texturepacker_test.json
similarity index 100%
rename from Tests/assets/pics/texturepacker_test.json
rename to examples/assets/pics/texturepacker_test.json
diff --git a/Tests/assets/pics/texturepacker_test.png b/examples/assets/pics/texturepacker_test.png
similarity index 100%
rename from Tests/assets/pics/texturepacker_test.png
rename to examples/assets/pics/texturepacker_test.png
diff --git a/Tests/assets/pics/thorn_lazur.png b/examples/assets/pics/thorn_lazur.png
similarity index 100%
rename from Tests/assets/pics/thorn_lazur.png
rename to examples/assets/pics/thorn_lazur.png
diff --git a/Tests/assets/pics/titan_mech.png b/examples/assets/pics/titan_mech.png
similarity index 100%
rename from Tests/assets/pics/titan_mech.png
rename to examples/assets/pics/titan_mech.png
diff --git a/Tests/assets/pics/title_page.png b/examples/assets/pics/title_page.png
similarity index 100%
rename from Tests/assets/pics/title_page.png
rename to examples/assets/pics/title_page.png
diff --git a/Tests/assets/pics/touhou_teng_soldier.png b/examples/assets/pics/touhou_teng_soldier.png
similarity index 100%
rename from Tests/assets/pics/touhou_teng_soldier.png
rename to examples/assets/pics/touhou_teng_soldier.png
diff --git a/Tests/assets/pics/trsipic1_lazur.JPG b/examples/assets/pics/trsipic1_lazur.JPG
similarity index 100%
rename from Tests/assets/pics/trsipic1_lazur.JPG
rename to examples/assets/pics/trsipic1_lazur.JPG
diff --git a/Tests/assets/pics/tvzor_lazur.png b/examples/assets/pics/tvzor_lazur.png
similarity index 100%
rename from Tests/assets/pics/tvzor_lazur.png
rename to examples/assets/pics/tvzor_lazur.png
diff --git a/Tests/assets/pics/unknown-the_starwars_pic.png b/examples/assets/pics/unknown-the_starwars_pic.png
similarity index 100%
rename from Tests/assets/pics/unknown-the_starwars_pic.png
rename to examples/assets/pics/unknown-the_starwars_pic.png
diff --git a/Tests/assets/pics/vulkaiser_red.png b/examples/assets/pics/vulkaiser_red.png
similarity index 100%
rename from Tests/assets/pics/vulkaiser_red.png
rename to examples/assets/pics/vulkaiser_red.png
diff --git a/Tests/assets/pics/zod4.png b/examples/assets/pics/zod4.png
similarity index 100%
rename from Tests/assets/pics/zod4.png
rename to examples/assets/pics/zod4.png
diff --git a/Tests/assets/psds/button.psd b/examples/assets/psds/button.psd
similarity index 100%
rename from Tests/assets/psds/button.psd
rename to examples/assets/psds/button.psd
diff --git a/Tests/assets/psds/down.png b/examples/assets/psds/down.png
similarity index 100%
rename from Tests/assets/psds/down.png
rename to examples/assets/psds/down.png
diff --git a/Tests/assets/psds/out.png b/examples/assets/psds/out.png
similarity index 100%
rename from Tests/assets/psds/out.png
rename to examples/assets/psds/out.png
diff --git a/Tests/assets/psds/over.png b/examples/assets/psds/over.png
similarity index 100%
rename from Tests/assets/psds/over.png
rename to examples/assets/psds/over.png
diff --git a/Tests/assets/sprites/advanced_wars_land.png b/examples/assets/sprites/advanced_wars_land.png
similarity index 100%
rename from Tests/assets/sprites/advanced_wars_land.png
rename to examples/assets/sprites/advanced_wars_land.png
diff --git a/Tests/assets/sprites/advanced_wars_tank.png b/examples/assets/sprites/advanced_wars_tank.png
similarity index 100%
rename from Tests/assets/sprites/advanced_wars_tank.png
rename to examples/assets/sprites/advanced_wars_tank.png
diff --git a/Tests/assets/sprites/aqua_ball.png b/examples/assets/sprites/aqua_ball.png
similarity index 100%
rename from Tests/assets/sprites/aqua_ball.png
rename to examples/assets/sprites/aqua_ball.png
diff --git a/Tests/assets/sprites/arrows.png b/examples/assets/sprites/arrows.png
similarity index 100%
rename from Tests/assets/sprites/arrows.png
rename to examples/assets/sprites/arrows.png
diff --git a/Tests/assets/sprites/asteroids_ship.png b/examples/assets/sprites/asteroids_ship.png
similarity index 100%
rename from Tests/assets/sprites/asteroids_ship.png
rename to examples/assets/sprites/asteroids_ship.png
diff --git a/Tests/assets/sprites/asteroids_ship_white.png b/examples/assets/sprites/asteroids_ship_white.png
similarity index 100%
rename from Tests/assets/sprites/asteroids_ship_white.png
rename to examples/assets/sprites/asteroids_ship_white.png
diff --git a/Tests/assets/sprites/atari1200xl.png b/examples/assets/sprites/atari1200xl.png
similarity index 100%
rename from Tests/assets/sprites/atari1200xl.png
rename to examples/assets/sprites/atari1200xl.png
diff --git a/Tests/assets/sprites/atari130xe.png b/examples/assets/sprites/atari130xe.png
similarity index 100%
rename from Tests/assets/sprites/atari130xe.png
rename to examples/assets/sprites/atari130xe.png
diff --git a/Tests/assets/sprites/atari400.png b/examples/assets/sprites/atari400.png
similarity index 100%
rename from Tests/assets/sprites/atari400.png
rename to examples/assets/sprites/atari400.png
diff --git a/Tests/assets/sprites/atari800.png b/examples/assets/sprites/atari800.png
similarity index 100%
rename from Tests/assets/sprites/atari800.png
rename to examples/assets/sprites/atari800.png
diff --git a/Tests/assets/sprites/atari800xl.png b/examples/assets/sprites/atari800xl.png
similarity index 100%
rename from Tests/assets/sprites/atari800xl.png
rename to examples/assets/sprites/atari800xl.png
diff --git a/Tests/assets/sprites/baddie_cat_1.png b/examples/assets/sprites/baddie_cat_1.png
similarity index 100%
rename from Tests/assets/sprites/baddie_cat_1.png
rename to examples/assets/sprites/baddie_cat_1.png
diff --git a/Tests/assets/sprites/balls.png b/examples/assets/sprites/balls.png
similarity index 100%
rename from Tests/assets/sprites/balls.png
rename to examples/assets/sprites/balls.png
diff --git a/Tests/assets/sprites/blue_ball.png b/examples/assets/sprites/blue_ball.png
similarity index 100%
rename from Tests/assets/sprites/blue_ball.png
rename to examples/assets/sprites/blue_ball.png
diff --git a/Tests/assets/sprites/bullet.png b/examples/assets/sprites/bullet.png
similarity index 100%
rename from Tests/assets/sprites/bullet.png
rename to examples/assets/sprites/bullet.png
diff --git a/Tests/assets/sprites/bunny.png b/examples/assets/sprites/bunny.png
similarity index 100%
rename from Tests/assets/sprites/bunny.png
rename to examples/assets/sprites/bunny.png
diff --git a/Tests/assets/sprites/car.png b/examples/assets/sprites/car.png
similarity index 100%
rename from Tests/assets/sprites/car.png
rename to examples/assets/sprites/car.png
diff --git a/Tests/assets/sprites/car90.png b/examples/assets/sprites/car90.png
similarity index 100%
rename from Tests/assets/sprites/car90.png
rename to examples/assets/sprites/car90.png
diff --git a/Tests/assets/sprites/carrot.png b/examples/assets/sprites/carrot.png
similarity index 100%
rename from Tests/assets/sprites/carrot.png
rename to examples/assets/sprites/carrot.png
diff --git a/Tests/assets/sprites/chick.png b/examples/assets/sprites/chick.png
similarity index 100%
rename from Tests/assets/sprites/chick.png
rename to examples/assets/sprites/chick.png
diff --git a/Tests/assets/sprites/chunk.png b/examples/assets/sprites/chunk.png
similarity index 100%
rename from Tests/assets/sprites/chunk.png
rename to examples/assets/sprites/chunk.png
diff --git a/Tests/assets/sprites/coin.png b/examples/assets/sprites/coin.png
similarity index 100%
rename from Tests/assets/sprites/coin.png
rename to examples/assets/sprites/coin.png
diff --git a/Tests/assets/sprites/cokecan.png b/examples/assets/sprites/cokecan.png
similarity index 100%
rename from Tests/assets/sprites/cokecan.png
rename to examples/assets/sprites/cokecan.png
diff --git a/Tests/assets/sprites/darkwing_crazy.png b/examples/assets/sprites/darkwing_crazy.png
similarity index 100%
rename from Tests/assets/sprites/darkwing_crazy.png
rename to examples/assets/sprites/darkwing_crazy.png
diff --git a/Tests/assets/sprites/diamond.png b/examples/assets/sprites/diamond.png
similarity index 100%
rename from Tests/assets/sprites/diamond.png
rename to examples/assets/sprites/diamond.png
diff --git a/Tests/assets/sprites/eggplant.png b/examples/assets/sprites/eggplant.png
similarity index 100%
rename from Tests/assets/sprites/eggplant.png
rename to examples/assets/sprites/eggplant.png
diff --git a/Tests/assets/sprites/enemy-bullet.png b/examples/assets/sprites/enemy-bullet.png
similarity index 100%
rename from Tests/assets/sprites/enemy-bullet.png
rename to examples/assets/sprites/enemy-bullet.png
diff --git a/Tests/assets/sprites/explosion.png b/examples/assets/sprites/explosion.png
similarity index 100%
rename from Tests/assets/sprites/explosion.png
rename to examples/assets/sprites/explosion.png
diff --git a/Tests/assets/sprites/firstaid.png b/examples/assets/sprites/firstaid.png
similarity index 100%
rename from Tests/assets/sprites/firstaid.png
rename to examples/assets/sprites/firstaid.png
diff --git a/Tests/assets/sprites/flectrum.png b/examples/assets/sprites/flectrum.png
similarity index 100%
rename from Tests/assets/sprites/flectrum.png
rename to examples/assets/sprites/flectrum.png
diff --git a/Tests/assets/sprites/flectrum2.png b/examples/assets/sprites/flectrum2.png
similarity index 100%
rename from Tests/assets/sprites/flectrum2.png
rename to examples/assets/sprites/flectrum2.png
diff --git a/Tests/assets/sprites/green_ball.png b/examples/assets/sprites/green_ball.png
similarity index 100%
rename from Tests/assets/sprites/green_ball.png
rename to examples/assets/sprites/green_ball.png
diff --git a/Tests/assets/sprites/healthbar.png b/examples/assets/sprites/healthbar.png
similarity index 100%
rename from Tests/assets/sprites/healthbar.png
rename to examples/assets/sprites/healthbar.png
diff --git a/Tests/assets/sprites/humstar.png b/examples/assets/sprites/humstar.png
similarity index 100%
rename from Tests/assets/sprites/humstar.png
rename to examples/assets/sprites/humstar.png
diff --git a/Tests/assets/sprites/ilkke.png b/examples/assets/sprites/ilkke.png
similarity index 100%
rename from Tests/assets/sprites/ilkke.png
rename to examples/assets/sprites/ilkke.png
diff --git a/Tests/assets/sprites/invaderpig.json b/examples/assets/sprites/invaderpig.json
similarity index 100%
rename from Tests/assets/sprites/invaderpig.json
rename to examples/assets/sprites/invaderpig.json
diff --git a/Tests/assets/sprites/invaderpig.png b/examples/assets/sprites/invaderpig.png
similarity index 100%
rename from Tests/assets/sprites/invaderpig.png
rename to examples/assets/sprites/invaderpig.png
diff --git a/Tests/assets/sprites/jets.png b/examples/assets/sprites/jets.png
similarity index 100%
rename from Tests/assets/sprites/jets.png
rename to examples/assets/sprites/jets.png
diff --git a/Tests/assets/sprites/mana_card.png b/examples/assets/sprites/mana_card.png
similarity index 100%
rename from Tests/assets/sprites/mana_card.png
rename to examples/assets/sprites/mana_card.png
diff --git a/Tests/assets/sprites/melon.png b/examples/assets/sprites/melon.png
similarity index 100%
rename from Tests/assets/sprites/melon.png
rename to examples/assets/sprites/melon.png
diff --git a/Tests/assets/sprites/metalslug_monster39x40.png b/examples/assets/sprites/metalslug_monster39x40.png
similarity index 100%
rename from Tests/assets/sprites/metalslug_monster39x40.png
rename to examples/assets/sprites/metalslug_monster39x40.png
diff --git a/Tests/assets/sprites/metalslug_mummy37x45.png b/examples/assets/sprites/metalslug_mummy37x45.png
similarity index 100%
rename from Tests/assets/sprites/metalslug_mummy37x45.png
rename to examples/assets/sprites/metalslug_mummy37x45.png
diff --git a/Tests/assets/sprites/mushroom.png b/examples/assets/sprites/mushroom.png
similarity index 100%
rename from Tests/assets/sprites/mushroom.png
rename to examples/assets/sprites/mushroom.png
diff --git a/Tests/assets/sprites/mushroom2.png b/examples/assets/sprites/mushroom2.png
similarity index 100%
rename from Tests/assets/sprites/mushroom2.png
rename to examples/assets/sprites/mushroom2.png
diff --git a/Tests/assets/sprites/onion.png b/examples/assets/sprites/onion.png
similarity index 100%
rename from Tests/assets/sprites/onion.png
rename to examples/assets/sprites/onion.png
diff --git a/Tests/assets/sprites/oz_pov_melting_disk.png b/examples/assets/sprites/oz_pov_melting_disk.png
similarity index 100%
rename from Tests/assets/sprites/oz_pov_melting_disk.png
rename to examples/assets/sprites/oz_pov_melting_disk.png
diff --git a/Tests/assets/sprites/parsec.png b/examples/assets/sprites/parsec.png
similarity index 100%
rename from Tests/assets/sprites/parsec.png
rename to examples/assets/sprites/parsec.png
diff --git a/Tests/assets/sprites/particle1.png b/examples/assets/sprites/particle1.png
similarity index 100%
rename from Tests/assets/sprites/particle1.png
rename to examples/assets/sprites/particle1.png
diff --git a/Tests/assets/sprites/pepper.png b/examples/assets/sprites/pepper.png
similarity index 100%
rename from Tests/assets/sprites/pepper.png
rename to examples/assets/sprites/pepper.png
diff --git a/Tests/assets/sprites/pineapple.png b/examples/assets/sprites/pineapple.png
similarity index 100%
rename from Tests/assets/sprites/pineapple.png
rename to examples/assets/sprites/pineapple.png
diff --git a/Tests/assets/sprites/platform.png b/examples/assets/sprites/platform.png
similarity index 100%
rename from Tests/assets/sprites/platform.png
rename to examples/assets/sprites/platform.png
diff --git a/Tests/assets/sprites/player.png b/examples/assets/sprites/player.png
similarity index 100%
rename from Tests/assets/sprites/player.png
rename to examples/assets/sprites/player.png
diff --git a/Tests/assets/sprites/purple_ball.png b/examples/assets/sprites/purple_ball.png
similarity index 100%
rename from Tests/assets/sprites/purple_ball.png
rename to examples/assets/sprites/purple_ball.png
diff --git a/Tests/assets/sprites/ra_dont_crack_under_pressure.png b/examples/assets/sprites/ra_dont_crack_under_pressure.png
similarity index 100%
rename from Tests/assets/sprites/ra_dont_crack_under_pressure.png
rename to examples/assets/sprites/ra_dont_crack_under_pressure.png
diff --git a/Tests/assets/sprites/red_ball.png b/examples/assets/sprites/red_ball.png
similarity index 100%
rename from Tests/assets/sprites/red_ball.png
rename to examples/assets/sprites/red_ball.png
diff --git a/Tests/assets/sprites/robot/arm-l.png b/examples/assets/sprites/robot/arm-l.png
similarity index 100%
rename from Tests/assets/sprites/robot/arm-l.png
rename to examples/assets/sprites/robot/arm-l.png
diff --git a/Tests/assets/sprites/robot/arm-r.png b/examples/assets/sprites/robot/arm-r.png
similarity index 100%
rename from Tests/assets/sprites/robot/arm-r.png
rename to examples/assets/sprites/robot/arm-r.png
diff --git a/Tests/assets/sprites/robot/body.png b/examples/assets/sprites/robot/body.png
similarity index 100%
rename from Tests/assets/sprites/robot/body.png
rename to examples/assets/sprites/robot/body.png
diff --git a/Tests/assets/sprites/robot/eye.png b/examples/assets/sprites/robot/eye.png
similarity index 100%
rename from Tests/assets/sprites/robot/eye.png
rename to examples/assets/sprites/robot/eye.png
diff --git a/Tests/assets/sprites/robot/leg-l.png b/examples/assets/sprites/robot/leg-l.png
similarity index 100%
rename from Tests/assets/sprites/robot/leg-l.png
rename to examples/assets/sprites/robot/leg-l.png
diff --git a/Tests/assets/sprites/robot/leg-r.png b/examples/assets/sprites/robot/leg-r.png
similarity index 100%
rename from Tests/assets/sprites/robot/leg-r.png
rename to examples/assets/sprites/robot/leg-r.png
diff --git a/Tests/assets/sprites/running_bot.json b/examples/assets/sprites/running_bot.json
similarity index 100%
rename from Tests/assets/sprites/running_bot.json
rename to examples/assets/sprites/running_bot.json
diff --git a/Tests/assets/sprites/running_bot.png b/examples/assets/sprites/running_bot.png
similarity index 100%
rename from Tests/assets/sprites/running_bot.png
rename to examples/assets/sprites/running_bot.png
diff --git a/Tests/assets/sprites/shinyball.png b/examples/assets/sprites/shinyball.png
similarity index 100%
rename from Tests/assets/sprites/shinyball.png
rename to examples/assets/sprites/shinyball.png
diff --git a/Tests/assets/sprites/shmup-ship.png b/examples/assets/sprites/shmup-ship.png
similarity index 100%
rename from Tests/assets/sprites/shmup-ship.png
rename to examples/assets/sprites/shmup-ship.png
diff --git a/Tests/assets/sprites/shoebot.png b/examples/assets/sprites/shoebot.png
similarity index 100%
rename from Tests/assets/sprites/shoebot.png
rename to examples/assets/sprites/shoebot.png
diff --git a/Tests/assets/sprites/shoebot.xml b/examples/assets/sprites/shoebot.xml
similarity index 100%
rename from Tests/assets/sprites/shoebot.xml
rename to examples/assets/sprites/shoebot.xml
diff --git a/Tests/assets/sprites/shoebox.png b/examples/assets/sprites/shoebox.png
similarity index 100%
rename from Tests/assets/sprites/shoebox.png
rename to examples/assets/sprites/shoebox.png
diff --git a/Tests/assets/sprites/shoebox.xml b/examples/assets/sprites/shoebox.xml
similarity index 100%
rename from Tests/assets/sprites/shoebox.xml
rename to examples/assets/sprites/shoebox.xml
diff --git a/Tests/assets/sprites/slime.png b/examples/assets/sprites/slime.png
similarity index 100%
rename from Tests/assets/sprites/slime.png
rename to examples/assets/sprites/slime.png
diff --git a/Tests/assets/sprites/slimeeyes.png b/examples/assets/sprites/slimeeyes.png
similarity index 100%
rename from Tests/assets/sprites/slimeeyes.png
rename to examples/assets/sprites/slimeeyes.png
diff --git a/Tests/assets/sprites/sonic_havok_sanity.png b/examples/assets/sprites/sonic_havok_sanity.png
similarity index 100%
rename from Tests/assets/sprites/sonic_havok_sanity.png
rename to examples/assets/sprites/sonic_havok_sanity.png
diff --git a/Tests/assets/sprites/soundtracker.png b/examples/assets/sprites/soundtracker.png
similarity index 100%
rename from Tests/assets/sprites/soundtracker.png
rename to examples/assets/sprites/soundtracker.png
diff --git a/Tests/assets/sprites/space-baddie-purple.png b/examples/assets/sprites/space-baddie-purple.png
similarity index 100%
rename from Tests/assets/sprites/space-baddie-purple.png
rename to examples/assets/sprites/space-baddie-purple.png
diff --git a/Tests/assets/sprites/space-baddie.png b/examples/assets/sprites/space-baddie.png
similarity index 100%
rename from Tests/assets/sprites/space-baddie.png
rename to examples/assets/sprites/space-baddie.png
diff --git a/Tests/assets/sprites/thrust_ship.png b/examples/assets/sprites/thrust_ship.png
similarity index 100%
rename from Tests/assets/sprites/thrust_ship.png
rename to examples/assets/sprites/thrust_ship.png
diff --git a/Tests/assets/sprites/tinycar.png b/examples/assets/sprites/tinycar.png
similarity index 100%
rename from Tests/assets/sprites/tinycar.png
rename to examples/assets/sprites/tinycar.png
diff --git a/Tests/assets/sprites/tomato.png b/examples/assets/sprites/tomato.png
similarity index 100%
rename from Tests/assets/sprites/tomato.png
rename to examples/assets/sprites/tomato.png
diff --git a/Tests/assets/sprites/ufo.png b/examples/assets/sprites/ufo.png
similarity index 100%
rename from Tests/assets/sprites/ufo.png
rename to examples/assets/sprites/ufo.png
diff --git a/Tests/assets/sprites/wabbit.png b/examples/assets/sprites/wabbit.png
similarity index 100%
rename from Tests/assets/sprites/wabbit.png
rename to examples/assets/sprites/wabbit.png
diff --git a/Tests/assets/sprites/x.png b/examples/assets/sprites/x.png
similarity index 100%
rename from Tests/assets/sprites/x.png
rename to examples/assets/sprites/x.png
diff --git a/Tests/assets/sprites/xenon2_bomb.png b/examples/assets/sprites/xenon2_bomb.png
similarity index 100%
rename from Tests/assets/sprites/xenon2_bomb.png
rename to examples/assets/sprites/xenon2_bomb.png
diff --git a/Tests/assets/sprites/xenon2_ship.png b/examples/assets/sprites/xenon2_ship.png
similarity index 100%
rename from Tests/assets/sprites/xenon2_ship.png
rename to examples/assets/sprites/xenon2_ship.png
diff --git a/Tests/assets/sprites/yellow_ball.png b/examples/assets/sprites/yellow_ball.png
similarity index 100%
rename from Tests/assets/sprites/yellow_ball.png
rename to examples/assets/sprites/yellow_ball.png
diff --git a/Tests/assets/sprites/zelda-hearts.png b/examples/assets/sprites/zelda-hearts.png
similarity index 100%
rename from Tests/assets/sprites/zelda-hearts.png
rename to examples/assets/sprites/zelda-hearts.png
diff --git a/Tests/assets/sprites/zelda-life.png b/examples/assets/sprites/zelda-life.png
similarity index 100%
rename from Tests/assets/sprites/zelda-life.png
rename to examples/assets/sprites/zelda-life.png
diff --git a/Tests/assets/suite/background.png b/examples/assets/suite/background.png
similarity index 100%
rename from Tests/assets/suite/background.png
rename to examples/assets/suite/background.png
diff --git a/Tests/assets/tests/200x100corners.png b/examples/assets/tests/200x100corners.png
similarity index 100%
rename from Tests/assets/tests/200x100corners.png
rename to examples/assets/tests/200x100corners.png
diff --git a/Tests/assets/tests/200x100corners2.png b/examples/assets/tests/200x100corners2.png
similarity index 100%
rename from Tests/assets/tests/200x100corners2.png
rename to examples/assets/tests/200x100corners2.png
diff --git a/Tests/assets/tests/320x200.png b/examples/assets/tests/320x200.png
similarity index 100%
rename from Tests/assets/tests/320x200.png
rename to examples/assets/tests/320x200.png
diff --git a/Tests/assets/tests/320x200g.png b/examples/assets/tests/320x200g.png
similarity index 100%
rename from Tests/assets/tests/320x200g.png
rename to examples/assets/tests/320x200g.png
diff --git a/Tests/assets/tests/SuperMarioKartMapMushroomCup1.png b/examples/assets/tests/SuperMarioKartMapMushroomCup1.png
similarity index 100%
rename from Tests/assets/tests/SuperMarioKartMapMushroomCup1.png
rename to examples/assets/tests/SuperMarioKartMapMushroomCup1.png
diff --git a/Tests/assets/tests/blue-circle.png b/examples/assets/tests/blue-circle.png
similarity index 100%
rename from Tests/assets/tests/blue-circle.png
rename to examples/assets/tests/blue-circle.png
diff --git a/Tests/assets/tests/cloud-big-2x.png b/examples/assets/tests/cloud-big-2x.png
similarity index 100%
rename from Tests/assets/tests/cloud-big-2x.png
rename to examples/assets/tests/cloud-big-2x.png
diff --git a/Tests/assets/tests/cloud-big.png b/examples/assets/tests/cloud-big.png
similarity index 100%
rename from Tests/assets/tests/cloud-big.png
rename to examples/assets/tests/cloud-big.png
diff --git a/Tests/assets/tests/cloud-narrow-2x.png b/examples/assets/tests/cloud-narrow-2x.png
similarity index 100%
rename from Tests/assets/tests/cloud-narrow-2x.png
rename to examples/assets/tests/cloud-narrow-2x.png
diff --git a/Tests/assets/tests/cloud-narrow.png b/examples/assets/tests/cloud-narrow.png
similarity index 100%
rename from Tests/assets/tests/cloud-narrow.png
rename to examples/assets/tests/cloud-narrow.png
diff --git a/Tests/assets/tests/cloud-small-2x.png b/examples/assets/tests/cloud-small-2x.png
similarity index 100%
rename from Tests/assets/tests/cloud-small-2x.png
rename to examples/assets/tests/cloud-small-2x.png
diff --git a/Tests/assets/tests/cloud-small.png b/examples/assets/tests/cloud-small.png
similarity index 100%
rename from Tests/assets/tests/cloud-small.png
rename to examples/assets/tests/cloud-small.png
diff --git a/Tests/assets/tests/debug-grid-1920x1920.png b/examples/assets/tests/debug-grid-1920x1920.png
similarity index 100%
rename from Tests/assets/tests/debug-grid-1920x1920.png
rename to examples/assets/tests/debug-grid-1920x1920.png
diff --git a/Tests/assets/tests/grass1.png b/examples/assets/tests/grass1.png
similarity index 100%
rename from Tests/assets/tests/grass1.png
rename to examples/assets/tests/grass1.png
diff --git a/Tests/assets/tests/ground-2x.png b/examples/assets/tests/ground-2x.png
similarity index 100%
rename from Tests/assets/tests/ground-2x.png
rename to examples/assets/tests/ground-2x.png
diff --git a/Tests/assets/tests/ground.png b/examples/assets/tests/ground.png
similarity index 100%
rename from Tests/assets/tests/ground.png
rename to examples/assets/tests/ground.png
diff --git a/Tests/assets/tests/harrier-bg.png b/examples/assets/tests/harrier-bg.png
similarity index 100%
rename from Tests/assets/tests/harrier-bg.png
rename to examples/assets/tests/harrier-bg.png
diff --git a/Tests/assets/tests/harrier-bg2.png b/examples/assets/tests/harrier-bg2.png
similarity index 100%
rename from Tests/assets/tests/harrier-bg2.png
rename to examples/assets/tests/harrier-bg2.png
diff --git a/Tests/assets/tests/harrier.png b/examples/assets/tests/harrier.png
similarity index 100%
rename from Tests/assets/tests/harrier.png
rename to examples/assets/tests/harrier.png
diff --git a/Tests/assets/tests/harrier2.png b/examples/assets/tests/harrier2.png
similarity index 100%
rename from Tests/assets/tests/harrier2.png
rename to examples/assets/tests/harrier2.png
diff --git a/Tests/assets/tests/harrier3.png b/examples/assets/tests/harrier3.png
similarity index 100%
rename from Tests/assets/tests/harrier3.png
rename to examples/assets/tests/harrier3.png
diff --git a/Tests/assets/tests/horizon.png b/examples/assets/tests/horizon.png
similarity index 100%
rename from Tests/assets/tests/horizon.png
rename to examples/assets/tests/horizon.png
diff --git a/Tests/assets/tests/magenta-circle.png b/examples/assets/tests/magenta-circle.png
similarity index 100%
rename from Tests/assets/tests/magenta-circle.png
rename to examples/assets/tests/magenta-circle.png
diff --git a/Tests/assets/tests/radar-surface.png b/examples/assets/tests/radar-surface.png
similarity index 100%
rename from Tests/assets/tests/radar-surface.png
rename to examples/assets/tests/radar-surface.png
diff --git a/Tests/assets/tests/river-2x.png b/examples/assets/tests/river-2x.png
similarity index 100%
rename from Tests/assets/tests/river-2x.png
rename to examples/assets/tests/river-2x.png
diff --git a/Tests/assets/tests/river.png b/examples/assets/tests/river.png
similarity index 100%
rename from Tests/assets/tests/river.png
rename to examples/assets/tests/river.png
diff --git a/Tests/assets/tests/road1.png b/examples/assets/tests/road1.png
similarity index 100%
rename from Tests/assets/tests/road1.png
rename to examples/assets/tests/road1.png
diff --git a/Tests/assets/tests/sky-2x.png b/examples/assets/tests/sky-2x.png
similarity index 100%
rename from Tests/assets/tests/sky-2x.png
rename to examples/assets/tests/sky-2x.png
diff --git a/Tests/assets/tests/sky.png b/examples/assets/tests/sky.png
similarity index 100%
rename from Tests/assets/tests/sky.png
rename to examples/assets/tests/sky.png
diff --git a/Tests/assets/tests/tree.png b/examples/assets/tests/tree.png
similarity index 100%
rename from Tests/assets/tests/tree.png
rename to examples/assets/tests/tree.png
diff --git a/Tests/assets/tests/tween/PHASER.png b/examples/assets/tests/tween/PHASER.png
similarity index 100%
rename from Tests/assets/tests/tween/PHASER.png
rename to examples/assets/tests/tween/PHASER.png
diff --git a/Tests/assets/tests/tween/ribbon.png b/examples/assets/tests/tween/ribbon.png
similarity index 100%
rename from Tests/assets/tests/tween/ribbon.png
rename to examples/assets/tests/tween/ribbon.png
diff --git a/Tests/assets/tests/tween/shadow.png b/examples/assets/tests/tween/shadow.png
similarity index 100%
rename from Tests/assets/tests/tween/shadow.png
rename to examples/assets/tests/tween/shadow.png
diff --git a/Tests/assets/tests/venus-the-flytrap.png b/examples/assets/tests/venus-the-flytrap.png
similarity index 100%
rename from Tests/assets/tests/venus-the-flytrap.png
rename to examples/assets/tests/venus-the-flytrap.png
diff --git a/Tests/assets/tests/yellow-circle.png b/examples/assets/tests/yellow-circle.png
similarity index 100%
rename from Tests/assets/tests/yellow-circle.png
rename to examples/assets/tests/yellow-circle.png
diff --git a/Tests/assets/tiles/catastrophi_tiles.png b/examples/assets/tiles/catastrophi_tiles.png
similarity index 100%
rename from Tests/assets/tiles/catastrophi_tiles.png
rename to examples/assets/tiles/catastrophi_tiles.png
diff --git a/Tests/assets/tiles/catastrophi_tiles_16.png b/examples/assets/tiles/catastrophi_tiles_16.png
similarity index 100%
rename from Tests/assets/tiles/catastrophi_tiles_16.png
rename to examples/assets/tiles/catastrophi_tiles_16.png
diff --git a/Tests/assets/tiles/ground-tile.png b/examples/assets/tiles/ground-tile.png
similarity index 100%
rename from Tests/assets/tiles/ground-tile.png
rename to examples/assets/tiles/ground-tile.png
diff --git a/Tests/assets/tiles/muddy-ground.png b/examples/assets/tiles/muddy-ground.png
similarity index 100%
rename from Tests/assets/tiles/muddy-ground.png
rename to examples/assets/tiles/muddy-ground.png
diff --git a/Tests/assets/tiles/platformer_tiles.png b/examples/assets/tiles/platformer_tiles.png
similarity index 100%
rename from Tests/assets/tiles/platformer_tiles.png
rename to examples/assets/tiles/platformer_tiles.png
diff --git a/Tests/assets/tiles/sci-fi-tiles.png b/examples/assets/tiles/sci-fi-tiles.png
similarity index 100%
rename from Tests/assets/tiles/sci-fi-tiles.png
rename to examples/assets/tiles/sci-fi-tiles.png
diff --git a/Tests/assets/tiles/tiles.png b/examples/assets/tiles/tiles.png
similarity index 100%
rename from Tests/assets/tiles/tiles.png
rename to examples/assets/tiles/tiles.png
diff --git a/Tests/assets/tiles/tmw_desert_spacing.png b/examples/assets/tiles/tmw_desert_spacing.png
similarity index 100%
rename from Tests/assets/tiles/tmw_desert_spacing.png
rename to examples/assets/tiles/tmw_desert_spacing.png
diff --git a/Tests/assets/warning - copyright.txt b/examples/assets/warning - copyright.txt
similarity index 100%
rename from Tests/assets/warning - copyright.txt
rename to examples/assets/warning - copyright.txt
diff --git a/examples/loader 2.html b/examples/loader 2.html
new file mode 100644
index 00000000..048ac00e
--- /dev/null
+++ b/examples/loader 2.html
@@ -0,0 +1,59 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/loader atlas json.html b/examples/loader atlas json.html
new file mode 100644
index 00000000..df0a42f5
--- /dev/null
+++ b/examples/loader atlas json.html
@@ -0,0 +1,57 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/loader atlas xml.html b/examples/loader atlas xml.html
new file mode 100644
index 00000000..e89d70e6
--- /dev/null
+++ b/examples/loader atlas xml.html
@@ -0,0 +1,57 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/loader audio.html b/examples/loader audio.html
new file mode 100644
index 00000000..137ade9b
--- /dev/null
+++ b/examples/loader audio.html
@@ -0,0 +1,57 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/loader spritesheet.html b/examples/loader spritesheet.html
new file mode 100644
index 00000000..12cf925f
--- /dev/null
+++ b/examples/loader spritesheet.html
@@ -0,0 +1,57 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/loader.html b/examples/loader.html
new file mode 100644
index 00000000..955593f6
--- /dev/null
+++ b/examples/loader.html
@@ -0,0 +1,48 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/net.html b/examples/net.html
new file mode 100644
index 00000000..b9864eb2
--- /dev/null
+++ b/examples/net.html
@@ -0,0 +1,42 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Reload with query string
+
+
+
\ No newline at end of file
diff --git a/examples/rnd.html b/examples/rnd.html
new file mode 100644
index 00000000..a6bd1f57
--- /dev/null
+++ b/examples/rnd.html
@@ -0,0 +1,25 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/signals.html b/examples/signals.html
new file mode 100644
index 00000000..0871cc32
--- /dev/null
+++ b/examples/signals.html
@@ -0,0 +1,35 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/wip1.html b/examples/wip1.html
new file mode 100644
index 00000000..f04f1fd3
--- /dev/null
+++ b/examples/wip1.html
@@ -0,0 +1,31 @@
+
+
+
+ phaser.js - a(nother) new beginning
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Game.js b/src/Game.js
new file mode 100644
index 00000000..f0e642a9
--- /dev/null
+++ b/src/Game.js
@@ -0,0 +1,204 @@
+/**
+* Phaser.Game
+*
+* This is where the magic happens. The Game object is the heart of your game,
+* providing quick access to common functions and handling the boot process.
+*
+* "Hell, there are no rules here - we're trying to accomplish something."
+* Thomas A. Edison
+*
+* @package Phaser.Game
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+*/
+
+Phaser.Game = function (callbackContext, parent, width, height, preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
+
+ if (typeof parent === "undefined") { parent = ''; }
+ if (typeof width === "undefined") { width = 800; }
+ if (typeof height === "undefined") { height = 600; }
+ if (typeof preloadCallback === "undefined") { preloadCallback = null; }
+ if (typeof createCallback === "undefined") { createCallback = null; }
+ if (typeof updateCallback === "undefined") { updateCallback = null; }
+ if (typeof renderCallback === "undefined") { renderCallback = null; }
+ if (typeof destroyCallback === "undefined") { destroyCallback = null; }
+
+ this.id = Phaser.GAMES.push(this) - 1;
+
+ this.callbackContext = callbackContext;
+ this.onPreloadCallback = preloadCallback;
+ this.onCreateCallback = createCallback;
+ this.onUpdateCallback = updateCallback;
+ this.onRenderCallback = renderCallback;
+ this.onDestroyCallback = destroyCallback;
+
+ var _this = this;
+
+ if (document.readyState === 'complete' || document.readyState === 'interactive')
+ {
+ setTimeout(function () {
+ return Phaser.GAMES[_this.id].boot(parent, width, height);
+ });
+ }
+ else
+ {
+ document.addEventListener('DOMContentLoaded', Phaser.GAMES[_this.id].boot(parent, width, height), false);
+ window.addEventListener('load', Phaser.GAMES[_this.id].boot(parent, width, height), false);
+ }
+
+};
+
+Phaser.Game.prototype = {
+
+ /**
+ * Phaser Game ID.
+ * @type {number}
+ */
+ id: 0,
+
+ /**
+ * Whether load complete loading or not.
+ * @type {bool}
+ */
+ _loadComplete: false,
+
+ /**
+ * Game is paused?
+ * @type {bool}
+ */
+ _paused: false,
+
+ /**
+ * The state to be switched to in the next frame.
+ * @type {State}
+ */
+ _pendingState: null,
+
+ /**
+ * The current State object (defaults to null)
+ * @type {State}
+ */
+ state: null,
+
+ /**
+ * This will be called when init states. (loading assets...)
+ * @type {function}
+ */
+ onPreloadCallback: null,
+
+ /**
+ * This will be called when create states. (setup states...)
+ * @type {function}
+ */
+ onCreateCallback: null,
+
+ /**
+ * This will be called when State is updated, this doesn't happen during load (see onLoadUpdateCallback)
+ * @type {function}
+ */
+ onUpdateCallback: null,
+
+ /**
+ * This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback)
+ * @type {function}
+ */
+ onRenderCallback: null,
+
+ /**
+ * This will be called before the State is rendered and before the stage is cleared
+ * @type {function}
+ */
+ onPreRenderCallback: null,
+
+ /**
+ * This will be called when the State is updated but only during the load process
+ * @type {function}
+ */
+ onLoadUpdateCallback: null,
+
+ /**
+ * This will be called when the State is rendered but only during the load process
+ * @type {function}
+ */
+ onLoadRenderCallback: null,
+
+ /**
+ * This will be called when states paused.
+ * @type {function}
+ */
+ onPausedCallback: null,
+
+ /**
+ * This will be called when the state is destroyed (i.e. swapping to a new state)
+ * @type {function}
+ */
+ onDestroyCallback: null,
+
+ /**
+ * Whether the game engine is booted, aka available.
+ * @type {bool}
+ */
+ isBooted: false,
+
+ /**
+ * Is game running or paused?
+ * @type {bool}
+ */
+ isRunning: false,
+
+ /**
+ * Initialize engine sub modules and start the game.
+ * @param parent {string} ID of parent Dom element.
+ * @param width {number} Width of the game screen.
+ * @param height {number} Height of the game screen.
+ */
+ boot: function (parent, width, height) {
+
+ var _this = this;
+
+ if (this.isBooted) {
+ return;
+ }
+
+ if (!document.body) {
+ setTimeout(function () {
+ return Phaser.GAMES[_this.id].boot(parent, width, height);
+ }, 13);
+ }
+ else
+ {
+ document.removeEventListener('DOMContentLoaded', Phaser.GAMES[_this.id].boot);
+ window.removeEventListener('load', Phaser.GAMES[_this.id].boot);
+
+ console.log('Phaser', Phaser.VERSION, 'alive');
+
+ // this.onPause = new Phaser.Signal();
+ // this.onResume = new Phaser.Signal();
+ this.device = new Phaser.Device();
+ this.net = new Phaser.Net(this);
+ // this.math = new Phaser.GameMath(this);
+ // this.stage = new Phaser.Stage(this, parent, width, height);
+ // this.world = new Phaser.World(this, width, height);
+ // this.add = new Phaser.GameObjectFactory(this);
+ this.cache = new Phaser.Cache(this);
+ this.load = new Phaser.Loader(this);
+ this.time = new Phaser.Time(this);
+ // this.tweens = new Phaser.TweenManager(this);
+ // this.input = new Phaser.InputManager(this);
+ // this.sound = new Phaser.SoundManager(this);
+ this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
+ // this.physics = new Phaser.Physics.PhysicsManager(this);
+ // this.plugins = new Phaser.PluginManager(this, this);
+ // this.load.onLoadComplete.add(this.loadComplete, this);
+ // this.setRenderer(Phaser.Types.RENDERER_CANVAS);
+ // this.world.boot();
+ // this.stage.boot();
+ // this.input.boot();
+
+ this.isBooted = true;
+ }
+
+ },
+
+};
diff --git a/src/Phaser.js b/src/Phaser.js
new file mode 100644
index 00000000..78eb26a0
--- /dev/null
+++ b/src/Phaser.js
@@ -0,0 +1,26 @@
+/**
+* Phaser - http://www.phaser.io
+*
+* v1.0.0 - Released at some point during 2013
+*
+* @author Richard Davey http://www.photonstorm.com @photonstorm
+*
+* A feature-packed 2D HTML5 game framework born from the smouldering pits of Flixel and
+* constructed via plenty of blood, sweat, tears and coffee by Richard Davey (@photonstorm).
+*
+* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
+* and my love of game development originate.
+*
+* Internally Phaser uses pixi.js by Mat Groves http://matgroves.com/ @Doormat23 for rendering.
+*
+* Follow Phaser development progress at http://www.photonstorm.com
+*
+* "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
+*/
+
+/**
+ * @module Phaser
+ */
+var Phaser = Phaser || { VERSION: '1.0.0', GAMES: [] };
diff --git a/src/animation/Animation.js b/src/animation/Animation.js
new file mode 100644
index 00000000..9a031144
--- /dev/null
+++ b/src/animation/Animation.js
@@ -0,0 +1,3 @@
+Phaser.Animation = {
+
+};
\ No newline at end of file
diff --git a/src/animation/Frame.js b/src/animation/Frame.js
new file mode 100644
index 00000000..6d992731
--- /dev/null
+++ b/src/animation/Frame.js
@@ -0,0 +1,139 @@
+/**
+* Frame
+*
+* A Frame is a single frame of an animation and is part of a FrameData collection.
+*
+* @package Phaser.Animation.Frame
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+*/
+Phaser.Animation.Frame = function (x, y, width, height, name) {
+
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.name = name;
+
+};
+
+Phaser.Animation.Frame.prototype = {
+
+ /**
+ * X position within the image to cut from.
+ * @type {number}
+ */
+ x: 0,
+
+ /**
+ * Y position within the image to cut from.
+ * @type {number}
+ */
+ y: 0,
+
+ /**
+ * Width of the frame.
+ * @type {number}
+ */
+ width: 0,
+
+ /**
+ * Height of the frame.
+ * @type {number}
+ */
+ height: 0,
+
+ /**
+ * Useful for Sprite Sheets.
+ * @type {number}
+ */
+ index: 0,
+
+ /**
+ * Useful for Texture Atlas files. (is set to the filename value)
+ */
+ name: '',
+
+ /**
+ * Rotated? (not yet implemented)
+ */
+ rotated: false,
+
+ /**
+ * Either cw or ccw, rotation is always 90 degrees.
+ */
+ rotationDirection: 'cw',
+
+ /**
+ * Was it trimmed when packed?
+ * @type {bool}
+ */
+ trimmed: false,
+
+ // The coordinates of the trimmed sprite inside the original sprite
+
+ /**
+ * Width of the original sprite.
+ * @type {number}
+ */
+ sourceSizeW: 0,
+
+ /**
+ * Height of the original sprite.
+ * @type {number}
+ */
+ sourceSizeH: 0,
+
+ /**
+ * X position of the trimmed sprite inside original sprite.
+ * @type {number}
+ */
+ spriteSourceSizeX: 0,
+
+ /**
+ * Y position of the trimmed sprite inside original sprite.
+ * @type {number}
+ */
+ spriteSourceSizeY: 0,
+
+ /**
+ * Width of the trimmed sprite.
+ * @type {number}
+ */
+ spriteSourceSizeW: 0,
+
+ /**
+ * Height of the trimmed sprite.
+ * @type {number}
+ */
+ spriteSourceSizeH: 0,
+
+ /**
+ * Set trim of the frame.
+ * @param trimmed {bool} Whether this frame trimmed or not.
+ * @param actualWidth {number} Actual width of this frame.
+ * @param actualHeight {number} Actual height of this frame.
+ * @param destX {number} Destination x position.
+ * @param destY {number} Destination y position.
+ * @param destWidth {number} Destination draw width.
+ * @param destHeight {number} Destination draw height.
+ */
+ setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
+
+ this.trimmed = trimmed;
+
+ if (trimmed) {
+ this.width = actualWidth;
+ this.height = actualHeight;
+ this.sourceSizeW = actualWidth;
+ this.sourceSizeH = actualHeight;
+ this.spriteSourceSizeX = destX;
+ this.spriteSourceSizeY = destY;
+ this.spriteSourceSizeW = destWidth;
+ this.spriteSourceSizeH = destHeight;
+ }
+
+ }
+
+};
diff --git a/src/animation/FrameData.js b/src/animation/FrameData.js
new file mode 100644
index 00000000..548be101
--- /dev/null
+++ b/src/animation/FrameData.js
@@ -0,0 +1,182 @@
+/**
+* FrameData
+*
+* FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser.
+*
+* @package Phaser.Animation.FrameData
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+*/
+Phaser.Animation.FrameData = function () {
+};
+
+Phaser.Animation.FrameData.prototype = {
+
+ /**
+ * Local frame container.
+ * @type {Phaser.Frame[]}
+ * @private
+ */
+ _frames: [],
+
+ /**
+ * Local frameName<->index container.
+ * @private
+ */
+ _frameNames: [],
+
+ /**
+ * Add a new frame.
+ * @param frame {Frame} The frame you want to add.
+ * @return {Frame} The frame you just added.
+ */
+ addFrame: function (frame) {
+
+ frame.index = this._frames.length;
+
+ this._frames.push(frame);
+
+ if (frame.name !== '') {
+ this._frameNames[frame.name] = frame.index;
+ }
+
+ return frame;
+
+ },
+
+ /**
+ * Get a frame by its index.
+ * @param index {number} Index of the frame you want to get.
+ * @return {Frame} The frame you want.
+ */
+ getFrame: function (index) {
+
+ if (this._frames[index]) {
+ return this._frames[index];
+ }
+
+ return null;
+
+ },
+
+ /**
+ * Get a frame by its name.
+ * @param name {string} Name of the frame you want to get.
+ * @return {Frame} The frame you want.
+ */
+ getFrameByName: function (name) {
+
+ if (this._frameNames[name] !== '') {
+ return this._frames[this._frameNames[name]];
+ }
+
+ return null;
+
+ },
+
+ /**
+ * Check whether there's a frame with given name.
+ * @param name {string} Name of the frame you want to check.
+ * @return {bool} True if frame with given name found, otherwise return false.
+ */
+ checkFrameName: function (name) {
+
+ if (this._frameNames[name] == null) {
+ return false;
+ }
+
+ return true;
+ },
+
+ /**
+ * Get ranges of frames in an array.
+ * @param start {number} Start index of frames you want.
+ * @param end {number} End index of frames you want.
+ * @param [output] {Frame[]} result will be added into this array.
+ * @return {Frame[]} Ranges of specific frames in an array.
+ */
+ getFrameRange: function (start, end, output) {
+
+ if (typeof output === "undefined") { output = []; }
+
+ for (var i = start; i <= end; i++) {
+ output.push(this._frames[i]);
+ }
+
+ return output;
+
+ },
+
+ /**
+ * Get all indexes of frames by giving their name.
+ * @param [output] {number[]} result will be added into this array.
+ * @return {number[]} Indexes of specific frames in an array.
+ */
+ getFrameIndexes: function (output) {
+
+ if (typeof output === "undefined") { output = []; }
+
+ for (var i = 0; i < this._frames.length; i++) {
+ output.push(i);
+ }
+
+ return output;
+
+ },
+
+ /**
+ * Get the frame indexes by giving the frame names.
+ * @param [output] {number[]} result will be added into this array.
+ * @return {number[]} Names of specific frames in an array.
+ */
+ getFrameIndexesByName: function (input) {
+
+ var output = [];
+
+ for (var i = 0; i < input.length; i++) {
+
+ if (this.getFrameByName(input[i])) {
+ output.push(this.getFrameByName(input[i]).index);
+ }
+
+ }
+
+ return output;
+
+ },
+
+ /**
+ * Get all frames in this frame data.
+ * @return {Frame[]} All the frames in an array.
+ */
+ getAllFrames: function () {
+ return this._frames;
+ },
+
+ /**
+ * Get All frames with specific ranges.
+ * @param range {number[]} Ranges in an array.
+ * @return {Frame[]} All frames in an array.
+ */
+ getFrames: function (range) {
+
+ var output = [];
+
+ for (var i = 0; i < range.length; i++) {
+ output.push(this._frames[i]);
+ }
+
+ return output;
+ }
+
+};
+
+Object.defineProperty(Phaser.Animation.FrameData.prototype, "total", {
+ get: function () {
+ return this._frames.length;
+ },
+ enumerable: true,
+ configurable: true
+});
+
diff --git a/src/animation/Parser.js b/src/animation/Parser.js
new file mode 100644
index 00000000..cfe13fdd
--- /dev/null
+++ b/src/animation/Parser.js
@@ -0,0 +1,159 @@
+/**
+* Animation Parser
+*
+* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
+*
+* @package Phaser.Animation.Parser
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+*/
+Phaser.Animation.Parser = {
+
+ /**
+ * Parse a sprite sheet from asset data.
+ * @param key {string} Asset key for the sprite sheet data.
+ * @param frameWidth {number} Width of animation frame.
+ * @param frameHeight {number} Height of animation frame.
+ * @param frameMax {number} Number of animation frames.
+ * @return {FrameData} Generated FrameData object.
+ */
+ spriteSheet: function (game, key, frameWidth, frameHeight, frameMax) {
+
+ // How big is our image?
+ var img = game.cache.getImage(key);
+
+ if (img == null) {
+ return null;
+ }
+
+ var width = img.width;
+ var height = img.height;
+ var row = Math.round(width / frameWidth);
+ var column = Math.round(height / frameHeight);
+ var total = row * column;
+
+ if (frameMax !== -1) {
+ total = frameMax;
+ }
+
+ // Zero or smaller than frame sizes?
+ if (width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
+ throw new Error("AnimationLoader.parseSpriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
+ return null;
+ }
+
+ // Let's create some frames then
+ var data = new Phaser.Animation.FrameData();
+ var x = 0;
+ var y = 0;
+
+ for (var i = 0; i < total; i++) {
+
+ data.addFrame(new Phaser.Animation.Frame(x, y, frameWidth, frameHeight, ''));
+
+ x += frameWidth;
+
+ if (x === width) {
+ x = 0;
+ y += frameHeight;
+ }
+ }
+
+ return data;
+
+ },
+
+ /**
+ * Parse frame data from json.
+ * @param json {object} Json data you want to parse.
+ * @return {FrameData} Generated FrameData object.
+ */
+ JSONData: function (game, json) {
+
+ // Malformed?
+ if (!json['frames']) {
+ console.log(json);
+ throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
+ }
+
+ // Let's create some frames then
+ var data = new Phaser.Animation.FrameData();
+
+ // By this stage frames is a fully parsed array
+ var frames = json['frames'];
+ var newFrame;
+
+ for (var i = 0; i < frames.length; i++) {
+
+ newFrame = data.addFrame(new Phaser.Animation.Frame(
+ frames[i].frame.x,
+ frames[i].frame.y,
+ frames[i].frame.w,
+ frames[i].frame.h,
+ frames[i].filename
+ ));
+
+ newFrame.setTrim(
+ frames[i].trimmed,
+ frames[i].sourceSize.w,
+ frames[i].sourceSize.h,
+ frames[i].spriteSourceSize.x,
+ frames[i].spriteSourceSize.y,
+ frames[i].spriteSourceSize.w,
+ frames[i].spriteSourceSize.h
+ );
+ }
+
+ return data;
+
+ },
+
+ /**
+ * Parse frame data from an XML file.
+ * @param xml {object} XML data you want to parse.
+ * @return {FrameData} Generated FrameData object.
+ */
+ XMLData: function (game, xml, format) {
+
+ // Malformed?
+ if (!xml.getElementsByTagName('TextureAtlas')) {
+ throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing tag");
+ }
+
+ // Let's create some frames then
+ var data = new Phaser.Animation.FrameData();
+ var frames = xml.getElementsByTagName('SubTexture');
+ var newFrame;
+
+ for (var i = 0; i < frames.length; i++) {
+
+ var frame = frames[i].attributes;
+
+ newFrame = data.addFrame(new Phaser.Animation.Frame(
+ frame.x.nodeValue,
+ frame.y.nodeValue,
+ frame.width.nodeValue,
+ frame.height.nodeValue,
+ frame.name.nodeValue
+ ));
+
+ // Trimmed?
+ if (frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0') {
+ newFrame.setTrim(
+ true,
+ frame.width.nodeValue,
+ frame.height.nodeValue,
+ Math.abs(frame.frameX.nodeValue),
+ Math.abs(frame.frameY.nodeValue),
+ frame.frameWidth.nodeValue,
+ frame.frameHeight.nodeValue
+ );
+ }
+ }
+
+ return data;
+
+ }
+
+};
diff --git a/src/core/Signal.js b/src/core/Signal.js
new file mode 100644
index 00000000..98bc1598
--- /dev/null
+++ b/src/core/Signal.js
@@ -0,0 +1,247 @@
+/**
+* Phaser.Signal
+*
+* A Signal is used for object communication via a custom broadcaster instead of Events.
+*
+* @author Miller Medeiros http://millermedeiros.github.com/js-signals/
+* @constructor
+*/
+Phaser.Signal = function () {
+
+ /**
+ * @type Array.
+ * @private
+ */
+ this._bindings = [];
+ this._prevParams = null;
+
+ // enforce dispatch to aways work on same context (#47)
+ var self = this;
+
+ this.dispatch = function(){
+ Phaser.Signal.prototype.dispatch.apply(self, arguments);
+ };
+
+};
+
+Phaser.Signal.prototype = {
+
+ /**
+ * If Signal should keep record of previously dispatched parameters and
+ * automatically execute listener during `add()`/`addOnce()` if Signal was
+ * already dispatched before.
+ * @type boolean
+ */
+ memorize: false,
+
+ /**
+ * @type boolean
+ * @private
+ */
+ _shouldPropagate: true,
+
+ /**
+ * If Signal is active and should broadcast events.
+ * IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
+ * @type boolean
+ */
+ active: true,
+
+ validateListener: function (listener, fnName) {
+ if (typeof listener !== 'function') {
+ throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
+ }
+ },
+
+ /**
+ * @param {Function} listener
+ * @param {boolean} isOnce
+ * @param {Object} [listenerContext]
+ * @param {Number} [priority]
+ * @return {Phaser.SignalBinding}
+ * @private
+ */
+ _registerListener: function (listener, isOnce, listenerContext, priority) {
+
+ var prevIndex = this._indexOfListener(listener, listenerContext),
+ binding;
+
+ if (prevIndex !== -1) {
+ binding = this._bindings[prevIndex];
+ if (binding.isOnce() !== isOnce) {
+ throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
+ }
+ } else {
+ binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
+ this._addBinding(binding);
+ }
+
+ if(this.memorize && this._prevParams){
+ binding.execute(this._prevParams);
+ }
+
+ return binding;
+ },
+
+ /**
+ * @param {Phaser.SignalBinding} binding
+ * @private
+ */
+ _addBinding: function (binding) {
+ //simplified insertion sort
+ var n = this._bindings.length;
+ do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
+ this._bindings.splice(n + 1, 0, binding);
+ },
+
+ /**
+ * @param {Function} listener
+ * @return {number}
+ * @private
+ */
+ _indexOfListener: function (listener, context) {
+ var n = this._bindings.length,
+ cur;
+ while (n--) {
+ cur = this._bindings[n];
+ if (cur._listener === listener && cur.context === context) {
+ return n;
+ }
+ }
+ return -1;
+ },
+
+ /**
+ * Check if listener was attached to Signal.
+ * @param {Function} listener
+ * @param {Object} [context]
+ * @return {boolean} if Signal has the specified listener.
+ */
+ has: function (listener, context) {
+ return this._indexOfListener(listener, context) !== -1;
+ },
+
+ /**
+ * Add a listener to the signal.
+ * @param {Function} listener Signal handler function.
+ * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
+ * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ add: function (listener, listenerContext, priority) {
+ this.validateListener(listener, 'add');
+ return this._registerListener(listener, false, listenerContext, priority);
+ },
+
+ /**
+ * Add listener to the signal that should be removed after first execution (will be executed only once).
+ * @param {Function} listener Signal handler function.
+ * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
+ * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ addOnce: function (listener, listenerContext, priority) {
+ this.validateListener(listener, 'addOnce');
+ return this._registerListener(listener, true, listenerContext, priority);
+ },
+
+ /**
+ * Remove a single listener from the dispatch queue.
+ * @param {Function} listener Handler function that should be removed.
+ * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
+ * @return {Function} Listener handler function.
+ */
+ remove: function (listener, context) {
+ this.validateListener(listener, 'remove');
+
+ var i = this._indexOfListener(listener, context);
+ if (i !== -1) {
+ this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
+ this._bindings.splice(i, 1);
+ }
+ return listener;
+ },
+
+ /**
+ * Remove all listeners from the Signal.
+ */
+ removeAll: function () {
+ var n = this._bindings.length;
+ while (n--) {
+ this._bindings[n]._destroy();
+ }
+ this._bindings.length = 0;
+ },
+
+ /**
+ * @return {number} Number of listeners attached to the Signal.
+ */
+ getNumListeners: function () {
+ return this._bindings.length;
+ },
+
+ /**
+ * Stop propagation of the event, blocking the dispatch to next listeners on the queue.
+ * IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
+ * @see Signal.prototype.disable
+ */
+ halt: function () {
+ this._shouldPropagate = false;
+ },
+
+ /**
+ * Dispatch/Broadcast Signal to all listeners added to the queue.
+ * @param {...*} [params] Parameters that should be passed to each handler.
+ */
+ dispatch: function (params) {
+ if (! this.active) {
+ return;
+ }
+
+ var paramsArr = Array.prototype.slice.call(arguments),
+ n = this._bindings.length,
+ bindings;
+
+ if (this.memorize) {
+ this._prevParams = paramsArr;
+ }
+
+ if (! n) {
+ //should come after memorize
+ return;
+ }
+
+ bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
+ this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
+
+ //execute all callbacks until end of the list or until a callback returns `false` or stops propagation
+ //reverse loop since listeners with higher priority will be added at the end of the list
+ do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
+ },
+
+ /**
+ * Forget memorized arguments.
+ * @see Signal.memorize
+ */
+ forget: function(){
+ this._prevParams = null;
+ },
+
+ /**
+ * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
+ * IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
+ */
+ dispose: function () {
+ this.removeAll();
+ delete this._bindings;
+ delete this._prevParams;
+ },
+
+ /**
+ * @return {string} String representation of the object.
+ */
+ toString: function () {
+ return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
+ }
+
+};
diff --git a/src/core/SignalBinding.js b/src/core/SignalBinding.js
new file mode 100644
index 00000000..3617838d
--- /dev/null
+++ b/src/core/SignalBinding.js
@@ -0,0 +1,151 @@
+/**
+* Phaser.SignalBinding
+*
+* Object that represents a binding between a Signal and a listener function.
+*
- This is an internal constructor and shouldn't be called by regular users.
+*
- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
+*
+* @author Miller Medeiros http://millermedeiros.github.com/js-signals/
+* @constructor
+* @internal
+* @name SignalBinding
+* @param {Signal} signal Reference to Signal object that listener is currently bound to.
+* @param {Function} listener Handler function bound to the signal.
+* @param {boolean} isOnce If binding should be executed just once.
+* @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+* @param {Number} [priority] The priority level of the event listener. (default = 0).
+*/
+Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority) {
+
+ /**
+ * Handler function bound to the signal.
+ * @type Function
+ * @private
+ */
+ this._listener = listener;
+
+ /**
+ * If binding should be executed just once.
+ * @type boolean
+ * @private
+ */
+ this._isOnce = isOnce;
+
+ /**
+ * Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @memberOf SignalBinding.prototype
+ * @name context
+ * @type Object|undefined|null
+ */
+ this.context = listenerContext;
+
+ /**
+ * Reference to Signal object that listener is currently bound to.
+ * @type Signal
+ * @private
+ */
+ this._signal = signal;
+
+ /**
+ * Listener priority
+ * @type Number
+ * @private
+ */
+ this._priority = priority || 0;
+
+};
+
+Phaser.SignalBinding.prototype = {
+
+ /**
+ * If binding is active and should be executed.
+ * @type boolean
+ */
+ active: true,
+
+ /**
+ * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters)
+ * @type Array|null
+ */
+ params: null,
+
+ /**
+ * Call listener passing arbitrary parameters.
+ * If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
+ * @param {Array} [paramsArr] Array of parameters that should be passed to the listener
+ * @return {*} Value returned by the listener.
+ */
+ execute: function (paramsArr) {
+
+ var handlerReturn, params;
+
+ if (this.active && !!this._listener)
+ {
+ params = this.params? this.params.concat(paramsArr) : paramsArr;
+ handlerReturn = this._listener.apply(this.context, params);
+
+ if (this._isOnce)
+ {
+ this.detach();
+ }
+ }
+
+ return handlerReturn;
+
+ },
+
+ /**
+ * Detach binding from signal.
+ * - alias to: mySignal.remove(myBinding.getListener());
+ * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
+ */
+ detach: function () {
+ return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
+ },
+
+ /**
+ * @return {Boolean} `true` if binding is still bound to the signal and have a listener.
+ */
+ isBound: function () {
+ return (!!this._signal && !!this._listener);
+ },
+
+ /**
+ * @return {boolean} If SignalBinding will only be executed once.
+ */
+ isOnce: function () {
+ return this._isOnce;
+ },
+
+ /**
+ * @return {Function} Handler function bound to the signal.
+ */
+ getListener: function () {
+ return this._listener;
+ },
+
+ /**
+ * @return {Signal} Signal that listener is currently bound to.
+ */
+ getSignal: function () {
+ return this._signal;
+ },
+
+ /**
+ * Delete instance properties
+ * @private
+ */
+ _destroy: function () {
+ delete this._signal;
+ delete this._listener;
+ delete this.context;
+ },
+
+ /**
+ * @return {string} String representation of the object.
+ */
+ toString: function () {
+ return '[Phaser.SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']';
+ }
+
+};
diff --git a/src/loader/Cache.js b/src/loader/Cache.js
new file mode 100644
index 00000000..d29af14e
--- /dev/null
+++ b/src/loader/Cache.js
@@ -0,0 +1,391 @@
+/**
+* Cache
+*
+* A game only has one instance of a Cache and it is used to store all externally loaded assets such
+* as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up.
+*
+* @package Phaser.Cache
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+*/
+Phaser.Cache = function (game) {
+ this.game = game;
+};
+
+Phaser.Cache.prototype = {
+
+ /**
+ * Local reference to Game.
+ */
+ game: null,
+
+ /**
+ * Canvas key-value container.
+ * @type {object}
+ * @private
+ */
+ _canvases: {},
+
+ /**
+ * Image key-value container.
+ * @type {object}
+ */
+ _images: {},
+
+ /**
+ * Sound key-value container.
+ * @type {object}
+ */
+ _sounds: {},
+
+ /**
+ * Text key-value container.
+ * @type {object}
+ */
+ _text: {},
+
+ /**
+ * Add a new canvas.
+ * @param key {string} Asset key for this canvas.
+ * @param canvas {HTMLCanvasElement} Canvas DOM element.
+ * @param context {CanvasRenderingContext2D} Render context of this canvas.
+ */
+ addCanvas: function (key, canvas, context) {
+
+ this._canvases[key] = { canvas: canvas, context: context };
+
+ },
+
+ /**
+ * Add a new sprite sheet.
+ * @param key {string} Asset key for the sprite sheet.
+ * @param url {string} URL of this sprite sheet file.
+ * @param data {object} Extra sprite sheet data.
+ * @param frameWidth {number} Width of the sprite sheet.
+ * @param frameHeight {number} Height of the sprite sheet.
+ * @param frameMax {number} How many frames stored in the sprite sheet.
+ */
+ addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax) {
+
+ this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
+ this._images[key].frameData = Phaser.Animation.Parser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
+
+ },
+
+ /**
+ * Add a new texture atlas.
+ * @param key {string} Asset key for the texture atlas.
+ * @param url {string} URL of this texture atlas file.
+ * @param data {object} Extra texture atlas data.
+ * @param atlasData {object} Texture atlas frames data.
+ */
+ addTextureAtlas: function (key, url, data, atlasData, format) {
+
+ this._images[key] = { url: url, data: data, spriteSheet: true };
+
+ if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY)
+ {
+ this._images[key].frameData = Phaser.Animation.Parser.JSONData(this.game, atlasData);
+ }
+ else if (format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
+ {
+ this._images[key].frameData = Phaser.Animation.Parser.XMLData(this.game, atlasData, format);
+ }
+
+ },
+
+ /**
+ * Add a new image.
+ * @param key {string} Asset key for the image.
+ * @param url {string} URL of this image file.
+ * @param data {object} Extra image data.
+ */
+ addImage: function (key, url, data) {
+
+ this._images[key] = { url: url, data: data, spriteSheet: false };
+
+ },
+
+ /**
+ * Add a new sound.
+ * @param key {string} Asset key for the sound.
+ * @param url {string} URL of this sound file.
+ * @param data {object} Extra sound data.
+ */
+ addSound: function (key, url, data, webAudio, audioTag) {
+
+ if (typeof webAudio === "undefined") { webAudio = true; }
+ if (typeof audioTag === "undefined") { audioTag = false; }
+
+ var locked = this.game.sound.touchLocked;
+ var decoded = false;
+
+ if (audioTag) {
+ decoded = true;
+ }
+
+ this._sounds[key] = { url: url, data: data, locked: locked, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag };
+
+ },
+
+ reloadSound: function (key) {
+
+ var _this = this;
+
+ if (this._sounds[key]) {
+
+ this._sounds[key].data.src = this._sounds[key].url;
+
+ this._sounds[key].data.addEventListener('canplaythrough', function () {
+ return _this.reloadSoundComplete(key);
+ }, false);
+
+ this._sounds[key].data.load();
+ }
+ },
+
+ reloadSoundComplete: function (key) {
+
+ if (this._sounds[key]) {
+ this._sounds[key].locked = false;
+ this.onSoundUnlock.dispatch(key);
+ }
+
+ },
+
+ updateSound: function (key, property, value) {
+
+ if (this._sounds[key]) {
+ this._sounds[key][property] = value;
+ }
+
+ },
+
+ /**
+ * Add a new decoded sound.
+ * @param key {string} Asset key for the sound.
+ * @param data {object} Extra sound data.
+ */
+ decodedSound: function (key, data) {
+
+ this._sounds[key].data = data;
+ this._sounds[key].decoded = true;
+ this._sounds[key].isDecoding = false;
+
+ },
+
+ /**
+ * Add a new text data.
+ * @param key {string} Asset key for the text data.
+ * @param url {string} URL of this text data file.
+ * @param data {object} Extra text data.
+ */
+ addText: function (key, url, data) {
+
+ this._text[key] = {
+ url: url,
+ data: data
+ };
+
+ },
+
+ /**
+ * Get canvas by key.
+ * @param key Asset key of the canvas you want.
+ * @return {object} The canvas you want.
+ */
+ getCanvas: function (key) {
+
+ if (this._canvases[key]) {
+ return this._canvases[key].canvas;
+ }
+
+ return null;
+ },
+
+ /**
+ * Get image data by key.
+ * @param key Asset key of the image you want.
+ * @return {object} The image data you want.
+ */
+ getImage: function (key) {
+
+ if (this._images[key]) {
+ return this._images[key].data;
+ }
+
+ return null;
+ },
+
+ /**
+ * Get frame data by key.
+ * @param key Asset key of the frame data you want.
+ * @return {object} The frame data you want.
+ */
+ getFrameData: function (key) {
+
+ if (this._images[key] && this._images[key].frameData) {
+ return this._images[key].frameData;
+ }
+
+ return null;
+ },
+
+ /**
+ * Get sound by key.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound you want.
+ */
+ getSound: function (key) {
+
+ if (this._sounds[key]) {
+ return this._sounds[key];
+ }
+
+ return null;
+
+ },
+
+ /**
+ * Get sound data by key.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound data you want.
+ */
+ getSoundData: function (key) {
+
+ if (this._sounds[key]) {
+ return this._sounds[key].data;
+ }
+
+ return null;
+
+ },
+
+ /**
+ * Check whether an asset is decoded sound.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound data you want.
+ */
+ isSoundDecoded: function (key) {
+
+ if (this._sounds[key]) {
+ return this._sounds[key].decoded;
+ }
+
+ },
+
+ /**
+ * Check whether an asset is decoded sound.
+ * @param key Asset key of the sound you want.
+ * @return {object} The sound data you want.
+ */
+ isSoundReady: function (key) {
+ return (this._sounds[key] && this._sounds[key].decoded == true && this._sounds[key].locked == false);
+ },
+
+ /**
+ * Check whether an asset is sprite sheet.
+ * @param key Asset key of the sprite sheet you want.
+ * @return {object} The sprite sheet data you want.
+ */
+ isSpriteSheet: function (key) {
+
+ if (this._images[key]) {
+ return this._images[key].spriteSheet;
+ }
+
+ return false;
+
+ },
+
+ /**
+ * Get text data by key.
+ * @param key Asset key of the text data you want.
+ * @return {object} The text data you want.
+ */
+ getText: function (key) {
+
+ if (this._text[key]) {
+ return this._text[key].data;
+ }
+
+ return null;
+
+ },
+
+ getKeys: function (array) {
+
+ var output = [];
+
+ for (var item in array) {
+ output.push(item);
+ }
+
+ return output;
+
+ },
+
+ /**
+ * Returns an array containing all of the keys of Images in the Cache.
+ * @return {Array} The string based keys in the Cache.
+ */
+ getImageKeys: function () {
+ return this.getKeys(this._images);
+ },
+
+ /**
+ * Returns an array containing all of the keys of Sounds in the Cache.
+ * @return {Array} The string based keys in the Cache.
+ */
+ getSoundKeys: function () {
+ return this.getKeys(this._sounds);
+ },
+
+ /**
+ * Returns an array containing all of the keys of Text Files in the Cache.
+ * @return {Array} The string based keys in the Cache.
+ */
+ getTextKeys: function () {
+ return this.getKeys(this._text);
+ },
+
+ removeCanvas: function (key) {
+ delete this._canvases[key];
+ },
+
+ removeImage: function (key) {
+ delete this._images[key];
+ },
+
+ removeSound: function (key) {
+ delete this._sounds[key];
+ },
+
+ removeText: function (key) {
+ delete this._text[key];
+ },
+
+ /**
+ * Clean up cache memory.
+ */
+ destroy: function () {
+
+ for (var item in this._canvases) {
+ delete this._canvases[item['key']];
+ }
+
+ for (var item in this._images) {
+ delete this._images[item['key']];
+ }
+
+ for (var item in this._sounds) {
+ delete this._sounds[item['key']];
+ }
+
+ for (var item in this._text) {
+ delete this._text[item['key']];
+ }
+ }
+
+};
diff --git a/src/loader/Loader.js b/src/loader/Loader.js
new file mode 100644
index 00000000..2490d578
--- /dev/null
+++ b/src/loader/Loader.js
@@ -0,0 +1,682 @@
+/**
+* Phaser.Loader
+*
+* The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.
+* It uses a combination of Image() loading and xhr and provides progress and completion callbacks.
+*/
+Phaser.Loader = function (game) {
+
+ this.game = game;
+
+ this._xhr = new XMLHttpRequest();
+
+ this.onFileComplete = new Phaser.Signal;
+ this.onFileError = new Phaser.Signal;
+ this.onLoadStart = new Phaser.Signal;
+ this.onLoadComplete = new Phaser.Signal;
+
+};
+
+/**
+ * TextureAtlas data format constants
+ */
+Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY = 0;
+Phaser.Loader.TEXTURE_ATLAS_JSON_HASH = 1;
+Phaser.Loader.TEXTURE_ATLAS_XML_STARLING = 2;
+
+Phaser.Loader.prototype = {
+
+ /**
+ * Local reference to Game.
+ */
+ game: null,
+
+ /**
+ * Array stores assets keys. So you can get that asset by its unique key.
+ */
+ _keys: [],
+
+ /**
+ * Contains all the assets file infos.
+ */
+ _fileList: {},
+
+ /**
+ * Indicates assets loading progress. (from 0 to 100)
+ * @type {number}
+ */
+ _progressChunk: 0,
+
+ /**
+ * An XMLHttpRequest object used for loading text and audio data
+ * @type {XMLHttpRequest}
+ */
+ _xhr: null,
+
+ /**
+ * Length of assets queue.
+ * @type {number}
+ */
+ queueSize: 0,
+
+ /**
+ * True if the Loader is in the process of loading the queue.
+ * @type {bool}
+ */
+ isLoading: false,
+
+ /**
+ * True if all assets in the queue have finished loading.
+ * @type {bool}
+ */
+ hasLoaded: false,
+
+ /**
+ * The Load progress percentage value (from 0 to 100)
+ * @type {number}
+ */
+ progress: 0,
+
+ /**
+ * The crossOrigin value applied to loaded images
+ * @type {string}
+ */
+ crossOrigin: '',
+
+ /**
+ * If you want to append a URL before the path of any asset you can set this here.
+ * Useful if you need to allow an asset url to be configured outside of the game code.
+ * MUST have / on the end of it!
+ * @type {string}
+ */
+ baseURL: '',
+
+ /**
+ * Event Signals
+ */
+ onFileComplete: null,
+ onFileError: null,
+ onLoadStart: null,
+ onLoadComplete: null,
+
+ /**
+ * Check whether asset exists with a specific key.
+ * @param key {string} Key of the asset you want to check.
+ * @return {bool} Return true if exists, otherwise return false.
+ */
+ checkKeyExists: function (key) {
+
+ if (this._fileList[key]) {
+ return true;
+ } else {
+ return false;
+ }
+
+ },
+
+ /**
+ * Reset loader, this will remove all loaded assets.
+ */
+ reset: function () {
+ this.queueSize = 0;
+ this.isLoading = false;
+ },
+
+ /**
+ * Internal function that adds a new entry to the file list.
+ */
+ addToFileList: function (type, key, url, properties) {
+
+ var entry = {
+ type: type,
+ key: key,
+ url: url,
+ data: null,
+ error: false,
+ loaded: false
+ };
+
+ if (typeof properties !== "undefined") {
+
+ for (var prop in properties) {
+ entry[prop] = properties[prop];
+ }
+
+ }
+
+ this._fileList[key] = entry;
+
+ this._keys.push(key);
+
+ this.queueSize++;
+
+ },
+
+ /**
+ * Add an image to the Loader.
+ * @param key {string} Unique asset key of this image file.
+ * @param url {string} URL of image file.
+ * @param overwrite {boolean} If an entry with a matching key already exists this will over-write it
+ */
+ image: function (key, url, overwrite) {
+
+ if (typeof overwrite === "undefined") { overwrite = false; }
+
+ if (overwrite || this.checkKeyExists(key) == false) {
+ this.addToFileList('image', key, url);
+ }
+
+ },
+
+ /**
+ * Add a text file to the Loader.
+ * @param key {string} Unique asset key of the text file.
+ * @param url {string} URL of the text file.
+ */
+ text: function (key, url, overwrite) {
+
+ if (typeof overwrite === "undefined") { overwrite = false; }
+
+ if (overwrite || this.checkKeyExists(key) == false) {
+ this.addToFileList('text', key, url);
+ }
+
+ },
+
+ /**
+ * Add a new sprite sheet loading request.
+ * @param key {string} Unique asset key of the sheet file.
+ * @param url {string} URL of sheet file.
+ * @param frameWidth {number} Width of each single frame.
+ * @param frameHeight {number} Height of each single frame.
+ * @param frameMax {number} How many frames in this sprite sheet.
+ */
+ spritesheet: function (key, url, frameWidth, frameHeight, frameMax) {
+
+ if (typeof frameMax === "undefined") { frameMax = -1; }
+
+ if (this.checkKeyExists(key) === false) {
+ this.addToFileList('spritesheet', key, url, { frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax });
+ }
+
+ },
+
+ /**
+ * Add a new audio file loading request.
+ * @param key {string} Unique asset key of the audio file.
+ * @param urls {Array} An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ]
+ * @param autoDecode {bool} When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process.
+ */
+ audio: function (key, urls, autoDecode) {
+
+ if (typeof autoDecode === "undefined") { autoDecode = true; }
+
+ if (this.checkKeyExists(key) === false) {
+ this.addToFileList('audio', key, urls, { buffer: null, autoDecode: autoDecode });
+ }
+
+ },
+
+ atlasJSON: function (key, textureURL, atlasURL, atlasData) {
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY);
+ },
+
+ atlasJSONHash: function (key, textureURL, atlasURL, atlasData) {
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_HASH);
+ },
+
+ atlasXML: function (key, textureURL, atlasURL, atlasData) {
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING);
+ },
+
+ /**
+ * Add a new texture atlas loading request.
+ * @param key {string} Unique asset key of the texture atlas file.
+ * @param textureURL {string} The url of the texture atlas image file.
+ * @param [atlasURL] {string} The url of the texture atlas data file (json/xml)
+ * @param [atlasData] {object} A JSON or XML data object.
+ * @param [format] {number} A value describing the format of the data.
+ */
+ atlas: function (key, textureURL, atlasURL, atlasData, format) {
+
+ if (typeof atlasURL === "undefined") { atlasURL = null; }
+ if (typeof atlasData === "undefined") { atlasData = null; }
+ if (typeof format === "undefined") { format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY; }
+
+ if (this.checkKeyExists(key) === false) {
+
+ // A URL to a json/xml file has been given
+ if (atlasURL) {
+ this.addToFileList('textureatlas', key, textureURL, { atlasURL: atlasURL, format: format });
+ }
+ else
+ {
+ switch (format) {
+
+ // A json string or object has been given
+ case Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY:
+
+ if (typeof atlasData === 'string') {
+ atlasData = JSON.parse(atlasData);
+ }
+ break;
+
+ // An xml string or object has been given
+ case Phaser.Loader.TEXTURE_ATLAS_XML_STARLING:
+
+ if (typeof atlasData === 'string') {
+ var xml;
+ try {
+ if (window['DOMParser']) {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ } else {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ } catch (e) {
+ xml = undefined;
+ }
+
+ if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
+ throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
+ } else {
+ atlasData = xml;
+ }
+ }
+ break;
+ }
+
+ this.addToFileList('textureatlas', key, textureURL, { atlasURL: null, atlasData: atlasData, format: format });
+
+ }
+
+
+ }
+
+ },
+
+ /**
+ * Remove loading request of a file.
+ * @param key {string} Key of the file you want to remove.
+ */
+ removeFile: function (key) {
+
+ delete this._fileList[key];
+
+ },
+
+ /**
+ * Remove all file loading requests.
+ */
+ removeAll: function () {
+
+ this._fileList = {};
+
+ },
+
+ /**
+ * Load assets.
+ */
+ start: function () {
+
+ if (this.isLoading)
+ {
+ return;
+ }
+
+ this.progress = 0;
+ this.hasLoaded = false;
+ this.isLoading = true;
+
+ this.onLoadStart.dispatch(this.queueSize);
+
+ if (this._keys.length > 0)
+ {
+ this._progressChunk = 100 / this._keys.length;
+ this.loadFile();
+ }
+ else
+ {
+ this.progress = 100;
+ this.hasLoaded = true;
+ this.onLoadComplete.dispatch();
+ }
+
+ },
+
+ /**
+ * Load files. Private method ONLY used by loader.
+ * @private
+ */
+ loadFile: function () {
+
+ var file = this._fileList[this._keys.shift()];
+ var _this = this;
+
+ // Image or Data?
+ switch (file.type)
+ {
+ case 'image':
+ case 'spritesheet':
+ case 'textureatlas':
+ file.data = new Image();
+ file.data.name = file.key;
+ file.data.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.crossOrigin = this.crossOrigin;
+ file.data.src = this.baseURL + file.url;
+ break;
+
+ case 'audio':
+ file.url = this.getAudioURL(file.url);
+
+ if (file.url !== null)
+ {
+ // WebAudio or Audio Tag?
+ if (this.game.sound.usingWebAudio)
+ {
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "arraybuffer";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ }
+ else if (this.game.sound.usingAudioTag)
+ {
+ if (this.game.sound.touchLocked)
+ {
+ // If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ this.fileComplete(file.key);
+ }
+ else
+ {
+ file.data = new Audio();
+ file.data.name = file.key;
+ file.data.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ file.data.preload = 'auto';
+ file.data.src = this.baseURL + file.url;
+ file.data.addEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete(file.key), false);
+ file.data.load();
+ }
+ }
+ }
+
+ break;
+
+ case 'text':
+ this._xhr.open("GET", this.baseURL + file.url, true);
+ this._xhr.responseType = "text";
+ this._xhr.onload = function () {
+ return _this.fileComplete(file.key);
+ };
+ this._xhr.onerror = function () {
+ return _this.fileError(file.key);
+ };
+ this._xhr.send();
+ break;
+ }
+
+ },
+
+ getAudioURL: function (urls) {
+
+ var extension;
+
+ for (var i = 0; i < urls.length; i++)
+ {
+ extension = urls[i].toLowerCase();
+ extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
+
+ if (this.game.device.canPlayAudio(extension))
+ {
+ return urls[i];
+ }
+
+ }
+
+ return null;
+
+ },
+
+ /**
+ * Error occured when load a file.
+ * @param key {string} Key of the error loading file.
+ */
+ fileError: function (key) {
+
+ this._fileList[key].loaded = true;
+ this._fileList[key].error = true;
+
+ this.onFileError.dispatch(key);
+
+ throw new Error("Phaser.Loader error loading file: " + key);
+
+ this.nextFile(key, false);
+
+ },
+
+ /**
+ * Called when a file is successfully loaded.
+ * @param key {string} Key of the successfully loaded file.
+ */
+ fileComplete: function (key) {
+
+ if (!this._fileList[key])
+ {
+ throw new Error('Phaser.Loader fileComplete invalid key ' + key);
+ return;
+ }
+
+ this._fileList[key].loaded = true;
+
+ var file = this._fileList[key];
+ var loadNext = true;
+ var _this = this;
+
+ switch (file.type)
+ {
+ case 'image':
+ this.game.cache.addImage(file.key, file.url, file.data);
+ break;
+
+ case 'spritesheet':
+ this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax);
+ break;
+
+ case 'textureatlas':
+ if (file.atlasURL == null)
+ {
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData, file.format);
+ }
+ else
+ {
+ // Load the JSON or XML before carrying on with the next file
+ loadNext = false;
+ this._xhr.open("GET", this.baseURL + file.atlasURL, true);
+ this._xhr.responseType = "text";
+
+ if (file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY || file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
+ {
+ this._xhr.onload = function () {
+ return _this.jsonLoadComplete(file.key);
+ };
+ }
+ else if (file.format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
+ {
+ this._xhr.onload = function () {
+ return _this.xmlLoadComplete(file.key);
+ };
+ }
+
+ this._xhr.onerror = function () {
+ return _this.dataLoadError(file.key);
+ };
+ this._xhr.send();
+ }
+ break;
+
+ case 'audio':
+
+ if (this.game.sound.usingWebAudio)
+ {
+ file.data = this._xhr.response;
+
+ this.game.cache.addSound(file.key, file.url, file.data, true, false);
+
+ if (file.autoDecode)
+ {
+ this.game.cache.updateSound(key, 'isDecoding', true);
+
+ var that = this;
+ var key = file.key;
+
+ this.game.sound.context.decodeAudioData(file.data, function (buffer) {
+ if (buffer)
+ {
+ that.game.cache.decodedSound(key, buffer);
+ }
+ });
+ }
+ }
+ else
+ {
+ file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete);
+ this.game.cache.addSound(file.key, file.url, file.data, false, true);
+ }
+ break;
+
+ case 'text':
+ file.data = this._xhr.response;
+ this.game.cache.addText(file.key, file.url, file.data);
+ break;
+ }
+
+ if (loadNext)
+ {
+ this.nextFile(key, true);
+ }
+
+ },
+
+ /**
+ * Successfully loaded a JSON file.
+ * @param key {string} Key of the loaded JSON file.
+ */
+ jsonLoadComplete: function (key) {
+
+ var data = JSON.parse(this._xhr.response);
+ var file = this._fileList[key];
+
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
+
+ this.nextFile(key, true);
+
+ },
+
+ /**
+ * Error occured when load a JSON.
+ * @param key {string} Key of the error loading JSON file.
+ */
+ dataLoadError: function (key) {
+
+ var file = this._fileList[key];
+
+ file.error = true;
+
+ throw new Error("Phaser.Loader dataLoadError: " + key);
+
+ this.nextFile(key, true);
+
+ },
+
+ xmlLoadComplete: function (key) {
+
+ var atlasData = this._xhr.response;
+ var xml;
+
+ try
+ {
+ if (window['DOMParser'])
+ {
+ var domparser = new DOMParser();
+ xml = domparser.parseFromString(atlasData, "text/xml");
+ }
+ else
+ {
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async = 'false';
+ xml.loadXML(atlasData);
+ }
+ }
+ catch (e)
+ {
+ xml = undefined;
+ }
+
+ if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
+ {
+ throw new Error("Phaser.Loader. Invalid XML given");
+ }
+
+ var file = this._fileList[key];
+ this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
+
+ this.nextFile(key, true);
+
+ },
+
+ /**
+ * Handle loading next file.
+ * @param previousKey {string} Key of previous loaded asset.
+ * @param success {bool} Whether the previous asset loaded successfully or not.
+ */
+ nextFile: function (previousKey, success) {
+
+ this.progress = Math.round(this.progress + this._progressChunk);
+
+ if (this.progress > 100)
+ {
+ this.progress = 100;
+ }
+
+ this.onFileComplete.dispatch(this.progress, previousKey, success, this.queueSize - this._keys.length, this.queueSize);
+
+ if (this._keys.length > 0)
+ {
+ this.loadFile();
+ }
+ else
+ {
+ this.hasLoaded = true;
+ this.isLoading = false;
+
+ this.removeAll();
+
+ this.onLoadComplete.dispatch();
+ }
+
+ }
+
+};
\ No newline at end of file
diff --git a/src/math/RandomDataGenerator.js b/src/math/RandomDataGenerator.js
new file mode 100644
index 00000000..c34ba800
--- /dev/null
+++ b/src/math/RandomDataGenerator.js
@@ -0,0 +1,233 @@
+/**
+* Phaser.RandomDataGenerator
+*
+* An extremely useful repeatable random data generator. Access it via Phaser.Game.rnd
+* Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense
+* Random number generator from http://baagoe.org/en/wiki/Better_random_numbers_for_javascript
+*/
+Phaser.RandomDataGenerator = function (seeds) {
+
+ if (typeof seeds === "undefined") { seeds = []; }
+
+ this.sow(seeds);
+
+};
+
+Phaser.RandomDataGenerator.prototype = {
+
+ /**
+ * @property c
+ * @type Number
+ * @private
+ */
+ c: 1,
+
+ /**
+ * @property s0
+ * @type Number
+ * @private
+ */
+ s0: 0,
+
+ /**
+ * @property s1
+ * @type Number
+ * @private
+ */
+ s1: 0,
+
+ /**
+ * @property s2
+ * @type Number
+ * @private
+ */
+ s2: 0,
+
+ /**
+ * Private random helper
+ * @method rnd
+ * @private
+ */
+ rnd: function () {
+
+ var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
+
+ this.c = t | 0;
+ this.s0 = this.s1;
+ this.s1 = this.s2;
+ this.s2 = t - this.c;
+
+ return this.s2;
+ },
+
+ /**
+ * Reset the seed of the random data generator
+ * @method sow
+ * @param {Array} seeds
+ */
+ sow: function (seeds) {
+
+ if (typeof seeds === "undefined") { seeds = []; }
+
+ this.s0 = this.hash(' ');
+ this.s1 = this.hash(this.s0);
+ this.s2 = this.hash(this.s1);
+
+ var seed;
+
+ for (var i = 0; seed = seeds[i++]; ) {
+ this.s0 -= this.hash(seed);
+ this.s0 += ~~(this.s0 < 0);
+ this.s1 -= this.hash(seed);
+ this.s1 += ~~(this.s1 < 0);
+ this.s2 -= this.hash(seed);
+ this.s2 += ~~(this.s2 < 0);
+ }
+
+ },
+
+ /**
+ * @method hash
+ * @param {Any} data
+ * @private
+ */
+ hash: function (data) {
+
+ var h, i, n;
+ n = 0xefc8249d;
+ data = data.toString();
+
+ for (i = 0; i < data.length; i++) {
+ n += data.charCodeAt(i);
+ h = 0.02519603282416938 * n;
+ n = h >>> 0;
+ h -= n;
+ h *= n;
+ n = h >>> 0;
+ h -= n;
+ n += h * 0x100000000;// 2^32
+ }
+
+ return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
+
+ },
+
+ /**
+ * Returns a random integer between 0 and 2^32
+ * @method integer
+ * @return {Number}
+ */
+ integer: function() {
+ return this.rnd.apply(this) * 0x100000000;// 2^32
+ },
+
+ /**
+ * Returns a random real number between 0 and 1
+ * @method frac
+ * @return {Number}
+ */
+ frac: function() {
+ return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
+ },
+
+ /**
+ * Returns a random real number between 0 and 2^32
+ * @method real
+ * @return {Number}
+ */
+ real: function() {
+ return this.integer() + this.frac();
+ },
+
+ /**
+ * Returns a random integer between min and max
+ * @method integerInRange
+ * @param {Number} min
+ * @param {Number} max
+ * @return {Number}
+ */
+ integerInRange: function (min, max) {
+ return Math.floor(this.realInRange(min, max));
+ },
+
+ /**
+ * Returns a random real number between min and max
+ * @method realInRange
+ * @param {Number} min
+ * @param {Number} max
+ * @return {Number}
+ */
+ realInRange: function (min, max) {
+
+ min = min || 0;
+ max = max || 0;
+
+ return this.frac() * (max - min) + min;
+
+ },
+
+ /**
+ * Returns a random real number between -1 and 1
+ * @method normal
+ * @return {Number}
+ */
+ normal: function () {
+ return 1 - 2 * this.frac();
+ },
+
+ /**
+ * Returns a valid RFC4122 version4 ID hex string (from https://gist.github.com/1308368)
+ * @method uuid
+ * @return {String}
+ */
+ uuid: function () {
+
+ var a, b;
+
+ for (
+ b=a='';
+ a++<36;
+ b+=~a%5|a*3&4?(a^15?8^this.frac()*(a^20?16:4):4).toString(16):'-'
+ );
+
+ return b;
+
+ },
+
+ /**
+ * Returns a random member of `array`
+ * @method pick
+ * @param {Any} array
+ */
+ pick: function (ary) {
+ return ary[this.integerInRange(0, ary.length)];
+ },
+
+ /**
+ * Returns a random member of `array`, favoring the earlier entries
+ * @method weightedPick
+ * @param {Any} array
+ */
+ weightedPick: function (ary) {
+ return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
+ },
+
+ /**
+ * Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified
+ * @method timestamp
+ * @param {Number} min
+ * @param {Number} max
+ */
+ timestamp: function (a, b) {
+ return this.realInRange(a || 946684800000, b || 1577862000000);
+ },
+
+ /**
+ * Returns a random angle between -180 and 180
+ * @method angle
+ */
+ angle: function() {
+ return this.integerInRange(-180, 180);
+ }
+
+};
diff --git a/src/net/Net.js b/src/net/Net.js
new file mode 100644
index 00000000..0e6e7c60
--- /dev/null
+++ b/src/net/Net.js
@@ -0,0 +1,130 @@
+Phaser.Net = function (game) {
+
+ this.game = game;
+
+};
+
+Phaser.Net.prototype = {
+
+ /**
+ * Returns the hostname given by the browser.
+ */
+ getHostName: function () {
+
+ if (window.location && window.location.hostname) {
+ return window.location.hostname;
+ }
+
+ return null;
+
+ },
+
+ /**
+ * Compares the given domain name against the hostname of the browser containing the game.
+ * If the domain name is found it returns true.
+ * You can specify a part of a domain, for example 'google' would match 'google.com', 'google.co.uk', etc.
+ * Do not include 'http://' at the start.
+ */
+ checkDomainName: function (domain) {
+ return window.location.hostname.indexOf(domain) !== -1;
+ },
+
+ /**
+ * Updates a value on the Query String and returns it in full.
+ * If the value doesn't already exist it is set.
+ * If the value exists it is replaced with the new value given. If you don't provide a new value it is removed from the query string.
+ * Optionally you can redirect to the new url, or just return it as a string.
+ */
+ updateQueryString: function (key, value, redirect, url) {
+
+ if (typeof redirect === "undefined") { redirect = false; }
+ if (typeof url === "undefined") { url = ''; }
+
+ if (url == '') {
+ url = window.location.href;
+ }
+
+ var output = '';
+ var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)(.*)", "gi");
+
+ if (re.test(url))
+ {
+ if (typeof value !== 'undefined' && value !== null)
+ {
+ output = url.replace(re, '$1' + key + "=" + value + '$2$3');
+ }
+ else
+ {
+ output = url.replace(re, '$1$3').replace(/(&|\?)$/, '');
+ }
+ }
+ else
+ {
+ if (typeof value !== 'undefined' && value !== null)
+ {
+ var separator = url.indexOf('?') !== -1 ? '&' : '?';
+ var hash = url.split('#');
+ url = hash[0] + separator + key + '=' + value;
+
+ if (hash[1]) {
+ url += '#' + hash[1];
+ }
+
+ output = url;
+
+ }
+ else
+ {
+ output = url;
+ }
+ }
+
+ if (redirect)
+ {
+ window.location.href = output;
+ }
+ else
+ {
+ return output;
+ }
+
+ },
+
+ /**
+ * Returns the Query String as an object.
+ * If you specify a parameter it will return just the value of that parameter, should it exist.
+ */
+ getQueryString: function (parameter) {
+
+ if (typeof parameter === "undefined") { parameter = ''; }
+
+ var output = {};
+ var keyValues = location.search.substring(1).split('&');
+
+ for (var i in keyValues) {
+
+ var key = keyValues[i].split('=');
+
+ if (key.length > 1)
+ {
+ if (parameter && parameter == this.decodeURI(key[0]))
+ {
+ return this.decodeURI(key[1]);
+ }
+ else
+ {
+ output[this.decodeURI(key[0])] = this.decodeURI(key[1]);
+ }
+ }
+ }
+
+ return output;
+
+ },
+
+ decodeURI: function (value) {
+ return decodeURIComponent(value.replace(/\+/g, " "));
+ }
+
+};
+
diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js
new file mode 100644
index 00000000..bd803339
--- /dev/null
+++ b/src/pixi/InteractionManager.js
@@ -0,0 +1,654 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+
+/**
+ * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive
+ * This manager also supports multitouch.
+ *
+ * @class InteractionManager
+ * @constructor
+ * @param stage {Stage} The stage to handle interactions
+ */
+PIXI.InteractionManager = function(stage)
+{
+ /**
+ * a refference to the stage
+ *
+ * @property stage
+ * @type Stage
+ */
+ this.stage = stage;
+
+ /**
+ * the mouse data
+ *
+ * @property mouse
+ * @type InteractionData
+ */
+ this.mouse = new PIXI.InteractionData();
+
+ /**
+ * an object that stores current touches (InteractionData) by id reference
+ *
+ * @property touchs
+ * @type Object
+ */
+ this.touchs = {};
+
+
+
+ // helpers
+ this.tempPoint = new PIXI.Point();
+ //this.tempMatrix = mat3.create();
+
+ this.mouseoverEnabled = true;
+
+ //tiny little interactiveData pool!
+ this.pool = [];
+
+ this.interactiveItems = [];
+
+
+ this.last = 0;
+}
+
+// constructor
+PIXI.InteractionManager.prototype.constructor = PIXI.InteractionManager;
+
+/**
+ * Collects an interactive sprite recursively to have their interactions managed
+ *
+ * @method collectInteractiveSprite
+ * @param displayObject {DisplayObject} the displayObject to collect
+ * @param iParent {DisplayObject}
+ * @private
+ */
+PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObject, iParent)
+{
+ var children = displayObject.children;
+ var length = children.length;
+
+ /// make an interaction tree... {item.__interactiveParent}
+ for (var i = length-1; i >= 0; i--)
+ {
+ var child = children[i];
+
+// if(child.visible) {
+ // push all interactive bits
+ if(child.interactive)
+ {
+ iParent.interactiveChildren = true;
+ //child.__iParent = iParent;
+ this.interactiveItems.push(child);
+
+ if(child.children.length > 0)
+ {
+ this.collectInteractiveSprite(child, child);
+ }
+ }
+ else
+ {
+ child.__iParent = null;
+
+ if(child.children.length > 0)
+ {
+ this.collectInteractiveSprite(child, iParent);
+ }
+ }
+// }
+ }
+}
+
+/**
+ * Sets the target for event delegation
+ *
+ * @method setTarget
+ * @param target {WebGLRenderer|CanvasRenderer} the renderer to bind events to
+ * @private
+ */
+PIXI.InteractionManager.prototype.setTarget = function(target)
+{
+ if (window.navigator.msPointerEnabled)
+ {
+ // time to remove some of that zoom in ja..
+ target.view.style["-ms-content-zooming"] = "none";
+ target.view.style["-ms-touch-action"] = "none"
+
+ // DO some window specific touch!
+ }
+
+ this.target = target;
+ target.view.addEventListener('mousemove', this.onMouseMove.bind(this), true);
+ target.view.addEventListener('mousedown', this.onMouseDown.bind(this), true);
+ document.body.addEventListener('mouseup', this.onMouseUp.bind(this), true);
+ target.view.addEventListener('mouseout', this.onMouseOut.bind(this), true);
+
+ // aint no multi touch just yet!
+ target.view.addEventListener("touchstart", this.onTouchStart.bind(this), true);
+ target.view.addEventListener("touchend", this.onTouchEnd.bind(this), true);
+ target.view.addEventListener("touchmove", this.onTouchMove.bind(this), true);
+}
+
+/**
+ * updates the state of interactive objects
+ *
+ * @method update
+ * @private
+ */
+PIXI.InteractionManager.prototype.update = function()
+{
+ if(!this.target)return;
+
+ // frequency of 30fps??
+ var now = Date.now();
+ var diff = now - this.last;
+ diff = (diff * 30) / 1000;
+ if(diff < 1)return;
+ this.last = now;
+ //
+
+ // ok.. so mouse events??
+ // yes for now :)
+ // OPTIMSE - how often to check??
+ if(this.dirty)
+ {
+ this.dirty = false;
+
+ var len = this.interactiveItems.length;
+
+ for (var i=0; i < len; i++) {
+ this.interactiveItems[i].interactiveChildren = false;
+ }
+
+ this.interactiveItems = [];
+
+ if(this.stage.interactive)this.interactiveItems.push(this.stage);
+ // go through and collect all the objects that are interactive..
+ this.collectInteractiveSprite(this.stage, this.stage);
+ }
+
+ // loop through interactive objects!
+ var length = this.interactiveItems.length;
+
+ this.target.view.style.cursor = "default";
+
+ for (var i = 0; i < length; i++)
+ {
+ var item = this.interactiveItems[i];
+
+
+ //if(!item.visible)continue;
+
+ // OPTIMISATION - only calculate every time if the mousemove function exists..
+ // OK so.. does the object have any other interactive functions?
+ // hit-test the clip!
+
+
+ if(item.mouseover || item.mouseout || item.buttonMode)
+ {
+ // ok so there are some functions so lets hit test it..
+ item.__hit = this.hitTest(item, this.mouse);
+ this.mouse.target = item;
+ // ok so deal with interactions..
+ // loks like there was a hit!
+ if(item.__hit)
+ {
+ if(item.buttonMode)this.target.view.style.cursor = "pointer";
+
+ if(!item.__isOver)
+ {
+
+ if(item.mouseover)item.mouseover(this.mouse);
+ item.__isOver = true;
+ }
+ }
+ else
+ {
+ if(item.__isOver)
+ {
+ // roll out!
+ if(item.mouseout)item.mouseout(this.mouse);
+ item.__isOver = false;
+ }
+ }
+ }
+
+ // --->
+ }
+}
+
+/**
+ * Is called when the mouse moves accross the renderer element
+ *
+ * @method onMouseMove
+ * @param event {Event} The DOM event of the mouse moving
+ * @private
+ */
+PIXI.InteractionManager.prototype.onMouseMove = function(event)
+{
+ this.mouse.originalEvent = event || window.event; //IE uses window.event
+ // TODO optimize by not check EVERY TIME! maybe half as often? //
+ var rect = this.target.view.getBoundingClientRect();
+
+ this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width);
+ this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height);
+
+ var length = this.interactiveItems.length;
+ var global = this.mouse.global;
+
+
+ for (var i = 0; i < length; i++)
+ {
+ var item = this.interactiveItems[i];
+
+ if(item.mousemove)
+ {
+ //call the function!
+ item.mousemove(this.mouse);
+ }
+ }
+}
+
+/**
+ * Is called when the mouse button is pressed down on the renderer element
+ *
+ * @method onMouseDown
+ * @param event {Event} The DOM event of a mouse button being pressed down
+ * @private
+ */
+PIXI.InteractionManager.prototype.onMouseDown = function(event)
+{
+ this.mouse.originalEvent = event || window.event; //IE uses window.event
+
+ // loop through inteaction tree...
+ // hit test each item! ->
+ // get interactive items under point??
+ //stage.__i
+ var length = this.interactiveItems.length;
+ var global = this.mouse.global;
+
+ var index = 0;
+ var parent = this.stage;
+
+ // while
+ // hit test
+ for (var i = 0; i < length; i++)
+ {
+ var item = this.interactiveItems[i];
+
+ if(item.mousedown || item.click)
+ {
+ item.__mouseIsDown = true;
+ item.__hit = this.hitTest(item, this.mouse);
+
+ if(item.__hit)
+ {
+ //call the function!
+ if(item.mousedown)item.mousedown(this.mouse);
+ item.__isDown = true;
+
+ // just the one!
+ if(!item.interactiveChildren)break;
+ }
+ }
+ }
+}
+
+
+PIXI.InteractionManager.prototype.onMouseOut = function(event)
+{
+ var length = this.interactiveItems.length;
+
+ this.target.view.style.cursor = "default";
+
+ for (var i = 0; i < length; i++)
+ {
+ var item = this.interactiveItems[i];
+
+ if(item.__isOver)
+ {
+ this.mouse.target = item;
+ if(item.mouseout)item.mouseout(this.mouse);
+ item.__isOver = false;
+ }
+ }
+}
+
+/**
+ * Is called when the mouse button is released on the renderer element
+ *
+ * @method onMouseUp
+ * @param event {Event} The DOM event of a mouse button being released
+ * @private
+ */
+PIXI.InteractionManager.prototype.onMouseUp = function(event)
+{
+ this.mouse.originalEvent = event || window.event; //IE uses window.event
+
+ var global = this.mouse.global;
+
+
+ var length = this.interactiveItems.length;
+ var up = false;
+
+ for (var i = 0; i < length; i++)
+ {
+ var item = this.interactiveItems[i];
+
+ if(item.mouseup || item.mouseupoutside || item.click)
+ {
+ item.__hit = this.hitTest(item, this.mouse);
+
+ if(item.__hit && !up)
+ {
+ //call the function!
+ if(item.mouseup)
+ {
+ item.mouseup(this.mouse);
+ }
+ if(item.__isDown)
+ {
+ if(item.click)item.click(this.mouse);
+ }
+
+ if(!item.interactiveChildren)up = true;
+ }
+ else
+ {
+ if(item.__isDown)
+ {
+ if(item.mouseupoutside)item.mouseupoutside(this.mouse);
+ }
+ }
+
+ item.__isDown = false;
+ }
+ }
+}
+
+/**
+ * Tests if the current mouse coords hit a sprite
+ *
+ * @method hitTest
+ * @param item {DisplayObject} The displayObject to test for a hit
+ * @param interactionData {InteractionData} The interactiondata object to update in the case of a hit
+ * @private
+ */
+PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
+{
+ var global = interactionData.global;
+
+ if(item.vcount !== PIXI.visibleCount)return false;
+
+ var isSprite = (item instanceof PIXI.Sprite),
+ worldTransform = item.worldTransform,
+ a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2],
+ a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5],
+ id = 1 / (a00 * a11 + a01 * -a10),
+ x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
+ y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id;
+
+ interactionData.target = item;
+
+ //a sprite or display object with a hit area defined
+ if(item.hitArea && item.hitArea.contains) {
+ if(item.hitArea.contains(x, y)) {
+ //if(isSprite)
+ interactionData.target = item;
+
+ return true;
+ }
+
+ return false;
+ }
+ // a sprite with no hitarea defined
+ else if(isSprite)
+ {
+ var width = item.texture.frame.width,
+ height = item.texture.frame.height,
+ x1 = -width * item.anchor.x,
+ y1;
+
+ if(x > x1 && x < x1 + width)
+ {
+ y1 = -height * item.anchor.y;
+
+ if(y > y1 && y < y1 + height)
+ {
+ // set the target property if a hit is true!
+ interactionData.target = item
+ return true;
+ }
+ }
+ }
+
+ var length = item.children.length;
+
+ for (var i = 0; i < length; i++)
+ {
+ var tempItem = item.children[i];
+ var hit = this.hitTest(tempItem, interactionData);
+ if(hit)
+ {
+ // hmm.. TODO SET CORRECT TARGET?
+ interactionData.target = item
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Is called when a touch is moved accross the renderer element
+ *
+ * @method onTouchMove
+ * @param event {Event} The DOM event of a touch moving accross the renderer view
+ * @private
+ */
+PIXI.InteractionManager.prototype.onTouchMove = function(event)
+{
+ var rect = this.target.view.getBoundingClientRect();
+ var changedTouches = event.changedTouches;
+
+ for (var i=0; i < changedTouches.length; i++)
+ {
+ var touchEvent = changedTouches[i];
+ var touchData = this.touchs[touchEvent.identifier];
+ touchData.originalEvent = event || window.event;
+
+ // update the touch position
+ touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
+ touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
+ }
+
+ var length = this.interactiveItems.length;
+ for (var i = 0; i < length; i++)
+ {
+ var item = this.interactiveItems[i];
+ if(item.touchmove)item.touchmove(touchData);
+ }
+}
+
+/**
+ * Is called when a touch is started on the renderer element
+ *
+ * @method onTouchStart
+ * @param event {Event} The DOM event of a touch starting on the renderer view
+ * @private
+ */
+PIXI.InteractionManager.prototype.onTouchStart = function(event)
+{
+ var rect = this.target.view.getBoundingClientRect();
+
+ var changedTouches = event.changedTouches;
+ for (var i=0; i < changedTouches.length; i++)
+ {
+ var touchEvent = changedTouches[i];
+
+ var touchData = this.pool.pop();
+ if(!touchData)touchData = new PIXI.InteractionData();
+
+ touchData.originalEvent = event || window.event;
+
+ this.touchs[touchEvent.identifier] = touchData;
+ touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
+ touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
+
+ var length = this.interactiveItems.length;
+
+ for (var j = 0; j < length; j++)
+ {
+ var item = this.interactiveItems[j];
+
+ if(item.touchstart || item.tap)
+ {
+ item.__hit = this.hitTest(item, touchData);
+
+ if(item.__hit)
+ {
+ //call the function!
+ if(item.touchstart)item.touchstart(touchData);
+ item.__isDown = true;
+ item.__touchData = touchData;
+
+ if(!item.interactiveChildren)break;
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Is called when a touch is ended on the renderer element
+ *
+ * @method onTouchEnd
+ * @param event {Event} The DOM event of a touch ending on the renderer view
+ * @private
+ */
+PIXI.InteractionManager.prototype.onTouchEnd = function(event)
+{
+ //this.mouse.originalEvent = event || window.event; //IE uses window.event
+ var rect = this.target.view.getBoundingClientRect();
+ var changedTouches = event.changedTouches;
+
+ for (var i=0; i < changedTouches.length; i++)
+ {
+ var touchEvent = changedTouches[i];
+ var touchData = this.touchs[touchEvent.identifier];
+ var up = false;
+ touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
+ touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
+
+ var length = this.interactiveItems.length;
+ for (var j = 0; j < length; j++)
+ {
+ var item = this.interactiveItems[j];
+ var itemTouchData = item.__touchData; // <-- Here!
+ item.__hit = this.hitTest(item, touchData);
+
+ if(itemTouchData == touchData)
+ {
+ // so this one WAS down...
+ touchData.originalEvent = event || window.event;
+ // hitTest??
+
+ if(item.touchend || item.tap)
+ {
+ if(item.__hit && !up)
+ {
+ if(item.touchend)item.touchend(touchData);
+ if(item.__isDown)
+ {
+ if(item.tap)item.tap(touchData);
+ }
+
+ if(!item.interactiveChildren)up = true;
+ }
+ else
+ {
+ if(item.__isDown)
+ {
+ if(item.touchendoutside)item.touchendoutside(touchData);
+ }
+ }
+
+ item.__isDown = false;
+ }
+
+ item.__touchData = null;
+
+ }
+ else
+ {
+
+ }
+ }
+ // remove the touch..
+ this.pool.push(touchData);
+ this.touchs[touchEvent.identifier] = null;
+ }
+}
+
+/**
+ * Holds all information related to an Interaction event
+ *
+ * @class InteractionData
+ * @constructor
+ */
+PIXI.InteractionData = function()
+{
+ /**
+ * This point stores the global coords of where the touch/mouse event happened
+ *
+ * @property global
+ * @type Point
+ */
+ this.global = new PIXI.Point();
+
+ // this is here for legacy... but will remove
+ this.local = new PIXI.Point();
+
+ /**
+ * The target Sprite that was interacted with
+ *
+ * @property target
+ * @type Sprite
+ */
+ this.target;
+
+ /**
+ * When passed to an event handler, this will be the original DOM Event that was captured
+ *
+ * @property originalEvent
+ * @type Event
+ */
+ this.originalEvent;
+}
+
+/**
+ * This will return the local coords of the specified displayObject for this InteractionData
+ *
+ * @method getLocalPosition
+ * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off
+ * @return {Point} A point containing the coords of the InteractionData position relative to the DisplayObject
+ */
+PIXI.InteractionData.prototype.getLocalPosition = function(displayObject)
+{
+ var worldTransform = displayObject.worldTransform;
+ var global = this.global;
+
+ // do a cheeky transform to get the mouse coords;
+ var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2],
+ a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5],
+ id = 1 / (a00 * a11 + a01 * -a10);
+ // set the mouse coords...
+ return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
+ a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id)
+}
+
+// constructor
+PIXI.InteractionData.prototype.constructor = PIXI.InteractionData;
diff --git a/src/pixi/Intro.js b/src/pixi/Intro.js
new file mode 100644
index 00000000..4023084f
--- /dev/null
+++ b/src/pixi/Intro.js
@@ -0,0 +1,7 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+(function(){
+
+ var root = this;
diff --git a/src/pixi/Outro.js b/src/pixi/Outro.js
new file mode 100644
index 00000000..e53cad5e
--- /dev/null
+++ b/src/pixi/Outro.js
@@ -0,0 +1,15 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+ if (typeof exports !== 'undefined') {
+ if (typeof module !== 'undefined' && module.exports) {
+ exports = module.exports = PIXI;
+ }
+ exports.PIXI = PIXI;
+ } else {
+ root.PIXI = PIXI;
+ }
+
+
+}).call(this);
\ No newline at end of file
diff --git a/src/pixi/Pixi.js b/src/pixi/Pixi.js
new file mode 100644
index 00000000..bc71d47c
--- /dev/null
+++ b/src/pixi/Pixi.js
@@ -0,0 +1,8 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * @module PIXI
+ */
+var PIXI = PIXI || {};
diff --git a/src/pixi/core/Circle.js b/src/pixi/core/Circle.js
new file mode 100644
index 00000000..a9ceed02
--- /dev/null
+++ b/src/pixi/core/Circle.js
@@ -0,0 +1,73 @@
+/**
+ * @author Chad Engler
+ */
+
+/**
+ * The Circle object can be used to specify a hit area for displayobjects
+ *
+ * @class Circle
+ * @constructor
+ * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle
+ * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle
+ * @param radius {Number} The radius of the circle
+ */
+PIXI.Circle = function(x, y, radius)
+{
+ /**
+ * @property x
+ * @type Number
+ * @default 0
+ */
+ this.x = x || 0;
+
+ /**
+ * @property y
+ * @type Number
+ * @default 0
+ */
+ this.y = y || 0;
+
+ /**
+ * @property radius
+ * @type Number
+ * @default 0
+ */
+ this.radius = radius || 0;
+}
+
+/**
+ * Creates a clone of this Circle instance
+ *
+ * @method clone
+ * @return {Circle} a copy of the polygon
+ */
+PIXI.Circle.prototype.clone = function()
+{
+ return new PIXI.Circle(this.x, this.y, this.radius);
+}
+
+/**
+ * Checks if the x, and y coords passed to this function are contained within this circle
+ *
+ * @method contains
+ * @param x {Number} The X coord of the point to test
+ * @param y {Number} The Y coord of the point to test
+ * @return {Boolean} if the x/y coords are within this polygon
+ */
+PIXI.Circle.prototype.contains = function(x, y)
+{
+ if(this.radius <= 0)
+ return false;
+
+ var dx = (this.x - x),
+ dy = (this.y - y),
+ r2 = this.radius * this.radius;
+
+ dx *= dx;
+ dy *= dy;
+
+ return (dx + dy <= r2);
+}
+
+PIXI.Circle.prototype.constructor = PIXI.Circle;
+
diff --git a/src/pixi/core/Ellipse.js b/src/pixi/core/Ellipse.js
new file mode 100644
index 00000000..dd369daa
--- /dev/null
+++ b/src/pixi/core/Ellipse.js
@@ -0,0 +1,87 @@
+/**
+ * @author Chad Engler
+ */
+
+/**
+ * The Ellipse object can be used to specify a hit area for displayobjects
+ *
+ * @class Ellipse
+ * @constructor
+ * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this ellipse
+ * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this ellipse
+ * @param width {Number} The overall height of this ellipse
+ * @param height {Number} The overall width of this ellipse
+ */
+PIXI.Ellipse = function(x, y, width, height)
+{
+ /**
+ * @property x
+ * @type Number
+ * @default 0
+ */
+ this.x = x || 0;
+
+ /**
+ * @property y
+ * @type Number
+ * @default 0
+ */
+ this.y = y || 0;
+
+ /**
+ * @property width
+ * @type Number
+ * @default 0
+ */
+ this.width = width || 0;
+
+ /**
+ * @property height
+ * @type Number
+ * @default 0
+ */
+ this.height = height || 0;
+}
+
+/**
+ * Creates a clone of this Ellipse instance
+ *
+ * @method clone
+ * @return {Ellipse} a copy of the ellipse
+ */
+PIXI.Ellipse.prototype.clone = function()
+{
+ return new PIXI.Ellipse(this.x, this.y, this.width, this.height);
+}
+
+/**
+ * Checks if the x, and y coords passed to this function are contained within this ellipse
+ *
+ * @method contains
+ * @param x {Number} The X coord of the point to test
+ * @param y {Number} The Y coord of the point to test
+ * @return {Boolean} if the x/y coords are within this ellipse
+ */
+PIXI.Ellipse.prototype.contains = function(x, y)
+{
+ if(this.width <= 0 || this.height <= 0)
+ return false;
+
+ //normalize the coords to an ellipse with center 0,0
+ //and a radius of 0.5
+ var normx = ((x - this.x) / this.width) - 0.5,
+ normy = ((y - this.y) / this.height) - 0.5;
+
+ normx *= normx;
+ normy *= normy;
+
+ return (normx + normy < 0.25);
+}
+
+PIXI.Ellipse.getBounds = function()
+{
+ return new PIXI.Rectangle(this.x, this.y, this.width, this.height);
+}
+
+PIXI.Ellipse.prototype.constructor = PIXI.Ellipse;
+
diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js
new file mode 100644
index 00000000..780fcd68
--- /dev/null
+++ b/src/pixi/core/Matrix.js
@@ -0,0 +1,293 @@
+
+
+/*
+ * A lighter version of the rad gl-matrix created by Brandon Jones, Colin MacKenzie IV
+ * you both rock!
+ */
+
+function determineMatrixArrayType() {
+ PIXI.Matrix = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
+ return PIXI.Matrix;
+}
+
+determineMatrixArrayType();
+
+PIXI.mat3 = {};
+
+PIXI.mat3.create = function()
+{
+ var matrix = new PIXI.Matrix(9);
+
+ matrix[0] = 1;
+ matrix[1] = 0;
+ matrix[2] = 0;
+ matrix[3] = 0;
+ matrix[4] = 1;
+ matrix[5] = 0;
+ matrix[6] = 0;
+ matrix[7] = 0;
+ matrix[8] = 1;
+
+ return matrix;
+}
+
+
+PIXI.mat3.identity = function(matrix)
+{
+ matrix[0] = 1;
+ matrix[1] = 0;
+ matrix[2] = 0;
+ matrix[3] = 0;
+ matrix[4] = 1;
+ matrix[5] = 0;
+ matrix[6] = 0;
+ matrix[7] = 0;
+ matrix[8] = 1;
+
+ return matrix;
+}
+
+
+PIXI.mat4 = {};
+
+PIXI.mat4.create = function()
+{
+ var matrix = new PIXI.Matrix(16);
+
+ matrix[0] = 1;
+ matrix[1] = 0;
+ matrix[2] = 0;
+ matrix[3] = 0;
+ matrix[4] = 0;
+ matrix[5] = 1;
+ matrix[6] = 0;
+ matrix[7] = 0;
+ matrix[8] = 0;
+ matrix[9] = 0;
+ matrix[10] = 1;
+ matrix[11] = 0;
+ matrix[12] = 0;
+ matrix[13] = 0;
+ matrix[14] = 0;
+ matrix[15] = 1;
+
+ return matrix;
+}
+
+PIXI.mat3.multiply = function (mat, mat2, dest)
+{
+ if (!dest) { dest = mat; }
+
+ // Cache the matrix values (makes for huge speed increases!)
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2],
+ a10 = mat[3], a11 = mat[4], a12 = mat[5],
+ a20 = mat[6], a21 = mat[7], a22 = mat[8],
+
+ b00 = mat2[0], b01 = mat2[1], b02 = mat2[2],
+ b10 = mat2[3], b11 = mat2[4], b12 = mat2[5],
+ b20 = mat2[6], b21 = mat2[7], b22 = mat2[8];
+
+ dest[0] = b00 * a00 + b01 * a10 + b02 * a20;
+ dest[1] = b00 * a01 + b01 * a11 + b02 * a21;
+ dest[2] = b00 * a02 + b01 * a12 + b02 * a22;
+
+ dest[3] = b10 * a00 + b11 * a10 + b12 * a20;
+ dest[4] = b10 * a01 + b11 * a11 + b12 * a21;
+ dest[5] = b10 * a02 + b11 * a12 + b12 * a22;
+
+ dest[6] = b20 * a00 + b21 * a10 + b22 * a20;
+ dest[7] = b20 * a01 + b21 * a11 + b22 * a21;
+ dest[8] = b20 * a02 + b21 * a12 + b22 * a22;
+
+ return dest;
+}
+
+PIXI.mat3.clone = function(mat)
+{
+ var matrix = new PIXI.Matrix(9);
+
+ matrix[0] = mat[0];
+ matrix[1] = mat[1];
+ matrix[2] = mat[2];
+ matrix[3] = mat[3];
+ matrix[4] = mat[4];
+ matrix[5] = mat[5];
+ matrix[6] = mat[6];
+ matrix[7] = mat[7];
+ matrix[8] = mat[8];
+
+ return matrix;
+}
+
+PIXI.mat3.transpose = function (mat, dest)
+{
+ // If we are transposing ourselves we can skip a few steps but have to cache some values
+ if (!dest || mat === dest) {
+ var a01 = mat[1], a02 = mat[2],
+ a12 = mat[5];
+
+ mat[1] = mat[3];
+ mat[2] = mat[6];
+ mat[3] = a01;
+ mat[5] = mat[7];
+ mat[6] = a02;
+ mat[7] = a12;
+ return mat;
+ }
+
+ dest[0] = mat[0];
+ dest[1] = mat[3];
+ dest[2] = mat[6];
+ dest[3] = mat[1];
+ dest[4] = mat[4];
+ dest[5] = mat[7];
+ dest[6] = mat[2];
+ dest[7] = mat[5];
+ dest[8] = mat[8];
+ return dest;
+}
+
+PIXI.mat3.toMat4 = function (mat, dest)
+{
+ if (!dest) { dest = PIXI.mat4.create(); }
+
+ dest[15] = 1;
+ dest[14] = 0;
+ dest[13] = 0;
+ dest[12] = 0;
+
+ dest[11] = 0;
+ dest[10] = mat[8];
+ dest[9] = mat[7];
+ dest[8] = mat[6];
+
+ dest[7] = 0;
+ dest[6] = mat[5];
+ dest[5] = mat[4];
+ dest[4] = mat[3];
+
+ dest[3] = 0;
+ dest[2] = mat[2];
+ dest[1] = mat[1];
+ dest[0] = mat[0];
+
+ return dest;
+}
+
+
+/////
+
+
+PIXI.mat4.create = function()
+{
+ var matrix = new PIXI.Matrix(16);
+
+ matrix[0] = 1;
+ matrix[1] = 0;
+ matrix[2] = 0;
+ matrix[3] = 0;
+ matrix[4] = 0;
+ matrix[5] = 1;
+ matrix[6] = 0;
+ matrix[7] = 0;
+ matrix[8] = 0;
+ matrix[9] = 0;
+ matrix[10] = 1;
+ matrix[11] = 0;
+ matrix[12] = 0;
+ matrix[13] = 0;
+ matrix[14] = 0;
+ matrix[15] = 1;
+
+ return matrix;
+}
+
+PIXI.mat4.transpose = function (mat, dest)
+{
+ // If we are transposing ourselves we can skip a few steps but have to cache some values
+ if (!dest || mat === dest)
+ {
+ var a01 = mat[1], a02 = mat[2], a03 = mat[3],
+ a12 = mat[6], a13 = mat[7],
+ a23 = mat[11];
+
+ mat[1] = mat[4];
+ mat[2] = mat[8];
+ mat[3] = mat[12];
+ mat[4] = a01;
+ mat[6] = mat[9];
+ mat[7] = mat[13];
+ mat[8] = a02;
+ mat[9] = a12;
+ mat[11] = mat[14];
+ mat[12] = a03;
+ mat[13] = a13;
+ mat[14] = a23;
+ return mat;
+ }
+
+ dest[0] = mat[0];
+ dest[1] = mat[4];
+ dest[2] = mat[8];
+ dest[3] = mat[12];
+ dest[4] = mat[1];
+ dest[5] = mat[5];
+ dest[6] = mat[9];
+ dest[7] = mat[13];
+ dest[8] = mat[2];
+ dest[9] = mat[6];
+ dest[10] = mat[10];
+ dest[11] = mat[14];
+ dest[12] = mat[3];
+ dest[13] = mat[7];
+ dest[14] = mat[11];
+ dest[15] = mat[15];
+ return dest;
+}
+
+PIXI.mat4.multiply = function (mat, mat2, dest)
+{
+ if (!dest) { dest = mat; }
+
+ // Cache the matrix values (makes for huge speed increases!)
+ var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3];
+ var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7];
+ var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11];
+ var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
+
+ // Cache only the current line of the second matrix
+ var b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3];
+ dest[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
+ dest[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
+ dest[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
+ dest[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
+
+ b0 = mat2[4];
+ b1 = mat2[5];
+ b2 = mat2[6];
+ b3 = mat2[7];
+ dest[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
+ dest[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
+ dest[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
+ dest[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
+
+ b0 = mat2[8];
+ b1 = mat2[9];
+ b2 = mat2[10];
+ b3 = mat2[11];
+ dest[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
+ dest[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
+ dest[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
+ dest[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
+
+ b0 = mat2[12];
+ b1 = mat2[13];
+ b2 = mat2[14];
+ b3 = mat2[15];
+ dest[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
+ dest[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
+ dest[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
+ dest[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
+
+ return dest;
+}
diff --git a/src/pixi/core/Point.js b/src/pixi/core/Point.js
new file mode 100644
index 00000000..85208615
--- /dev/null
+++ b/src/pixi/core/Point.js
@@ -0,0 +1,43 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
+ *
+ * @class Point
+ * @constructor
+ * @param x {Number} position of the point
+ * @param y {Number} position of the point
+ */
+PIXI.Point = function(x, y)
+{
+ /**
+ * @property x
+ * @type Number
+ * @default 0
+ */
+ this.x = x || 0;
+
+ /**
+ * @property y
+ * @type Number
+ * @default 0
+ */
+ this.y = y || 0;
+}
+
+/**
+ * Creates a clone of this point
+ *
+ * @method clone
+ * @return {Point} a copy of the point
+ */
+PIXI.Point.prototype.clone = function()
+{
+ return new PIXI.Point(this.x, this.y);
+}
+
+// constructor
+PIXI.Point.prototype.constructor = PIXI.Point;
+
diff --git a/src/pixi/core/Polygon.js b/src/pixi/core/Polygon.js
new file mode 100644
index 00000000..47cf17bc
--- /dev/null
+++ b/src/pixi/core/Polygon.js
@@ -0,0 +1,77 @@
+/**
+ * @author Adrien Brault
+ */
+
+/**
+ * @class Polygon
+ * @constructor
+ * @param points* {Array|Array|Point...|Number...} This can be an array of Points that form the polygon,
+ * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arugments passed can be
+ * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the
+ * arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are
+ * Numbers.
+ */
+PIXI.Polygon = function(points)
+{
+ //if points isn't an array, use arguments as the array
+ if(!(points instanceof Array))
+ points = Array.prototype.slice.call(arguments);
+
+ //if this is a flat array of numbers, convert it to points
+ if(typeof points[0] === 'number') {
+ var p = [];
+ for(var i = 0, il = points.length; i < il; i+=2) {
+ p.push(
+ new PIXI.Point(points[i], points[i + 1])
+ );
+ }
+
+ points = p;
+ }
+
+ this.points = points;
+}
+
+/**
+ * Creates a clone of this polygon
+ *
+ * @method clone
+ * @return {Polygon} a copy of the polygon
+ */
+PIXI.Polygon.prototype.clone = function()
+{
+ var points = [];
+ for (var i=0; i y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
+
+ if(intersect) inside = !inside;
+ }
+
+ return inside;
+}
+
+PIXI.Polygon.prototype.constructor = PIXI.Polygon;
+
diff --git a/src/pixi/core/Rectangle.js b/src/pixi/core/Rectangle.js
new file mode 100644
index 00000000..57484175
--- /dev/null
+++ b/src/pixi/core/Rectangle.js
@@ -0,0 +1,86 @@
+/**
+ * @author Mat Groves http://matgroves.com/
+ */
+
+/**
+ * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.
+ *
+ * @class Rectangle
+ * @constructor
+ * @param x {Number} The X coord of the upper-left corner of the rectangle
+ * @param y {Number} The Y coord of the upper-left corner of the rectangle
+ * @param width {Number} The overall wisth of this rectangle
+ * @param height {Number} The overall height of this rectangle
+ */
+PIXI.Rectangle = function(x, y, width, height)
+{
+ /**
+ * @property x
+ * @type Number
+ * @default 0
+ */
+ this.x = x || 0;
+
+ /**
+ * @property y
+ * @type Number
+ * @default 0
+ */
+ this.y = y || 0;
+
+ /**
+ * @property width
+ * @type Number
+ * @default 0
+ */
+ this.width = width || 0;
+
+ /**
+ * @property height
+ * @type Number
+ * @default 0
+ */
+ this.height = height || 0;
+}
+
+/**
+ * Creates a clone of this Rectangle
+ *
+ * @method clone
+ * @return {Rectangle} a copy of the rectangle
+ */
+PIXI.Rectangle.prototype.clone = function()
+{
+ return new PIXI.Rectangle(this.x, this.y, this.width, this.height);
+}
+
+/**
+ * Checks if the x, and y coords passed to this function are contained within this Rectangle
+ *
+ * @method contains
+ * @param x {Number} The X coord of the point to test
+ * @param y {Number} The Y coord of the point to test
+ * @return {Boolean} if the x/y coords are within this Rectangle
+ */
+PIXI.Rectangle.prototype.contains = function(x, y)
+{
+ if(this.width <= 0 || this.height <= 0)
+ return false;
+
+ var x1 = this.x;
+ if(x >= x1 && x <= x1 + this.width)
+ {
+ var y1 = this.y;
+
+ if(y >= y1 && y <= y1 + this.height)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// constructor
+PIXI.Rectangle.prototype.constructor = PIXI.Rectangle;
+
diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js
new file mode 100644
index 00000000..82d53663
--- /dev/null
+++ b/src/pixi/display/DisplayObject.js
@@ -0,0 +1,513 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * The base class for all objects that are rendered on the screen.
+ *
+ * @class DisplayObject
+ * @constructor
+ */
+PIXI.DisplayObject = function()
+{
+ this.last = this;
+ this.first = this;
+
+ /**
+ * The coordinate of the object relative to the local coordinates of the parent.
+ *
+ * @property position
+ * @type Point
+ */
+ this.position = new PIXI.Point();
+
+ /**
+ * The scale factor of the object.
+ *
+ * @property scale
+ * @type Point
+ */
+ this.scale = new PIXI.Point(1,1);//{x:1, y:1};
+
+ /**
+ * The pivot point of the displayObject that it rotates around
+ *
+ * @property pivot
+ * @type Point
+ */
+ this.pivot = new PIXI.Point(0,0);
+
+ /**
+ * The rotation of the object in radians.
+ *
+ * @property rotation
+ * @type Number
+ */
+ this.rotation = 0;
+
+ /**
+ * The opacity of the object.
+ *
+ * @property alpha
+ * @type Number
+ */
+ this.alpha = 1;
+
+ /**
+ * The visibility of the object.
+ *
+ * @property visible
+ * @type Boolean
+ */
+ this.visible = true;
+
+ /**
+ * This is the defined area that will pick up mouse / touch events. It is null by default.
+ * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)
+ *
+ * @property hitArea
+ * @type Rectangle|Circle|Ellipse|Polygon
+ */
+ this.hitArea = null;
+
+ /**
+ * This is used to indicate if the displayObject should display a mouse hand cursor on rollover
+ *
+ * @property buttonMode
+ * @type Boolean
+ */
+ this.buttonMode = false;
+
+ /**
+ * Can this object be rendered
+ *
+ * @property renderable
+ * @type Boolean
+ */
+ this.renderable = false;
+
+ /**
+ * [read-only] The display object container that contains this display object.
+ *
+ * @property parent
+ * @type DisplayObjectContainer
+ * @readOnly
+ */
+ this.parent = null;
+
+ /**
+ * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.
+ *
+ * @property stage
+ * @type Stage
+ * @readOnly
+ */
+ this.stage = null;
+
+ /**
+ * [read-only] The multiplied alpha of the displayobject
+ *
+ * @property worldAlpha
+ * @type Number
+ * @readOnly
+ */
+ this.worldAlpha = 1;
+
+ /**
+ * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property
+ *
+ * @property _interactive
+ * @type Boolean
+ * @readOnly
+ * @private
+ */
+ this._interactive = false;
+
+ /**
+ * [read-only] Current transform of the object based on world (parent) factors
+ *
+ * @property worldTransform
+ * @type Mat3
+ * @readOnly
+ * @private
+ */
+ this.worldTransform = PIXI.mat3.create()//mat3.identity();
+
+ /**
+ * [read-only] Current transform of the object locally
+ *
+ * @property localTransform
+ * @type Mat3
+ * @readOnly
+ * @private
+ */
+ this.localTransform = PIXI.mat3.create()//mat3.identity();
+
+ /**
+ * [NYI] Unkown
+ *
+ * @property color
+ * @type Array<>
+ * @private
+ */
+ this.color = [];
+
+ /**
+ * [NYI] Holds whether or not this object is dynamic, for rendering optimization
+ *
+ * @property dynamic
+ * @type Boolean
+ * @private
+ */
+ this.dynamic = true;
+
+ // chach that puppy!
+ this._sr = 0;
+ this._cr = 1;
+
+ /*
+ * MOUSE Callbacks
+ */
+
+ /**
+ * A callback that is used when the users clicks on the displayObject with their mouse
+ * @method click
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the user clicks the mouse down over the sprite
+ * @method mousedown
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the user releases the mouse that was over the displayObject
+ * for this callback to be fired the mouse must have been pressed down over the displayObject
+ * @method mouseup
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject
+ * for this callback to be fired, The touch must have started over the displayObject
+ * @method mouseupoutside
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the users mouse rolls over the displayObject
+ * @method mouseover
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the users mouse leaves the displayObject
+ * @method mouseout
+ * @param interactionData {InteractionData}
+ */
+
+
+ /*
+ * TOUCH Callbacks
+ */
+
+ /**
+ * A callback that is used when the users taps on the sprite with their finger
+ * basically a touch version of click
+ * @method tap
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the user touch's over the displayObject
+ * @method touchstart
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the user releases a touch over the displayObject
+ * @method touchend
+ * @param interactionData {InteractionData}
+ */
+
+ /**
+ * A callback that is used when the user releases the touch that was over the displayObject
+ * for this callback to be fired, The touch must have started over the sprite
+ * @method touchendoutside
+ * @param interactionData {InteractionData}
+ */
+}
+
+// constructor
+PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject;
+
+/**
+ * [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default
+ * Instead of using this function you can now simply set the interactive property to true or false
+ *
+ * @method setInteractive
+ * @param interactive {Boolean}
+ * @deprecated Simply set the `interactive` property directly
+ */
+PIXI.DisplayObject.prototype.setInteractive = function(interactive)
+{
+ this.interactive = interactive;
+}
+
+/**
+ * Indicates if the sprite will have touch and mouse interactivity. It is false by default
+ *
+ * @property interactive
+ * @type Boolean
+ * @default false
+ */
+Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', {
+ get: function() {
+ return this._interactive;
+ },
+ set: function(value) {
+ this._interactive = value;
+
+ // TODO more to be done here..
+ // need to sort out a re-crawl!
+ if(this.stage)this.stage.dirty = true;
+ }
+});
+
+/**
+ * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it.
+ * In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping.
+ * To remove a mask, set this property to null.
+ *
+ * @property mask
+ * @type Graphics
+ */
+Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', {
+ get: function() {
+ return this._mask;
+ },
+ set: function(value) {
+
+ this._mask = value;
+
+ if(value)
+ {
+ this.addFilter(value)
+ }
+ else
+ {
+ this.removeFilter();
+ }
+ }
+});
+
+/*
+ * Adds a filter to this displayObject
+ *
+ * @method addFilter
+ * @param mask {Graphics} the graphics object to use as a filter
+ * @private
+ */
+PIXI.DisplayObject.prototype.addFilter = function(mask)
+{
+ if(this.filter)return;
+ this.filter = true;
+
+ // insert a filter block..
+ var start = new PIXI.FilterBlock();
+ var end = new PIXI.FilterBlock();
+
+ start.mask = mask;
+ end.mask = mask;
+
+ start.first = start.last = this;
+ end.first = end.last = this;
+
+ start.open = true;
+
+ /*
+ * insert start
+ */
+
+ var childFirst = start
+ var childLast = start
+ var nextObject;
+ var previousObject;
+
+ previousObject = this.first._iPrev;
+
+ if(previousObject)
+ {
+ nextObject = previousObject._iNext;
+ childFirst._iPrev = previousObject;
+ previousObject._iNext = childFirst;
+ }
+ else
+ {
+ nextObject = this;
+ }
+
+ if(nextObject)
+ {
+ nextObject._iPrev = childLast;
+ childLast._iNext = nextObject;
+ }
+
+
+ // now insert the end filter block..
+
+ /*
+ * insert end filter
+ */
+ var childFirst = end
+ var childLast = end
+ var nextObject = null;
+ var previousObject = null;
+
+ previousObject = this.last;
+ nextObject = previousObject._iNext;
+
+ if(nextObject)
+ {
+ nextObject._iPrev = childLast;
+ childLast._iNext = nextObject;
+ }
+
+ childFirst._iPrev = previousObject;
+ previousObject._iNext = childFirst;
+
+ var updateLast = this;
+
+ var prevLast = this.last;
+ while(updateLast)
+ {
+ if(updateLast.last == prevLast)
+ {
+ updateLast.last = end;
+ }
+ updateLast = updateLast.parent;
+ }
+
+ this.first = start;
+
+ // if webGL...
+ if(this.__renderGroup)
+ {
+ this.__renderGroup.addFilterBlocks(start, end);
+ }
+
+ mask.renderable = false;
+
+}
+
+/*
+ * Removes the filter to this displayObject
+ *
+ * @method removeFilter
+ * @private
+ */
+PIXI.DisplayObject.prototype.removeFilter = function()
+{
+ if(!this.filter)return;
+ this.filter = false;
+
+ // modify the list..
+ var startBlock = this.first;
+
+ var nextObject = startBlock._iNext;
+ var previousObject = startBlock._iPrev;
+
+ if(nextObject)nextObject._iPrev = previousObject;
+ if(previousObject)previousObject._iNext = nextObject;
+
+ this.first = startBlock._iNext;
+
+
+ // remove the end filter
+ var lastBlock = this.last;
+
+ var nextObject = lastBlock._iNext;
+ var previousObject = lastBlock._iPrev;
+
+ if(nextObject)nextObject._iPrev = previousObject;
+ previousObject._iNext = nextObject;
+
+ // this is always true too!
+ var tempLast = lastBlock._iPrev;
+ // need to make sure the parents last is updated too
+ var updateLast = this;
+ while(updateLast.last == lastBlock)
+ {
+ updateLast.last = tempLast;
+ updateLast = updateLast.parent;
+ if(!updateLast)break;
+ }
+
+ var mask = startBlock.mask
+ mask.renderable = true;
+
+ // if webGL...
+ if(this.__renderGroup)
+ {
+ this.__renderGroup.removeFilterBlocks(startBlock, lastBlock);
+ }
+}
+
+/*
+ * Updates the object transform for rendering
+ *
+ * @method updateTransform
+ * @private
+ */
+PIXI.DisplayObject.prototype.updateTransform = function()
+{
+ // TODO OPTIMIZE THIS!! with dirty
+ if(this.rotation !== this.rotationCache)
+ {
+ this.rotationCache = this.rotation;
+ this._sr = Math.sin(this.rotation);
+ this._cr = Math.cos(this.rotation);
+ }
+
+ var localTransform = this.localTransform;
+ var parentTransform = this.parent.worldTransform;
+ var worldTransform = this.worldTransform;
+ //console.log(localTransform)
+ localTransform[0] = this._cr * this.scale.x;
+ localTransform[1] = -this._sr * this.scale.y
+ localTransform[3] = this._sr * this.scale.x;
+ localTransform[4] = this._cr * this.scale.y;
+
+ // TODO --> do we even need a local matrix???
+
+ var px = this.pivot.x;
+ var py = this.pivot.y;
+
+ // Cache the matrix values (makes for huge speed increases!)
+ var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1],
+ a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3],
+
+ b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2],
+ b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5];
+
+ localTransform[2] = a02
+ localTransform[5] = a12
+
+ worldTransform[0] = b00 * a00 + b01 * a10;
+ worldTransform[1] = b00 * a01 + b01 * a11;
+ worldTransform[2] = b00 * a02 + b01 * a12 + b02;
+
+ worldTransform[3] = b10 * a00 + b11 * a10;
+ worldTransform[4] = b10 * a01 + b11 * a11;
+ worldTransform[5] = b10 * a02 + b11 * a12 + b12;
+
+ // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo!
+ // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform);
+ this.worldAlpha = this.alpha * this.parent.worldAlpha;
+
+ this.vcount = PIXI.visibleCount;
+
+}
+
+PIXI.visibleCount = 0;
\ No newline at end of file
diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js
new file mode 100644
index 00000000..01b566d2
--- /dev/null
+++ b/src/pixi/display/DisplayObjectContainer.js
@@ -0,0 +1,368 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+/**
+ * A DisplayObjectContainer represents a collection of display objects.
+ * It is the base class of all display objects that act as a container for other objects.
+ *
+ * @class DisplayObjectContainer
+ * @extends DisplayObject
+ * @constructor
+ */
+PIXI.DisplayObjectContainer = function()
+{
+ PIXI.DisplayObject.call( this );
+
+ /**
+ * [read-only] The of children of this container.
+ *
+ * @property children
+ * @type Array
+ * @readOnly
+ */
+ this.children = [];
+}
+
+// constructor
+PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype );
+PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer;
+
+//TODO make visible a getter setter
+/*
+Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'visible', {
+ get: function() {
+ return this._visible;
+ },
+ set: function(value) {
+ this._visible = value;
+
+ }
+});*/
+
+/**
+ * Adds a child to the container.
+ *
+ * @method addChild
+ * @param child {DisplayObject} The DisplayObject to add to the container
+ */
+PIXI.DisplayObjectContainer.prototype.addChild = function(child)
+{
+ if(child.parent != undefined)
+ {
+
+ //// COULD BE THIS???
+ child.parent.removeChild(child);
+ // return;
+ }
+
+ child.parent = this;
+
+ this.children.push(child);
+
+ // update the stage refference..
+
+ if(this.stage)
+ {
+ var tmpChild = child;
+ do
+ {
+ if(tmpChild.interactive)this.stage.dirty = true;
+ tmpChild.stage = this.stage;
+ tmpChild = tmpChild._iNext;
+ }
+ while(tmpChild)
+ }
+
+ // LINKED LIST //
+
+ // modify the list..
+ var childFirst = child.first
+ var childLast = child.last;
+ var nextObject;
+ var previousObject;
+
+ // this could be wrong if there is a filter??
+ if(this.filter)
+ {
+ previousObject = this.last._iPrev;
+ }
+ else
+ {
+ previousObject = this.last;
+ }
+
+ nextObject = previousObject._iNext;
+
+ // always true in this case
+ // need to make sure the parents last is updated too
+ var updateLast = this;
+ var prevLast = previousObject;
+
+ while(updateLast)
+ {
+ if(updateLast.last == prevLast)
+ {
+ updateLast.last = child.last;
+ }
+ updateLast = updateLast.parent;
+ }
+
+ if(nextObject)
+ {
+ nextObject._iPrev = childLast;
+ childLast._iNext = nextObject;
+ }
+
+ childFirst._iPrev = previousObject;
+ previousObject._iNext = childFirst;
+
+ // need to remove any render groups..
+ if(this.__renderGroup)
+ {
+ // being used by a renderTexture.. if it exists then it must be from a render texture;
+ if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child);
+ // add them to the new render group..
+ this.__renderGroup.addDisplayObjectAndChildren(child);
+ }
+
+}
+
+/**
+ * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
+ *
+ * @method addChildAt
+ * @param child {DisplayObject} The child to add
+ * @param index {Number} The index to place the child in
+ */
+PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
+{
+ if(index >= 0 && index <= this.children.length)
+ {
+ if(child.parent != undefined)
+ {
+ child.parent.removeChild(child);
+ }
+ child.parent = this;
+
+ if(this.stage)
+ {
+ var tmpChild = child;
+ do
+ {
+ if(tmpChild.interactive)this.stage.dirty = true;
+ tmpChild.stage = this.stage;
+ tmpChild = tmpChild._iNext;
+ }
+ while(tmpChild)
+ }
+
+ // modify the list..
+ var childFirst = child.first;
+ var childLast = child.last;
+ var nextObject;
+ var previousObject;
+
+ if(index == this.children.length)
+ {
+ previousObject = this.last;
+ var updateLast = this;
+ var prevLast = this.last;
+ while(updateLast)
+ {
+ if(updateLast.last == prevLast)
+ {
+ updateLast.last = child.last;
+ }
+ updateLast = updateLast.parent;
+ }
+ }
+ else if(index == 0)
+ {
+ previousObject = this;
+ }
+ else
+ {
+ previousObject = this.children[index-1].last;
+ }
+
+ nextObject = previousObject._iNext;
+
+ // always true in this case
+ if(nextObject)
+ {
+ nextObject._iPrev = childLast;
+ childLast._iNext = nextObject;
+ }
+
+ childFirst._iPrev = previousObject;
+ previousObject._iNext = childFirst;
+
+ this.children.splice(index, 0, child);
+ // need to remove any render groups..
+ if(this.__renderGroup)
+ {
+ // being used by a renderTexture.. if it exists then it must be from a render texture;
+ if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child);
+ // add them to the new render group..
+ this.__renderGroup.addDisplayObjectAndChildren(child);
+ }
+
+ }
+ else
+ {
+ throw new Error(child + " The index "+ index +" supplied is out of bounds " + this.children.length);
+ }
+}
+
+/**
+ * [NYI] Swaps the depth of 2 displayObjects
+ *
+ * @method swapChildren
+ * @param child {DisplayObject}
+ * @param child2 {DisplayObject}
+ * @private
+ */
+PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
+{
+ /*
+ * this funtion needs to be recoded..
+ * can be done a lot faster..
+ */
+ return;
+
+ // need to fix this function :/
+ /*
+ // TODO I already know this??
+ var index = this.children.indexOf( child );
+ var index2 = this.children.indexOf( child2 );
+
+ if ( index !== -1 && index2 !== -1 )
+ {
+ // cool
+
+ /*
+ if(this.stage)
+ {
+ // this is to satisfy the webGL batching..
+ // TODO sure there is a nicer way to achieve this!
+ this.stage.__removeChild(child);
+ this.stage.__removeChild(child2);
+
+ this.stage.__addChild(child);
+ this.stage.__addChild(child2);
+ }
+
+ // swap the positions..
+ this.children[index] = child2;
+ this.children[index2] = child;
+
+ }
+ else
+ {
+ throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this);
+ }*/
+}
+
+/**
+ * Returns the Child at the specified index
+ *
+ * @method getChildAt
+ * @param index {Number} The index to get the child from
+ */
+PIXI.DisplayObjectContainer.prototype.getChildAt = function(index)
+{
+ if(index >= 0 && index < this.children.length)
+ {
+ return this.children[index];
+ }
+ else
+ {
+ throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this);
+ }
+}
+
+/**
+ * Removes a child from the container.
+ *
+ * @method removeChild
+ * @param child {DisplayObject} The DisplayObject to remove
+ */
+PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
+{
+ var index = this.children.indexOf( child );
+ if ( index !== -1 )
+ {
+ // unlink //
+ // modify the list..
+ var childFirst = child.first;
+ var childLast = child.last;
+
+ var nextObject = childLast._iNext;
+ var previousObject = childFirst._iPrev;
+
+ if(nextObject)nextObject._iPrev = previousObject;
+ previousObject._iNext = nextObject;
+
+ if(this.last == childLast)
+ {
+ var tempLast = childFirst._iPrev;
+ // need to make sure the parents last is updated too
+ var updateLast = this;
+ while(updateLast.last == childLast.last)
+ {
+ updateLast.last = tempLast;
+ updateLast = updateLast.parent;
+ if(!updateLast)break;
+ }
+ }
+
+ childLast._iNext = null;
+ childFirst._iPrev = null;
+
+ // update the stage reference..
+ if(this.stage)
+ {
+ var tmpChild = child;
+ do
+ {
+ if(tmpChild.interactive)this.stage.dirty = true;
+ tmpChild.stage = null;
+ tmpChild = tmpChild._iNext;
+ }
+ while(tmpChild)
+ }
+
+ // webGL trim
+ if(child.__renderGroup)
+ {
+ child.__renderGroup.removeDisplayObjectAndChildren(child);
+ }
+
+ child.parent = undefined;
+ this.children.splice( index, 1 );
+ }
+ else
+ {
+ throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this);
+ }
+}
+
+/*
+ * Updates the container's children's transform for rendering
+ *
+ * @method updateTransform
+ * @private
+ */
+PIXI.DisplayObjectContainer.prototype.updateTransform = function()
+{
+ if(!this.visible)return;
+
+ PIXI.DisplayObject.prototype.updateTransform.call( this );
+
+ for(var i=0,j=this.children.length; i} an array of {Texture} objects that make up the animation
+ */
+PIXI.MovieClip = function(textures)
+{
+ PIXI.Sprite.call(this, textures[0]);
+
+ /**
+ * The array of textures that make up the animation
+ *
+ * @property textures
+ * @type Array
+ */
+ this.textures = textures;
+
+ /**
+ * The speed that the MovieClip will play at. Higher is faster, lower is slower
+ *
+ * @property animationSpeed
+ * @type Number
+ * @default 1
+ */
+ this.animationSpeed = 1;
+
+ /**
+ * Whether or not the movie clip repeats after playing.
+ *
+ * @property loop
+ * @type Boolean
+ * @default true
+ */
+ this.loop = true;
+
+ /**
+ * Function to call when a MovieClip finishes playing
+ *
+ * @property onComplete
+ * @type Function
+ */
+ this.onComplete = null;
+
+ /**
+ * [read-only] The index MovieClips current frame (this may not have to be a whole number)
+ *
+ * @property currentFrame
+ * @type Number
+ * @default 0
+ * @readOnly
+ */
+ this.currentFrame = 0;
+
+ /**
+ * [read-only] Indicates if the MovieClip is currently playing
+ *
+ * @property playing
+ * @type Boolean
+ * @readOnly
+ */
+ this.playing = false;
+}
+
+// constructor
+PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype );
+PIXI.MovieClip.prototype.constructor = PIXI.MovieClip;
+
+/**
+ * Stops the MovieClip
+ *
+ * @method stop
+ */
+PIXI.MovieClip.prototype.stop = function()
+{
+ this.playing = false;
+}
+
+/**
+ * Plays the MovieClip
+ *
+ * @method play
+ */
+PIXI.MovieClip.prototype.play = function()
+{
+ this.playing = true;
+}
+
+/**
+ * Stops the MovieClip and goes to a specific frame
+ *
+ * @method gotoAndStop
+ * @param frameNumber {Number} frame index to stop at
+ */
+PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber)
+{
+ this.playing = false;
+ this.currentFrame = frameNumber;
+ var round = (this.currentFrame + 0.5) | 0;
+ this.setTexture(this.textures[round % this.textures.length]);
+}
+
+/**
+ * Goes to a specific frame and begins playing the MovieClip
+ *
+ * @method gotoAndPlay
+ * @param frameNumber {Number} frame index to start at
+ */
+PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber)
+{
+ this.currentFrame = frameNumber;
+ this.playing = true;
+}
+
+/*
+ * Updates the object transform for rendering
+ *
+ * @method updateTransform
+ * @private
+ */
+PIXI.MovieClip.prototype.updateTransform = function()
+{
+ PIXI.Sprite.prototype.updateTransform.call(this);
+
+ if(!this.playing)return;
+
+ this.currentFrame += this.animationSpeed;
+
+ var round = (this.currentFrame + 0.5) | 0;
+
+ if(this.loop || round < this.textures.length)
+ {
+ this.setTexture(this.textures[round % this.textures.length]);
+ }
+ else if(round >= this.textures.length)
+ {
+ this.gotoAndStop(this.textures.length - 1);
+ if(this.onComplete)
+ {
+ this.onComplete();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js
new file mode 100644
index 00000000..4a6e65a8
--- /dev/null
+++ b/src/pixi/display/Sprite.js
@@ -0,0 +1,197 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+PIXI.blendModes = {};
+PIXI.blendModes.NORMAL = 0;
+PIXI.blendModes.SCREEN = 1;
+
+
+/**
+ * The SPrite object is the base for all textured objects that are rendered to the screen
+ *
+ * @class Sprite
+ * @extends DisplayObjectContainer
+ * @constructor
+ * @param texture {Texture} The texture for this sprite
+ * @type String
+ */
+PIXI.Sprite = function(texture)
+{
+ PIXI.DisplayObjectContainer.call( this );
+
+ /**
+ * The anchor sets the origin point of the texture.
+ * The default is 0,0 this means the textures origin is the top left
+ * Setting than anchor to 0.5,0.5 means the textures origin is centered
+ * Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
+ *
+ * @property anchor
+ * @type Point
+ */
+ this.anchor = new PIXI.Point();
+
+ /**
+ * The texture that the sprite is using
+ *
+ * @property texture
+ * @type Texture
+ */
+ this.texture = texture;
+
+ /**
+ * The blend mode of sprite.
+ * currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN
+ *
+ * @property blendMode
+ * @type Number
+ */
+ this.blendMode = PIXI.blendModes.NORMAL;
+
+ /**
+ * The width of the sprite (this is initially set by the texture)
+ *
+ * @property _width
+ * @type Number
+ * @private
+ */
+ this._width = 0;
+
+ /**
+ * The height of the sprite (this is initially set by the texture)
+ *
+ * @property _height
+ * @type Number
+ * @private
+ */
+ this._height = 0;
+
+ if(texture.baseTexture.hasLoaded)
+ {
+ this.updateFrame = true;
+ }
+ else
+ {
+ this.onTextureUpdateBind = this.onTextureUpdate.bind(this);
+ this.texture.addEventListener( 'update', this.onTextureUpdateBind );
+ }
+
+ this.renderable = true;
+}
+
+// constructor
+PIXI.Sprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
+PIXI.Sprite.prototype.constructor = PIXI.Sprite;
+
+/**
+ * The width of the sprite, setting this will actually modify the scale to acheive the value set
+ *
+ * @property width
+ * @type Number
+ */
+Object.defineProperty(PIXI.Sprite.prototype, 'width', {
+ get: function() {
+ return this.scale.x * this.texture.frame.width;
+ },
+ set: function(value) {
+ this.scale.x = value / this.texture.frame.width
+ this._width = value;
+ }
+});
+
+/**
+ * The height of the sprite, setting this will actually modify the scale to acheive the value set
+ *
+ * @property height
+ * @type Number
+ */
+Object.defineProperty(PIXI.Sprite.prototype, 'height', {
+ get: function() {
+ return this.scale.y * this.texture.frame.height;
+ },
+ set: function(value) {
+ this.scale.y = value / this.texture.frame.height
+ this._height = value;
+ }
+});
+
+/**
+ * Sets the texture of the sprite
+ *
+ * @method setTexture
+ * @param texture {Texture} The PIXI texture that is displayed by the sprite
+ */
+PIXI.Sprite.prototype.setTexture = function(texture)
+{
+ // stop current texture;
+ if(this.texture.baseTexture != texture.baseTexture)
+ {
+ this.textureChange = true;
+ this.texture = texture;
+
+ if(this.__renderGroup)
+ {
+ this.__renderGroup.updateTexture(this);
+ }
+ }
+ else
+ {
+ this.texture = texture;
+ }
+
+ this.updateFrame = true;
+}
+
+/**
+ * When the texture is updated, this event will fire to update the scale and frame
+ *
+ * @method onTextureUpdate
+ * @param event
+ * @private
+ */
+PIXI.Sprite.prototype.onTextureUpdate = function(event)
+{
+ //this.texture.removeEventListener( 'update', this.onTextureUpdateBind );
+
+ // so if _width is 0 then width was not set..
+ if(this._width)this.scale.x = this._width / this.texture.frame.width;
+ if(this._height)this.scale.y = this._height / this.texture.frame.height;
+
+ this.updateFrame = true;
+}
+
+// some helper functions..
+
+/**
+ *
+ * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId
+ * The frame ids are created when a Texture packer file has been loaded
+ *
+ * @method fromFrame
+ * @static
+ * @param frameId {String} The frame Id of the texture in the cache
+ * @return {Sprite} A new Sprite using a texture from the texture cache matching the frameId
+ */
+PIXI.Sprite.fromFrame = function(frameId)
+{
+ var texture = PIXI.TextureCache[frameId];
+ if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache" + this);
+ return new PIXI.Sprite(texture);
+}
+
+/**
+ *
+ * Helper function that creates a sprite that will contain a texture based on an image url
+ * If the image is not in the texture cache it will be loaded
+ *
+ * @method fromImage
+ * @static
+ * @param imageId {String} The image url of the texture
+ * @return {Sprite} A new Sprite using a texture from the texture cache matching the image id
+ */
+PIXI.Sprite.fromImage = function(imageId)
+{
+ var texture = PIXI.Texture.fromImage(imageId);
+ return new PIXI.Sprite(texture);
+}
+
diff --git a/src/pixi/display/Stage.js b/src/pixi/display/Stage.js
new file mode 100644
index 00000000..ca76d9e3
--- /dev/null
+++ b/src/pixi/display/Stage.js
@@ -0,0 +1,123 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * A Stage represents the root of the display tree. Everything connected to the stage is rendered
+ *
+ * @class Stage
+ * @extends DisplayObjectContainer
+ * @constructor
+ * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format
+ * like: 0xFFFFFF for white
+ * @param interactive {Boolean} enable / disable interaction (default is false)
+ */
+PIXI.Stage = function(backgroundColor, interactive)
+{
+ PIXI.DisplayObjectContainer.call( this );
+
+ /**
+ * [read-only] Current transform of the object based on world (parent) factors
+ *
+ * @property worldTransform
+ * @type Mat3
+ * @readOnly
+ * @private
+ */
+ this.worldTransform = PIXI.mat3.create();
+
+ /**
+ * Whether or not the stage is interactive
+ *
+ * @property interactive
+ * @type Boolean
+ */
+ this.interactive = interactive;
+
+ /**
+ * The interaction manage for this stage, manages all interactive activity on the stage
+ *
+ * @property interactive
+ * @type InteractionManager
+ */
+ this.interactionManager = new PIXI.InteractionManager(this);
+
+ /**
+ * Whether the stage is dirty and needs to have interactions updated
+ *
+ * @property dirty
+ * @type Boolean
+ * @private
+ */
+ this.dirty = true;
+
+ this.__childrenAdded = [];
+ this.__childrenRemoved = [];
+
+ //the stage is it's own stage
+ this.stage = this;
+
+ //optimize hit detection a bit
+ this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000);
+
+ this.setBackgroundColor(backgroundColor);
+ this.worldVisible = true;
+}
+
+// constructor
+PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
+PIXI.Stage.prototype.constructor = PIXI.Stage;
+
+/*
+ * Updates the object transform for rendering
+ *
+ * @method updateTransform
+ * @private
+ */
+PIXI.Stage.prototype.updateTransform = function()
+{
+ this.worldAlpha = 1;
+ this.vcount = PIXI.visibleCount;
+
+ for(var i=0,j=this.children.length; i 1)ratio = 1;
+
+ var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y);
+ var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio;
+ perp.x /= perpLength;
+ perp.y /= perpLength;
+
+ perp.x *= num;
+ perp.y *= num;
+
+ verticies[index] = point.x + perp.x
+ verticies[index+1] = point.y + perp.y
+ verticies[index+2] = point.x - perp.x
+ verticies[index+3] = point.y - perp.y
+
+ lastPoint = point;
+ }
+
+ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this );
+}
+
+PIXI.Rope.prototype.setTexture = function(texture)
+{
+ // stop current texture
+ this.texture = texture;
+ this.updateFrame = true;
+}
+
+
+
+
diff --git a/src/pixi/extras/Spine.js b/src/pixi/extras/Spine.js
new file mode 100644
index 00000000..8dda8c1f
--- /dev/null
+++ b/src/pixi/extras/Spine.js
@@ -0,0 +1,1460 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi
+ *
+ * Awesome JS run time provided by EsotericSoftware
+ * https://github.com/EsotericSoftware/spine-runtimes
+ *
+ */
+
+/**
+ * A class that enables the you to import and run your spine animations in pixi.
+ * Spine animation data needs to be loaded using the PIXI.AssetLoader or PIXI.SpineLoader before it can be used by this class
+ * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source
+ *
+ * @class Spine
+ * @extends DisplayObjectContainer
+ * @constructor
+ * @param url {String} The url of the spine anim file to be used
+ */
+PIXI.Spine = function (url) {
+ PIXI.DisplayObjectContainer.call(this);
+
+ this.spineData = PIXI.AnimCache[url];
+
+ if (!this.spineData) {
+ throw new Error("Spine data must be preloaded using PIXI.SpineLoader or PIXI.AssetLoader: " + url);
+ }
+
+ this.skeleton = new spine.Skeleton(this.spineData);
+ this.skeleton.updateWorldTransform();
+
+ this.stateData = new spine.AnimationStateData(this.spineData);
+ this.state = new spine.AnimationState(this.stateData);
+
+ this.slotContainers = [];
+
+ for (var i = 0, n = this.skeleton.drawOrder.length; i < n; i++) {
+ var slot = this.skeleton.drawOrder[i];
+ var attachment = slot.attachment;
+ var slotContainer = new PIXI.DisplayObjectContainer();
+ this.slotContainers.push(slotContainer);
+ this.addChild(slotContainer);
+ if (!(attachment instanceof spine.RegionAttachment)) {
+ continue;
+ }
+ var spriteName = attachment.rendererObject.name;
+ var sprite = this.createSprite(slot, attachment.rendererObject);
+ slot.currentSprite = sprite;
+ slot.currentSpriteName = spriteName;
+ slotContainer.addChild(sprite);
+ }
+};
+
+PIXI.Spine.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
+PIXI.Spine.prototype.constructor = PIXI.Spine;
+
+/*
+ * Updates the object transform for rendering
+ *
+ * @method updateTransform
+ * @private
+ */
+PIXI.Spine.prototype.updateTransform = function () {
+ this.lastTime = this.lastTime || Date.now();
+ var timeDelta = (Date.now() - this.lastTime) * 0.001;
+ this.lastTime = Date.now();
+ this.state.update(timeDelta);
+ this.state.apply(this.skeleton);
+ this.skeleton.updateWorldTransform();
+
+ var drawOrder = this.skeleton.drawOrder;
+ for (var i = 0, n = drawOrder.length; i < n; i++) {
+ var slot = drawOrder[i];
+ var attachment = slot.attachment;
+ var slotContainer = this.slotContainers[i];
+ if (!(attachment instanceof spine.RegionAttachment)) {
+ slotContainer.visible = false;
+ continue;
+ }
+
+ if (attachment.rendererObject) {
+ if (!slot.currentSpriteName || slot.currentSpriteName != attachment.name) {
+ var spriteName = attachment.rendererObject.name;
+ if (slot.currentSprite !== undefined) {
+ slot.currentSprite.visible = false;
+ }
+ slot.sprites = slot.sprites || {};
+ if (slot.sprites[spriteName] !== undefined) {
+ slot.sprites[spriteName].visible = true;
+ } else {
+ var sprite = this.createSprite(slot, attachment.rendererObject);
+ slotContainer.addChild(sprite);
+ }
+ slot.currentSprite = slot.sprites[spriteName];
+ slot.currentSpriteName = spriteName;
+ }
+ }
+ slotContainer.visible = true;
+
+ var bone = slot.bone;
+
+ slotContainer.position.x = bone.worldX + attachment.x * bone.m00 + attachment.y * bone.m01;
+ slotContainer.position.y = bone.worldY + attachment.x * bone.m10 + attachment.y * bone.m11;
+ slotContainer.scale.x = bone.worldScaleX;
+ slotContainer.scale.y = bone.worldScaleY;
+
+ slotContainer.rotation = -(slot.bone.worldRotation * Math.PI / 180);
+ }
+
+ PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
+};
+
+
+PIXI.Spine.prototype.createSprite = function (slot, descriptor) {
+ var name = PIXI.TextureCache[descriptor.name] ? descriptor.name : descriptor.name + ".png";
+ var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(name));
+ sprite.scale = descriptor.scale;
+ sprite.rotation = descriptor.rotation;
+ sprite.anchor.x = sprite.anchor.y = 0.5;
+
+ slot.sprites = slot.sprites || {};
+ slot.sprites[descriptor.name] = sprite;
+ return sprite;
+};
+
+/*
+ * Awesome JS run time provided by EsotericSoftware
+ *
+ * https://github.com/EsotericSoftware/spine-runtimes
+ *
+ */
+
+var spine = {};
+
+spine.BoneData = function (name, parent) {
+ this.name = name;
+ this.parent = parent;
+};
+spine.BoneData.prototype = {
+ length: 0,
+ x: 0, y: 0,
+ rotation: 0,
+ scaleX: 1, scaleY: 1
+};
+
+spine.SlotData = function (name, boneData) {
+ this.name = name;
+ this.boneData = boneData;
+};
+spine.SlotData.prototype = {
+ r: 1, g: 1, b: 1, a: 1,
+ attachmentName: null
+};
+
+spine.Bone = function (boneData, parent) {
+ this.data = boneData;
+ this.parent = parent;
+ this.setToSetupPose();
+};
+spine.Bone.yDown = false;
+spine.Bone.prototype = {
+ x: 0, y: 0,
+ rotation: 0,
+ scaleX: 1, scaleY: 1,
+ m00: 0, m01: 0, worldX: 0, // a b x
+ m10: 0, m11: 0, worldY: 0, // c d y
+ worldRotation: 0,
+ worldScaleX: 1, worldScaleY: 1,
+ updateWorldTransform: function (flipX, flipY) {
+ var parent = this.parent;
+ if (parent != null) {
+ this.worldX = this.x * parent.m00 + this.y * parent.m01 + parent.worldX;
+ this.worldY = this.x * parent.m10 + this.y * parent.m11 + parent.worldY;
+ this.worldScaleX = parent.worldScaleX * this.scaleX;
+ this.worldScaleY = parent.worldScaleY * this.scaleY;
+ this.worldRotation = parent.worldRotation + this.rotation;
+ } else {
+ this.worldX = this.x;
+ this.worldY = this.y;
+ this.worldScaleX = this.scaleX;
+ this.worldScaleY = this.scaleY;
+ this.worldRotation = this.rotation;
+ }
+ var radians = this.worldRotation * Math.PI / 180;
+ var cos = Math.cos(radians);
+ var sin = Math.sin(radians);
+ this.m00 = cos * this.worldScaleX;
+ this.m10 = sin * this.worldScaleX;
+ this.m01 = -sin * this.worldScaleY;
+ this.m11 = cos * this.worldScaleY;
+ if (flipX) {
+ this.m00 = -this.m00;
+ this.m01 = -this.m01;
+ }
+ if (flipY) {
+ this.m10 = -this.m10;
+ this.m11 = -this.m11;
+ }
+ if (spine.Bone.yDown) {
+ this.m10 = -this.m10;
+ this.m11 = -this.m11;
+ }
+ },
+ setToSetupPose: function () {
+ var data = this.data;
+ this.x = data.x;
+ this.y = data.y;
+ this.rotation = data.rotation;
+ this.scaleX = data.scaleX;
+ this.scaleY = data.scaleY;
+ }
+};
+
+spine.Slot = function (slotData, skeleton, bone) {
+ this.data = slotData;
+ this.skeleton = skeleton;
+ this.bone = bone;
+ this.setToSetupPose();
+};
+spine.Slot.prototype = {
+ r: 1, g: 1, b: 1, a: 1,
+ _attachmentTime: 0,
+ attachment: null,
+ setAttachment: function (attachment) {
+ this.attachment = attachment;
+ this._attachmentTime = this.skeleton.time;
+ },
+ setAttachmentTime: function (time) {
+ this._attachmentTime = this.skeleton.time - time;
+ },
+ getAttachmentTime: function () {
+ return this.skeleton.time - this._attachmentTime;
+ },
+ setToSetupPose: function () {
+ var data = this.data;
+ this.r = data.r;
+ this.g = data.g;
+ this.b = data.b;
+ this.a = data.a;
+
+ var slotDatas = this.skeleton.data.slots;
+ for (var i = 0, n = slotDatas.length; i < n; i++) {
+ if (slotDatas[i] == data) {
+ this.setAttachment(!data.attachmentName ? null : this.skeleton.getAttachmentBySlotIndex(i, data.attachmentName));
+ break;
+ }
+ }
+ }
+};
+
+spine.Skin = function (name) {
+ this.name = name;
+ this.attachments = {};
+};
+spine.Skin.prototype = {
+ addAttachment: function (slotIndex, name, attachment) {
+ this.attachments[slotIndex + ":" + name] = attachment;
+ },
+ getAttachment: function (slotIndex, name) {
+ return this.attachments[slotIndex + ":" + name];
+ },
+ _attachAll: function (skeleton, oldSkin) {
+ for (var key in oldSkin.attachments) {
+ var colon = key.indexOf(":");
+ var slotIndex = parseInt(key.substring(0, colon));
+ var name = key.substring(colon + 1);
+ var slot = skeleton.slots[slotIndex];
+ if (slot.attachment && slot.attachment.name == name) {
+ var attachment = this.getAttachment(slotIndex, name);
+ if (attachment) slot.setAttachment(attachment);
+ }
+ }
+ }
+};
+
+spine.Animation = function (name, timelines, duration) {
+ this.name = name;
+ this.timelines = timelines;
+ this.duration = duration;
+};
+spine.Animation.prototype = {
+ apply: function (skeleton, time, loop) {
+ if (loop && this.duration != 0) time %= this.duration;
+ var timelines = this.timelines;
+ for (var i = 0, n = timelines.length; i < n; i++)
+ timelines[i].apply(skeleton, time, 1);
+ },
+ mix: function (skeleton, time, loop, alpha) {
+ if (loop && this.duration != 0) time %= this.duration;
+ var timelines = this.timelines;
+ for (var i = 0, n = timelines.length; i < n; i++)
+ timelines[i].apply(skeleton, time, alpha);
+ }
+};
+
+spine.binarySearch = function (values, target, step) {
+ var low = 0;
+ var high = Math.floor(values.length / step) - 2;
+ if (high == 0) return step;
+ var current = high >>> 1;
+ while (true) {
+ if (values[(current + 1) * step] <= target)
+ low = current + 1;
+ else
+ high = current;
+ if (low == high) return (low + 1) * step;
+ current = (low + high) >>> 1;
+ }
+};
+spine.linearSearch = function (values, target, step) {
+ for (var i = 0, last = values.length - step; i <= last; i += step)
+ if (values[i] > target) return i;
+ return -1;
+};
+
+spine.Curves = function (frameCount) {
+ this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ...
+ this.curves.length = (frameCount - 1) * 6;
+};
+spine.Curves.prototype = {
+ setLinear: function (frameIndex) {
+ this.curves[frameIndex * 6] = 0/*LINEAR*/;
+ },
+ setStepped: function (frameIndex) {
+ this.curves[frameIndex * 6] = -1/*STEPPED*/;
+ },
+ /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
+ * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
+ * the difference between the keyframe's values. */
+ setCurve: function (frameIndex, cx1, cy1, cx2, cy2) {
+ var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/;
+ var subdiv_step2 = subdiv_step * subdiv_step;
+ var subdiv_step3 = subdiv_step2 * subdiv_step;
+ var pre1 = 3 * subdiv_step;
+ var pre2 = 3 * subdiv_step2;
+ var pre4 = 6 * subdiv_step2;
+ var pre5 = 6 * subdiv_step3;
+ var tmp1x = -cx1 * 2 + cx2;
+ var tmp1y = -cy1 * 2 + cy2;
+ var tmp2x = (cx1 - cx2) * 3 + 1;
+ var tmp2y = (cy1 - cy2) * 3 + 1;
+ var i = frameIndex * 6;
+ var curves = this.curves;
+ curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
+ curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
+ curves[i + 2] = tmp1x * pre4 + tmp2x * pre5;
+ curves[i + 3] = tmp1y * pre4 + tmp2y * pre5;
+ curves[i + 4] = tmp2x * pre5;
+ curves[i + 5] = tmp2y * pre5;
+ },
+ getCurvePercent: function (frameIndex, percent) {
+ percent = percent < 0 ? 0 : (percent > 1 ? 1 : percent);
+ var curveIndex = frameIndex * 6;
+ var curves = this.curves;
+ var dfx = curves[curveIndex];
+ if (!dfx/*LINEAR*/) return percent;
+ if (dfx == -1/*STEPPED*/) return 0;
+ var dfy = curves[curveIndex + 1];
+ var ddfx = curves[curveIndex + 2];
+ var ddfy = curves[curveIndex + 3];
+ var dddfx = curves[curveIndex + 4];
+ var dddfy = curves[curveIndex + 5];
+ var x = dfx, y = dfy;
+ var i = 10/*BEZIER_SEGMENTS*/ - 2;
+ while (true) {
+ if (x >= percent) {
+ var lastX = x - dfx;
+ var lastY = y - dfy;
+ return lastY + (y - lastY) * (percent - lastX) / (x - lastX);
+ }
+ if (i == 0) break;
+ i--;
+ dfx += ddfx;
+ dfy += ddfy;
+ ddfx += dddfx;
+ ddfy += dddfy;
+ x += dfx;
+ y += dfy;
+ }
+ return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
+ }
+};
+
+spine.RotateTimeline = function (frameCount) {
+ this.curves = new spine.Curves(frameCount);
+ this.frames = []; // time, angle, ...
+ this.frames.length = frameCount * 2;
+};
+spine.RotateTimeline.prototype = {
+ boneIndex: 0,
+ getFrameCount: function () {
+ return this.frames.length / 2;
+ },
+ setFrame: function (frameIndex, time, angle) {
+ frameIndex *= 2;
+ this.frames[frameIndex] = time;
+ this.frames[frameIndex + 1] = angle;
+ },
+ apply: function (skeleton, time, alpha) {
+ var frames = this.frames;
+ if (time < frames[0]) return; // Time is before first frame.
+
+ var bone = skeleton.bones[this.boneIndex];
+
+ if (time >= frames[frames.length - 2]) { // Time is after last frame.
+ var amount = bone.data.rotation + frames[frames.length - 1] - bone.rotation;
+ while (amount > 180)
+ amount -= 360;
+ while (amount < -180)
+ amount += 360;
+ bone.rotation += amount * alpha;
+ return;
+ }
+
+ // Interpolate between the last frame and the current frame.
+ var frameIndex = spine.binarySearch(frames, time, 2);
+ var lastFrameValue = frames[frameIndex - 1];
+ var frameTime = frames[frameIndex];
+ var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime);
+ percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent);
+
+ var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue;
+ while (amount > 180)
+ amount -= 360;
+ while (amount < -180)
+ amount += 360;
+ amount = bone.data.rotation + (lastFrameValue + amount * percent) - bone.rotation;
+ while (amount > 180)
+ amount -= 360;
+ while (amount < -180)
+ amount += 360;
+ bone.rotation += amount * alpha;
+ }
+};
+
+spine.TranslateTimeline = function (frameCount) {
+ this.curves = new spine.Curves(frameCount);
+ this.frames = []; // time, x, y, ...
+ this.frames.length = frameCount * 3;
+};
+spine.TranslateTimeline.prototype = {
+ boneIndex: 0,
+ getFrameCount: function () {
+ return this.frames.length / 3;
+ },
+ setFrame: function (frameIndex, time, x, y) {
+ frameIndex *= 3;
+ this.frames[frameIndex] = time;
+ this.frames[frameIndex + 1] = x;
+ this.frames[frameIndex + 2] = y;
+ },
+ apply: function (skeleton, time, alpha) {
+ var frames = this.frames;
+ if (time < frames[0]) return; // Time is before first frame.
+
+ var bone = skeleton.bones[this.boneIndex];
+
+ if (time >= frames[frames.length - 3]) { // Time is after last frame.
+ bone.x += (bone.data.x + frames[frames.length - 2] - bone.x) * alpha;
+ bone.y += (bone.data.y + frames[frames.length - 1] - bone.y) * alpha;
+ return;
+ }
+
+ // Interpolate between the last frame and the current frame.
+ var frameIndex = spine.binarySearch(frames, time, 3);
+ var lastFrameX = frames[frameIndex - 2];
+ var lastFrameY = frames[frameIndex - 1];
+ var frameTime = frames[frameIndex];
+ var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime);
+ percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent);
+
+ bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha;
+ bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha;
+ }
+};
+
+spine.ScaleTimeline = function (frameCount) {
+ this.curves = new spine.Curves(frameCount);
+ this.frames = []; // time, x, y, ...
+ this.frames.length = frameCount * 3;
+};
+spine.ScaleTimeline.prototype = {
+ boneIndex: 0,
+ getFrameCount: function () {
+ return this.frames.length / 3;
+ },
+ setFrame: function (frameIndex, time, x, y) {
+ frameIndex *= 3;
+ this.frames[frameIndex] = time;
+ this.frames[frameIndex + 1] = x;
+ this.frames[frameIndex + 2] = y;
+ },
+ apply: function (skeleton, time, alpha) {
+ var frames = this.frames;
+ if (time < frames[0]) return; // Time is before first frame.
+
+ var bone = skeleton.bones[this.boneIndex];
+
+ if (time >= frames[frames.length - 3]) { // Time is after last frame.
+ bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha;
+ bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha;
+ return;
+ }
+
+ // Interpolate between the last frame and the current frame.
+ var frameIndex = spine.binarySearch(frames, time, 3);
+ var lastFrameX = frames[frameIndex - 2];
+ var lastFrameY = frames[frameIndex - 1];
+ var frameTime = frames[frameIndex];
+ var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime);
+ percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent);
+
+ bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha;
+ bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha;
+ }
+};
+
+spine.ColorTimeline = function (frameCount) {
+ this.curves = new spine.Curves(frameCount);
+ this.frames = []; // time, r, g, b, a, ...
+ this.frames.length = frameCount * 5;
+};
+spine.ColorTimeline.prototype = {
+ slotIndex: 0,
+ getFrameCount: function () {
+ return this.frames.length / 2;
+ },
+ setFrame: function (frameIndex, time, x, y) {
+ frameIndex *= 5;
+ this.frames[frameIndex] = time;
+ this.frames[frameIndex + 1] = r;
+ this.frames[frameIndex + 2] = g;
+ this.frames[frameIndex + 3] = b;
+ this.frames[frameIndex + 4] = a;
+ },
+ apply: function (skeleton, time, alpha) {
+ var frames = this.frames;
+ if (time < frames[0]) return; // Time is before first frame.
+
+ var slot = skeleton.slots[this.slotIndex];
+
+ if (time >= frames[frames.length - 5]) { // Time is after last frame.
+ var i = frames.length - 1;
+ slot.r = frames[i - 3];
+ slot.g = frames[i - 2];
+ slot.b = frames[i - 1];
+ slot.a = frames[i];
+ return;
+ }
+
+ // Interpolate between the last frame and the current frame.
+ var frameIndex = spine.binarySearch(frames, time, 5);
+ var lastFrameR = frames[frameIndex - 4];
+ var lastFrameG = frames[frameIndex - 3];
+ var lastFrameB = frames[frameIndex - 2];
+ var lastFrameA = frames[frameIndex - 1];
+ var frameTime = frames[frameIndex];
+ var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime);
+ percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent);
+
+ var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent;
+ var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent;
+ var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent;
+ var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent;
+ if (alpha < 1) {
+ slot.r += (r - slot.r) * alpha;
+ slot.g += (g - slot.g) * alpha;
+ slot.b += (b - slot.b) * alpha;
+ slot.a += (a - slot.a) * alpha;
+ } else {
+ slot.r = r;
+ slot.g = g;
+ slot.b = b;
+ slot.a = a;
+ }
+ }
+};
+
+spine.AttachmentTimeline = function (frameCount) {
+ this.curves = new spine.Curves(frameCount);
+ this.frames = []; // time, ...
+ this.frames.length = frameCount;
+ this.attachmentNames = []; // time, ...
+ this.attachmentNames.length = frameCount;
+};
+spine.AttachmentTimeline.prototype = {
+ slotIndex: 0,
+ getFrameCount: function () {
+ return this.frames.length;
+ },
+ setFrame: function (frameIndex, time, attachmentName) {
+ this.frames[frameIndex] = time;
+ this.attachmentNames[frameIndex] = attachmentName;
+ },
+ apply: function (skeleton, time, alpha) {
+ var frames = this.frames;
+ if (time < frames[0]) return; // Time is before first frame.
+
+ var frameIndex;
+ if (time >= frames[frames.length - 1]) // Time is after last frame.
+ frameIndex = frames.length - 1;
+ else
+ frameIndex = spine.binarySearch(frames, time, 1) - 1;
+
+ var attachmentName = this.attachmentNames[frameIndex];
+ skeleton.slots[this.slotIndex].setAttachment(!attachmentName ? null : skeleton.getAttachmentBySlotIndex(this.slotIndex, attachmentName));
+ }
+};
+
+spine.SkeletonData = function () {
+ this.bones = [];
+ this.slots = [];
+ this.skins = [];
+ this.animations = [];
+};
+spine.SkeletonData.prototype = {
+ defaultSkin: null,
+ /** @return May be null. */
+ findBone: function (boneName) {
+ var bones = this.bones;
+ for (var i = 0, n = bones.length; i < n; i++)
+ if (bones[i].name == boneName) return bones[i];
+ return null;
+ },
+ /** @return -1 if the bone was not found. */
+ findBoneIndex: function (boneName) {
+ var bones = this.bones;
+ for (var i = 0, n = bones.length; i < n; i++)
+ if (bones[i].name == boneName) return i;
+ return -1;
+ },
+ /** @return May be null. */
+ findSlot: function (slotName) {
+ var slots = this.slots;
+ for (var i = 0, n = slots.length; i < n; i++) {
+ if (slots[i].name == slotName) return slot[i];
+ }
+ return null;
+ },
+ /** @return -1 if the bone was not found. */
+ findSlotIndex: function (slotName) {
+ var slots = this.slots;
+ for (var i = 0, n = slots.length; i < n; i++)
+ if (slots[i].name == slotName) return i;
+ return -1;
+ },
+ /** @return May be null. */
+ findSkin: function (skinName) {
+ var skins = this.skins;
+ for (var i = 0, n = skins.length; i < n; i++)
+ if (skins[i].name == skinName) return skins[i];
+ return null;
+ },
+ /** @return May be null. */
+ findAnimation: function (animationName) {
+ var animations = this.animations;
+ for (var i = 0, n = animations.length; i < n; i++)
+ if (animations[i].name == animationName) return animations[i];
+ return null;
+ }
+};
+
+spine.Skeleton = function (skeletonData) {
+ this.data = skeletonData;
+
+ this.bones = [];
+ for (var i = 0, n = skeletonData.bones.length; i < n; i++) {
+ var boneData = skeletonData.bones[i];
+ var parent = !boneData.parent ? null : this.bones[skeletonData.bones.indexOf(boneData.parent)];
+ this.bones.push(new spine.Bone(boneData, parent));
+ }
+
+ this.slots = [];
+ this.drawOrder = [];
+ for (var i = 0, n = skeletonData.slots.length; i < n; i++) {
+ var slotData = skeletonData.slots[i];
+ var bone = this.bones[skeletonData.bones.indexOf(slotData.boneData)];
+ var slot = new spine.Slot(slotData, this, bone);
+ this.slots.push(slot);
+ this.drawOrder.push(slot);
+ }
+};
+spine.Skeleton.prototype = {
+ x: 0, y: 0,
+ skin: null,
+ r: 1, g: 1, b: 1, a: 1,
+ time: 0,
+ flipX: false, flipY: false,
+ /** Updates the world transform for each bone. */
+ updateWorldTransform: function () {
+ var flipX = this.flipX;
+ var flipY = this.flipY;
+ var bones = this.bones;
+ for (var i = 0, n = bones.length; i < n; i++)
+ bones[i].updateWorldTransform(flipX, flipY);
+ },
+ /** Sets the bones and slots to their setup pose values. */
+ setToSetupPose: function () {
+ this.setBonesToSetupPose();
+ this.setSlotsToSetupPose();
+ },
+ setBonesToSetupPose: function () {
+ var bones = this.bones;
+ for (var i = 0, n = bones.length; i < n; i++)
+ bones[i].setToSetupPose();
+ },
+ setSlotsToSetupPose: function () {
+ var slots = this.slots;
+ for (var i = 0, n = slots.length; i < n; i++)
+ slots[i].setToSetupPose(i);
+ },
+ /** @return May return null. */
+ getRootBone: function () {
+ return this.bones.length == 0 ? null : this.bones[0];
+ },
+ /** @return May be null. */
+ findBone: function (boneName) {
+ var bones = this.bones;
+ for (var i = 0, n = bones.length; i < n; i++)
+ if (bones[i].data.name == boneName) return bones[i];
+ return null;
+ },
+ /** @return -1 if the bone was not found. */
+ findBoneIndex: function (boneName) {
+ var bones = this.bones;
+ for (var i = 0, n = bones.length; i < n; i++)
+ if (bones[i].data.name == boneName) return i;
+ return -1;
+ },
+ /** @return May be null. */
+ findSlot: function (slotName) {
+ var slots = this.slots;
+ for (var i = 0, n = slots.length; i < n; i++)
+ if (slots[i].data.name == slotName) return slots[i];
+ return null;
+ },
+ /** @return -1 if the bone was not found. */
+ findSlotIndex: function (slotName) {
+ var slots = this.slots;
+ for (var i = 0, n = slots.length; i < n; i++)
+ if (slots[i].data.name == slotName) return i;
+ return -1;
+ },
+ setSkinByName: function (skinName) {
+ var skin = this.data.findSkin(skinName);
+ if (!skin) throw "Skin not found: " + skinName;
+ this.setSkin(skin);
+ },
+ /** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments
+ * from the new skin are attached if the corresponding attachment from the old skin was attached.
+ * @param newSkin May be null. */
+ setSkin: function (newSkin) {
+ if (this.skin && newSkin) newSkin._attachAll(this, this.skin);
+ this.skin = newSkin;
+ },
+ /** @return May be null. */
+ getAttachmentBySlotName: function (slotName, attachmentName) {
+ return this.getAttachmentBySlotIndex(this.data.findSlotIndex(slotName), attachmentName);
+ },
+ /** @return May be null. */
+ getAttachmentBySlotIndex: function (slotIndex, attachmentName) {
+ if (this.skin) {
+ var attachment = this.skin.getAttachment(slotIndex, attachmentName);
+ if (attachment) return attachment;
+ }
+ if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
+ return null;
+ },
+ /** @param attachmentName May be null. */
+ setAttachment: function (slotName, attachmentName) {
+ var slots = this.slots;
+ for (var i = 0, n = slots.size; i < n; i++) {
+ var slot = slots[i];
+ if (slot.data.name == slotName) {
+ var attachment = null;
+ if (attachmentName) {
+ attachment = this.getAttachment(i, attachmentName);
+ if (attachment == null) throw "Attachment not found: " + attachmentName + ", for slot: " + slotName;
+ }
+ slot.setAttachment(attachment);
+ return;
+ }
+ }
+ throw "Slot not found: " + slotName;
+ },
+ update: function (delta) {
+ time += delta;
+ }
+};
+
+spine.AttachmentType = {
+ region: 0
+};
+
+spine.RegionAttachment = function () {
+ this.offset = [];
+ this.offset.length = 8;
+ this.uvs = [];
+ this.uvs.length = 8;
+};
+spine.RegionAttachment.prototype = {
+ x: 0, y: 0,
+ rotation: 0,
+ scaleX: 1, scaleY: 1,
+ width: 0, height: 0,
+ rendererObject: null,
+ regionOffsetX: 0, regionOffsetY: 0,
+ regionWidth: 0, regionHeight: 0,
+ regionOriginalWidth: 0, regionOriginalHeight: 0,
+ setUVs: function (u, v, u2, v2, rotate) {
+ var uvs = this.uvs;
+ if (rotate) {
+ uvs[2/*X2*/] = u;
+ uvs[3/*Y2*/] = v2;
+ uvs[4/*X3*/] = u;
+ uvs[5/*Y3*/] = v;
+ uvs[6/*X4*/] = u2;
+ uvs[7/*Y4*/] = v;
+ uvs[0/*X1*/] = u2;
+ uvs[1/*Y1*/] = v2;
+ } else {
+ uvs[0/*X1*/] = u;
+ uvs[1/*Y1*/] = v2;
+ uvs[2/*X2*/] = u;
+ uvs[3/*Y2*/] = v;
+ uvs[4/*X3*/] = u2;
+ uvs[5/*Y3*/] = v;
+ uvs[6/*X4*/] = u2;
+ uvs[7/*Y4*/] = v2;
+ }
+ },
+ updateOffset: function () {
+ var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX;
+ var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY;
+ var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX;
+ var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY;
+ var localX2 = localX + this.regionWidth * regionScaleX;
+ var localY2 = localY + this.regionHeight * regionScaleY;
+ var radians = this.rotation * Math.PI / 180;
+ var cos = Math.cos(radians);
+ var sin = Math.sin(radians);
+ var localXCos = localX * cos + this.x;
+ var localXSin = localX * sin;
+ var localYCos = localY * cos + this.y;
+ var localYSin = localY * sin;
+ var localX2Cos = localX2 * cos + this.x;
+ var localX2Sin = localX2 * sin;
+ var localY2Cos = localY2 * cos + this.y;
+ var localY2Sin = localY2 * sin;
+ var offset = this.offset;
+ offset[0/*X1*/] = localXCos - localYSin;
+ offset[1/*Y1*/] = localYCos + localXSin;
+ offset[2/*X2*/] = localXCos - localY2Sin;
+ offset[3/*Y2*/] = localY2Cos + localXSin;
+ offset[4/*X3*/] = localX2Cos - localY2Sin;
+ offset[5/*Y3*/] = localY2Cos + localX2Sin;
+ offset[6/*X4*/] = localX2Cos - localYSin;
+ offset[7/*Y4*/] = localYCos + localX2Sin;
+ },
+ computeVertices: function (x, y, bone, vertices) {
+ x += bone.worldX;
+ y += bone.worldY;
+ var m00 = bone.m00;
+ var m01 = bone.m01;
+ var m10 = bone.m10;
+ var m11 = bone.m11;
+ var offset = this.offset;
+ vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x;
+ vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y;
+ vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x;
+ vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y;
+ vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x;
+ vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y;
+ vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x;
+ vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y;
+ }
+}
+
+spine.AnimationStateData = function (skeletonData) {
+ this.skeletonData = skeletonData;
+ this.animationToMixTime = {};
+};
+spine.AnimationStateData.prototype = {
+ defaultMix: 0,
+ setMixByName: function (fromName, toName, duration) {
+ var from = this.skeletonData.findAnimation(fromName);
+ if (!from) throw "Animation not found: " + fromName;
+ var to = this.skeletonData.findAnimation(toName);
+ if (!to) throw "Animation not found: " + toName;
+ this.setMix(from, to, duration);
+ },
+ setMix: function (from, to, duration) {
+ this.animationToMixTime[from.name + ":" + to.name] = duration;
+ },
+ getMix: function (from, to) {
+ var time = this.animationToMixTime[from.name + ":" + to.name];
+ return time ? time : this.defaultMix;
+ }
+};
+
+spine.AnimationState = function (stateData) {
+ this.data = stateData;
+ this.queue = [];
+};
+spine.AnimationState.prototype = {
+ current: null,
+ previous: null,
+ currentTime: 0,
+ previousTime: 0,
+ currentLoop: false,
+ previousLoop: false,
+ mixTime: 0,
+ mixDuration: 0,
+ update: function (delta) {
+ this.currentTime += delta;
+ this.previousTime += delta;
+ this.mixTime += delta;
+
+ if (this.queue.length > 0) {
+ var entry = this.queue[0];
+ if (this.currentTime >= entry.delay) {
+ this._setAnimation(entry.animation, entry.loop);
+ this.queue.shift();
+ }
+ }
+ },
+ apply: function (skeleton) {
+ if (!this.current) return;
+ if (this.previous) {
+ this.previous.apply(skeleton, this.previousTime, this.previousLoop);
+ var alpha = this.mixTime / this.mixDuration;
+ if (alpha >= 1) {
+ alpha = 1;
+ this.previous = null;
+ }
+ this.current.mix(skeleton, this.currentTime, this.currentLoop, alpha);
+ } else
+ this.current.apply(skeleton, this.currentTime, this.currentLoop);
+ },
+ clearAnimation: function () {
+ this.previous = null;
+ this.current = null;
+ this.queue.length = 0;
+ },
+ _setAnimation: function (animation, loop) {
+ this.previous = null;
+ if (animation && this.current) {
+ this.mixDuration = this.data.getMix(this.current, animation);
+ if (this.mixDuration > 0) {
+ this.mixTime = 0;
+ this.previous = this.current;
+ this.previousTime = this.currentTime;
+ this.previousLoop = this.currentLoop;
+ }
+ }
+ this.current = animation;
+ this.currentLoop = loop;
+ this.currentTime = 0;
+ },
+ /** @see #setAnimation(Animation, Boolean) */
+ setAnimationByName: function (animationName, loop) {
+ var animation = this.data.skeletonData.findAnimation(animationName);
+ if (!animation) throw "Animation not found: " + animationName;
+ this.setAnimation(animation, loop);
+ },
+ /** Set the current animation. Any queued animations are cleared and the current animation time is set to 0.
+ * @param animation May be null. */
+ setAnimation: function (animation, loop) {
+ this.queue.length = 0;
+ this._setAnimation(animation, loop);
+ },
+ /** @see #addAnimation(Animation, Boolean, Number) */
+ addAnimationByName: function (animationName, loop, delay) {
+ var animation = this.data.skeletonData.findAnimation(animationName);
+ if (!animation) throw "Animation not found: " + animationName;
+ this.addAnimation(animation, loop, delay);
+ },
+ /** Adds an animation to be played delay seconds after the current or last queued animation.
+ * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */
+ addAnimation: function (animation, loop, delay) {
+ var entry = {};
+ entry.animation = animation;
+ entry.loop = loop;
+
+ if (!delay || delay <= 0) {
+ var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation;
+ if (previousAnimation != null)
+ delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0);
+ else
+ delay = 0;
+ }
+ entry.delay = delay;
+
+ this.queue.push(entry);
+ },
+ /** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */
+ isComplete: function () {
+ return !this.current || this.currentTime >= this.current.duration;
+ }
+};
+
+spine.SkeletonJson = function (attachmentLoader) {
+ this.attachmentLoader = attachmentLoader;
+};
+spine.SkeletonJson.prototype = {
+ scale: 1,
+ readSkeletonData: function (root) {
+ var skeletonData = new spine.SkeletonData();
+
+ // Bones.
+ var bones = root["bones"];
+ for (var i = 0, n = bones.length; i < n; i++) {
+ var boneMap = bones[i];
+ var parent = null;
+ if (boneMap["parent"]) {
+ parent = skeletonData.findBone(boneMap["parent"]);
+ if (!parent) throw "Parent bone not found: " + boneMap["parent"];
+ }
+ var boneData = new spine.BoneData(boneMap["name"], parent);
+ boneData.length = (boneMap["length"] || 0) * this.scale;
+ boneData.x = (boneMap["x"] || 0) * this.scale;
+ boneData.y = (boneMap["y"] || 0) * this.scale;
+ boneData.rotation = (boneMap["rotation"] || 0);
+ boneData.scaleX = boneMap["scaleX"] || 1;
+ boneData.scaleY = boneMap["scaleY"] || 1;
+ skeletonData.bones.push(boneData);
+ }
+
+ // Slots.
+ var slots = root["slots"];
+ for (var i = 0, n = slots.length; i < n; i++) {
+ var slotMap = slots[i];
+ var boneData = skeletonData.findBone(slotMap["bone"]);
+ if (!boneData) throw "Slot bone not found: " + slotMap["bone"];
+ var slotData = new spine.SlotData(slotMap["name"], boneData);
+
+ var color = slotMap["color"];
+ if (color) {
+ slotData.r = spine.SkeletonJson.toColor(color, 0);
+ slotData.g = spine.SkeletonJson.toColor(color, 1);
+ slotData.b = spine.SkeletonJson.toColor(color, 2);
+ slotData.a = spine.SkeletonJson.toColor(color, 3);
+ }
+
+ slotData.attachmentName = slotMap["attachment"];
+
+ skeletonData.slots.push(slotData);
+ }
+
+ // Skins.
+ var skins = root["skins"];
+ for (var skinName in skins) {
+ if (!skins.hasOwnProperty(skinName)) continue;
+ var skinMap = skins[skinName];
+ var skin = new spine.Skin(skinName);
+ for (var slotName in skinMap) {
+ if (!skinMap.hasOwnProperty(slotName)) continue;
+ var slotIndex = skeletonData.findSlotIndex(slotName);
+ var slotEntry = skinMap[slotName];
+ for (var attachmentName in slotEntry) {
+ if (!slotEntry.hasOwnProperty(attachmentName)) continue;
+ var attachment = this.readAttachment(skin, attachmentName, slotEntry[attachmentName]);
+ if (attachment != null) skin.addAttachment(slotIndex, attachmentName, attachment);
+ }
+ }
+ skeletonData.skins.push(skin);
+ if (skin.name == "default") skeletonData.defaultSkin = skin;
+ }
+
+ // Animations.
+ var animations = root["animations"];
+ for (var animationName in animations) {
+ if (!animations.hasOwnProperty(animationName)) continue;
+ this.readAnimation(animationName, animations[animationName], skeletonData);
+ }
+
+ return skeletonData;
+ },
+ readAttachment: function (skin, name, map) {
+ name = map["name"] || name;
+
+ var type = spine.AttachmentType[map["type"] || "region"];
+
+ if (type == spine.AttachmentType.region) {
+ var attachment = new spine.RegionAttachment();
+ attachment.x = (map["x"] || 0) * this.scale;
+ attachment.y = (map["y"] || 0) * this.scale;
+ attachment.scaleX = map["scaleX"] || 1;
+ attachment.scaleY = map["scaleY"] || 1;
+ attachment.rotation = map["rotation"] || 0;
+ attachment.width = (map["width"] || 32) * this.scale;
+ attachment.height = (map["height"] || 32) * this.scale;
+ attachment.updateOffset();
+
+ attachment.rendererObject = {};
+ attachment.rendererObject.name = name;
+ attachment.rendererObject.scale = {};
+ attachment.rendererObject.scale.x = attachment.scaleX;
+ attachment.rendererObject.scale.y = attachment.scaleY;
+ attachment.rendererObject.rotation = -attachment.rotation * Math.PI / 180;
+ return attachment;
+ }
+
+ throw "Unknown attachment type: " + type;
+ },
+
+ readAnimation: function (name, map, skeletonData) {
+ var timelines = [];
+ var duration = 0;
+
+ var bones = map["bones"];
+ for (var boneName in bones) {
+ if (!bones.hasOwnProperty(boneName)) continue;
+ var boneIndex = skeletonData.findBoneIndex(boneName);
+ if (boneIndex == -1) throw "Bone not found: " + boneName;
+ var boneMap = bones[boneName];
+
+ for (var timelineName in boneMap) {
+ if (!boneMap.hasOwnProperty(timelineName)) continue;
+ var values = boneMap[timelineName];
+ if (timelineName == "rotate") {
+ var timeline = new spine.RotateTimeline(values.length);
+ timeline.boneIndex = boneIndex;
+
+ var frameIndex = 0;
+ for (var i = 0, n = values.length; i < n; i++) {
+ var valueMap = values[i];
+ timeline.setFrame(frameIndex, valueMap["time"], valueMap["angle"]);
+ spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap);
+ frameIndex++;
+ }
+ timelines.push(timeline);
+ duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]);
+
+ } else if (timelineName == "translate" || timelineName == "scale") {
+ var timeline;
+ var timelineScale = 1;
+ if (timelineName == "scale")
+ timeline = new spine.ScaleTimeline(values.length);
+ else {
+ timeline = new spine.TranslateTimeline(values.length);
+ timelineScale = this.scale;
+ }
+ timeline.boneIndex = boneIndex;
+
+ var frameIndex = 0;
+ for (var i = 0, n = values.length; i < n; i++) {
+ var valueMap = values[i];
+ var x = (valueMap["x"] || 0) * timelineScale;
+ var y = (valueMap["y"] || 0) * timelineScale;
+ timeline.setFrame(frameIndex, valueMap["time"], x, y);
+ spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap);
+ frameIndex++;
+ }
+ timelines.push(timeline);
+ duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]);
+
+ } else
+ throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")";
+ }
+ }
+ var slots = map["slots"];
+ for (var slotName in slots) {
+ if (!slots.hasOwnProperty(slotName)) continue;
+ var slotMap = slots[slotName];
+ var slotIndex = skeletonData.findSlotIndex(slotName);
+
+ for (var timelineName in slotMap) {
+ if (!slotMap.hasOwnProperty(timelineName)) continue;
+ var values = slotMap[timelineName];
+ if (timelineName == "color") {
+ var timeline = new spine.ColorTimeline(values.length);
+ timeline.slotIndex = slotIndex;
+
+ var frameIndex = 0;
+ for (var i = 0, n = values.length; i < n; i++) {
+ var valueMap = values[i];
+ var color = valueMap["color"];
+ var r = spine.SkeletonJson.toColor(color, 0);
+ var g = spine.SkeletonJson.toColor(color, 1);
+ var b = spine.SkeletonJson.toColor(color, 2);
+ var a = spine.SkeletonJson.toColor(color, 3);
+ timeline.setFrame(frameIndex, valueMap["time"], r, g, b, a);
+ spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap);
+ frameIndex++;
+ }
+ timelines.push(timeline);
+ duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]);
+
+ } else if (timelineName == "attachment") {
+ var timeline = new spine.AttachmentTimeline(values.length);
+ timeline.slotIndex = slotIndex;
+
+ var frameIndex = 0;
+ for (var i = 0, n = values.length; i < n; i++) {
+ var valueMap = values[i];
+ timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]);
+ }
+ timelines.push(timeline);
+ duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
+
+ } else
+ throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")";
+ }
+ }
+ skeletonData.animations.push(new spine.Animation(name, timelines, duration));
+ }
+};
+spine.SkeletonJson.readCurve = function (timeline, frameIndex, valueMap) {
+ var curve = valueMap["curve"];
+ if (!curve) return;
+ if (curve == "stepped")
+ timeline.curves.setStepped(frameIndex);
+ else if (curve instanceof Array)
+ timeline.curves.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]);
+};
+spine.SkeletonJson.toColor = function (hexString, colorIndex) {
+ if (hexString.length != 8) throw "Color hexidecimal length must be 8, recieved: " + hexString;
+ return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255;
+};
+
+spine.Atlas = function (atlasText, textureLoader) {
+ this.textureLoader = textureLoader;
+ this.pages = [];
+ this.regions = [];
+
+ var reader = new spine.AtlasReader(atlasText);
+ var tuple = [];
+ tuple.length = 4;
+ var page = null;
+ while (true) {
+ var line = reader.readLine();
+ if (line == null) break;
+ line = reader.trim(line);
+ if (line.length == 0)
+ page = null;
+ else if (!page) {
+ page = new spine.AtlasPage();
+ page.name = line;
+
+ page.format = spine.Atlas.Format[reader.readValue()];
+
+ reader.readTuple(tuple);
+ page.minFilter = spine.Atlas.TextureFilter[tuple[0]];
+ page.magFilter = spine.Atlas.TextureFilter[tuple[1]];
+
+ var direction = reader.readValue();
+ page.uWrap = spine.Atlas.TextureWrap.clampToEdge;
+ page.vWrap = spine.Atlas.TextureWrap.clampToEdge;
+ if (direction == "x")
+ page.uWrap = spine.Atlas.TextureWrap.repeat;
+ else if (direction == "y")
+ page.vWrap = spine.Atlas.TextureWrap.repeat;
+ else if (direction == "xy")
+ page.uWrap = page.vWrap = spine.Atlas.TextureWrap.repeat;
+
+ textureLoader.load(page, line);
+
+ this.pages.push(page);
+
+ } else {
+ var region = new spine.AtlasRegion();
+ region.name = line;
+ region.page = page;
+
+ region.rotate = reader.readValue() == "true";
+
+ reader.readTuple(tuple);
+ var x = parseInt(tuple[0]);
+ var y = parseInt(tuple[1]);
+
+ reader.readTuple(tuple);
+ var width = parseInt(tuple[0]);
+ var height = parseInt(tuple[1]);
+
+ region.u = x / page.width;
+ region.v = y / page.height;
+ if (region.rotate) {
+ region.u2 = (x + height) / page.width;
+ region.v2 = (y + width) / page.height;
+ } else {
+ region.u2 = (x + width) / page.width;
+ region.v2 = (y + height) / page.height;
+ }
+ region.x = x;
+ region.y = y;
+ region.width = Math.abs(width);
+ region.height = Math.abs(height);
+
+ if (reader.readTuple(tuple) == 4) { // split is optional
+ region.splits = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])];
+
+ if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits
+ region.pads = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])];
+
+ reader.readTuple(tuple);
+ }
+ }
+
+ region.originalWidth = parseInt(tuple[0]);
+ region.originalHeight = parseInt(tuple[1]);
+
+ reader.readTuple(tuple);
+ region.offsetX = parseInt(tuple[0]);
+ region.offsetY = parseInt(tuple[1]);
+
+ region.index = parseInt(reader.readValue());
+
+ this.regions.push(region);
+ }
+ }
+};
+spine.Atlas.prototype = {
+ findRegion: function (name) {
+ var regions = this.regions;
+ for (var i = 0, n = regions.length; i < n; i++)
+ if (regions[i].name == name) return regions[i];
+ return null;
+ },
+ dispose: function () {
+ var pages = this.pages;
+ for (var i = 0, n = pages.length; i < n; i++)
+ this.textureLoader.unload(pages[i].rendererObject);
+ },
+ updateUVs: function (page) {
+ var regions = this.regions;
+ for (var i = 0, n = regions.length; i < n; i++) {
+ var region = regions[i];
+ if (region.page != page) continue;
+ region.u = region.x / page.width;
+ region.v = region.y / page.height;
+ if (region.rotate) {
+ region.u2 = (region.x + region.height) / page.width;
+ region.v2 = (region.y + region.width) / page.height;
+ } else {
+ region.u2 = (region.x + region.width) / page.width;
+ region.v2 = (region.y + region.height) / page.height;
+ }
+ }
+ }
+};
+
+spine.Atlas.Format = {
+ alpha: 0,
+ intensity: 1,
+ luminanceAlpha: 2,
+ rgb565: 3,
+ rgba4444: 4,
+ rgb888: 5,
+ rgba8888: 6
+};
+
+spine.Atlas.TextureFilter = {
+ nearest: 0,
+ linear: 1,
+ mipMap: 2,
+ mipMapNearestNearest: 3,
+ mipMapLinearNearest: 4,
+ mipMapNearestLinear: 5,
+ mipMapLinearLinear: 6
+};
+
+spine.Atlas.TextureWrap = {
+ mirroredRepeat: 0,
+ clampToEdge: 1,
+ repeat: 2
+};
+
+spine.AtlasPage = function () {};
+spine.AtlasPage.prototype = {
+ name: null,
+ format: null,
+ minFilter: null,
+ magFilter: null,
+ uWrap: null,
+ vWrap: null,
+ rendererObject: null,
+ width: 0,
+ height: 0
+};
+
+spine.AtlasRegion = function () {};
+spine.AtlasRegion.prototype = {
+ page: null,
+ name: null,
+ x: 0, y: 0,
+ width: 0, height: 0,
+ u: 0, v: 0, u2: 0, v2: 0,
+ offsetX: 0, offsetY: 0,
+ originalWidth: 0, originalHeight: 0,
+ index: 0,
+ rotate: false,
+ splits: null,
+ pads: null,
+};
+
+spine.AtlasReader = function (text) {
+ this.lines = text.split(/\r\n|\r|\n/);
+};
+spine.AtlasReader.prototype = {
+ index: 0,
+ trim: function (value) {
+ return value.replace(/^\s+|\s+$/g, "");
+ },
+ readLine: function () {
+ if (this.index >= this.lines.length) return null;
+ return this.lines[this.index++];
+ },
+ readValue: function () {
+ var line = this.readLine();
+ var colon = line.indexOf(":");
+ if (colon == -1) throw "Invalid line: " + line;
+ return this.trim(line.substring(colon + 1));
+ },
+ /** Returns the number of tuple values read (2 or 4). */
+ readTuple: function (tuple) {
+ var line = this.readLine();
+ var colon = line.indexOf(":");
+ if (colon == -1) throw "Invalid line: " + line;
+ var i = 0, lastMatch= colon + 1;
+ for (; i < 3; i++) {
+ var comma = line.indexOf(",", lastMatch);
+ if (comma == -1) {
+ if (i == 0) throw "Invalid line: " + line;
+ break;
+ }
+ tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch));
+ lastMatch = comma + 1;
+ }
+ tuple[i] = this.trim(line.substring(lastMatch));
+ return i + 1;
+ }
+}
+
+spine.AtlasAttachmentLoader = function (atlas) {
+ this.atlas = atlas;
+}
+spine.AtlasAttachmentLoader.prototype = {
+ newAttachment: function (skin, type, name) {
+ switch (type) {
+ case spine.AttachmentType.region:
+ var region = this.atlas.findRegion(name);
+ if (!region) throw "Region not found in atlas: " + name + " (" + type + ")";
+ var attachment = new spine.RegionAttachment(name);
+ attachment.rendererObject = region;
+ attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate);
+ attachment.regionOffsetX = region.offsetX;
+ attachment.regionOffsetY = region.offsetY;
+ attachment.regionWidth = region.width;
+ attachment.regionHeight = region.height;
+ attachment.regionOriginalWidth = region.originalWidth;
+ attachment.regionOriginalHeight = region.originalHeight;
+ return attachment;
+ }
+ throw "Unknown attachment type: " + type;
+ }
+}
+
+PIXI.AnimCache = {};
+spine.Bone.yDown = true;
diff --git a/src/pixi/extras/Strip.js b/src/pixi/extras/Strip.js
new file mode 100644
index 00000000..1e5ba3bf
--- /dev/null
+++ b/src/pixi/extras/Strip.js
@@ -0,0 +1,89 @@
+/**
+ * @author Mat Groves http://matgroves.com/
+ */
+
+PIXI.Strip = function(texture, width, height)
+{
+ PIXI.DisplayObjectContainer.call( this );
+ this.texture = texture;
+ this.blendMode = PIXI.blendModes.NORMAL;
+
+ try
+ {
+ this.uvs = new Float32Array([0, 1,
+ 1, 1,
+ 1, 0, 0,1]);
+
+ this.verticies = new Float32Array([0, 0,
+ 0,0,
+ 0,0, 0,
+ 0, 0]);
+
+ this.colors = new Float32Array([1, 1, 1, 1]);
+
+ this.indices = new Uint16Array([0, 1, 2, 3]);
+ }
+ catch(error)
+ {
+ this.uvs = [0, 1,
+ 1, 1,
+ 1, 0, 0,1];
+
+ this.verticies = [0, 0,
+ 0,0,
+ 0,0, 0,
+ 0, 0];
+
+ this.colors = [1, 1, 1, 1];
+
+ this.indices = [0, 1, 2, 3];
+ }
+
+
+ /*
+ this.uvs = new Float32Array()
+ this.verticies = new Float32Array()
+ this.colors = new Float32Array()
+ this.indices = new Uint16Array()
+*/
+ this.width = width;
+ this.height = height;
+
+ // load the texture!
+ if(texture.baseTexture.hasLoaded)
+ {
+ this.width = this.texture.frame.width;
+ this.height = this.texture.frame.height;
+ this.updateFrame = true;
+ }
+ else
+ {
+ this.onTextureUpdateBind = this.onTextureUpdate.bind(this);
+ this.texture.addEventListener( 'update', this.onTextureUpdateBind );
+ }
+
+ this.renderable = true;
+}
+
+// constructor
+PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
+PIXI.Strip.prototype.constructor = PIXI.Strip;
+
+PIXI.Strip.prototype.setTexture = function(texture)
+{
+ //TODO SET THE TEXTURES
+ //TODO VISIBILITY
+
+ // stop current texture
+ this.texture = texture;
+ this.width = texture.frame.width;
+ this.height = texture.frame.height;
+ this.updateFrame = true;
+}
+
+PIXI.Strip.prototype.onTextureUpdate = function(event)
+{
+ this.updateFrame = true;
+}
+// some helper functions..
+
diff --git a/src/pixi/extras/TilingSprite.js b/src/pixi/extras/TilingSprite.js
new file mode 100644
index 00000000..2cb17fae
--- /dev/null
+++ b/src/pixi/extras/TilingSprite.js
@@ -0,0 +1,95 @@
+/**
+ * @author Mat Groves http://matgroves.com/
+ */
+
+/**
+ * A tiling sprite is a fast way of rendering a tiling image
+ *
+ * @class TilingSprite
+ * @extends DisplayObjectContainer
+ * @constructor
+ * @param texture {Texture} the texture of the tiling sprite
+ * @param width {Number} the width of the tiling sprite
+ * @param height {Number} the height of the tiling sprite
+ */
+PIXI.TilingSprite = function(texture, width, height)
+{
+ PIXI.DisplayObjectContainer.call( this );
+
+ /**
+ * The texture that the sprite is using
+ *
+ * @property texture
+ * @type Texture
+ */
+ this.texture = texture;
+
+ /**
+ * The width of the tiling sprite
+ *
+ * @property width
+ * @type Number
+ */
+ this.width = width;
+
+ /**
+ * The height of the tiling sprite
+ *
+ * @property height
+ * @type Number
+ */
+ this.height = height;
+
+ /**
+ * The scaling of the image that is being tiled
+ *
+ * @property tileScale
+ * @type Point
+ */
+ this.tileScale = new PIXI.Point(1,1);
+
+ /**
+ * The offset position of the image that is being tiled
+ *
+ * @property tilePosition
+ * @type Point
+ */
+ this.tilePosition = new PIXI.Point(0,0);
+
+ this.renderable = true;
+
+ this.blendMode = PIXI.blendModes.NORMAL
+}
+
+// constructor
+PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
+PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite;
+
+/**
+ * Sets the texture of the tiling sprite
+ *
+ * @method setTexture
+ * @param texture {Texture} The PIXI texture that is displayed by the sprite
+ */
+PIXI.TilingSprite.prototype.setTexture = function(texture)
+{
+ //TODO SET THE TEXTURES
+ //TODO VISIBILITY
+
+ // stop current texture
+ this.texture = texture;
+ this.updateFrame = true;
+}
+
+/**
+ * When the texture is updated, this event will fire to update the frame
+ *
+ * @method onTextureUpdate
+ * @param event
+ * @private
+ */
+PIXI.TilingSprite.prototype.onTextureUpdate = function(event)
+{
+ this.updateFrame = true;
+}
+
diff --git a/src/pixi/filters/FilterBlock.js b/src/pixi/filters/FilterBlock.js
new file mode 100644
index 00000000..c4732338
--- /dev/null
+++ b/src/pixi/filters/FilterBlock.js
@@ -0,0 +1,13 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+
+PIXI.FilterBlock = function(mask)
+{
+ this.graphics = mask
+ this.visible = true;
+ this.renderable = true;
+}
+
diff --git a/src/pixi/filters/MaskFilter.js b/src/pixi/filters/MaskFilter.js
new file mode 100644
index 00000000..1cf00ebe
--- /dev/null
+++ b/src/pixi/filters/MaskFilter.js
@@ -0,0 +1,12 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+
+PIXI.MaskFilter = function(graphics)
+{
+ // the graphics data that will be used for filtering
+ this.graphics;
+}
+
diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js
new file mode 100644
index 00000000..168a5f86
--- /dev/null
+++ b/src/pixi/loaders/AssetLoader.js
@@ -0,0 +1,122 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the
+ * assets have been loaded they are added to the PIXI Texture cache and can be accessed
+ * easily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage()
+ * When all items have been loaded this class will dispatch a "onLoaded" event
+ * As each individual item is loaded this class will dispatch a "onProgress" event
+ *
+ * @class AssetLoader
+ * @constructor
+ * @uses EventTarget
+ * @param {Array} assetURLs an array of image/sprite sheet urls that you would like loaded
+ * supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported
+ * sprite sheet data formats only include "JSON" at this time. Supported bitmap font
+ * data formats include "xml" and "fnt".
+ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
+ */
+PIXI.AssetLoader = function(assetURLs, crossorigin)
+{
+ PIXI.EventTarget.call(this);
+
+ /**
+ * The array of asset URLs that are going to be loaded
+ *
+ * @property assetURLs
+ * @type Array
+ */
+ this.assetURLs = assetURLs;
+
+ /**
+ * Whether the requests should be treated as cross origin
+ *
+ * @property crossorigin
+ * @type Boolean
+ */
+ this.crossorigin = crossorigin;
+
+ /**
+ * Maps file extension to loader types
+ *
+ * @property loadersByType
+ * @type Object
+ */
+ this.loadersByType = {
+ "jpg": PIXI.ImageLoader,
+ "jpeg": PIXI.ImageLoader,
+ "png": PIXI.ImageLoader,
+ "gif": PIXI.ImageLoader,
+ "json": PIXI.JsonLoader,
+ "anim": PIXI.SpineLoader,
+ "xml": PIXI.BitmapFontLoader,
+ "fnt": PIXI.BitmapFontLoader
+ };
+
+
+};
+
+/**
+ * Fired when an item has loaded
+ * @event onProgress
+ */
+
+/**
+ * Fired when all the assets have loaded
+ * @event onComplete
+ */
+
+// constructor
+PIXI.AssetLoader.prototype.constructor = PIXI.AssetLoader;
+
+/**
+ * Starts loading the assets sequentially
+ *
+ * @method load
+ */
+PIXI.AssetLoader.prototype.load = function()
+{
+ var scope = this;
+
+ this.loadCount = this.assetURLs.length;
+
+ for (var i=0; i < this.assetURLs.length; i++)
+ {
+ var fileName = this.assetURLs[i];
+ var fileType = fileName.split(".").pop().toLowerCase();
+
+ var loaderClass = this.loadersByType[fileType];
+ if(!loaderClass)
+ throw new Error(fileType + " is an unsupported file type");
+
+ var loader = new loaderClass(fileName, this.crossorigin);
+
+ loader.addEventListener("loaded", function()
+ {
+ scope.onAssetLoaded();
+ });
+ loader.load();
+ }
+};
+
+/**
+ * Invoked after each file is loaded
+ *
+ * @method onAssetLoaded
+ * @private
+ */
+PIXI.AssetLoader.prototype.onAssetLoaded = function()
+{
+ this.loadCount--;
+ this.dispatchEvent({type: "onProgress", content: this});
+ if(this.onProgress) this.onProgress();
+
+ if(this.loadCount == 0)
+ {
+ this.dispatchEvent({type: "onComplete", content: this});
+ if(this.onComplete) this.onComplete();
+ }
+};
+
diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js
new file mode 100644
index 00000000..4afd8aa2
--- /dev/null
+++ b/src/pixi/loaders/BitmapFontLoader.js
@@ -0,0 +1,163 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * The xml loader is used to load in XML bitmap font data ("xml" or "fnt")
+ * To generate the data you can use http://www.angelcode.com/products/bmfont/
+ * This loader will also load the image file as the data.
+ * When loaded this class will dispatch a "loaded" event
+ *
+ * @class BitmapFontLoader
+ * @uses EventTarget
+ * @constructor
+ * @param url {String} The url of the sprite sheet JSON file
+ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
+ */
+PIXI.BitmapFontLoader = function(url, crossorigin)
+{
+ /*
+ * i use texture packer to load the assets..
+ * http://www.codeandweb.com/texturepacker
+ * make sure to set the format as "JSON"
+ */
+ PIXI.EventTarget.call(this);
+
+ /**
+ * The url of the bitmap font data
+ *
+ * @property url
+ * @type String
+ */
+ this.url = url;
+
+ /**
+ * Whether the requests should be treated as cross origin
+ *
+ * @property crossorigin
+ * @type Boolean
+ */
+ this.crossorigin = crossorigin;
+
+ /**
+ * [read-only] The base url of the bitmap font data
+ *
+ * @property baseUrl
+ * @type String
+ * @readOnly
+ */
+ this.baseUrl = url.replace(/[^\/]*$/, "");
+
+ /**
+ * [read-only] The texture of the bitmap font
+ *
+ * @property baseUrl
+ * @type String
+ */
+ this.texture = null;
+};
+
+// constructor
+PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader;
+
+/**
+ * Loads the XML font data
+ *
+ * @method load
+ */
+PIXI.BitmapFontLoader.prototype.load = function()
+{
+ this.ajaxRequest = new XMLHttpRequest();
+ var scope = this;
+ this.ajaxRequest.onreadystatechange = function()
+ {
+ scope.onXMLLoaded();
+ };
+
+ this.ajaxRequest.open("GET", this.url, true);
+ if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml");
+ this.ajaxRequest.send(null)
+};
+
+/**
+ * Invoked when XML file is loaded, parses the data
+ *
+ * @method onXMLLoaded
+ * @private
+ */
+PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
+{
+ if (this.ajaxRequest.readyState == 4)
+ {
+ if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
+ {
+ var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName("page")[0].attributes.getNamedItem("file").nodeValue;
+ var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
+ this.texture = image.texture.baseTexture;
+
+ var data = {};
+ var info = this.ajaxRequest.responseXML.getElementsByTagName("info")[0];
+ var common = this.ajaxRequest.responseXML.getElementsByTagName("common")[0];
+ data.font = info.attributes.getNamedItem("face").nodeValue;
+ data.size = parseInt(info.attributes.getNamedItem("size").nodeValue, 10);
+ data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10);
+ data.chars = {};
+
+ //parse letters
+ var letters = this.ajaxRequest.responseXML.getElementsByTagName("char");
+
+ for (var i = 0; i < letters.length; i++)
+ {
+ var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10);
+
+ var textureRect = {
+ x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10),
+ y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10),
+ width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10),
+ height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10)
+ };
+ PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect);
+
+ data.chars[charCode] = {
+ xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
+ yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
+ xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
+ kerning: {},
+ texture:new PIXI.Texture(this.texture, textureRect)
+
+ };
+ }
+
+ //parse kernings
+ var kernings = this.ajaxRequest.responseXML.getElementsByTagName("kerning");
+ for (i = 0; i < kernings.length; i++)
+ {
+ var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10);
+ var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10);
+ var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10);
+
+ data.chars[second].kerning[first] = amount;
+
+ }
+
+ PIXI.BitmapText.fonts[data.font] = data;
+
+ var scope = this;
+ image.addEventListener("loaded", function() {
+ scope.onLoaded();
+ });
+ image.load();
+ }
+ }
+};
+
+/**
+ * Invoked when all files are loaded (xml/fnt and texture)
+ *
+ * @method onLoaded
+ * @private
+ */
+PIXI.BitmapFontLoader.prototype.onLoaded = function()
+{
+ this.dispatchEvent({type: "loaded", content: this});
+};
diff --git a/src/pixi/loaders/ImageLoader.js b/src/pixi/loaders/ImageLoader.js
new file mode 100644
index 00000000..971c0129
--- /dev/null
+++ b/src/pixi/loaders/ImageLoader.js
@@ -0,0 +1,62 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif")
+ * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()
+ * When loaded this class will dispatch a 'loaded' event
+ *
+ * @class ImageLoader
+ * @uses EventTarget
+ * @constructor
+ * @param url {String} The url of the image
+ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
+ */
+PIXI.ImageLoader = function(url, crossorigin)
+{
+ PIXI.EventTarget.call(this);
+
+ /**
+ * The texture being loaded
+ *
+ * @property texture
+ * @type Texture
+ */
+ this.texture = PIXI.Texture.fromImage(url, crossorigin);
+};
+
+// constructor
+PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader;
+
+/**
+ * Loads image or takes it from cache
+ *
+ * @method load
+ */
+PIXI.ImageLoader.prototype.load = function()
+{
+ if(!this.texture.baseTexture.hasLoaded)
+ {
+ var scope = this;
+ this.texture.baseTexture.addEventListener("loaded", function()
+ {
+ scope.onLoaded();
+ });
+ }
+ else
+ {
+ this.onLoaded();
+ }
+};
+
+/**
+ * Invoked when image file is loaded or it is already cached and ready to use
+ *
+ * @method onLoaded
+ * @private
+ */
+PIXI.ImageLoader.prototype.onLoaded = function()
+{
+ this.dispatchEvent({type: "loaded", content: this});
+};
diff --git a/src/pixi/loaders/JsonLoader.js b/src/pixi/loaders/JsonLoader.js
new file mode 100644
index 00000000..1f4ecfef
--- /dev/null
+++ b/src/pixi/loaders/JsonLoader.js
@@ -0,0 +1,165 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * The json file loader is used to load in JSON data and parsing it
+ * When loaded this class will dispatch a "loaded" event
+ * If load failed this class will dispatch a "error" event
+ *
+ * @class JsonLoader
+ * @uses EventTarget
+ * @constructor
+ * @param url {String} The url of the JSON file
+ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
+ */
+PIXI.JsonLoader = function (url, crossorigin) {
+ PIXI.EventTarget.call(this);
+
+ /**
+ * The url of the bitmap font data
+ *
+ * @property url
+ * @type String
+ */
+ this.url = url;
+
+ /**
+ * Whether the requests should be treated as cross origin
+ *
+ * @property crossorigin
+ * @type Boolean
+ */
+ this.crossorigin = crossorigin;
+
+ /**
+ * [read-only] The base url of the bitmap font data
+ *
+ * @property baseUrl
+ * @type String
+ * @readOnly
+ */
+ this.baseUrl = url.replace(/[^\/]*$/, "");
+
+ /**
+ * [read-only] Whether the data has loaded yet
+ *
+ * @property loaded
+ * @type Boolean
+ * @readOnly
+ */
+ this.loaded = false;
+
+};
+
+// constructor
+PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader;
+
+/**
+ * Loads the JSON data
+ *
+ * @method load
+ */
+PIXI.JsonLoader.prototype.load = function () {
+ this.ajaxRequest = new AjaxRequest();
+ var scope = this;
+ this.ajaxRequest.onreadystatechange = function () {
+ scope.onJSONLoaded();
+ };
+
+ this.ajaxRequest.open("GET", this.url, true);
+ if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
+ this.ajaxRequest.send(null);
+};
+
+/**
+ * Invoke when JSON file is loaded
+ *
+ * @method onJSONLoaded
+ * @private
+ */
+PIXI.JsonLoader.prototype.onJSONLoaded = function () {
+ if (this.ajaxRequest.readyState == 4) {
+ if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
+ this.json = JSON.parse(this.ajaxRequest.responseText);
+
+ if(this.json.frames)
+ {
+ // sprite sheet
+ var scope = this;
+ var textureUrl = this.baseUrl + this.json.meta.image;
+ var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
+ var frameData = this.json.frames;
+
+ this.texture = image.texture.baseTexture;
+ image.addEventListener("loaded", function (event) {
+ scope.onLoaded();
+ });
+
+ for (var i in frameData) {
+ var rect = frameData[i].frame;
+ if (rect) {
+ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
+ x: rect.x,
+ y: rect.y,
+ width: rect.w,
+ height: rect.h
+ });
+ if (frameData[i].trimmed) {
+ //var realSize = frameData[i].spriteSourceSize;
+ PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
+ PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
+ // calculate the offset!
+ }
+ }
+ }
+
+ image.load();
+
+ }
+ else if(this.json.bones)
+ {
+ // spine animation
+ var spineJsonParser = new spine.SkeletonJson();
+ var skeletonData = spineJsonParser.readSkeletonData(this.json);
+ PIXI.AnimCache[this.url] = skeletonData;
+ this.onLoaded();
+ }
+ else
+ {
+ this.onLoaded();
+ }
+ }
+ else
+ {
+ this.onError();
+ }
+ }
+};
+
+/**
+ * Invoke when json file loaded
+ *
+ * @method onLoaded
+ * @private
+ */
+PIXI.JsonLoader.prototype.onLoaded = function () {
+ this.loaded = true;
+ this.dispatchEvent({
+ type: "loaded",
+ content: this
+ });
+};
+
+/**
+ * Invoke when error occured
+ *
+ * @method onError
+ * @private
+ */
+PIXI.JsonLoader.prototype.onError = function () {
+ this.dispatchEvent({
+ type: "error",
+ content: this
+ });
+};
\ No newline at end of file
diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js
new file mode 100644
index 00000000..f5e16b01
--- /dev/null
+++ b/src/pixi/loaders/SpineLoader.js
@@ -0,0 +1,97 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi
+ *
+ * Awesome JS run time provided by EsotericSoftware
+ * https://github.com/EsotericSoftware/spine-runtimes
+ *
+ */
+
+/**
+ * The Spine loader is used to load in JSON spine data
+ * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format
+ * Due to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load
+ * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source
+ * You will need to generate a sprite sheet to accompany the spine data
+ * When loaded this class will dispatch a "loaded" event
+ *
+ * @class Spine
+ * @uses EventTarget
+ * @constructor
+ * @param url {String} The url of the JSON file
+ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
+ */
+PIXI.SpineLoader = function(url, crossorigin)
+{
+ PIXI.EventTarget.call(this);
+
+ /**
+ * The url of the bitmap font data
+ *
+ * @property url
+ * @type String
+ */
+ this.url = url;
+
+ /**
+ * Whether the requests should be treated as cross origin
+ *
+ * @property crossorigin
+ * @type Boolean
+ */
+ this.crossorigin = crossorigin;
+
+ /**
+ * [read-only] Whether the data has loaded yet
+ *
+ * @property loaded
+ * @type Boolean
+ * @readOnly
+ */
+ this.loaded = false;
+}
+
+PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader;
+
+/**
+ * Loads the JSON data
+ *
+ * @method load
+ */
+PIXI.SpineLoader.prototype.load = function () {
+
+ var scope = this;
+ var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
+ jsonLoader.addEventListener("loaded", function (event) {
+ scope.json = event.content.json;
+ scope.onJSONLoaded();
+ });
+ jsonLoader.load();
+};
+
+/**
+ * Invoke when JSON file is loaded
+ *
+ * @method onJSONLoaded
+ * @private
+ */
+PIXI.SpineLoader.prototype.onJSONLoaded = function (event) {
+ var spineJsonParser = new spine.SkeletonJson();
+ var skeletonData = spineJsonParser.readSkeletonData(this.json);
+
+ PIXI.AnimCache[this.url] = skeletonData;
+
+ this.onLoaded();
+};
+
+/**
+ * Invoke when JSON file is loaded
+ *
+ * @method onLoaded
+ * @private
+ */
+PIXI.SpineLoader.prototype.onLoaded = function () {
+ this.loaded = true;
+ this.dispatchEvent({type: "loaded", content: this});
+};
+
diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js
new file mode 100644
index 00000000..169fb70d
--- /dev/null
+++ b/src/pixi/loaders/SpriteSheetLoader.js
@@ -0,0 +1,137 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * The sprite sheet loader is used to load in JSON sprite sheet data
+ * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format
+ * There is a free version so thats nice, although the paid version is great value for money.
+ * It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed.
+ * Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()
+ * This loader will also load the image file that the Spritesheet points to as well as the data.
+ * When loaded this class will dispatch a "loaded" event
+ *
+ * @class SpriteSheetLoader
+ * @uses EventTarget
+ * @constructor
+ * @param url {String} The url of the sprite sheet JSON file
+ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
+ */
+
+PIXI.SpriteSheetLoader = function (url, crossorigin) {
+ /*
+ * i use texture packer to load the assets..
+ * http://www.codeandweb.com/texturepacker
+ * make sure to set the format as "JSON"
+ */
+ PIXI.EventTarget.call(this);
+
+ /**
+ * The url of the bitmap font data
+ *
+ * @property url
+ * @type String
+ */
+ this.url = url;
+
+ /**
+ * Whether the requests should be treated as cross origin
+ *
+ * @property crossorigin
+ * @type Boolean
+ */
+ this.crossorigin = crossorigin;
+
+ /**
+ * [read-only] The base url of the bitmap font data
+ *
+ * @property baseUrl
+ * @type String
+ * @readOnly
+ */
+ this.baseUrl = url.replace(/[^\/]*$/, "");
+
+ /**
+ * The texture being loaded
+ *
+ * @property texture
+ * @type Texture
+ */
+ this.texture = null;
+
+ /**
+ * The frames of the sprite sheet
+ *
+ * @property frames
+ * @type Object
+ */
+ this.frames = {};
+};
+
+// constructor
+PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader;
+
+/**
+ * This will begin loading the JSON file
+ *
+ * @method load
+ */
+PIXI.SpriteSheetLoader.prototype.load = function () {
+ var scope = this;
+ var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
+ jsonLoader.addEventListener("loaded", function (event) {
+ scope.json = event.content.json;
+ scope.onJSONLoaded();
+ });
+ jsonLoader.load();
+};
+
+/**
+ * Invoke when JSON file is loaded
+ *
+ * @method onJSONLoaded
+ * @private
+ */
+PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
+ var scope = this;
+ var textureUrl = this.baseUrl + this.json.meta.image;
+ var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
+ var frameData = this.json.frames;
+
+ this.texture = image.texture.baseTexture;
+ image.addEventListener("loaded", function (event) {
+ scope.onLoaded();
+ });
+
+ for (var i in frameData) {
+ var rect = frameData[i].frame;
+ if (rect) {
+ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
+ x: rect.x,
+ y: rect.y,
+ width: rect.w,
+ height: rect.h
+ });
+ if (frameData[i].trimmed) {
+ //var realSize = frameData[i].spriteSourceSize;
+ PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
+ PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
+ // calculate the offset!
+ }
+ }
+ }
+
+ image.load();
+};
+/**
+ * Invoke when all files are loaded (json and texture)
+ *
+ * @method onLoaded
+ * @private
+ */
+PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
+ this.dispatchEvent({
+ type: "loaded",
+ content: this
+ });
+};
diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js
new file mode 100644
index 00000000..cd599fa8
--- /dev/null
+++ b/src/pixi/primitives/Graphics.js
@@ -0,0 +1,230 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+/**
+ * The Graphics class contains a set of methods that you can use to create primitive shapes and lines.
+ * It is important to know that with the webGL renderer only simple polys can be filled at this stage
+ * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png
+ *
+ * @class Graphics
+ * @extends DisplayObjectContainer
+ * @constructor
+ */
+PIXI.Graphics = function()
+{
+ PIXI.DisplayObjectContainer.call( this );
+
+ this.renderable = true;
+
+ /**
+ * The alpha of the fill of this graphics object
+ *
+ * @property fillAlpha
+ * @type Number
+ */
+ this.fillAlpha = 1;
+
+ /**
+ * The width of any lines drawn
+ *
+ * @property lineWidth
+ * @type Number
+ */
+ this.lineWidth = 0;
+
+ /**
+ * The color of any lines drawn
+ *
+ * @property lineColor
+ * @type String
+ */
+ this.lineColor = "black";
+
+ /**
+ * Graphics data
+ *
+ * @property graphicsData
+ * @type Array
+ * @private
+ */
+ this.graphicsData = [];
+
+ /**
+ * Current path
+ *
+ * @property currentPath
+ * @type Object
+ * @private
+ */
+ this.currentPath = {points:[]};
+}
+
+// constructor
+PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
+PIXI.Graphics.prototype.constructor = PIXI.Graphics;
+
+/**
+ * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method.
+ *
+ * @method lineStyle
+ * @param lineWidth {Number} width of the line to draw, will update the object's stored style
+ * @param color {Number} color of the line to draw, will update the object's stored style
+ * @param alpha {Number} alpha of the line to draw, will update the object's stored style
+ */
+PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
+{
+ if(this.currentPath.points.length == 0)this.graphicsData.pop();
+
+ this.lineWidth = lineWidth || 0;
+ this.lineColor = color || 0;
+ this.lineAlpha = (alpha == undefined) ? 1 : alpha;
+
+ this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
+ fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY};
+
+ this.graphicsData.push(this.currentPath);
+}
+
+/**
+ * Moves the current drawing position to (x, y).
+ *
+ * @method moveTo
+ * @param x {Number} the X coord to move to
+ * @param y {Number} the Y coord to move to
+ */
+PIXI.Graphics.prototype.moveTo = function(x, y)
+{
+ if(this.currentPath.points.length == 0)this.graphicsData.pop();
+
+ this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
+ fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY};
+
+ this.currentPath.points.push(x, y);
+
+ this.graphicsData.push(this.currentPath);
+}
+
+/**
+ * Draws a line using the current line style from the current drawing position to (x, y);
+ * the current drawing position is then set to (x, y).
+ *
+ * @method lineTo
+ * @param x {Number} the X coord to draw to
+ * @param y {Number} the Y coord to draw to
+ */
+PIXI.Graphics.prototype.lineTo = function(x, y)
+{
+ this.currentPath.points.push(x, y);
+ this.dirty = true;
+}
+
+/**
+ * Specifies a simple one-color fill that subsequent calls to other Graphics methods
+ * (such as lineTo() or drawCircle()) use when drawing.
+ *
+ * @method beginFill
+ * @param color {uint} the color of the fill
+ * @param alpha {Number} the alpha
+ */
+PIXI.Graphics.prototype.beginFill = function(color, alpha)
+{
+ this.filling = true;
+ this.fillColor = color || 0;
+ this.fillAlpha = (alpha == undefined) ? 1 : alpha;
+}
+
+/**
+ * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method.
+ *
+ * @method endFill
+ */
+PIXI.Graphics.prototype.endFill = function()
+{
+ this.filling = false;
+ this.fillColor = null;
+ this.fillAlpha = 1;
+}
+
+/**
+ * @method drawRect
+ *
+ * @param x {Number} The X coord of the top-left of the rectangle
+ * @param y {Number} The Y coord of the top-left of the rectangle
+ * @param width {Number} The width of the rectangle
+ * @param height {Number} The height of the rectangle
+ */
+PIXI.Graphics.prototype.drawRect = function( x, y, width, height )
+{
+ if(this.currentPath.points.length == 0)this.graphicsData.pop();
+
+ this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
+ fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
+ points:[x, y, width, height], type:PIXI.Graphics.RECT};
+
+ this.graphicsData.push(this.currentPath);
+ this.dirty = true;
+}
+
+/**
+ * Draws a circle.
+ *
+ * @method drawCircle
+ * @param x {Number} The X coord of the center of the circle
+ * @param y {Number} The Y coord of the center of the circle
+ * @param radius {Number} The radius of the circle
+ */
+PIXI.Graphics.prototype.drawCircle = function( x, y, radius)
+{
+ if(this.currentPath.points.length == 0)this.graphicsData.pop();
+
+ this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
+ fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
+ points:[x, y, radius, radius], type:PIXI.Graphics.CIRC};
+
+ this.graphicsData.push(this.currentPath);
+ this.dirty = true;
+}
+
+/**
+ * Draws an elipse.
+ *
+ * @method drawElipse
+ * @param x {Number}
+ * @param y {Number}
+ * @param width {Number}
+ * @param height {Number}
+ */
+PIXI.Graphics.prototype.drawElipse = function( x, y, width, height)
+{
+ if(this.currentPath.points.length == 0)this.graphicsData.pop();
+
+ this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
+ fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
+ points:[x, y, width, height], type:PIXI.Graphics.ELIP};
+
+ this.graphicsData.push(this.currentPath);
+ this.dirty = true;
+}
+
+/**
+ * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings.
+ *
+ * @method clear
+ */
+PIXI.Graphics.prototype.clear = function()
+{
+ this.lineWidth = 0;
+ this.filling = false;
+
+ this.dirty = true;
+ this.clearDirty = true;
+ this.graphicsData = [];
+}
+
+// SOME TYPES:
+PIXI.Graphics.POLY = 0;
+PIXI.Graphics.RECT = 1;
+PIXI.Graphics.CIRC = 2;
+PIXI.Graphics.ELIP = 3;
diff --git a/src/pixi/renderers/canvas/CanvasGraphics.js b/src/pixi/renderers/canvas/CanvasGraphics.js
new file mode 100644
index 00000000..7f1093b9
--- /dev/null
+++ b/src/pixi/renderers/canvas/CanvasGraphics.js
@@ -0,0 +1,239 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+/**
+ * A set of functions used by the canvas renderer to draw the primitive graphics data
+ *
+ * @class CanvasGraphics
+ */
+PIXI.CanvasGraphics = function()
+{
+
+}
+
+
+/*
+ * Renders the graphics object
+ *
+ * @static
+ * @private
+ * @method renderGraphics
+ * @param graphics {Graphics}
+ * @param context {Context2D}
+ */
+PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
+{
+ var worldAlpha = graphics.worldAlpha;
+
+ for (var i=0; i < graphics.graphicsData.length; i++)
+ {
+ var data = graphics.graphicsData[i];
+ var points = data.points;
+
+ context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6);
+
+ context.lineWidth = data.lineWidth;
+
+ if(data.type == PIXI.Graphics.POLY)
+ {
+ context.beginPath();
+
+ context.moveTo(points[0], points[1]);
+
+ for (var j=1; j < points.length/2; j++)
+ {
+ context.lineTo(points[j * 2], points[j * 2 + 1]);
+ }
+
+ // if the first and last point are the same close the path - much neater :)
+ if(points[0] == points[points.length-2] && points[1] == points[points.length-1])
+ {
+ context.closePath();
+ }
+
+ if(data.fill)
+ {
+ context.globalAlpha = data.fillAlpha * worldAlpha;
+ context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6);
+ context.fill();
+ }
+ if(data.lineWidth)
+ {
+ context.globalAlpha = data.lineAlpha * worldAlpha;
+ context.stroke();
+ }
+ }
+ else if(data.type == PIXI.Graphics.RECT)
+ {
+
+ // TODO - need to be Undefined!
+ if(data.fillColor)
+ {
+ context.globalAlpha = data.fillAlpha * worldAlpha;
+ context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6);
+ context.fillRect(points[0], points[1], points[2], points[3]);
+
+ }
+ if(data.lineWidth)
+ {
+ context.globalAlpha = data.lineAlpha * worldAlpha;
+ context.strokeRect(points[0], points[1], points[2], points[3]);
+ }
+
+ }
+ else if(data.type == PIXI.Graphics.CIRC)
+ {
+ // TODO - need to be Undefined!
+ context.beginPath();
+ context.arc(points[0], points[1], points[2],0,2*Math.PI);
+ context.closePath();
+
+ if(data.fill)
+ {
+ context.globalAlpha = data.fillAlpha * worldAlpha;
+ context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6);
+ context.fill();
+ }
+ if(data.lineWidth)
+ {
+ context.globalAlpha = data.lineAlpha * worldAlpha;
+ context.stroke();
+ }
+ }
+ else if(data.type == PIXI.Graphics.ELIP)
+ {
+
+ // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
+
+ var elipseData = data.points;
+
+ var w = elipseData[2] * 2;
+ var h = elipseData[3] * 2;
+
+ var x = elipseData[0] - w/2;
+ var y = elipseData[1] - h/2;
+
+ context.beginPath();
+
+ var kappa = .5522848,
+ ox = (w / 2) * kappa, // control point offset horizontal
+ oy = (h / 2) * kappa, // control point offset vertical
+ xe = x + w, // x-end
+ ye = y + h, // y-end
+ xm = x + w / 2, // x-middle
+ ym = y + h / 2; // y-middle
+
+ context.moveTo(x, ym);
+ context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
+ context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
+ context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
+ context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
+
+ context.closePath();
+
+ if(data.fill)
+ {
+ context.globalAlpha = data.fillAlpha * worldAlpha;
+ context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6);
+ context.fill();
+ }
+ if(data.lineWidth)
+ {
+ context.globalAlpha = data.lineAlpha * worldAlpha;
+ context.stroke();
+ }
+ }
+
+ };
+}
+
+/*
+ * Renders a graphics mask
+ *
+ * @static
+ * @private
+ * @method renderGraphicsMask
+ * @param graphics {Graphics}
+ * @param context {Context2D}
+ */
+PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context)
+{
+ var worldAlpha = graphics.worldAlpha;
+
+ var len = graphics.graphicsData.length;
+ if(len > 1)
+ {
+ len = 1;
+ console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object")
+ }
+
+ for (var i=0; i < 1; i++)
+ {
+ var data = graphics.graphicsData[i];
+ var points = data.points;
+
+ if(data.type == PIXI.Graphics.POLY)
+ {
+ context.beginPath();
+ context.moveTo(points[0], points[1]);
+
+ for (var j=1; j < points.length/2; j++)
+ {
+ context.lineTo(points[j * 2], points[j * 2 + 1]);
+ }
+
+ // if the first and last point are the same close the path - much neater :)
+ if(points[0] == points[points.length-2] && points[1] == points[points.length-1])
+ {
+ context.closePath();
+ }
+
+ }
+ else if(data.type == PIXI.Graphics.RECT)
+ {
+ context.beginPath();
+ context.rect(points[0], points[1], points[2], points[3]);
+ context.closePath();
+ }
+ else if(data.type == PIXI.Graphics.CIRC)
+ {
+ // TODO - need to be Undefined!
+ context.beginPath();
+ context.arc(points[0], points[1], points[2],0,2*Math.PI);
+ context.closePath();
+ }
+ else if(data.type == PIXI.Graphics.ELIP)
+ {
+
+ // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
+ var elipseData = data.points;
+
+ var w = elipseData[2] * 2;
+ var h = elipseData[3] * 2;
+
+ var x = elipseData[0] - w/2;
+ var y = elipseData[1] - h/2;
+
+ context.beginPath();
+
+ var kappa = .5522848,
+ ox = (w / 2) * kappa, // control point offset horizontal
+ oy = (h / 2) * kappa, // control point offset vertical
+ xe = x + w, // x-end
+ ye = y + h, // y-end
+ xm = x + w / 2, // x-middle
+ ym = y + h / 2; // y-middle
+
+ context.moveTo(x, ym);
+ context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
+ context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
+ context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
+ context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
+ context.closePath();
+ }
+
+
+ };
+}
diff --git a/src/pixi/renderers/canvas/CanvasRenderer.js b/src/pixi/renderers/canvas/CanvasRenderer.js
new file mode 100644
index 00000000..f0b9b918
--- /dev/null
+++ b/src/pixi/renderers/canvas/CanvasRenderer.js
@@ -0,0 +1,370 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+/**
+ * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL.
+ * Dont forget to add the view to your DOM or you will not see anything :)
+ *
+ * @class CanvasRenderer
+ * @constructor
+ * @param width=0 {Number} the width of the canvas view
+ * @param height=0 {Number} the height of the canvas view
+ * @param view {Canvas} the canvas to use as a view, optional
+ * @param transparent=false {Boolean} the transparency of the render view, default false
+ */
+PIXI.CanvasRenderer = function(width, height, view, transparent)
+{
+ this.transparent = transparent;
+
+ /**
+ * The width of the canvas view
+ *
+ * @property width
+ * @type Number
+ * @default 800
+ */
+ this.width = width || 800;
+
+ /**
+ * The height of the canvas view
+ *
+ * @property height
+ * @type Number
+ * @default 600
+ */
+ this.height = height || 600;
+
+ /**
+ * The canvas element that the everything is drawn to
+ *
+ * @property view
+ * @type Canvas
+ */
+ this.view = view || document.createElement( 'canvas' );
+
+ /**
+ * The canvas context that the everything is drawn to
+ * @property context
+ * @type Canvas 2d Context
+ */
+ this.context = this.view.getContext("2d");
+
+ this.refresh = true;
+ // hack to enable some hardware acceleration!
+ //this.view.style["transform"] = "translatez(0)";
+
+ this.view.width = this.width;
+ this.view.height = this.height;
+ this.count = 0;
+}
+
+// constructor
+PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer;
+
+/**
+ * Renders the stage to its canvas view
+ *
+ * @method render
+ * @param stage {Stage} the Stage element to be rendered
+ */
+PIXI.CanvasRenderer.prototype.render = function(stage)
+{
+
+ //stage.__childrenAdded = [];
+ //stage.__childrenRemoved = [];
+
+ // update textures if need be
+ PIXI.texturesToUpdate = [];
+ PIXI.texturesToDestroy = [];
+
+ PIXI.visibleCount++;
+ stage.updateTransform();
+
+ // update the background color
+ if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString;
+
+ this.context.setTransform(1,0,0,1,0,0);
+ this.context.clearRect(0, 0, this.width, this.height)
+ this.renderDisplayObject(stage);
+ //as
+
+ // run interaction!
+ if(stage.interactive)
+ {
+ //need to add some events!
+ if(!stage._interactiveEventsAdded)
+ {
+ stage._interactiveEventsAdded = true;
+ stage.interactionManager.setTarget(this);
+ }
+ }
+
+ // remove frame updates..
+ if(PIXI.Texture.frameUpdates.length > 0)
+ {
+ PIXI.Texture.frameUpdates = [];
+ }
+
+
+}
+
+/**
+ * resizes the canvas view to the specified width and height
+ *
+ * @method resize
+ * @param width {Number} the new width of the canvas view
+ * @param height {Number} the new height of the canvas view
+ */
+PIXI.CanvasRenderer.prototype.resize = function(width, height)
+{
+ this.width = width;
+ this.height = height;
+
+ this.view.width = width;
+ this.view.height = height;
+}
+
+/**
+ * Renders a display object
+ *
+ * @method renderDisplayObject
+ * @param displayObject {DisplayObject} The displayObject to render
+ * @private
+ */
+PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
+{
+ // no loger recurrsive!
+ var transform;
+ var context = this.context;
+
+ context.globalCompositeOperation = 'source-over';
+
+ // one the display object hits this. we can break the loop
+ var testObject = displayObject.last._iNext;
+ displayObject = displayObject.first;
+
+ do
+ {
+ transform = displayObject.worldTransform;
+
+ if(!displayObject.visible)
+ {
+ displayObject = displayObject.last._iNext;
+ continue;
+ }
+
+ if(!displayObject.renderable)
+ {
+ displayObject = displayObject._iNext;
+ continue;
+ }
+
+ if(displayObject instanceof PIXI.Sprite)
+ {
+
+ var frame = displayObject.texture.frame;
+
+ if(frame)
+ {
+ context.globalAlpha = displayObject.worldAlpha;
+
+ context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
+
+ context.drawImage(displayObject.texture.baseTexture.source,
+ frame.x,
+ frame.y,
+ frame.width,
+ frame.height,
+ (displayObject.anchor.x) * -frame.width,
+ (displayObject.anchor.y) * -frame.height,
+ frame.width,
+ frame.height);
+ }
+ }
+ else if(displayObject instanceof PIXI.Strip)
+ {
+ context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
+ this.renderStrip(displayObject);
+ }
+ else if(displayObject instanceof PIXI.TilingSprite)
+ {
+ context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
+ this.renderTilingSprite(displayObject);
+ }
+ else if(displayObject instanceof PIXI.CustomRenderable)
+ {
+ displayObject.renderCanvas(this);
+ }
+ else if(displayObject instanceof PIXI.Graphics)
+ {
+ context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
+ PIXI.CanvasGraphics.renderGraphics(displayObject, context);
+ }
+ else if(displayObject instanceof PIXI.FilterBlock)
+ {
+ if(displayObject.open)
+ {
+ context.save();
+
+ var cacheAlpha = displayObject.mask.alpha;
+ var maskTransform = displayObject.mask.worldTransform;
+
+ context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
+
+ displayObject.mask.worldAlpha = 0.5;
+
+ context.worldAlpha = 0;
+
+ PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context);
+ context.clip();
+
+ displayObject.mask.worldAlpha = cacheAlpha;
+ }
+ else
+ {
+ context.restore();
+ }
+ }
+ // count++
+ displayObject = displayObject._iNext;
+
+
+ }
+ while(displayObject != testObject)
+
+
+}
+
+/**
+ * Renders a flat strip
+ *
+ * @method renderStripFlat
+ * @param strip {Strip} The Strip to render
+ * @private
+ */
+PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip)
+{
+ var context = this.context;
+ var verticies = strip.verticies;
+ var uvs = strip.uvs;
+
+ var length = verticies.length/2;
+ this.count++;
+
+ context.beginPath();
+ for (var i=1; i < length-2; i++)
+ {
+
+ // draw some triangles!
+ var index = i*2;
+
+ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4];
+ var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5];
+
+ context.moveTo(x0, y0);
+ context.lineTo(x1, y1);
+ context.lineTo(x2, y2);
+
+ };
+
+ context.fillStyle = "#FF0000";
+ context.fill();
+ context.closePath();
+}
+
+/**
+ * Renders a tiling sprite
+ *
+ * @method renderTilingSprite
+ * @param sprite {TilingSprite} The tilingsprite to render
+ * @private
+ */
+PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite)
+{
+ var context = this.context;
+
+ context.globalAlpha = sprite.worldAlpha;
+
+ if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, "repeat");
+
+ context.beginPath();
+
+ var tilePosition = sprite.tilePosition;
+ var tileScale = sprite.tileScale;
+
+ // offset
+ context.scale(tileScale.x,tileScale.y);
+ context.translate(tilePosition.x, tilePosition.y);
+
+ context.fillStyle = sprite.__tilePattern;
+ context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y);
+
+ context.scale(1/tileScale.x, 1/tileScale.y);
+ context.translate(-tilePosition.x, -tilePosition.y);
+
+ context.closePath();
+}
+
+/**
+ * Renders a strip
+ *
+ * @method renderStrip
+ * @param strip {Strip} The Strip to render
+ * @private
+ */
+PIXI.CanvasRenderer.prototype.renderStrip = function(strip)
+{
+ var context = this.context;
+
+ // draw triangles!!
+ var verticies = strip.verticies;
+ var uvs = strip.uvs;
+
+ var length = verticies.length/2;
+ this.count++;
+ for (var i=1; i < length-2; i++)
+ {
+
+ // draw some triangles!
+ var index = i*2;
+
+ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4];
+ var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5];
+
+ var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width;
+ var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height;
+
+
+ context.save();
+ context.beginPath();
+ context.moveTo(x0, y0);
+ context.lineTo(x1, y1);
+ context.lineTo(x2, y2);
+ context.closePath();
+
+ context.clip();
+
+
+ // Compute matrix transform
+ var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2;
+ var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2;
+ var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2;
+ var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2;
+ var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2;
+ var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2;
+ var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2;
+
+
+
+
+ context.transform(delta_a/delta, delta_d/delta,
+ delta_b/delta, delta_e/delta,
+ delta_c/delta, delta_f/delta);
+
+ context.drawImage(strip.texture.baseTexture.source, 0, 0);
+ context.restore();
+ };
+
+}
diff --git a/src/pixi/renderers/webgl/WebGLBatch.js b/src/pixi/renderers/webgl/WebGLBatch.js
new file mode 100644
index 00000000..410884b8
--- /dev/null
+++ b/src/pixi/renderers/webgl/WebGLBatch.js
@@ -0,0 +1,579 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+PIXI._batchs = [];
+
+/**
+ * @private
+ */
+PIXI._getBatch = function(gl)
+{
+ if(PIXI._batchs.length == 0)
+ {
+ return new PIXI.WebGLBatch(gl);
+ }
+ else
+ {
+ return PIXI._batchs.pop();
+ }
+}
+
+/**
+ * @private
+ */
+PIXI._returnBatch = function(batch)
+{
+ batch.clean();
+ PIXI._batchs.push(batch);
+}
+
+/**
+ * @private
+ */
+PIXI._restoreBatchs = function(gl)
+{
+ for (var i=0; i < PIXI._batchs.length; i++)
+ {
+ PIXI._batchs[i].restoreLostContext(gl);
+ };
+}
+
+/**
+ * A WebGLBatch Enables a group of sprites to be drawn using the same settings.
+ * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch.
+ * All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites
+ * in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled
+ * automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster
+ * the webGL renderer will run.
+ *
+ * @class WebGLBatch
+ * @constructor
+ * @param gl {WebGLContext} an instance of the webGL context
+ */
+PIXI.WebGLBatch = function(gl)
+{
+ this.gl = gl;
+
+ this.size = 0;
+
+ this.vertexBuffer = gl.createBuffer();
+ this.indexBuffer = gl.createBuffer();
+ this.uvBuffer = gl.createBuffer();
+ this.colorBuffer = gl.createBuffer();
+ this.blendMode = PIXI.blendModes.NORMAL;
+ this.dynamicSize = 1;
+}
+
+// constructor
+PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch;
+
+/**
+ * Cleans the batch so that is can be returned to an object pool and reused
+ *
+ * @method clean
+ */
+PIXI.WebGLBatch.prototype.clean = function()
+{
+ this.verticies = [];
+ this.uvs = [];
+ this.indices = [];
+ this.colors = [];
+ this.dynamicSize = 1;
+ this.texture = null;
+ this.last = null;
+ this.size = 0;
+ this.head;
+ this.tail;
+}
+
+/**
+ * Recreates the buffers in the event of a context loss
+ *
+ * @method restoreLostContext
+ * @param gl {WebGLContext}
+ */
+PIXI.WebGLBatch.prototype.restoreLostContext = function(gl)
+{
+ this.gl = gl;
+ this.vertexBuffer = gl.createBuffer();
+ this.indexBuffer = gl.createBuffer();
+ this.uvBuffer = gl.createBuffer();
+ this.colorBuffer = gl.createBuffer();
+}
+
+/**
+ * inits the batch's texture and blend mode based if the supplied sprite
+ *
+ * @method init
+ * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with
+ * the same base texture and blend mode will be allowed to be added to this batch
+ */
+PIXI.WebGLBatch.prototype.init = function(sprite)
+{
+ sprite.batch = this;
+ this.dirty = true;
+ this.blendMode = sprite.blendMode;
+ this.texture = sprite.texture.baseTexture;
+ this.head = sprite;
+ this.tail = sprite;
+ this.size = 1;
+
+ this.growBatch();
+}
+
+/**
+ * inserts a sprite before the specified sprite
+ *
+ * @method insertBefore
+ * @param sprite {Sprite} the sprite to be added
+ * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite
+ */
+PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite)
+{
+ this.size++;
+
+ sprite.batch = this;
+ this.dirty = true;
+ var tempPrev = nextSprite.__prev;
+ nextSprite.__prev = sprite;
+ sprite.__next = nextSprite;
+
+ if(tempPrev)
+ {
+ sprite.__prev = tempPrev;
+ tempPrev.__next = sprite;
+ }
+ else
+ {
+ this.head = sprite;
+ }
+}
+
+/**
+ * inserts a sprite after the specified sprite
+ *
+ * @method insertAfter
+ * @param sprite {Sprite} the sprite to be added
+ * @param previousSprite {Sprite} the first sprite will be inserted after this sprite
+ */
+PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite)
+{
+ this.size++;
+
+ sprite.batch = this;
+ this.dirty = true;
+
+ var tempNext = previousSprite.__next;
+ previousSprite.__next = sprite;
+ sprite.__prev = previousSprite;
+
+ if(tempNext)
+ {
+ sprite.__next = tempNext;
+ tempNext.__prev = sprite;
+ }
+ else
+ {
+ this.tail = sprite
+ }
+}
+
+/**
+ * removes a sprite from the batch
+ *
+ * @method remove
+ * @param sprite {Sprite} the sprite to be removed
+ */
+PIXI.WebGLBatch.prototype.remove = function(sprite)
+{
+ this.size--;
+
+ if(this.size == 0)
+ {
+ sprite.batch = null;
+ sprite.__prev = null;
+ sprite.__next = null;
+ return;
+ }
+
+ if(sprite.__prev)
+ {
+ sprite.__prev.__next = sprite.__next;
+ }
+ else
+ {
+ this.head = sprite.__next;
+ this.head.__prev = null;
+ }
+
+ if(sprite.__next)
+ {
+ sprite.__next.__prev = sprite.__prev;
+ }
+ else
+ {
+ this.tail = sprite.__prev;
+ this.tail.__next = null
+ }
+
+ sprite.batch = null;
+ sprite.__next = null;
+ sprite.__prev = null;
+ this.dirty = true;
+}
+
+/**
+ * Splits the batch into two with the specified sprite being the start of the new batch.
+ *
+ * @method split
+ * @param sprite {Sprite} the sprite that indicates where the batch should be split
+ * @return {WebGLBatch} the new batch
+ */
+PIXI.WebGLBatch.prototype.split = function(sprite)
+{
+ this.dirty = true;
+
+ var batch = new PIXI.WebGLBatch(this.gl);
+ batch.init(sprite);
+ batch.texture = this.texture;
+ batch.tail = this.tail;
+
+ this.tail = sprite.__prev;
+ this.tail.__next = null;
+
+ sprite.__prev = null;
+ // return a splite batch!
+
+ // TODO this size is wrong!
+ // need to recalculate :/ problem with a linked list!
+ // unless it gets calculated in the "clean"?
+
+ // need to loop through items as there is no way to know the length on a linked list :/
+ var tempSize = 0;
+ while(sprite)
+ {
+ tempSize++;
+ sprite.batch = batch;
+ sprite = sprite.__next;
+ }
+
+ batch.size = tempSize;
+ this.size -= tempSize;
+
+ return batch;
+}
+
+/**
+ * Merges two batchs together
+ *
+ * @method merge
+ * @param batch {WebGLBatch} the batch that will be merged
+ */
+PIXI.WebGLBatch.prototype.merge = function(batch)
+{
+ this.dirty = true;
+
+ this.tail.__next = batch.head;
+ batch.head.__prev = this.tail;
+
+ this.size += batch.size;
+
+ this.tail = batch.tail;
+
+ var sprite = batch.head;
+ while(sprite)
+ {
+ sprite.batch = this;
+ sprite = sprite.__next;
+ }
+}
+
+/**
+ * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this
+ * function is used to increase the size of the batch. It also creates a little extra room so
+ * that the batch does not need to be resized every time a sprite is added
+ *
+ * @method growBatch
+ */
+PIXI.WebGLBatch.prototype.growBatch = function()
+{
+ var gl = this.gl;
+ if( this.size == 1)
+ {
+ this.dynamicSize = 1;
+ }
+ else
+ {
+ this.dynamicSize = this.size * 1.5
+ }
+ // grow verts
+ this.verticies = new Float32Array(this.dynamicSize * 8);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW);
+
+ this.uvs = new Float32Array( this.dynamicSize * 8 );
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW);
+
+ this.dirtyUVS = true;
+
+ this.colors = new Float32Array( this.dynamicSize * 4 );
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW);
+
+ this.dirtyColors = true;
+
+ this.indices = new Uint16Array(this.dynamicSize * 6);
+ var length = this.indices.length/6;
+
+ for (var i=0; i < length; i++)
+ {
+ var index2 = i * 6;
+ var index3 = i * 4;
+ this.indices[index2 + 0] = index3 + 0;
+ this.indices[index2 + 1] = index3 + 1;
+ this.indices[index2 + 2] = index3 + 2;
+ this.indices[index2 + 3] = index3 + 0;
+ this.indices[index2 + 4] = index3 + 2;
+ this.indices[index2 + 5] = index3 + 3;
+ };
+
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
+}
+
+/**
+ * Refresh's all the data in the batch and sync's it with the webGL buffers
+ *
+ * @method refresh
+ */
+PIXI.WebGLBatch.prototype.refresh = function()
+{
+ var gl = this.gl;
+
+ if (this.dynamicSize < this.size)
+ {
+ this.growBatch();
+ }
+
+ var indexRun = 0;
+ var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index;
+ var a, b, c, d, tx, ty;
+
+ var displayObject = this.head;
+
+ while(displayObject)
+ {
+ index = indexRun * 8;
+
+ var texture = displayObject.texture;
+
+ var frame = texture.frame;
+ var tw = texture.baseTexture.width;
+ var th = texture.baseTexture.height;
+
+ this.uvs[index + 0] = frame.x / tw;
+ this.uvs[index +1] = frame.y / th;
+
+ this.uvs[index +2] = (frame.x + frame.width) / tw;
+ this.uvs[index +3] = frame.y / th;
+
+ this.uvs[index +4] = (frame.x + frame.width) / tw;
+ this.uvs[index +5] = (frame.y + frame.height) / th;
+
+ this.uvs[index +6] = frame.x / tw;
+ this.uvs[index +7] = (frame.y + frame.height) / th;
+
+ displayObject.updateFrame = false;
+
+ colorIndex = indexRun * 4;
+ this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
+
+ displayObject = displayObject.__next;
+
+ indexRun ++;
+ }
+
+ this.dirtyUVS = true;
+ this.dirtyColors = true;
+}
+
+/**
+ * Updates all the relevant geometry and uploads the data to the GPU
+ *
+ * @method update
+ */
+PIXI.WebGLBatch.prototype.update = function()
+{
+ var gl = this.gl;
+ var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3
+
+ var a, b, c, d, tx, ty;
+
+ var indexRun = 0;
+
+ var displayObject = this.head;
+
+ while(displayObject)
+ {
+ if(displayObject.vcount === PIXI.visibleCount)
+ {
+ width = displayObject.texture.frame.width;
+ height = displayObject.texture.frame.height;
+
+ // TODO trim??
+ aX = displayObject.anchor.x;// - displayObject.texture.trim.x
+ aY = displayObject.anchor.y; //- displayObject.texture.trim.y
+ w0 = width * (1-aX);
+ w1 = width * -aX;
+
+ h0 = height * (1-aY);
+ h1 = height * -aY;
+
+ index = indexRun * 8;
+
+ worldTransform = displayObject.worldTransform;
+
+ a = worldTransform[0];
+ b = worldTransform[3];
+ c = worldTransform[1];
+ d = worldTransform[4];
+ tx = worldTransform[2];
+ ty = worldTransform[5];
+
+ this.verticies[index + 0 ] = a * w1 + c * h1 + tx;
+ this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
+
+ this.verticies[index + 2 ] = a * w0 + c * h1 + tx;
+ this.verticies[index + 3 ] = d * h1 + b * w0 + ty;
+
+ this.verticies[index + 4 ] = a * w0 + c * h0 + tx;
+ this.verticies[index + 5 ] = d * h0 + b * w0 + ty;
+
+ this.verticies[index + 6] = a * w1 + c * h0 + tx;
+ this.verticies[index + 7] = d * h0 + b * w1 + ty;
+
+ if(displayObject.updateFrame || displayObject.texture.updateFrame)
+ {
+ this.dirtyUVS = true;
+
+ var texture = displayObject.texture;
+
+ var frame = texture.frame;
+ var tw = texture.baseTexture.width;
+ var th = texture.baseTexture.height;
+
+ this.uvs[index + 0] = frame.x / tw;
+ this.uvs[index +1] = frame.y / th;
+
+ this.uvs[index +2] = (frame.x + frame.width) / tw;
+ this.uvs[index +3] = frame.y / th;
+
+ this.uvs[index +4] = (frame.x + frame.width) / tw;
+ this.uvs[index +5] = (frame.y + frame.height) / th;
+
+ this.uvs[index +6] = frame.x / tw;
+ this.uvs[index +7] = (frame.y + frame.height) / th;
+
+ displayObject.updateFrame = false;
+ }
+
+ // TODO this probably could do with some optimisation....
+ if(displayObject.cacheAlpha != displayObject.worldAlpha)
+ {
+ displayObject.cacheAlpha = displayObject.worldAlpha;
+
+ var colorIndex = indexRun * 4;
+ this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
+ this.dirtyColors = true;
+ }
+ }
+ else
+ {
+ index = indexRun * 8;
+
+ this.verticies[index + 0 ] = 0;
+ this.verticies[index + 1 ] = 0;
+
+ this.verticies[index + 2 ] = 0;
+ this.verticies[index + 3 ] = 0;
+
+ this.verticies[index + 4 ] = 0;
+ this.verticies[index + 5 ] = 0;
+
+ this.verticies[index + 6] = 0;
+ this.verticies[index + 7] = 0;
+ }
+
+ indexRun++;
+ displayObject = displayObject.__next;
+ }
+}
+
+/**
+ * Draws the batch to the frame buffer
+ *
+ * @method render
+ */
+PIXI.WebGLBatch.prototype.render = function(start, end)
+{
+ start = start || 0;
+
+ if(end == undefined)end = this.size;
+
+ if(this.dirty)
+ {
+ this.refresh();
+ this.dirty = false;
+ }
+
+ if (this.size == 0)return;
+
+ this.update();
+ var gl = this.gl;
+
+ //TODO optimize this!
+
+ var shaderProgram = PIXI.shaderProgram;
+ gl.useProgram(shaderProgram);
+
+ // update the verts..
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
+ // ok..
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies)
+ gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
+ // update the uvs
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
+
+ if(this.dirtyUVS)
+ {
+ this.dirtyUVS = false;
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs);
+ }
+
+ gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture);
+
+ // update color!
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer);
+
+ if(this.dirtyColors)
+ {
+ this.dirtyColors = false;
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors);
+ }
+
+ gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
+
+ // dont need to upload!
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
+
+ var len = end - start;
+
+ // DRAW THAT this!
+ gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 );
+}
diff --git a/src/pixi/renderers/webgl/WebGLGraphics.js b/src/pixi/renderers/webgl/WebGLGraphics.js
new file mode 100644
index 00000000..bcddb142
--- /dev/null
+++ b/src/pixi/renderers/webgl/WebGLGraphics.js
@@ -0,0 +1,514 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * A set of functions used by the webGL renderer to draw the primitive graphics data
+ *
+ * @class CanvasGraphics
+ */
+PIXI.WebGLGraphics = function()
+{
+
+}
+
+/**
+ * Renders the graphics object
+ *
+ * @static
+ * @private
+ * @method renderGraphics
+ * @param graphics {Graphics}
+ * @param projection {Object}
+ */
+PIXI.WebGLGraphics.renderGraphics = function(graphics, projection)
+{
+ var gl = PIXI.gl;
+
+ if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0,
+ buffer:gl.createBuffer(),
+ indexBuffer:gl.createBuffer()};
+
+ if(graphics.dirty)
+ {
+ graphics.dirty = false;
+
+ if(graphics.clearDirty)
+ {
+ graphics.clearDirty = false;
+
+ graphics._webGL.lastIndex = 0;
+ graphics._webGL.points = [];
+ graphics._webGL.indices = [];
+
+ }
+
+ PIXI.WebGLGraphics.updateGraphics(graphics);
+ }
+
+
+ PIXI.activatePrimitiveShader();
+
+ // This could be speeded up fo sure!
+ var m = PIXI.mat3.clone(graphics.worldTransform);
+
+ PIXI.mat3.transpose(m);
+
+ // set the matrix transform for the
+ gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
+
+ gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m);
+
+ gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y);
+
+ gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer);
+
+ // WHY DOES THIS LINE NEED TO BE THERE???
+ gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
+ // its not even used.. but need to be set or it breaks?
+ // only on pc though..
+
+ gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0);
+ gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4);
+
+ // set the index buffer!
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer);
+
+ gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 );
+
+ // return to default shader...
+ PIXI.activateDefaultShader();
+}
+
+/**
+ * Updates the graphics object
+ *
+ * @static
+ * @private
+ * @method updateGraphics
+ * @param graphics {Graphics}
+ */
+PIXI.WebGLGraphics.updateGraphics = function(graphics)
+{
+ for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++)
+ {
+ var data = graphics.graphicsData[i];
+
+ if(data.type == PIXI.Graphics.POLY)
+ {
+ if(data.fill)
+ {
+ if(data.points.length>3)
+ PIXI.WebGLGraphics.buildPoly(data, graphics._webGL);
+ }
+
+ if(data.lineWidth > 0)
+ {
+ PIXI.WebGLGraphics.buildLine(data, graphics._webGL);
+ }
+ }
+ else if(data.type == PIXI.Graphics.RECT)
+ {
+ PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL);
+ }
+ else if(data.type == PIXI.Graphics.CIRC || data.type == PIXI.Graphics.ELIP)
+ {
+ PIXI.WebGLGraphics.buildCircle(data, graphics._webGL);
+ }
+ };
+
+ graphics._webGL.lastIndex = graphics.graphicsData.length;
+
+ var gl = PIXI.gl;
+
+ graphics._webGL.glPoints = new Float32Array(graphics._webGL.points);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer);
+ gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW);
+
+ graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices);
+
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer);
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW);
+}
+
+/**
+ * Builds a rectangle to draw
+ *
+ * @static
+ * @private
+ * @method buildRectangle
+ * @param graphics {Graphics}
+ * @param webGLData {Object}
+ */
+PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData)
+{
+ // --- //
+ // need to convert points to a nice regular data
+ //
+ var rectData = graphicsData.points;
+ var x = rectData[0];
+ var y = rectData[1];
+ var width = rectData[2];
+ var height = rectData[3];
+
+
+ if(graphicsData.fill)
+ {
+ var color = HEXtoRGB(graphicsData.fillColor);
+ var alpha = graphicsData.fillAlpha;
+
+ var r = color[0] * alpha;
+ var g = color[1] * alpha;
+ var b = color[2] * alpha;
+
+ var verts = webGLData.points;
+ var indices = webGLData.indices;
+
+ var vertPos = verts.length/6;
+
+ // start
+ verts.push(x, y);
+ verts.push(r, g, b, alpha);
+
+ verts.push(x + width, y);
+ verts.push(r, g, b, alpha);
+
+ verts.push(x , y + height);
+ verts.push(r, g, b, alpha);
+
+ verts.push(x + width, y + height);
+ verts.push(r, g, b, alpha);
+
+ // insert 2 dead triangles..
+ indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3)
+ }
+
+ if(graphicsData.lineWidth)
+ {
+ graphicsData.points = [x, y,
+ x + width, y,
+ x + width, y + height,
+ x, y + height,
+ x, y];
+
+ PIXI.WebGLGraphics.buildLine(graphicsData, webGLData);
+ }
+
+}
+
+/**
+ * Builds a circle to draw
+ *
+ * @static
+ * @private
+ * @method buildCircle
+ * @param graphics {Graphics}
+ * @param webGLData {Object}
+ */
+PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData)
+{
+ // --- //
+ // need to convert points to a nice regular data
+ //
+ var rectData = graphicsData.points;
+ var x = rectData[0];
+ var y = rectData[1];
+ var width = rectData[2];
+ var height = rectData[3];
+
+ var totalSegs = 40;
+ var seg = (Math.PI * 2) / totalSegs ;
+
+ if(graphicsData.fill)
+ {
+ var color = HEXtoRGB(graphicsData.fillColor);
+ var alpha = graphicsData.fillAlpha;
+
+ var r = color[0] * alpha;
+ var g = color[1] * alpha;
+ var b = color[2] * alpha;
+
+ var verts = webGLData.points;
+ var indices = webGLData.indices;
+
+ var vecPos = verts.length/6;
+
+ indices.push(vecPos);
+
+ for (var i=0; i < totalSegs + 1 ; i++)
+ {
+ verts.push(x,y, r, g, b, alpha);
+
+ verts.push(x + Math.sin(seg * i) * width,
+ y + Math.cos(seg * i) * height,
+ r, g, b, alpha);
+
+ indices.push(vecPos++, vecPos++);
+ };
+
+ indices.push(vecPos-1);
+ }
+
+ if(graphicsData.lineWidth)
+ {
+ graphicsData.points = [];
+
+ for (var i=0; i < totalSegs + 1; i++)
+ {
+ graphicsData.points.push(x + Math.sin(seg * i) * width,
+ y + Math.cos(seg * i) * height)
+ };
+
+ PIXI.WebGLGraphics.buildLine(graphicsData, webGLData);
+ }
+
+}
+
+/**
+ * Builds a line to draw
+ *
+ * @static
+ * @private
+ * @method buildLine
+ * @param graphics {Graphics}
+ * @param webGLData {Object}
+ */
+PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
+{
+ // TODO OPTIMISE!
+
+ var wrap = true;
+ var points = graphicsData.points;
+ if(points.length == 0)return;
+
+ // get first and last point.. figure out the middle!
+ var firstPoint = new PIXI.Point( points[0], points[1] );
+ var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] );
+
+ // if the first point is the last point - goona have issues :)
+ if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y)
+ {
+ points.pop();
+ points.pop();
+
+ lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] );
+
+ var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5;
+ var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5;
+
+ points.unshift(midPointX, midPointY);
+ points.push(midPointX, midPointY)
+ }
+
+ var verts = webGLData.points;
+ var indices = webGLData.indices;
+ var length = points.length / 2;
+ var indexCount = points.length;
+ var indexStart = verts.length/6;
+
+ // DRAW the Line
+ var width = graphicsData.lineWidth / 2;
+
+ // sort color
+ var color = HEXtoRGB(graphicsData.lineColor);
+ var alpha = graphicsData.lineAlpha;
+ var r = color[0] * alpha;
+ var g = color[1] * alpha;
+ var b = color[2] * alpha;
+
+ var p1x, p1y, p2x, p2y, p3x, p3y;
+ var perpx, perpy, perp2x, perp2y, perp3x, perp3y;
+ var ipx, ipy;
+ var a1, b1, c1, a2, b2, c2;
+ var denom, pdist, dist;
+
+ p1x = points[0];
+ p1y = points[1];
+
+ p2x = points[2];
+ p2y = points[3];
+
+ perpx = -(p1y - p2y);
+ perpy = p1x - p2x;
+
+ dist = Math.sqrt(perpx*perpx + perpy*perpy);
+
+ perpx /= dist;
+ perpy /= dist;
+ perpx *= width;
+ perpy *= width;
+
+ // start
+ verts.push(p1x - perpx , p1y - perpy,
+ r, g, b, alpha);
+
+ verts.push(p1x + perpx , p1y + perpy,
+ r, g, b, alpha);
+
+ for (var i = 1; i < length-1; i++)
+ {
+ p1x = points[(i-1)*2];
+ p1y = points[(i-1)*2 + 1];
+
+ p2x = points[(i)*2]
+ p2y = points[(i)*2 + 1]
+
+ p3x = points[(i+1)*2];
+ p3y = points[(i+1)*2 + 1];
+
+ perpx = -(p1y - p2y);
+ perpy = p1x - p2x;
+
+ dist = Math.sqrt(perpx*perpx + perpy*perpy);
+ perpx /= dist;
+ perpy /= dist;
+ perpx *= width;
+ perpy *= width;
+
+ perp2x = -(p2y - p3y);
+ perp2y = p2x - p3x;
+
+ dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y);
+ perp2x /= dist;
+ perp2y /= dist;
+ perp2x *= width;
+ perp2y *= width;
+
+ a1 = (-perpy + p1y) - (-perpy + p2y);
+ b1 = (-perpx + p2x) - (-perpx + p1x);
+ c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y);
+ a2 = (-perp2y + p3y) - (-perp2y + p2y);
+ b2 = (-perp2x + p2x) - (-perp2x + p3x);
+ c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y);
+
+ denom = a1*b2 - a2*b1;
+
+ if (denom == 0) {
+ denom+=1;
+ }
+
+ px = (b1*c2 - b2*c1)/denom;
+ py = (a2*c1 - a1*c2)/denom;
+
+ pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y);
+
+ if(pdist > 140 * 140)
+ {
+ perp3x = perpx - perp2x;
+ perp3y = perpy - perp2y;
+
+ dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y);
+ perp3x /= dist;
+ perp3y /= dist;
+ perp3x *= width;
+ perp3y *= width;
+
+ verts.push(p2x - perp3x, p2y -perp3y);
+ verts.push(r, g, b, alpha);
+
+ verts.push(p2x + perp3x, p2y +perp3y);
+ verts.push(r, g, b, alpha);
+
+ verts.push(p2x - perp3x, p2y -perp3y);
+ verts.push(r, g, b, alpha);
+
+ indexCount++;
+ }
+ else
+ {
+ verts.push(px , py);
+ verts.push(r, g, b, alpha);
+
+ verts.push(p2x - (px-p2x), p2y - (py - p2y));
+ verts.push(r, g, b, alpha);
+ }
+ }
+
+ p1x = points[(length-2)*2]
+ p1y = points[(length-2)*2 + 1]
+
+ p2x = points[(length-1)*2]
+ p2y = points[(length-1)*2 + 1]
+
+ perpx = -(p1y - p2y)
+ perpy = p1x - p2x;
+
+ dist = Math.sqrt(perpx*perpx + perpy*perpy);
+ perpx /= dist;
+ perpy /= dist;
+ perpx *= width;
+ perpy *= width;
+
+ verts.push(p2x - perpx , p2y - perpy)
+ verts.push(r, g, b, alpha);
+
+ verts.push(p2x + perpx , p2y + perpy)
+ verts.push(r, g, b, alpha);
+
+ indices.push(indexStart);
+
+ for (var i=0; i < indexCount; i++)
+ {
+ indices.push(indexStart++);
+ };
+
+ indices.push(indexStart-1);
+}
+
+/**
+ * Builds a polygon to draw
+ *
+ * @static
+ * @private
+ * @method buildPoly
+ * @param graphics {Graphics}
+ * @param webGLData {Object}
+ */
+PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData)
+{
+ var points = graphicsData.points;
+ if(points.length < 6)return;
+
+ // get first and last point.. figure out the middle!
+ var verts = webGLData.points;
+ var indices = webGLData.indices;
+
+ var length = points.length / 2;
+
+ // sort color
+ var color = HEXtoRGB(graphicsData.fillColor);
+ var alpha = graphicsData.fillAlpha;
+ var r = color[0] * alpha;
+ var g = color[1] * alpha;
+ var b = color[2] * alpha;
+
+ var triangles = PIXI.PolyK.Triangulate(points);
+
+ var vertPos = verts.length / 6;
+
+ for (var i=0; i < triangles.length; i+=3)
+ {
+ indices.push(triangles[i] + vertPos);
+ indices.push(triangles[i] + vertPos);
+ indices.push(triangles[i+1] + vertPos);
+ indices.push(triangles[i+2] +vertPos);
+ indices.push(triangles[i+2] + vertPos);
+ };
+
+ for (var i = 0; i < length; i++)
+ {
+ verts.push(points[i * 2], points[i * 2 + 1],
+ r, g, b, alpha);
+ };
+}
+
+function HEXtoRGB(hex) {
+ return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
+}
+
+
+
+
diff --git a/src/pixi/renderers/webgl/WebGLRenderGroup.js b/src/pixi/renderers/webgl/WebGLRenderGroup.js
new file mode 100644
index 00000000..a66ce6b6
--- /dev/null
+++ b/src/pixi/renderers/webgl/WebGLRenderGroup.js
@@ -0,0 +1,1020 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * A WebGLBatch Enables a group of sprites to be drawn using the same settings.
+ * if a group of sprites all have the same baseTexture and blendMode then they can be
+ * grouped into a batch. All the sprites in a batch can then be drawn in one go by the
+ * GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch
+ * even if the batch only contains one sprite. Batching is handled automatically by the
+ * webGL renderer. A good tip is: the smaller the number of batchs there are, the faster
+ * the webGL renderer will run.
+ *
+ * @class WebGLBatch
+ * @contructor
+ * @param gl {WebGLContext} An instance of the webGL context
+ */
+PIXI.WebGLRenderGroup = function(gl)
+{
+ this.gl = gl;
+ this.root;
+
+ this.backgroundColor;
+ this.batchs = [];
+ this.toRemove = [];
+}
+
+// constructor
+PIXI.WebGLRenderGroup.prototype.constructor = PIXI.WebGLRenderGroup;
+
+/**
+ * Add a display object to the webgl renderer
+ *
+ * @method setRenderable
+ * @param displayObject {DisplayObject}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.setRenderable = function(displayObject)
+{
+ // has this changed??
+ if(this.root)this.removeDisplayObjectAndChildren(this.root);
+
+ displayObject.worldVisible = displayObject.visible;
+
+ // soooooo //
+ // to check if any batchs exist already??
+
+ // TODO what if its already has an object? should remove it
+ this.root = displayObject;
+ this.addDisplayObjectAndChildren(displayObject);
+}
+
+/**
+ * Renders the stage to its webgl view
+ *
+ * @method render
+ * @param projection {Object}
+ */
+PIXI.WebGLRenderGroup.prototype.render = function(projection)
+{
+ PIXI.WebGLRenderer.updateTextures();
+
+ var gl = this.gl;
+
+
+ gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y);
+ gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
+
+ // will render all the elements in the group
+ var renderable;
+
+ for (var i=0; i < this.batchs.length; i++)
+ {
+
+ renderable = this.batchs[i];
+ if(renderable instanceof PIXI.WebGLBatch)
+ {
+ this.batchs[i].render();
+ continue;
+ }
+
+ // non sprite batch..
+ var worldVisible = renderable.vcount === PIXI.visibleCount;
+
+ if(renderable instanceof PIXI.TilingSprite)
+ {
+ if(worldVisible)this.renderTilingSprite(renderable, projection);
+ }
+ else if(renderable instanceof PIXI.Strip)
+ {
+ if(worldVisible)this.renderStrip(renderable, projection);
+ }
+ else if(renderable instanceof PIXI.Graphics)
+ {
+ if(worldVisible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);//, projectionMatrix);
+ }
+ else if(renderable instanceof PIXI.FilterBlock)
+ {
+ /*
+ * for now only masks are supported..
+ */
+ if(renderable.open)
+ {
+ gl.enable(gl.STENCIL_TEST);
+
+ gl.colorMask(false, false, false, false);
+ gl.stencilFunc(gl.ALWAYS,1,0xff);
+ gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE);
+
+ PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection);
+
+ gl.colorMask(true, true, true, false);
+ gl.stencilFunc(gl.NOTEQUAL,0,0xff);
+ gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);
+ }
+ else
+ {
+ gl.disable(gl.STENCIL_TEST);
+ }
+ }
+ }
+
+}
+
+/**
+ * Renders the stage to its webgl view
+ *
+ * @method handleFilter
+ * @param filter {FilterBlock}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.handleFilter = function(filter, projection)
+{
+
+}
+
+/**
+ * Renders a specific displayObject
+ *
+ * @method renderSpecific
+ * @param displayObject {DisplayObject}
+ * @param projection {Object}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection)
+{
+ PIXI.WebGLRenderer.updateTextures();
+
+ var gl = this.gl;
+
+ gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y);
+
+ // to do!
+ // render part of the scene...
+
+ var startIndex;
+ var startBatchIndex;
+
+ var endIndex;
+ var endBatchIndex;
+
+ /*
+ * LOOK FOR THE NEXT SPRITE
+ * This part looks for the closest next sprite that can go into a batch
+ * it keeps looking until it finds a sprite or gets to the end of the display
+ * scene graph
+ */
+ var nextRenderable = displayObject.first;
+ while(nextRenderable._iNext)
+ {
+ nextRenderable = nextRenderable._iNext;
+ if(nextRenderable.renderable && nextRenderable.__renderGroup)break;
+ }
+ var startBatch = nextRenderable.batch;
+
+ if(nextRenderable instanceof PIXI.Sprite)
+ {
+ startBatch = nextRenderable.batch;
+
+ var head = startBatch.head;
+ var next = head;
+
+ // ok now we have the batch.. need to find the start index!
+ if(head == nextRenderable)
+ {
+ startIndex = 0;
+ }
+ else
+ {
+ startIndex = 1;
+
+ while(head.__next != nextRenderable)
+ {
+ startIndex++;
+ head = head.__next;
+ }
+ }
+ }
+ else
+ {
+ startBatch = nextRenderable;
+ }
+
+ // Get the LAST renderable object
+ var lastRenderable = displayObject;
+ var endBatch;
+ var lastItem = displayObject;
+ while(lastItem.children.length > 0)
+ {
+ lastItem = lastItem.children[lastItem.children.length-1];
+ if(lastItem.renderable)lastRenderable = lastItem;
+ }
+
+ if(lastRenderable instanceof PIXI.Sprite)
+ {
+ endBatch = lastRenderable.batch;
+
+ var head = endBatch.head;
+
+ if(head == lastRenderable)
+ {
+ endIndex = 0;
+ }
+ else
+ {
+ endIndex = 1;
+
+ while(head.__next != lastRenderable)
+ {
+ endIndex++;
+ head = head.__next;
+ }
+ }
+ }
+ else
+ {
+ endBatch = lastRenderable;
+ }
+
+ // TODO - need to fold this up a bit!
+
+ if(startBatch == endBatch)
+ {
+ if(startBatch instanceof PIXI.WebGLBatch)
+ {
+ startBatch.render(startIndex, endIndex+1);
+ }
+ else
+ {
+ this.renderSpecial(startBatch, projection);
+ }
+ return;
+ }
+
+ // now we have first and last!
+ startBatchIndex = this.batchs.indexOf(startBatch);
+ endBatchIndex = this.batchs.indexOf(endBatch);
+
+ // DO the first batch
+ if(startBatch instanceof PIXI.WebGLBatch)
+ {
+ startBatch.render(startIndex);
+ }
+ else
+ {
+ this.renderSpecial(startBatch, projection);
+ }
+
+ // DO the middle batchs..
+ for (var i=startBatchIndex+1; i < endBatchIndex; i++)
+ {
+ renderable = this.batchs[i];
+
+ if(renderable instanceof PIXI.WebGLBatch)
+ {
+ this.batchs[i].render();
+ }
+ else
+ {
+ this.renderSpecial(renderable, projection);
+ }
+ }
+
+ // DO the last batch..
+ if(endBatch instanceof PIXI.WebGLBatch)
+ {
+ endBatch.render(0, endIndex+1);
+ }
+ else
+ {
+ this.renderSpecial(endBatch, projection);
+ }
+}
+
+/**
+ * Renders a specific renderable
+ *
+ * @method renderSpecial
+ * @param renderable {DisplayObject}
+ * @param projection {Object}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable, projection)
+{
+ var worldVisible = renderable.vcount === PIXI.visibleCount
+
+ if(renderable instanceof PIXI.TilingSprite)
+ {
+ if(worldVisible)this.renderTilingSprite(renderable, projection);
+ }
+ else if(renderable instanceof PIXI.Strip)
+ {
+ if(worldVisible)this.renderStrip(renderable, projection);
+ }
+ else if(renderable instanceof PIXI.CustomRenderable)
+ {
+ if(worldVisible) renderable.renderWebGL(this, projection);
+ }
+ else if(renderable instanceof PIXI.Graphics)
+ {
+ if(worldVisible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);
+ }
+ else if(renderable instanceof PIXI.FilterBlock)
+ {
+ /*
+ * for now only masks are supported..
+ */
+
+ var gl = PIXI.gl;
+
+ if(renderable.open)
+ {
+ gl.enable(gl.STENCIL_TEST);
+
+ gl.colorMask(false, false, false, false);
+ gl.stencilFunc(gl.ALWAYS,1,0xff);
+ gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE);
+
+ PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection);
+
+ // we know this is a render texture so enable alpha too..
+ gl.colorMask(true, true, true, true);
+ gl.stencilFunc(gl.NOTEQUAL,0,0xff);
+ gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);
+ }
+ else
+ {
+ gl.disable(gl.STENCIL_TEST);
+ }
+ }
+}
+
+/**
+ * Updates a webgl texture
+ *
+ * @method updateTexture
+ * @param displayObject {DisplayObject}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject)
+{
+
+ // TODO definitely can optimse this function..
+
+ this.removeObject(displayObject);
+
+ /*
+ * LOOK FOR THE PREVIOUS RENDERABLE
+ * This part looks for the closest previous sprite that can go into a batch
+ * It keeps going back until it finds a sprite or the stage
+ */
+ var previousRenderable = displayObject.first;
+ while(previousRenderable != this.root)
+ {
+ previousRenderable = previousRenderable._iPrev;
+ if(previousRenderable.renderable && previousRenderable.__renderGroup)break;
+ }
+
+ /*
+ * LOOK FOR THE NEXT SPRITE
+ * This part looks for the closest next sprite that can go into a batch
+ * it keeps looking until it finds a sprite or gets to the end of the display
+ * scene graph
+ */
+ var nextRenderable = displayObject.last;
+ while(nextRenderable._iNext)
+ {
+ nextRenderable = nextRenderable._iNext;
+ if(nextRenderable.renderable && nextRenderable.__renderGroup)break;
+ }
+
+ this.insertObject(displayObject, previousRenderable, nextRenderable);
+}
+
+/**
+ * Adds filter blocks
+ *
+ * @method addFilterBlocks
+ * @param start {FilterBlock}
+ * @param end {FilterBlock}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end)
+{
+ start.__renderGroup = this;
+ end.__renderGroup = this;
+ /*
+ * LOOK FOR THE PREVIOUS RENDERABLE
+ * This part looks for the closest previous sprite that can go into a batch
+ * It keeps going back until it finds a sprite or the stage
+ */
+ var previousRenderable = start;
+ while(previousRenderable != this.root)
+ {
+ previousRenderable = previousRenderable._iPrev;
+ if(previousRenderable.renderable && previousRenderable.__renderGroup)break;
+ }
+ this.insertAfter(start, previousRenderable);
+
+ /*
+ * LOOK FOR THE NEXT SPRITE
+ * This part looks for the closest next sprite that can go into a batch
+ * it keeps looking until it finds a sprite or gets to the end of the display
+ * scene graph
+ */
+ var previousRenderable2 = end;
+ while(previousRenderable2 != this.root)
+ {
+ previousRenderable2 = previousRenderable2._iPrev;
+ if(previousRenderable2.renderable && previousRenderable2.__renderGroup)break;
+ }
+ this.insertAfter(end, previousRenderable2);
+}
+
+/**
+ * Remove filter blocks
+ *
+ * @method removeFilterBlocks
+ * @param start {FilterBlock}
+ * @param end {FilterBlock}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.removeFilterBlocks = function(start, end)
+{
+ this.removeObject(start);
+ this.removeObject(end);
+}
+
+/**
+ * Adds a display object and children to the webgl context
+ *
+ * @method addDisplayObjectAndChildren
+ * @param displayObject {DisplayObject}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayObject)
+{
+ if(displayObject.__renderGroup)displayObject.__renderGroup.removeDisplayObjectAndChildren(displayObject);
+
+ /*
+ * LOOK FOR THE PREVIOUS RENDERABLE
+ * This part looks for the closest previous sprite that can go into a batch
+ * It keeps going back until it finds a sprite or the stage
+ */
+
+ var previousRenderable = displayObject.first;
+ while(previousRenderable != this.root.first)
+ {
+ previousRenderable = previousRenderable._iPrev;
+ if(previousRenderable.renderable && previousRenderable.__renderGroup)break;
+ }
+
+ /*
+ * LOOK FOR THE NEXT SPRITE
+ * This part looks for the closest next sprite that can go into a batch
+ * it keeps looking until it finds a sprite or gets to the end of the display
+ * scene graph
+ */
+ var nextRenderable = displayObject.last;
+ while(nextRenderable._iNext)
+ {
+ nextRenderable = nextRenderable._iNext;
+ if(nextRenderable.renderable && nextRenderable.__renderGroup)break;
+ }
+
+ // one the display object hits this. we can break the loop
+
+ var tempObject = displayObject.first;
+ var testObject = displayObject.last._iNext;
+ do
+ {
+ tempObject.__renderGroup = this;
+
+ if(tempObject.renderable)
+ {
+
+ this.insertObject(tempObject, previousRenderable, nextRenderable);
+ previousRenderable = tempObject;
+ }
+
+ tempObject = tempObject._iNext;
+ }
+ while(tempObject != testObject)
+}
+
+/**
+ * Removes a display object and children to the webgl context
+ *
+ * @method removeDisplayObjectAndChildren
+ * @param displayObject {DisplayObject}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displayObject)
+{
+ if(displayObject.__renderGroup != this)return;
+
+// var displayObject = displayObject.first;
+ var lastObject = displayObject.last;
+ do
+ {
+ displayObject.__renderGroup = null;
+ if(displayObject.renderable)this.removeObject(displayObject);
+ displayObject = displayObject._iNext;
+ }
+ while(displayObject)
+}
+
+/**
+ * Inserts a displayObject into the linked list
+ *
+ * @method insertObject
+ * @param displayObject {DisplayObject}
+ * @param previousObject {DisplayObject}
+ * @param nextObject {DisplayObject}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousObject, nextObject)
+{
+ // while looping below THE OBJECT MAY NOT HAVE BEEN ADDED
+ var previousSprite = previousObject;
+ var nextSprite = nextObject;
+
+ /*
+ * so now we have the next renderable and the previous renderable
+ *
+ */
+ if(displayObject instanceof PIXI.Sprite)
+ {
+ var previousBatch
+ var nextBatch
+
+ if(previousSprite instanceof PIXI.Sprite)
+ {
+ previousBatch = previousSprite.batch;
+ if(previousBatch)
+ {
+ if(previousBatch.texture == displayObject.texture.baseTexture && previousBatch.blendMode == displayObject.blendMode)
+ {
+ previousBatch.insertAfter(displayObject, previousSprite);
+ return;
+ }
+ }
+ }
+ else
+ {
+ // TODO reword!
+ previousBatch = previousSprite;
+ }
+
+ if(nextSprite)
+ {
+ if(nextSprite instanceof PIXI.Sprite)
+ {
+ nextBatch = nextSprite.batch;
+
+ //batch may not exist if item was added to the display list but not to the webGL
+ if(nextBatch)
+ {
+ if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode)
+ {
+ nextBatch.insertBefore(displayObject, nextSprite);
+ return;
+ }
+ else
+ {
+ if(nextBatch == previousBatch)
+ {
+ // THERE IS A SPLIT IN THIS BATCH! //
+ var splitBatch = previousBatch.split(nextSprite);
+ // COOL!
+ // add it back into the array
+ /*
+ * OOPS!
+ * seems the new sprite is in the middle of a batch
+ * lets split it..
+ */
+ var batch = PIXI.WebGLRenderer.getBatch();
+
+ var index = this.batchs.indexOf( previousBatch );
+ batch.init(displayObject);
+ this.batchs.splice(index+1, 0, batch, splitBatch);
+
+ return;
+ }
+ }
+ }
+ }
+ else
+ {
+ // TODO re-word!
+
+ nextBatch = nextSprite;
+ }
+ }
+
+ /*
+ * looks like it does not belong to any batch!
+ * but is also not intersecting one..
+ * time to create anew one!
+ */
+
+ var batch = PIXI.WebGLRenderer.getBatch();
+ batch.init(displayObject);
+
+ if(previousBatch) // if this is invalid it means
+ {
+ var index = this.batchs.indexOf( previousBatch );
+ this.batchs.splice(index+1, 0, batch);
+ }
+ else
+ {
+ this.batchs.push(batch);
+ }
+
+ return;
+ }
+ else if(displayObject instanceof PIXI.TilingSprite)
+ {
+
+ // add to a batch!!
+ this.initTilingSprite(displayObject);
+ // this.batchs.push(displayObject);
+
+ }
+ else if(displayObject instanceof PIXI.Strip)
+ {
+ // add to a batch!!
+ this.initStrip(displayObject);
+ // this.batchs.push(displayObject);
+ }
+ else if(displayObject)// instanceof PIXI.Graphics)
+ {
+ //displayObject.initWebGL(this);
+
+ // add to a batch!!
+ //this.initStrip(displayObject);
+ //this.batchs.push(displayObject);
+ }
+
+ this.insertAfter(displayObject, previousSprite);
+
+ // insert and SPLIT!
+
+}
+
+/**
+ * Inserts a displayObject into the linked list
+ *
+ * @method insertAfter
+ * @param item {DisplayObject}
+ * @param displayObject {DisplayObject} The object to insert
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject)
+{
+ if(displayObject instanceof PIXI.Sprite)
+ {
+ var previousBatch = displayObject.batch;
+
+ if(previousBatch)
+ {
+ // so this object is in a batch!
+
+ // is it not? need to split the batch
+ if(previousBatch.tail == displayObject)
+ {
+ // is it tail? insert in to batchs
+ var index = this.batchs.indexOf( previousBatch );
+ this.batchs.splice(index+1, 0, item);
+ }
+ else
+ {
+ // TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) //
+
+ // THERE IS A SPLIT IN THIS BATCH! //
+ var splitBatch = previousBatch.split(displayObject.__next);
+
+ // COOL!
+ // add it back into the array
+ /*
+ * OOPS!
+ * seems the new sprite is in the middle of a batch
+ * lets split it..
+ */
+ var index = this.batchs.indexOf( previousBatch );
+ this.batchs.splice(index+1, 0, item, splitBatch);
+ }
+ }
+ else
+ {
+ this.batchs.push(item);
+ }
+ }
+ else
+ {
+ var index = this.batchs.indexOf( displayObject );
+ this.batchs.splice(index+1, 0, item);
+ }
+}
+
+/**
+ * Removes a displayObject from the linked list
+ *
+ * @method removeObject
+ * @param displayObject {DisplayObject} The object to remove
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject)
+{
+ // loop through children..
+ // display object //
+
+ // add a child from the render group..
+ // remove it and all its children!
+ //displayObject.cacheVisible = false;//displayObject.visible;
+
+ /*
+ * removing is a lot quicker..
+ *
+ */
+ var batchToRemove;
+
+ if(displayObject instanceof PIXI.Sprite)
+ {
+ // should always have a batch!
+ var batch = displayObject.batch;
+ if(!batch)return; // this means the display list has been altered befre rendering
+
+ batch.remove(displayObject);
+
+ if(batch.size==0)
+ {
+ batchToRemove = batch;
+ }
+ }
+ else
+ {
+ batchToRemove = displayObject;
+ }
+
+ /*
+ * Looks like there is somthing that needs removing!
+ */
+ if(batchToRemove)
+ {
+ var index = this.batchs.indexOf( batchToRemove );
+ if(index == -1)return;// this means it was added then removed before rendered
+
+ // ok so.. check to see if you adjacent batchs should be joined.
+ // TODO may optimise?
+ if(index == 0 || index == this.batchs.length-1)
+ {
+ // wha - eva! just get of the empty batch!
+ this.batchs.splice(index, 1);
+ if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove);
+
+ return;
+ }
+
+ if(this.batchs[index-1] instanceof PIXI.WebGLBatch && this.batchs[index+1] instanceof PIXI.WebGLBatch)
+ {
+ if(this.batchs[index-1].texture == this.batchs[index+1].texture && this.batchs[index-1].blendMode == this.batchs[index+1].blendMode)
+ {
+ //console.log("MERGE")
+ this.batchs[index-1].merge(this.batchs[index+1]);
+
+ if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove);
+ PIXI.WebGLRenderer.returnBatch(this.batchs[index+1]);
+ this.batchs.splice(index, 2);
+ return;
+ }
+ }
+
+ this.batchs.splice(index, 1);
+ if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove);
+ }
+}
+
+/**
+ * Initializes a tiling sprite
+ *
+ * @method initTilingSprite
+ * @param sprite {TilingSprite} The tiling sprite to initialize
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite)
+{
+ var gl = this.gl;
+
+ // make the texture tilable..
+
+ sprite.verticies = new Float32Array([0, 0,
+ sprite.width, 0,
+ sprite.width, sprite.height,
+ 0, sprite.height]);
+
+ sprite.uvs = new Float32Array([0, 0,
+ 1, 0,
+ 1, 1,
+ 0, 1]);
+
+ sprite.colors = new Float32Array([1,1,1,1]);
+
+ sprite.indices = new Uint16Array([0, 1, 3,2])//, 2]);
+
+ sprite._vertexBuffer = gl.createBuffer();
+ sprite._indexBuffer = gl.createBuffer();
+ sprite._uvBuffer = gl.createBuffer();
+ sprite._colorBuffer = gl.createBuffer();
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, sprite._vertexBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, sprite.verticies, gl.STATIC_DRAW);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, sprite.uvs, gl.DYNAMIC_DRAW);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, sprite._colorBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, sprite.colors, gl.STATIC_DRAW);
+
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer);
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW);
+
+// return ( (x > 0) && ((x & (x - 1)) == 0) );
+
+ if(sprite.texture.baseTexture._glTexture)
+ {
+ gl.bindTexture(gl.TEXTURE_2D, sprite.texture.baseTexture._glTexture);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+ sprite.texture.baseTexture._powerOf2 = true;
+ }
+ else
+ {
+ sprite.texture.baseTexture._powerOf2 = true;
+ }
+}
+
+/**
+ * Renders a Strip
+ *
+ * @method renderStrip
+ * @param strip {Strip} The strip to render
+ * @param projection {Object}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection)
+{
+ var gl = this.gl;
+ var shaderProgram = PIXI.shaderProgram;
+// mat
+ //var mat4Real = PIXI.mat3.toMat4(strip.worldTransform);
+ //PIXI.mat4.transpose(mat4Real);
+ //PIXI.mat4.multiply(projectionMatrix, mat4Real, mat4Real )
+
+
+ gl.useProgram(PIXI.stripShaderProgram);
+
+ var m = PIXI.mat3.clone(strip.worldTransform);
+
+ PIXI.mat3.transpose(m);
+
+ // set the matrix transform for the
+ gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m);
+ gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y);
+ gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha);
+
+/*
+ if(strip.blendMode == PIXI.blendModes.NORMAL)
+ {
+ gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
+ }
+ else
+ {
+ gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR);
+ }
+ */
+
+
+ if(!strip.dirty)
+ {
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies)
+ gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
+
+ // update the uvs
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
+ gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
+ gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
+
+ // dont need to upload!
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
+ }
+ else
+ {
+ strip.dirty = false;
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW)
+ gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
+
+ // update the uvs
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW)
+ gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW)
+ gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
+
+ // dont need to upload!
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW);
+
+ }
+ //console.log(gl.TRIANGLE_STRIP);
+
+ gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0);
+
+ gl.useProgram(PIXI.shaderProgram);
+}
+
+/**
+ * Renders a TilingSprite
+ *
+ * @method renderTilingSprite
+ * @param sprite {TilingSprite} The tiling sprite to render
+ * @param projectionMatrix {Object}
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projectionMatrix)
+{
+ var gl = this.gl;
+ var shaderProgram = PIXI.shaderProgram;
+
+ var tilePosition = sprite.tilePosition;
+ var tileScale = sprite.tileScale;
+
+ var offsetX = tilePosition.x/sprite.texture.baseTexture.width;
+ var offsetY = tilePosition.y/sprite.texture.baseTexture.height;
+
+ var scaleX = (sprite.width / sprite.texture.baseTexture.width) / tileScale.x;
+ var scaleY = (sprite.height / sprite.texture.baseTexture.height) / tileScale.y;
+
+ sprite.uvs[0] = 0 - offsetX;
+ sprite.uvs[1] = 0 - offsetY;
+
+ sprite.uvs[2] = (1 * scaleX) -offsetX;
+ sprite.uvs[3] = 0 - offsetY;
+
+ sprite.uvs[4] = (1 *scaleX) - offsetX;
+ sprite.uvs[5] = (1 *scaleY) - offsetY;
+
+ sprite.uvs[6] = 0 - offsetX;
+ sprite.uvs[7] = (1 *scaleY) - offsetY;
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer);
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, sprite.uvs)
+
+ this.renderStrip(sprite, projectionMatrix);
+}
+
+/**
+ * Initializes a strip to be rendered
+ *
+ * @method initStrip
+ * @param strip {Strip} The strip to initialize
+ * @private
+ */
+PIXI.WebGLRenderGroup.prototype.initStrip = function(strip)
+{
+ // build the strip!
+ var gl = this.gl;
+ var shaderProgram = this.shaderProgram;
+
+ strip._vertexBuffer = gl.createBuffer();
+ strip._indexBuffer = gl.createBuffer();
+ strip._uvBuffer = gl.createBuffer();
+ strip._colorBuffer = gl.createBuffer();
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW);
+
+ gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW);
+
+
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW);
+}
diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js
new file mode 100644
index 00000000..f05c162e
--- /dev/null
+++ b/src/pixi/renderers/webgl/WebGLRenderer.js
@@ -0,0 +1,348 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1);
+
+// an instance of the gl context..
+// only one at the moment :/
+PIXI.gl;
+
+/**
+ * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer
+ * should be used for browsers support webGL. This Render works by automatically managing webGLBatchs.
+ * So no need for Sprite Batch's or Sprite Cloud's
+ * Dont forget to add the view to your DOM or you will not see anything :)
+ *
+ * @class WebGLRenderer
+ * @constructor
+ * @param width=0 {Number} the width of the canvas view
+ * @param height=0 {Number} the height of the canvas view
+ * @param view {Canvas} the canvas to use as a view, optional
+ * @param transparent=false {Boolean} the transparency of the render view, default false
+ * @param antialias=false {Boolean} sets antialias (only applicable in chrome at the moment)
+ *
+ */
+PIXI.WebGLRenderer = function(width, height, view, transparent, antialias)
+{
+ // do a catch.. only 1 webGL renderer..
+
+ this.transparent = !!transparent;
+
+ this.width = width || 800;
+ this.height = height || 600;
+
+ this.view = view || document.createElement( 'canvas' );
+ this.view.width = this.width;
+ this.view.height = this.height;
+
+ // deal with losing context..
+ var scope = this;
+ this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false)
+ this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false)
+
+ this.batchs = [];
+
+ try
+ {
+ PIXI.gl = this.gl = this.view.getContext("experimental-webgl", {
+ alpha: this.transparent,
+ antialias:!!antialias, // SPEED UP??
+ premultipliedAlpha:false,
+ stencil:true
+ });
+ }
+ catch (e)
+ {
+ throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this);
+ }
+
+ PIXI.initPrimitiveShader();
+ PIXI.initDefaultShader();
+ PIXI.initDefaultStripShader();
+
+ PIXI.activateDefaultShader();
+
+ var gl = this.gl;
+ PIXI.WebGLRenderer.gl = gl;
+
+ this.batch = new PIXI.WebGLBatch(gl);
+ gl.disable(gl.DEPTH_TEST);
+ gl.disable(gl.CULL_FACE);
+
+ gl.enable(gl.BLEND);
+ gl.colorMask(true, true, true, this.transparent);
+
+ PIXI.projection = new PIXI.Point(400, 300);
+
+ this.resize(this.width, this.height);
+ this.contextLost = false;
+
+ this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl);
+}
+
+// constructor
+PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer;
+
+/**
+ * Gets a new WebGLBatch from the pool
+ *
+ * @static
+ * @method getBatch
+ * @return {WebGLBatch}
+ * @private
+ */
+PIXI.WebGLRenderer.getBatch = function()
+{
+ if(PIXI._batchs.length == 0)
+ {
+ return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl);
+ }
+ else
+ {
+ return PIXI._batchs.pop();
+ }
+}
+
+/**
+ * Puts a batch back into the pool
+ *
+ * @static
+ * @method returnBatch
+ * @param batch {WebGLBatch} The batch to return
+ * @private
+ */
+PIXI.WebGLRenderer.returnBatch = function(batch)
+{
+ batch.clean();
+ PIXI._batchs.push(batch);
+}
+
+/**
+ * Renders the stage to its webGL view
+ *
+ * @method render
+ * @param stage {Stage} the Stage element to be rendered
+ */
+PIXI.WebGLRenderer.prototype.render = function(stage)
+{
+ if(this.contextLost)return;
+
+
+ // if rendering a new stage clear the batchs..
+ if(this.__stage !== stage)
+ {
+ // TODO make this work
+ // dont think this is needed any more?
+ this.__stage = stage;
+ this.stageRenderGroup.setRenderable(stage);
+ }
+
+ // TODO not needed now...
+ // update children if need be
+ // best to remove first!
+ /*for (var i=0; i < stage.__childrenRemoved.length; i++)
+ {
+ var group = stage.__childrenRemoved[i].__renderGroup
+ if(group)group.removeDisplayObject(stage.__childrenRemoved[i]);
+ }*/
+
+ // update any textures
+ PIXI.WebGLRenderer.updateTextures();
+
+ // update the scene graph
+ PIXI.visibleCount++;
+ stage.updateTransform();
+
+ var gl = this.gl;
+
+ // -- Does this need to be set every frame? -- //
+ gl.colorMask(true, true, true, this.transparent);
+ gl.viewport(0, 0, this.width, this.height);
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+
+ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ // HACK TO TEST
+
+ this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit;
+ this.stageRenderGroup.render(PIXI.projection);
+
+ // interaction
+ // run interaction!
+ if(stage.interactive)
+ {
+ //need to add some events!
+ if(!stage._interactiveEventsAdded)
+ {
+ stage._interactiveEventsAdded = true;
+ stage.interactionManager.setTarget(this);
+ }
+ }
+
+ // after rendering lets confirm all frames that have been uodated..
+ if(PIXI.Texture.frameUpdates.length > 0)
+ {
+ for (var i=0; i < PIXI.Texture.frameUpdates.length; i++)
+ {
+ PIXI.Texture.frameUpdates[i].updateFrame = false;
+ };
+
+ PIXI.Texture.frameUpdates = [];
+ }
+}
+
+/**
+ * Updates the textures loaded into this webgl renderer
+ *
+ * @static
+ * @method updateTextures
+ * @private
+ */
+PIXI.WebGLRenderer.updateTextures = function()
+{
+ //TODO break this out into a texture manager...
+ for (var i=0; i < PIXI.texturesToUpdate.length; i++) PIXI.WebGLRenderer.updateTexture(PIXI.texturesToUpdate[i]);
+ for (var i=0; i < PIXI.texturesToDestroy.length; i++) PIXI.WebGLRenderer.destroyTexture(PIXI.texturesToDestroy[i]);
+ PIXI.texturesToUpdate = [];
+ PIXI.texturesToDestroy = [];
+}
+
+/**
+ * Updates a loaded webgl texture
+ *
+ * @static
+ * @method updateTexture
+ * @param texture {Texture} The texture to update
+ * @private
+ */
+PIXI.WebGLRenderer.updateTexture = function(texture)
+{
+ //TODO break this out into a texture manager...
+ var gl = PIXI.gl;
+
+ if(!texture._glTexture)
+ {
+ texture._glTexture = gl.createTexture();
+ }
+
+ if(texture.hasLoaded)
+ {
+ gl.bindTexture(gl.TEXTURE_2D, texture._glTexture);
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
+
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+
+ // reguler...
+
+ if(!texture._powerOf2)
+ {
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ }
+ else
+ {
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+ }
+
+ gl.bindTexture(gl.TEXTURE_2D, null);
+ }
+}
+
+/**
+ * Destroys a loaded webgl texture
+ *
+ * @method destroyTexture
+ * @param texture {Texture} The texture to update
+ * @private
+ */
+PIXI.WebGLRenderer.destroyTexture = function(texture)
+{
+ //TODO break this out into a texture manager...
+ var gl = PIXI.gl;
+
+ if(texture._glTexture)
+ {
+ texture._glTexture = gl.createTexture();
+ gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture);
+ }
+}
+
+/**
+ * resizes the webGL view to the specified width and height
+ *
+ * @method resize
+ * @param width {Number} the new width of the webGL view
+ * @param height {Number} the new height of the webGL view
+ */
+PIXI.WebGLRenderer.prototype.resize = function(width, height)
+{
+ this.width = width;
+ this.height = height;
+
+ this.view.width = width;
+ this.view.height = height;
+
+ this.gl.viewport(0, 0, this.width, this.height);
+
+ //var projectionMatrix = this.projectionMatrix;
+
+ PIXI.projection.x = this.width/2;
+ PIXI.projection.y = this.height/2;
+
+// projectionMatrix[0] = 2/this.width;
+// projectionMatrix[5] = -2/this.height;
+// projectionMatrix[12] = -1;
+// projectionMatrix[13] = 1;
+}
+
+/**
+ * Handles a lost webgl context
+ *
+ * @method handleContextLost
+ * @param event {Event}
+ * @private
+ */
+PIXI.WebGLRenderer.prototype.handleContextLost = function(event)
+{
+ event.preventDefault();
+ this.contextLost = true;
+}
+
+/**
+ * Handles a restored webgl context
+ *
+ * @method handleContextRestored
+ * @param event {Event}
+ * @private
+ */
+PIXI.WebGLRenderer.prototype.handleContextRestored = function(event)
+{
+ this.gl = this.view.getContext("experimental-webgl", {
+ alpha: true
+ });
+
+ this.initShaders();
+
+ for(var key in PIXI.TextureCache)
+ {
+ var texture = PIXI.TextureCache[key].baseTexture;
+ texture._glTexture = null;
+ PIXI.WebGLRenderer.updateTexture(texture);
+ };
+
+ for (var i=0; i < this.batchs.length; i++)
+ {
+ this.batchs[i].restoreLostContext(this.gl)//
+ this.batchs[i].dirty = true;
+ };
+
+ PIXI._restoreBatchs(this.gl);
+
+ this.contextLost = false;
+}
diff --git a/src/pixi/renderers/webgl/WebGLShaders.js b/src/pixi/renderers/webgl/WebGLShaders.js
new file mode 100644
index 00000000..68e5b0b1
--- /dev/null
+++ b/src/pixi/renderers/webgl/WebGLShaders.js
@@ -0,0 +1,231 @@
+
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+
+/*
+ * the default suoer fast shader!
+ */
+
+PIXI.shaderFragmentSrc = [
+ "precision mediump float;",
+ "varying vec2 vTextureCoord;",
+ "varying float vColor;",
+ "uniform sampler2D uSampler;",
+ "void main(void) {",
+ "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
+ "gl_FragColor = gl_FragColor * vColor;",
+ "}"
+];
+
+PIXI.shaderVertexSrc = [
+ "attribute vec2 aVertexPosition;",
+ "attribute vec2 aTextureCoord;",
+ "attribute float aColor;",
+ //"uniform mat4 uMVMatrix;",
+
+ "uniform vec2 projectionVector;",
+ "varying vec2 vTextureCoord;",
+ "varying float vColor;",
+ "void main(void) {",
+ // "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);",
+ "gl_Position = vec4( aVertexPosition.x / projectionVector.x -1.0, aVertexPosition.y / -projectionVector.y + 1.0 , 0.0, 1.0);",
+ "vTextureCoord = aTextureCoord;",
+ "vColor = aColor;",
+ "}"
+];
+
+/*
+ * the triangle strip shader..
+ */
+
+PIXI.stripShaderFragmentSrc = [
+ "precision mediump float;",
+ "varying vec2 vTextureCoord;",
+ "varying float vColor;",
+ "uniform float alpha;",
+ "uniform sampler2D uSampler;",
+ "void main(void) {",
+ "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
+ "gl_FragColor = gl_FragColor * alpha;",
+ "}"
+];
+
+
+PIXI.stripShaderVertexSrc = [
+ "attribute vec2 aVertexPosition;",
+ "attribute vec2 aTextureCoord;",
+ "attribute float aColor;",
+ "uniform mat3 translationMatrix;",
+ "uniform vec2 projectionVector;",
+ "varying vec2 vTextureCoord;",
+ "varying float vColor;",
+ "void main(void) {",
+ "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);",
+ "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);",
+ "vTextureCoord = aTextureCoord;",
+ "vColor = aColor;",
+ "}"
+];
+
+
+/*
+ * primitive shader..
+ */
+
+PIXI.primitiveShaderFragmentSrc = [
+ "precision mediump float;",
+ "varying vec4 vColor;",
+ "void main(void) {",
+ "gl_FragColor = vColor;",
+ "}"
+];
+
+PIXI.primitiveShaderVertexSrc = [
+ "attribute vec2 aVertexPosition;",
+ "attribute vec4 aColor;",
+ "uniform mat3 translationMatrix;",
+ "uniform vec2 projectionVector;",
+ "uniform float alpha;",
+ "varying vec4 vColor;",
+ "void main(void) {",
+ "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);",
+ "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);",
+ "vColor = aColor * alpha;",
+ "}"
+];
+
+PIXI.initPrimitiveShader = function()
+{
+ var gl = PIXI.gl;
+
+ var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc)
+
+ gl.useProgram(shaderProgram);
+
+ shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
+ shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor");
+
+ shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
+ shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix");
+
+ shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha");
+
+ PIXI.primitiveProgram = shaderProgram;
+}
+
+PIXI.initDefaultShader = function()
+{
+ var gl = this.gl;
+ var shaderProgram = PIXI.compileProgram(PIXI.shaderVertexSrc, PIXI.shaderFragmentSrc)
+
+ gl.useProgram(shaderProgram);
+
+ shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
+ shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
+ shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
+ shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor");
+
+ // shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
+ shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
+
+ PIXI.shaderProgram = shaderProgram;
+}
+
+PIXI.initDefaultStripShader = function()
+{
+ var gl = this.gl;
+ var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc)
+
+ gl.useProgram(shaderProgram);
+
+ shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
+ shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
+ shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
+ shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix");
+ shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha");
+
+ shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor");
+
+ shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
+
+ shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
+
+ PIXI.stripShaderProgram = shaderProgram;
+}
+
+PIXI.CompileVertexShader = function(gl, shaderSrc)
+{
+ return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER);
+}
+
+PIXI.CompileFragmentShader = function(gl, shaderSrc)
+{
+ return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER);
+}
+
+PIXI._CompileShader = function(gl, shaderSrc, shaderType)
+{
+ var src = shaderSrc.join("\n");
+ var shader = gl.createShader(shaderType);
+ gl.shaderSource(shader, src);
+ gl.compileShader(shader);
+
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
+ alert(gl.getShaderInfoLog(shader));
+ return null;
+ }
+
+ return shader;
+}
+
+
+PIXI.compileProgram = function(vertexSrc, fragmentSrc)
+{
+ var gl = PIXI.gl;
+ var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc);
+ var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc);
+
+ var shaderProgram = gl.createProgram();
+
+ gl.attachShader(shaderProgram, vertexShader);
+ gl.attachShader(shaderProgram, fragmentShader);
+ gl.linkProgram(shaderProgram);
+
+ if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
+ alert("Could not initialise shaders");
+ }
+
+ return shaderProgram;
+}
+
+
+PIXI.activateDefaultShader = function()
+{
+ var gl = PIXI.gl;
+ var shaderProgram = PIXI.shaderProgram;
+
+ gl.useProgram(shaderProgram);
+
+
+ gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
+ gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
+ gl.enableVertexAttribArray(shaderProgram.colorAttribute);
+}
+
+
+
+PIXI.activatePrimitiveShader = function()
+{
+ var gl = PIXI.gl;
+
+ gl.disableVertexAttribArray(PIXI.shaderProgram.textureCoordAttribute);
+ gl.disableVertexAttribArray(PIXI.shaderProgram.colorAttribute);
+
+ gl.useProgram(PIXI.primitiveProgram);
+
+ gl.enableVertexAttribArray(PIXI.primitiveProgram.vertexPositionAttribute);
+ gl.enableVertexAttribArray(PIXI.primitiveProgram.colorAttribute);
+}
+
diff --git a/src/pixi/text/BitmapText.js b/src/pixi/text/BitmapText.js
new file mode 100644
index 00000000..b667172f
--- /dev/null
+++ b/src/pixi/text/BitmapText.js
@@ -0,0 +1,164 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n"
+ * You can generate the fnt files using
+ * http://www.angelcode.com/products/bmfont/ for windows or
+ * http://www.bmglyph.com/ for mac.
+ *
+ * @class BitmapText
+ * @extends DisplayObjectContainer
+ * @constructor
+ * @param text {String} The copy that you would like the text to display
+ * @param style {Object} The style parameters
+ * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
+ * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
+ */
+PIXI.BitmapText = function(text, style)
+{
+ PIXI.DisplayObjectContainer.call(this);
+
+ this.setText(text);
+ this.setStyle(style);
+ this.updateText();
+ this.dirty = false
+
+};
+
+// constructor
+PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
+PIXI.BitmapText.prototype.constructor = PIXI.BitmapText;
+
+/**
+ * Set the copy for the text object
+ *
+ * @method setText
+ * @param text {String} The copy that you would like the text to display
+ */
+PIXI.BitmapText.prototype.setText = function(text)
+{
+ this.text = text || " ";
+ this.dirty = true;
+};
+
+/**
+ * Set the style of the text
+ *
+ * @method setStyle
+ * @param style {Object} The style parameters
+ * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
+ * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
+ */
+PIXI.BitmapText.prototype.setStyle = function(style)
+{
+ style = style || {};
+ style.align = style.align || "left";
+ this.style = style;
+
+ var font = style.font.split(" ");
+ this.fontName = font[font.length - 1];
+ this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size;
+
+ this.dirty = true;
+};
+
+/**
+ * Renders text
+ *
+ * @method updateText
+ * @private
+ */
+PIXI.BitmapText.prototype.updateText = function()
+{
+ var data = PIXI.BitmapText.fonts[this.fontName];
+ var pos = new PIXI.Point();
+ var prevCharCode = null;
+ var chars = [];
+ var maxLineWidth = 0;
+ var lineWidths = [];
+ var line = 0;
+ var scale = this.fontSize / data.size;
+ for(var i = 0; i < this.text.length; i++)
+ {
+ var charCode = this.text.charCodeAt(i);
+ if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i)))
+ {
+ lineWidths.push(pos.x);
+ maxLineWidth = Math.max(maxLineWidth, pos.x);
+ line++;
+
+ pos.x = 0;
+ pos.y += data.lineHeight;
+ prevCharCode = null;
+ continue;
+ }
+
+ var charData = data.chars[charCode];
+ if(!charData) continue;
+
+ if(prevCharCode && charData[prevCharCode])
+ {
+ pos.x += charData.kerning[prevCharCode];
+ }
+ chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
+ pos.x += charData.xAdvance;
+
+ prevCharCode = charCode;
+ }
+
+ lineWidths.push(pos.x);
+ maxLineWidth = Math.max(maxLineWidth, pos.x);
+
+ var lineAlignOffsets = [];
+ for(i = 0; i <= line; i++)
+ {
+ var alignOffset = 0;
+ if(this.style.align == "right")
+ {
+ alignOffset = maxLineWidth - lineWidths[i];
+ }
+ else if(this.style.align == "center")
+ {
+ alignOffset = (maxLineWidth - lineWidths[i]) / 2;
+ }
+ lineAlignOffsets.push(alignOffset);
+ }
+
+ for(i = 0; i < chars.length; i++)
+ {
+ var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
+ c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
+ c.position.y = chars[i].position.y * scale;
+ c.scale.x = c.scale.y = scale;
+ this.addChild(c);
+ }
+
+ this.width = pos.x * scale;
+ this.height = (pos.y + data.lineHeight) * scale;
+};
+
+/**
+ * Updates the transfor of this object
+ *
+ * @method updateTransform
+ * @private
+ */
+PIXI.BitmapText.prototype.updateTransform = function()
+{
+ if(this.dirty)
+ {
+ while(this.children.length > 0)
+ {
+ this.removeChild(this.getChildAt(0));
+ }
+ this.updateText();
+
+ this.dirty = false;
+ }
+
+ PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
+};
+
+PIXI.BitmapText.fonts = {};
diff --git a/src/pixi/text/Text.js b/src/pixi/text/Text.js
new file mode 100644
index 00000000..0b136218
--- /dev/null
+++ b/src/pixi/text/Text.js
@@ -0,0 +1,285 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * A Text Object will create a line(s) of text to split a line you can use "\n"
+ *
+ * @class Text
+ * @extends Sprite
+ * @constructor
+ * @param text {String} The copy that you would like the text to display
+ * @param [style] {Object} The style parameters
+ * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font
+ * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00"
+ * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
+ * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
+ * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke)
+ * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used
+ * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap
+ */
+PIXI.Text = function(text, style)
+{
+ this.canvas = document.createElement("canvas");
+ this.context = this.canvas.getContext("2d");
+ PIXI.Sprite.call(this, PIXI.Texture.fromCanvas(this.canvas));
+
+ this.setText(text);
+ this.setStyle(style);
+
+ this.updateText();
+ this.dirty = false;
+};
+
+// constructor
+PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype);
+PIXI.Text.prototype.constructor = PIXI.Text;
+
+/**
+ * Set the style of the text
+ *
+ * @method setStyle
+ * @param [style] {Object} The style parameters
+ * @param [style.font="bold 20pt Arial"] {String} The style and size of the font
+ * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00"
+ * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
+ * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
+ * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke)
+ * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used
+ * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap
+ */
+PIXI.Text.prototype.setStyle = function(style)
+{
+ style = style || {};
+ style.font = style.font || "bold 20pt Arial";
+ style.fill = style.fill || "black";
+ style.align = style.align || "left";
+ style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136
+ style.strokeThickness = style.strokeThickness || 0;
+ style.wordWrap = style.wordWrap || false;
+ style.wordWrapWidth = style.wordWrapWidth || 100;
+ this.style = style;
+ this.dirty = true;
+};
+
+/**
+ * Set the copy for the text object. To split a line you can use "\n"
+ *
+ * @methos setText
+ * @param {String} text The copy that you would like the text to display
+ */
+PIXI.Sprite.prototype.setText = function(text)
+{
+ this.text = text.toString() || " ";
+ this.dirty = true;
+};
+
+/**
+ * Renders text
+ *
+ * @method updateText
+ * @private
+ */
+PIXI.Text.prototype.updateText = function()
+{
+ this.context.font = this.style.font;
+
+ var outputText = this.text;
+
+ // word wrap
+ // preserve original text
+ if(this.style.wordWrap)outputText = this.wordWrap(this.text);
+
+ //split text into lines
+ var lines = outputText.split(/(?:\r\n|\r|\n)/);
+
+ //calculate text width
+ var lineWidths = [];
+ var maxLineWidth = 0;
+ for (var i = 0; i < lines.length; i++)
+ {
+ var lineWidth = this.context.measureText(lines[i]).width;
+ lineWidths[i] = lineWidth;
+ maxLineWidth = Math.max(maxLineWidth, lineWidth);
+ }
+ this.canvas.width = maxLineWidth + this.style.strokeThickness;
+
+ //calculate text height
+ var lineHeight = this.determineFontHeight("font: " + this.style.font + ";") + this.style.strokeThickness;
+ this.canvas.height = lineHeight * lines.length;
+
+ //set canvas text styles
+ this.context.fillStyle = this.style.fill;
+ this.context.font = this.style.font;
+
+ this.context.strokeStyle = this.style.stroke;
+ this.context.lineWidth = this.style.strokeThickness;
+
+ this.context.textBaseline = "top";
+
+ //draw lines line by line
+ for (i = 0; i < lines.length; i++)
+ {
+ var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight);
+
+ if(this.style.align == "right")
+ {
+ linePosition.x += maxLineWidth - lineWidths[i];
+ }
+ else if(this.style.align == "center")
+ {
+ linePosition.x += (maxLineWidth - lineWidths[i]) / 2;
+ }
+
+ if(this.style.stroke && this.style.strokeThickness)
+ {
+ this.context.strokeText(lines[i], linePosition.x, linePosition.y);
+ }
+
+ if(this.style.fill)
+ {
+ this.context.fillText(lines[i], linePosition.x, linePosition.y);
+ }
+ }
+
+ this.updateTexture();
+};
+
+/**
+ * Updates texture size based on canvas size
+ *
+ * @method updateTexture
+ * @private
+ */
+PIXI.Text.prototype.updateTexture = function()
+{
+ this.texture.baseTexture.width = this.canvas.width;
+ this.texture.baseTexture.height = this.canvas.height;
+ this.texture.frame.width = this.canvas.width;
+ this.texture.frame.height = this.canvas.height;
+
+ this._width = this.canvas.width;
+ this._height = this.canvas.height;
+
+ PIXI.texturesToUpdate.push(this.texture.baseTexture);
+};
+
+/**
+ * Updates the transfor of this object
+ *
+ * @method updateTransform
+ * @private
+ */
+PIXI.Text.prototype.updateTransform = function()
+{
+ if(this.dirty)
+ {
+ this.updateText();
+ this.dirty = false;
+ }
+
+ PIXI.Sprite.prototype.updateTransform.call(this);
+};
+
+/*
+ * http://stackoverflow.com/users/34441/ellisbben
+ * great solution to the problem!
+ *
+ * @method determineFontHeight
+ * @param fontStyle {Object}
+ * @private
+ */
+PIXI.Text.prototype.determineFontHeight = function(fontStyle)
+{
+ // build a little reference dictionary so if the font style has been used return a
+ // cached version...
+ var result = PIXI.Text.heightCache[fontStyle];
+
+ if(!result)
+ {
+ var body = document.getElementsByTagName("body")[0];
+ var dummy = document.createElement("div");
+ var dummyText = document.createTextNode("M");
+ dummy.appendChild(dummyText);
+ dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0');
+ body.appendChild(dummy);
+
+ result = dummy.offsetHeight;
+ PIXI.Text.heightCache[fontStyle] = result;
+
+ body.removeChild(dummy);
+ }
+
+ return result;
+};
+
+/**
+ * A Text Object will apply wordwrap
+ *
+ * @method wordWrap
+ * @param text {String}
+ * @private
+ */
+PIXI.Text.prototype.wordWrap = function(text)
+{
+ // search good wrap position
+ var searchWrapPos = function(ctx, text, start, end, wrapWidth)
+ {
+ var p = Math.floor((end-start) / 2) + start;
+ if(p == start) {
+ return 1;
+ }
+
+ if(ctx.measureText(text.substring(0,p)).width <= wrapWidth)
+ {
+ if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth)
+ {
+ return p;
+ }
+ else
+ {
+ return arguments.callee(ctx, text, p, end, wrapWidth);
+ }
+ }
+ else
+ {
+ return arguments.callee(ctx, text, start, p, wrapWidth);
+ }
+ };
+
+ var lineWrap = function(ctx, text, wrapWidth)
+ {
+ if(ctx.measureText(text).width <= wrapWidth || text.length < 1)
+ {
+ return text;
+ }
+ var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth);
+ return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth);
+ };
+
+ var result = "";
+ var lines = text.split("\n");
+ for (var i = 0; i < lines.length; i++)
+ {
+ result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n";
+ }
+
+ return result;
+};
+
+/**
+ * Destroys this text object
+ *
+ * @method destroy
+ * @param destroyTexture {Boolean}
+ */
+PIXI.Text.prototype.destroy = function(destroyTexture)
+{
+ if(destroyTexture)
+ {
+ this.texture.destroy();
+ }
+
+};
+
+PIXI.Text.heightCache = {};
diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js
new file mode 100644
index 00000000..4b7e7acb
--- /dev/null
+++ b/src/pixi/textures/BaseTexture.js
@@ -0,0 +1,141 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+PIXI.BaseTextureCache = {};
+PIXI.texturesToUpdate = [];
+PIXI.texturesToDestroy = [];
+
+/**
+ * A texture stores the information that represents an image. All textures have a base texture
+ *
+ * @class BaseTexture
+ * @uses EventTarget
+ * @constructor
+ * @param source {String} the source object (image or canvas)
+ */
+PIXI.BaseTexture = function(source)
+{
+ PIXI.EventTarget.call( this );
+
+ /**
+ * [read-only] The width of the base texture set when the image has loaded
+ *
+ * @property width
+ * @type Number
+ * @readOnly
+ */
+ this.width = 100;
+
+ /**
+ * [read-only] The height of the base texture set when the image has loaded
+ *
+ * @property height
+ * @type Number
+ * @readOnly
+ */
+ this.height = 100;
+
+ /**
+ * [read-only] Describes if the base texture has loaded or not
+ *
+ * @property hasLoaded
+ * @type Boolean
+ * @readOnly
+ */
+ this.hasLoaded = false;
+
+ /**
+ * The source that is loaded to create the texture
+ *
+ * @property source
+ * @type Image
+ */
+ this.source = source;
+
+ if(!source)return;
+
+ if(this.source instanceof Image || this.source instanceof HTMLImageElement)
+ {
+ if(this.source.complete)
+ {
+ this.hasLoaded = true;
+ this.width = this.source.width;
+ this.height = this.source.height;
+
+ PIXI.texturesToUpdate.push(this);
+ }
+ else
+ {
+
+ var scope = this;
+ this.source.onload = function(){
+
+ scope.hasLoaded = true;
+ scope.width = scope.source.width;
+ scope.height = scope.source.height;
+
+ // add it to somewhere...
+ PIXI.texturesToUpdate.push(scope);
+ scope.dispatchEvent( { type: 'loaded', content: scope } );
+ }
+ // this.image.src = imageUrl;
+ }
+ }
+ else
+ {
+ this.hasLoaded = true;
+ this.width = this.source.width;
+ this.height = this.source.height;
+
+ PIXI.texturesToUpdate.push(this);
+ }
+
+ this._powerOf2 = false;
+}
+
+PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture;
+
+/**
+ * Destroys this base texture
+ *
+ * @method destroy
+ */
+PIXI.BaseTexture.prototype.destroy = function()
+{
+ if(this.source instanceof Image)
+ {
+ this.source.src = null;
+ }
+ this.source = null;
+ PIXI.texturesToDestroy.push(this);
+}
+
+/**
+ * Helper function that returns a base texture based on an image url
+ * If the image is not in the base texture cache it will be created and loaded
+ *
+ * @static
+ * @method fromImage
+ * @param imageUrl {String} The image url of the texture
+ * @return BaseTexture
+ */
+PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin)
+{
+ var baseTexture = PIXI.BaseTextureCache[imageUrl];
+ if(!baseTexture)
+ {
+ // new Image() breaks tex loading in some versions of Chrome.
+ // See https://code.google.com/p/chromium/issues/detail?id=238071
+ var image = new Image();//document.createElement('img');
+ if (crossorigin)
+ {
+ image.crossOrigin = '';
+ }
+ image.src = imageUrl;
+ baseTexture = new PIXI.BaseTexture(image);
+ PIXI.BaseTextureCache[imageUrl] = baseTexture;
+ }
+
+ return baseTexture;
+}
diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js
new file mode 100644
index 00000000..25b2cfe1
--- /dev/null
+++ b/src/pixi/textures/RenderTexture.js
@@ -0,0 +1,252 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it.
+
+ __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded.
+ Otherwise black rectangles will be drawn instead.
+
+ RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example:
+
+ var renderTexture = new PIXI.RenderTexture(800, 600);
+ var sprite = PIXI.Sprite.fromImage("spinObj_01.png");
+ sprite.position.x = 800/2;
+ sprite.position.y = 600/2;
+ sprite.anchor.x = 0.5;
+ sprite.anchor.y = 0.5;
+ renderTexture.render(sprite);
+
+ Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used:
+
+ var doc = new PIXI.DisplayObjectContainer();
+ doc.addChild(sprite);
+ renderTexture.render(doc); // Renders to center of renderTexture
+
+ @class RenderTexture
+ @extends Texture
+ @constructor
+ @param width {Number} The width of the render texture
+ @param height {Number} The height of the render texture
+ */
+PIXI.RenderTexture = function(width, height)
+{
+ PIXI.EventTarget.call( this );
+
+ this.width = width || 100;
+ this.height = height || 100;
+
+ this.indetityMatrix = PIXI.mat3.create();
+
+ this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
+
+ if(PIXI.gl)
+ {
+ this.initWebGL();
+ }
+ else
+ {
+ this.initCanvas();
+ }
+}
+
+PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype );
+PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture;
+
+/**
+ * Initializes the webgl data for this texture
+ *
+ * @method initWebGL
+ * @private
+ */
+PIXI.RenderTexture.prototype.initWebGL = function()
+{
+ var gl = PIXI.gl;
+ this.glFramebuffer = gl.createFramebuffer();
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
+
+ this.glFramebuffer.width = this.width;
+ this.glFramebuffer.height = this.height;
+
+ this.baseTexture = new PIXI.BaseTexture();
+
+ this.baseTexture.width = this.width;
+ this.baseTexture.height = this.height;
+
+ this.baseTexture._glTexture = gl.createTexture();
+ gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture);
+
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
+
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+
+ this.baseTexture.isRender = true;
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0);
+
+ // create a projection matrix..
+ this.projection = new PIXI.Point(this.width/2 , this.height/2);
+
+ // set the correct render function..
+ this.render = this.renderWebGL;
+
+
+}
+
+
+PIXI.RenderTexture.prototype.resize = function(width, height)
+{
+
+ this.width = width;
+ this.height = height;
+
+ if(PIXI.gl)
+ {
+ this.projection.x = this.width/2
+ this.projection.y = this.height/2;
+
+ var gl = PIXI.gl;
+ gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture);
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
+ }
+ else
+ {
+
+ this.frame.width = this.width
+ this.frame.height = this.height;
+ this.renderer.resize(this.width, this.height);
+ }
+}
+
+/**
+ * Initializes the canvas data for this texture
+ *
+ * @method initCanvas
+ * @private
+ */
+PIXI.RenderTexture.prototype.initCanvas = function()
+{
+ this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0);
+
+ this.baseTexture = new PIXI.BaseTexture(this.renderer.view);
+ this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
+
+ this.render = this.renderCanvas;
+}
+
+/**
+ * This function will draw the display object to the texture.
+ *
+ * @method renderWebGL
+ * @param displayObject {DisplayObject} The display object to render this texture on
+ * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
+ * @private
+ */
+PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear)
+{
+ var gl = PIXI.gl;
+
+ // enable the alpha color mask..
+ gl.colorMask(true, true, true, true);
+
+ gl.viewport(0, 0, this.width, this.height);
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
+
+ if(clear)
+ {
+ gl.clearColor(0,0,0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ }
+
+ // THIS WILL MESS WITH HIT TESTING!
+ var children = displayObject.children;
+
+ //TODO -? create a new one??? dont think so!
+ var originalWorldTransform = displayObject.worldTransform;
+ displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix;
+ // modify to flip...
+ displayObject.worldTransform[4] = -1;
+ displayObject.worldTransform[5] = this.projection.y * 2;
+
+
+ if(position)
+ {
+ displayObject.worldTransform[2] = position.x;
+ displayObject.worldTransform[5] -= position.y;
+ }
+
+ PIXI.visibleCount++;
+ displayObject.vcount = PIXI.visibleCount;
+
+ for(var i=0,j=children.length; i this.baseTexture.width || frame.y + frame.height > this.baseTexture.height)
+ {
+ throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this);
+ }
+
+ this.updateFrame = true;
+
+ PIXI.Texture.frameUpdates.push(this);
+ //this.dispatchEvent( { type: 'update', content: this } );
+}
+
+/**
+ * Helper function that returns a texture based on an image url
+ * If the image is not in the texture cache it will be created and loaded
+ *
+ * @static
+ * @method fromImage
+ * @param imageUrl {String} The image url of the texture
+ * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
+ * @return Texture
+ */
+PIXI.Texture.fromImage = function(imageUrl, crossorigin)
+{
+ var texture = PIXI.TextureCache[imageUrl];
+
+ if(!texture)
+ {
+ texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin));
+ PIXI.TextureCache[imageUrl] = texture;
+ }
+
+ return texture;
+}
+
+/**
+ * Helper function that returns a texture based on a frame id
+ * If the frame id is not in the texture cache an error will be thrown
+ *
+ * @static
+ * @method fromFrame
+ * @param frameId {String} The frame id of the texture
+ * @return Texture
+ */
+PIXI.Texture.fromFrame = function(frameId)
+{
+ var texture = PIXI.TextureCache[frameId];
+ if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache " + this);
+ return texture;
+}
+
+/**
+ * Helper function that returns a texture based on a canvas element
+ * If the canvas is not in the texture cache it will be created and loaded
+ *
+ * @static
+ * @method fromCanvas
+ * @param canvas {Canvas} The canvas element source of the texture
+ * @return Texture
+ */
+PIXI.Texture.fromCanvas = function(canvas)
+{
+ var baseTexture = new PIXI.BaseTexture(canvas);
+ return new PIXI.Texture(baseTexture);
+}
+
+
+/**
+ * Adds a texture to the textureCache.
+ *
+ * @static
+ * @method addTextureToCache
+ * @param texture {Texture}
+ * @param id {String} the id that the texture will be stored against.
+ */
+PIXI.Texture.addTextureToCache = function(texture, id)
+{
+ PIXI.TextureCache[id] = texture;
+}
+
+/**
+ * Remove a texture from the textureCache.
+ *
+ * @static
+ * @method removeTextureFromCache
+ * @param id {String} the id of the texture to be removed
+ * @return {Texture} the texture that was removed
+ */
+PIXI.Texture.removeTextureFromCache = function(id)
+{
+ var texture = PIXI.TextureCache[id]
+ PIXI.TextureCache[id] = null;
+ return texture;
+}
+
+// this is more for webGL.. it contains updated frames..
+PIXI.Texture.frameUpdates = [];
+
diff --git a/src/pixi/utils/Detector.js b/src/pixi/utils/Detector.js
new file mode 100644
index 00000000..d04a5687
--- /dev/null
+++ b/src/pixi/utils/Detector.js
@@ -0,0 +1,37 @@
+/**
+ * @author Mat Groves http://matgroves.com/ @Doormat23
+ */
+
+/**
+ * This helper function will automatically detect which renderer you should be using.
+ * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by
+ * the browser then this function will return a canvas renderer
+ *
+ * @method autoDetectRenderer
+ * @static
+ * @param width {Number} the width of the renderers view
+ * @param height {Number} the height of the renderers view
+ * @param view {Canvas} the canvas to use as a view, optional
+ * @param transparent=false {Boolean} the transparency of the render view, default false
+ * @param antialias=false {Boolean} sets antialias (only applicable in webGL chrome at the moment)
+ *
+ * antialias
+ */
+PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias)
+{
+ if(!width)width = 800;
+ if(!height)height = 600;
+
+ // BORROWED from Mr Doob (mrdoob.com)
+ var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )();
+
+ //console.log(webgl);
+ if( webgl )
+ {
+ return new PIXI.WebGLRenderer(width, height, view, transparent, antialias);
+ }
+
+ return new PIXI.CanvasRenderer(width, height, view, transparent);
+};
+
+
diff --git a/src/pixi/utils/EventTarget.js b/src/pixi/utils/EventTarget.js
new file mode 100644
index 00000000..8dc54a5f
--- /dev/null
+++ b/src/pixi/utils/EventTarget.js
@@ -0,0 +1,60 @@
+/**
+ * https://github.com/mrdoob/eventtarget.js/
+ * THankS mr DOob!
+ */
+
+/**
+ * Adds event emitter functionality to a class
+ *
+ * @class EventTarget
+ * @example
+ * function MyEmitter() {
+ * PIXI.EventTarget.call(this); //mixes in event target stuff
+ * }
+ *
+ * var em = new MyEmitter();
+ * em.emit({ type: 'eventName', data: 'some data' });
+ */
+PIXI.EventTarget = function () {
+
+ var listeners = {};
+
+ this.addEventListener = this.on = function ( type, listener ) {
+
+
+ if ( listeners[ type ] === undefined ) {
+
+ listeners[ type ] = [];
+
+ }
+
+ if ( listeners[ type ].indexOf( listener ) === - 1 ) {
+
+ listeners[ type ].push( listener );
+ }
+
+ };
+
+ this.dispatchEvent = this.emit = function ( event ) {
+
+ for ( var listener in listeners[ event.type ] ) {
+
+ listeners[ event.type ][ listener ]( event );
+
+ }
+
+ };
+
+ this.removeEventListener = this.off = function ( type, listener ) {
+
+ var index = listeners[ type ].indexOf( listener );
+
+ if ( index !== - 1 ) {
+
+ listeners[ type ].splice( index, 1 );
+
+ }
+
+ };
+
+};
diff --git a/src/pixi/utils/Polyk.js b/src/pixi/utils/Polyk.js
new file mode 100644
index 00000000..84d290f1
--- /dev/null
+++ b/src/pixi/utils/Polyk.js
@@ -0,0 +1,149 @@
+/*
+ PolyK library
+ url: http://polyk.ivank.net
+ Released under MIT licence.
+
+ Copyright (c) 2012 Ivan Kuckir
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ This is an amazing lib!
+
+ slightly modified by mat groves (matgroves.com);
+*/
+
+PIXI.PolyK = {};
+
+/**
+ * Triangulates shapes for webGL graphic fills
+ *
+ * @method Triangulate
+ * @namespace PolyK
+ * @constructor
+ */
+PIXI.PolyK.Triangulate = function(p)
+{
+ var sign = true;
+
+ var n = p.length>>1;
+ if(n<3) return [];
+ var tgs = [];
+ var avl = [];
+ for(var i=0; i 3)
+ {
+ var i0 = avl[(i+0)%al];
+ var i1 = avl[(i+1)%al];
+ var i2 = avl[(i+2)%al];
+
+ var ax = p[2*i0], ay = p[2*i0+1];
+ var bx = p[2*i1], by = p[2*i1+1];
+ var cx = p[2*i2], cy = p[2*i2+1];
+
+ var earFound = false;
+ if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign))
+ {
+ earFound = true;
+ for(var j=0; j 3*al)
+ {
+ // need to flip flip reverse it!
+ // reset!
+ if(sign)
+ {
+ var tgs = [];
+ avl = [];
+ for(var i=0; i= 0) && (v >= 0) && (u + v < 1);
+}
+
+/**
+ * Checks if a shape is convex
+ *
+ * @class _convex
+ * @namespace PolyK
+ * @private
+ */
+PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign)
+{
+ return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign;
+}
diff --git a/src/pixi/utils/Utils.js b/src/pixi/utils/Utils.js
new file mode 100644
index 00000000..9534c839
--- /dev/null
+++ b/src/pixi/utils/Utils.js
@@ -0,0 +1,142 @@
+// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
+// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
+
+// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
+
+// MIT license
+
+/**
+ * A polyfill for requestAnimationFrame
+ *
+ * @method requestAnimationFrame
+ */
+/**
+ * A polyfill for cancelAnimationFrame
+ *
+ * @method cancelAnimationFrame
+ */
+var lastTime = 0;
+var vendors = ['ms', 'moz', 'webkit', 'o'];
+for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
+ window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
+ window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
+ || window[vendors[x]+'CancelRequestAnimationFrame'];
+}
+
+if (!window.requestAnimationFrame)
+ window.requestAnimationFrame = function(callback, element) {
+ var currTime = new Date().getTime();
+ var timeToCall = Math.max(0, 16 - (currTime - lastTime));
+ var id = window.setTimeout(function() { callback(currTime + timeToCall); },
+ timeToCall);
+ lastTime = currTime + timeToCall;
+ return id;
+ };
+
+if (!window.cancelAnimationFrame)
+ window.cancelAnimationFrame = function(id) {
+ clearTimeout(id);
+ };
+
+window.requestAnimFrame = window.requestAnimationFrame;
+
+/**
+ * Converts a hex color number to an [R, G, B] array
+ *
+ * @method HEXtoRGB
+ * @param hex {Number}
+ */
+function HEXtoRGB(hex) {
+ return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
+}
+
+/**
+ * A polyfill for Function.prototype.bind
+ *
+ * @method bind
+ */
+if (typeof Function.prototype.bind != 'function') {
+ Function.prototype.bind = (function () {
+ var slice = Array.prototype.slice;
+ return function (thisArg) {
+ var target = this, boundArgs = slice.call(arguments, 1);
+
+ if (typeof target != 'function') throw new TypeError();
+
+ function bound() {
+ var args = boundArgs.concat(slice.call(arguments));
+ target.apply(this instanceof bound ? this : thisArg, args);
+ }
+
+ bound.prototype = (function F(proto) {
+ proto && (F.prototype = proto);
+ if (!(this instanceof F)) return new F;
+ })(target.prototype);
+
+ return bound;
+ };
+ })();
+}
+
+/**
+ * A wrapper for ajax requests to be handled cross browser
+ *
+ * @class AjaxRequest
+ * @constructor
+ */
+var AjaxRequest = PIXI.AjaxRequest = function()
+{
+ var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
+
+ if (window.ActiveXObject)
+ { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
+ for (var i=0; i>>>>>>>>")
+ console.log("_")
+ var safe = 0;
+ var tmp = item.first;
+ console.log(tmp);
+
+ while(tmp._iNext)
+ {
+ safe++;
+ tmp = tmp._iNext;
+ console.log(tmp);
+ // console.log(tmp);
+
+ if(safe > 100)
+ {
+ console.log("BREAK")
+ break
+ }
+ }
+}
+
+
+
+
+
diff --git a/src/system/Device.js b/src/system/Device.js
new file mode 100644
index 00000000..0f11e28c
--- /dev/null
+++ b/src/system/Device.js
@@ -0,0 +1,486 @@
+/**
+* Phaser - Device
+*
+* Detects device support capabilities. Using some elements from System.js by MrDoob and Modernizr
+* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/audio.js
+*/
+
+Phaser.Device = function () {
+
+ /**
+ * An optional 'fix' for the horrendous Android stock browser bug
+ * https://code.google.com/p/android/issues/detail?id=39247
+ * @type {boolean}
+ */
+ this.patchAndroidClearRectBug = false;
+
+ // Operating System
+
+ /**
+ * Is running desktop?
+ * @type {boolean}
+ */
+ this.desktop = false;
+
+ /**
+ * Is running on iOS?
+ * @type {boolean}
+ */
+ this.iOS = false;
+
+ /**
+ * Is running on android?
+ * @type {boolean}
+ */
+ this.android = false;
+
+ /**
+ * Is running on chromeOS?
+ * @type {boolean}
+ */
+ this.chromeOS = false;
+
+ /**
+ * Is running on linux?
+ * @type {boolean}
+ */
+ this.linux = false;
+
+ /**
+ * Is running on maxOS?
+ * @type {boolean}
+ */
+ this.macOS = false;
+
+ /**
+ * Is running on windows?
+ * @type {boolean}
+ */
+ this.windows = false;
+
+ // Features
+
+ /**
+ * Is canvas available?
+ * @type {boolean}
+ */
+ this.canvas = false;
+
+ /**
+ * Is file available?
+ * @type {boolean}
+ */
+ this.file = false;
+
+ /**
+ * Is fileSystem available?
+ * @type {boolean}
+ */
+ this.fileSystem = false;
+
+ /**
+ * Is localStorage available?
+ * @type {boolean}
+ */
+ this.localStorage = false;
+
+ /**
+ * Is webGL available?
+ * @type {boolean}
+ */
+ this.webGL = false;
+
+ /**
+ * Is worker available?
+ * @type {boolean}
+ */
+ this.worker = false;
+
+ /**
+ * Is touch available?
+ * @type {boolean}
+ */
+ this.touch = false;
+
+ /**
+ * Is mspointer available?
+ * @type {boolean}
+ */
+ this.mspointer = false;
+
+ /**
+ * Is css3D available?
+ * @type {boolean}
+ */
+ this.css3D = false;
+
+ // Browser
+
+ /**
+ * Is running in arora?
+ * @type {boolean}
+ */
+ this.arora = false;
+
+ /**
+ * Is running in chrome?
+ * @type {boolean}
+ */
+ this.chrome = false;
+
+ /**
+ * Is running in epiphany?
+ * @type {boolean}
+ */
+ this.epiphany = false;
+
+ /**
+ * Is running in firefox?
+ * @type {boolean}
+ */
+ this.firefox = false;
+
+ /**
+ * Is running in ie?
+ * @type {boolean}
+ */
+ this.ie = false;
+
+ /**
+ * Version of ie?
+ * @type Number
+ */
+ this.ieVersion = 0;
+
+ /**
+ * Is running in mobileSafari?
+ * @type {boolean}
+ */
+ this.mobileSafari = false;
+
+ /**
+ * Is running in midori?
+ * @type {boolean}
+ */
+ this.midori = false;
+
+ /**
+ * Is running in opera?
+ * @type {boolean}
+ */
+ this.opera = false;
+
+ /**
+ * Is running in safari?
+ * @type {boolean}
+ */
+ this.safari = false;
+ this.webApp = false;
+
+ // Audio
+
+ /**
+ * Are Audio tags available?
+ * @type {boolean}
+ */
+ this.audioData = false;
+
+ /**
+ * Is the WebAudio API available?
+ * @type {boolean}
+ */
+ this.webAudio = false;
+
+ /**
+ * Can this device play ogg files?
+ * @type {boolean}
+ */
+ this.ogg = false;
+
+ /**
+ * Can this device play opus files?
+ * @type {boolean}
+ */
+ this.opus = false;
+
+ /**
+ * Can this device play mp3 files?
+ * @type {boolean}
+ */
+ this.mp3 = false;
+
+ /**
+ * Can this device play wav files?
+ * @type {boolean}
+ */
+ this.wav = false;
+ /**
+ * Can this device play m4a files?
+ * @type {boolean}
+ */
+ this.m4a = false;
+
+ /**
+ * Can this device play webm files?
+ * @type {boolean}
+ */
+ this.webm = false;
+
+ // Device
+
+ /**
+ * Is running on iPhone?
+ * @type {boolean}
+ */
+ this.iPhone = false;
+
+ /**
+ * Is running on iPhone4?
+ * @type {boolean}
+ */
+ this.iPhone4 = false;
+
+ /**
+ * Is running on iPad?
+ * @type {boolean}
+ */
+ this.iPad = false;
+
+ /**
+ * PixelRatio of the host device?
+ * @type Number
+ */
+ this.pixelRatio = 0;
+
+ // Run the checks
+ this._checkAudio();
+ this._checkBrowser();
+ this._checkCSS3D();
+ this._checkDevice();
+ this._checkFeatures();
+ this._checkOS();
+
+};
+
+Phaser.Device.prototype = {
+
+ /**
+ * Check which OS is game running on.
+ * @private
+ */
+ _checkOS: function () {
+
+ var ua = navigator.userAgent;
+
+ if (/Android/.test(ua)) {
+ this.android = true;
+ } else if (/CrOS/.test(ua)) {
+ this.chromeOS = true;
+ } else if (/iP[ao]d|iPhone/i.test(ua)) {
+ this.iOS = true;
+ } else if (/Linux/.test(ua)) {
+ this.linux = true;
+ } else if (/Mac OS/.test(ua)) {
+ this.macOS = true;
+ } else if (/Windows/.test(ua)) {
+ this.windows = true;
+ }
+
+ if (this.windows || this.macOS || this.linux) {
+ this.desktop = true;
+ }
+
+ },
+
+ /**
+ * Check HTML5 features of the host environment.
+ * @private
+ */
+ _checkFeatures: function () {
+
+ this.canvas = !!window['CanvasRenderingContext2D'];
+
+ try {
+ this.localStorage = !!localStorage.getItem;
+ } catch (error) {
+ this.localStorage = false;
+ }
+
+ this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
+ this.fileSystem = !!window['requestFileSystem'];
+ this.webGL = !!window['WebGLRenderingContext'];
+ this.worker = !!window['Worker'];
+
+ if ('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) {
+ this.touch = true;
+ }
+
+ if (window.navigator.msPointerEnabled) {
+ this.mspointer = true;
+ }
+
+ },
+
+ /**
+ * Check what browser is game running in.
+ * @private
+ */
+ _checkBrowser: function () {
+
+ var ua = navigator.userAgent;
+
+ if (/Arora/.test(ua)) {
+ this.arora = true;
+ } else if (/Chrome/.test(ua)) {
+ this.chrome = true;
+ } else if (/Epiphany/.test(ua)) {
+ this.epiphany = true;
+ } else if (/Firefox/.test(ua)) {
+ this.firefox = true;
+ } else if (/Mobile Safari/.test(ua)) {
+ this.mobileSafari = true;
+ } else if (/MSIE (\d+\.\d+);/.test(ua)) {
+ this.ie = true;
+ this.ieVersion = parseInt(RegExp.$1);
+ } else if (/Midori/.test(ua)) {
+ this.midori = true;
+ } else if (/Opera/.test(ua)) {
+ this.opera = true;
+ } else if (/Safari/.test(ua)) {
+ this.safari = true;
+ }
+
+ // WebApp mode in iOS
+ if (navigator['standalone']) {
+ this.webApp = true;
+ }
+
+ },
+
+ /**
+ * Check audio support.
+ * @private
+ */
+ _checkAudio: function () {
+
+ this.audioData = !!(window['Audio']);
+ this.webAudio = !!(window['webkitAudioContext'] || window['AudioContext']);
+ var audioElement = document.createElement('audio');
+ var result = false;
+
+ try {
+ if (result = !!audioElement.canPlayType) {
+
+ if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
+ this.ogg = true;
+ }
+
+ if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '')) {
+ this.opus = true;
+ }
+
+ if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
+ this.mp3 = true;
+ }
+
+ // Mimetypes accepted:
+ // developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
+ // bit.ly/iphoneoscodecs
+ if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
+ this.wav = true;
+ }
+
+ if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
+ this.m4a = true;
+ }
+
+ if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
+ this.webm = true;
+ }
+ }
+ } catch (e) {
+ }
+
+ },
+
+ /**
+ * Check PixelRatio of devices.
+ * @private
+ */
+ _checkDevice: function () {
+
+ this.pixelRatio = window['devicePixelRatio'] || 1;
+ this.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
+ this.iPhone4 = (this.pixelRatio == 2 && this.iPhone);
+ this.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
+
+ },
+
+ /**
+ * Check whether the host environment support 3D CSS.
+ * @private
+ */
+ _checkCSS3D: function () {
+ var el = document.createElement('p');
+ var has3d;
+ var transforms = {
+ 'webkitTransform': '-webkit-transform',
+ 'OTransform': '-o-transform',
+ 'msTransform': '-ms-transform',
+ 'MozTransform': '-moz-transform',
+ 'transform': 'transform'
+ };
+ // Add it to the body to get the computed style.
+ document.body.insertBefore(el, null);
+
+ for (var t in transforms) {
+ if (el.style[t] !== undefined) {
+ el.style[t] = "translate3d(1px,1px,1px)";
+ has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
+ }
+ }
+ document.body.removeChild(el);
+ this.css3D = (has3d !== undefined && has3d.length > 0 && has3d !== "none");
+
+ },
+
+ canPlayAudio: function (type) {
+
+ if (type == 'mp3' && this.mp3) {
+ return true;
+ } else if (type == 'ogg' && (this.ogg || this.opus)) {
+ return true;
+ } else if (type == 'm4a' && this.m4a) {
+ return true;
+ } else if (type == 'wav' && this.wav) {
+ return true;
+ } else if (type == 'webm' && this.webm) {
+ return true;
+ }
+
+ return false;
+
+ },
+
+ isConsoleOpen: function () {
+
+ if (window.console && window.console['firebug']) {
+ return true;
+ }
+
+ if (window.console) {
+ console.profile();
+ console.profileEnd();
+
+ if (console.clear) {
+ console.clear();
+ }
+
+ return console['profiles'].length > 0;
+ }
+
+ return false;
+
+ }
+
+};
diff --git a/src/time/Time.js b/src/time/Time.js
new file mode 100644
index 00000000..b3cee2e9
--- /dev/null
+++ b/src/time/Time.js
@@ -0,0 +1,250 @@
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
+* @module Phaser.Time
+*/
+
+/**
+* This is the core internal game clock. It manages the elapsed time and calculation of delta values,
+* used for game object motion and tweens.
+*
+* @class Time
+* @constructor
+* @param {Phaser.Game} game A reference to the currently running game.
+*/
+Phaser.Time = function (game) {
+
+ this.game = game;
+
+ this.game.onPause.add(this.gamePaused, this);
+ this.game.onResume.add(this.gameResumed, this);
+
+};
+
+Phaser.Time.prototype = {
+
+ /**
+ * A reference to the currently running Game.
+ * @property game
+ * @type {Phaser.Game}
+ */
+ game: null,
+
+ /**
+ * The time at which the Game instance started.
+ * @property _started
+ * @private
+ * @type {Number}
+ */
+ _started: 0;
+
+ /**
+ * The time (in ms) that the last second counter ticked over.
+ * @property _timeLastSecond
+ * @private
+ * @type {Number}
+ */
+ _timeLastSecond: number = 0;
+
+ /**
+ * The time the game started being paused.
+ * @property _pauseStarted
+ * @private
+ * @type {Number}
+ */
+ _pauseStarted: 0,
+
+ /**
+ * The elapsed time calculated for the physics motion updates.
+ * @property physicsElapsed
+ * @public
+ * @type {Number}
+ */
+ physicsElapsed: 0,
+
+ /**
+ * Game time counter.
+ * @property time
+ * @public
+ * @type {Number}
+ */
+ time: 0,
+
+ /**
+ * Records how long the game has been paused for. Is reset each time the game pauses.
+ * @property pausedTime
+ * @public
+ * @type {Number}
+ */
+ pausedTime: 0,
+
+ /**
+ * The time right now.
+ * @property now
+ * @public
+ * @type {Number}
+ */
+ now: 0,
+
+ /**
+ * Elapsed time since the last frame.
+ * @property delta
+ * @public
+ * @type {Number}
+ */
+ delta: 0,
+
+ /**
+ * Frames per second.
+ * @property fps
+ * @public
+ * @type {Number}
+ */
+ fps: 0,
+
+ /**
+ * The lowest rate the fps has dropped to.
+ * @property fpsMin
+ * @public
+ * @type {Number}
+ */
+ fpsMin: 1000,
+
+ /**
+ * The highest rate the fps has reached (usually no higher than 60fps).
+ * @property fpsMax
+ * @public
+ * @type {Number}
+ */
+ fpsMax: 0,
+
+ /**
+ * The minimum amount of time the game has taken between two frames.
+ * @property msMin
+ * @public
+ * @type {Number}
+ */
+ msMin: 1000,
+
+ /**
+ * The maximum amount of time the game has taken between two frames.
+ * @property msMax
+ * @public
+ * @type {Number}
+ */
+ msMax: 0,
+
+ /**
+ * The number of frames record in the last second.
+ * @property frames
+ * @public
+ * @type {Number}
+ */
+ frames: 0,
+
+ /**
+ * Records how long the game was paused for in miliseconds.
+ * @property pauseDuration
+ * @public
+ * @type {Number}
+ */
+ pauseDuration: 0,
+
+ /**
+ * The number of seconds that have elapsed since the game was started.
+ * @method totalElapsedSeconds
+ * @return {Number}
+ */
+ totalElapsedSeconds: function() {
+ return (this.now - this._started) * 0.001;
+ },
+
+ /**
+ * Update clock and calculate the fps.
+ * This is called automatically by Game._raf
+ * @method update
+ * @param {Number} raf The current timestamp, either performance.now or Date.now
+ */
+ update: function (raf) {
+
+ this.now = raf;
+ this.delta = this.now - this.time;
+
+ this.msMin = Math.min(this.msMin, this.delta);
+ this.msMax = Math.max(this.msMax, this.delta);
+
+ this.frames++;
+
+ if (this.now > this._timeLastSecond + 1000)
+ {
+ this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
+ this.fpsMin = Math.min(this.fpsMin, this.fps);
+ this.fpsMax = Math.max(this.fpsMax, this.fps);
+ this._timeLastSecond = this.now;
+ this.frames = 0;
+ }
+
+ this.time = this.now;
+ this.physicsElapsed = 1.0 * (this.delta / 1000);
+
+ // Paused?
+ if (this.game.paused) {
+ this.pausedTime = this.now - this._pauseStarted;
+ }
+
+ },
+
+ /**
+ * Called when the game enters a paused state.
+ * @method gamePaused
+ * @private
+ */
+ gamePaused: function () {
+ this._pauseStarted = this.now;
+ },
+
+ /**
+ * Called when the game resumes from a paused state.
+ * @method gameResumed
+ * @private
+ */
+ gameResumed: function () {
+
+ // Level out the delta timer to avoid spikes
+ this.delta = 0;
+ this.physicsElapsed = 0;
+ this.time = Date.now();
+ this.pauseDuration = this.pausedTime;
+
+ },
+
+ /**
+ * How long has passed since the given time.
+ * @method elapsedSince
+ * @param {Number} since The time you want to measure against.
+ * @return {Number} The difference between the given time and now.
+ */
+ elapsedSince: function (since) {
+ return this.now - since;
+ },
+
+ /**
+ * How long has passed since the given time (in seconds).
+ * @method elapsedSecondsSince
+ * @param {Number} since The time you want to measure (in seconds).
+ * @return {Number} Duration between given time and now (in seconds).
+ */
+ elapsedSecondsSince: function (since) {
+ return (this.now - since) * 0.001;
+ },
+
+ /**
+ * Resets the private _started value to now.
+ * @method reset
+ */
+ reset: function () {
+ this._started = this.now;
+ }
+
+};
\ No newline at end of file