Physics updates

This commit is contained in:
Richard Davey 2013-06-26 14:18:48 +01:00
parent d19ad4976d
commit c647792c12
17 changed files with 998 additions and 1044 deletions

View file

@ -51,15 +51,23 @@ module.exports = function (grunt) {
comments: true
}
},
fx: {
src: ['SpecialFX/**/*.ts'],
dest: 'build/phaser-fx.js',
options: {
target: 'ES5',
declaration: true,
comments: true
}
}
//tests: {
// src: ['Tests/**/*.ts'],
// options: {
// target: 'ES5',
// declaration: true,
// comments: true
// }
// }
//fx: {
// src: ['SpecialFX/**/*.ts'],
// dest: 'build/phaser-fx.js',
// options: {
// target: 'ES5',
// declaration: true,
// comments: true
// }
//}
},
copy: {
main: {

View file

@ -1,5 +1,6 @@
/// <reference path="../Game.ts" />
/// <reference path="../math/Mat3.ts" />
/// <reference path="../geom/Point.ts" />
/**
* Phaser - Components - Transform
@ -98,7 +99,7 @@ module Phaser.Components {
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._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;
@ -240,22 +241,22 @@ module Phaser.Components {
/**
* Scale of the object. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
*/
public scale: Phaser.Vec2;
public scale: Vec2;
/**
* Skew the object along the x and y axis. A skew value of 0 is no skew.
*/
public skew: Phaser.Vec2;
public skew: Vec2;
/**
* The influence of camera movement upon the object, if supported.
*/
public scrollFactor: Phaser.Vec2;
public scrollFactor: Vec2;
/**
* The origin is the point around which scale and rotation takes place and defaults to the top-left of the sprite.
*/
public origin: Phaser.Vec2;
public origin: Vec2;
/**
* This value is added to the rotation of the object.

View file

@ -83,11 +83,12 @@ module Phaser {
* @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.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
* @param [shapeType] The default body shape is either 0 for a Box or 1 for a Circle. See Sprite.body.addShape for custom shapes (polygons, etc)
* @returns {Sprite} The newly created sprite object.
*/
public physicsSprite(x: number, y: number, key?: string = '', frame? = null, shapeType?:number = 0): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, Phaser.Types.BODY_DYNAMIC, shapeType));
public physicsSprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC, shapeType?:number = 0): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType, shapeType));
}
/**

View file

@ -23,6 +23,8 @@ module Phaser {
this.x = x;
this.y = y;
return this;
}
/**

View file

@ -68,7 +68,7 @@ module Phaser {
* @param {Vec2} out The output Vec2 that is the result of the operation.
* @return {Vec2} A Vec2 that is the scaled vector.
*/
static scale(a: Vec2, s: number, out?: Vec2 = new Vec2): Vec2 {
static scale(a: Phaser.Vec2, s: number, out?: Phaser.Vec2 = new Phaser.Vec2): Phaser.Vec2 {
return out.setTo(a.x * s, a.y * s);
}
@ -212,7 +212,7 @@ module Phaser {
* @param {Vec2} out The output Vec2 that is the result of the operation.
* @return {Vec2} A Vec2.
*/
static normalRightHand(a: Vec2, out?: Vec2 = this): Vec2 {
static normalRightHand(a: Vec2, out?: Vec2 = new Vec2): Vec2 {
return out.setTo(a.y * -1, a.x);
}

View file

@ -1,19 +1,3 @@
/**
* Phaser
*
* v1.0.0 - June XX 2013
*
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
*
* Richard Davey (@photonstorm)
*
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
* and my love of game development took a lot of inspiration.
*
* "If you want your children to be intelligent, read them fairy tales."
* "If you want them to be more intelligent, read them more fairy tales."
* -- Albert Einstein
*/
var Phaser;
(function (Phaser) {
Phaser.VERSION = 'Phaser version 1.0.0';

View file

@ -91,7 +91,7 @@ module Phaser.Physics {
/**
* Reference to Phaser.Game
*/
public game: Game;
public game: Phaser.Game;
/**
* Reference to the parent Sprite
@ -461,7 +461,7 @@ module Phaser.Physics {
this.bounds.clear();
for (var i = 0; i < this.shapes.length; i++)
for (var i = 0; i < this.shapesLength; i++)
{
var shape: IShape = this.shapes[i];
shape.cacheData(this.transform);
@ -534,13 +534,13 @@ module Phaser.Physics {
this.angle += this.angularVelocity * dt;
if (this.sprite)
{
this.sprite.x = this.position.x * 50;
this.sprite.y = this.position.y * 50;
if (this.sprite)
{
this.sprite.x = this.position.x * 50;
this.sprite.y = this.position.y * 50;
// Obey fixed rotation?
this.sprite.rotation = this.game.math.radiansToDegrees(this.angle);
}
this.sprite.rotation = this.game.math.radiansToDegrees(this.angle);
}
}

View file

@ -723,7 +723,7 @@ module Phaser.Physics {
Manager.dump("Velocity Solvers", this.bodies[1]);
// 6) Intergrate position
// 6) Integrate position
for (var i = 0; i < this._bl; i++)
{
if (this.bodies[i] && this.bodies[i].isDynamic && this.bodies[i].isAwake)

View file

@ -17,14 +17,20 @@ module Phaser.Physics.Shapes {
// Give in pixels
constructor(x, y, width, height) {
console.log('Box px', x, y, width, height);
x = Manager.pixelsToMeters(x);
y = Manager.pixelsToMeters(y);
width = Manager.pixelsToMeters(width);
height = Manager.pixelsToMeters(height);
console.log('Box m', x, y, width, height);
var hw = width * 0.5;
var hh = height * 0.5;
console.log('Box hh', hw, hh);
super([
{ x: -hw + x, y: +hh + y },
{ x: -hw + x, y: -hh + y },

View file

@ -33,8 +33,10 @@ module Phaser.Physics {
findEdgeByPoint(p: Phaser.Vec2, minDist: number): number;
findVertexByPoint(p: Phaser.Vec2, minDist: number): number;
// The verts of the shape (in local coordinate space)
verts: Phaser.Vec2[];
planes: Phaser.Physics.Plane[];
// The translated verts (in world space)
tverts: Phaser.Vec2[];
tplanes: Phaser.Physics.Plane[];
convexity: bool;

View file

@ -42,6 +42,40 @@ module Phaser {
}
/**
* 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)
*/
static renderPhysicsBodyInfo(body: Phaser.Physics.Body, x: number, y: number, color?: string = 'rgb(255,255,255)') {
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillText('Body ID: ' + body.name, x, y);
DebugUtils.context.fillText('Position x: ' + body.position.x.toFixed(1) + ' y: ' + body.position.y.toFixed(1) + ' rotation: ' + body.angle.toFixed(1), x, y + 14);
DebugUtils.context.fillText('World x: ' + (body.position.x * 50).toFixed(1) + ' y: ' + (body.position.y * 50).toFixed(1), x, y + 28);
DebugUtils.context.fillText('Velocity x: ' + body.velocity.x.toFixed(1) + ' y: ' + body.velocity.y.toFixed(1), x, y + 42);
if (body.shapes[0].verts.length > 0)
{
DebugUtils.context.fillText('Vert 1 x: ' + (body.shapes[0].verts[0].x * 50) + ' y: ' + (body.shapes[0].verts[0].y * 50), x, y + 56);
DebugUtils.context.fillText('Vert 2 x: ' + (body.shapes[0].verts[1].x * 50) + ' y: ' + (body.shapes[0].verts[1].y * 50), x, y + 70);
DebugUtils.context.fillText('Vert 3 x: ' + (body.shapes[0].tverts[2].x * 50) + ' y: ' + (body.shapes[0].tverts[2].y * 50), x, y + 84);
DebugUtils.context.fillText('Vert 4 x: ' + (body.shapes[0].tverts[3].x * 50) + ' y: ' + (body.shapes[0].tverts[3].y * 50), x, y + 98);
/*
DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56);
DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70);
DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84);
DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98);
*/
}
}
static renderSpriteBounds(sprite: Sprite, camera?: Camera = null, color?: string = 'rgba(0,255,0,0.2)') {
if (camera == null)
@ -59,7 +93,7 @@ module Phaser {
static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') {
for (var s = 0; s < body.shapes.length; s++)
for (var s = 0; s < body.shapesLength; s++)
{
DebugUtils.context.beginPath();
@ -67,13 +101,16 @@ module Phaser {
{
var verts = body.shapes[s].tverts;
DebugUtils.context.moveTo((body.position.x + verts[0].x) * 50, (body.position.y + verts[0].y) * 50);
// DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.moveTo(verts[0].x * 50, verts[0].y * 50);
for (var i = 0; i < verts.length; i++) {
DebugUtils.context.lineTo((body.position.x + verts[i].x) * 50, (body.position.y + verts[i].y) * 50);
for (var i = 1; i < verts.length; i++) {
// DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y);
DebugUtils.context.lineTo(verts[i].x * 50, verts[i].y * 50);
}
DebugUtils.context.lineTo((body.position.x + verts[verts.length - 1].x) * 50, (body.position.y + verts[verts.length - 1].y) * 50);
// DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50);
}
else if (body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_CIRCLE)
{

View file

@ -1,12 +1,6 @@
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Flash
*
* The camera is filled with the given color and returns to normal at the given duration.
*/
(function (Camera) {
var Flash = (function () {
function Flash(game) {
@ -15,21 +9,12 @@ var Phaser;
this._fxFlashAlpha = 0;
this._game = game;
}
Flash.prototype.start = /**
* The camera is filled with this color and returns to normal at the given duration.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
function (color, duration, onComplete, force) {
Flash.prototype.start = function (color, duration, onComplete, force) {
if (typeof color === "undefined") { color = 0xffffff; }
if (typeof duration === "undefined") { duration = 1; }
if (typeof onComplete === "undefined") { onComplete = null; }
if (typeof force === "undefined") { force = false; }
if(force === false && this._fxFlashAlpha > 0) {
// You can't flash again unless you force it
return;
}
if(duration <= 0) {
@ -44,7 +29,6 @@ var Phaser;
this._fxFlashComplete = onComplete;
};
Flash.prototype.postUpdate = function () {
// Update the Flash effect
if(this._fxFlashAlpha > 0) {
this._fxFlashAlpha -= this._game.time.elapsed / this._fxFlashDuration;
if(this._game.math.roundTo(this._fxFlashAlpha, -2) <= 0) {
@ -72,38 +56,17 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Border
*
* Creates a border around a camera.
*/
(function (Camera) {
var Border = (function () {
function Border(game, parent) {
/**
* Whether render border of this camera or not. (default is false)
* @type {boolean}
*/
this.showBorder = false;
/**
* Color of border of this camera. (in css color string)
* @type {string}
*/
this.borderColor = 'rgb(255,255,255)';
this._game = game;
this._parent = parent;
}
Border.prototype.start = /**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
function () {
Border.prototype.start = function () {
};
Border.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Border.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
if(this.showBorder == true) {
this._game.stage.context.strokeStyle = this.borderColor;
this._game.stage.context.lineWidth = 1;
@ -122,50 +85,23 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Template
*
* A Template FX file you can use to create your own Camera FX.
* If you don't use any of the methods below (i.e. preUpdate, render, etc) then DELETE THEM to avoid un-necessary calls by the FXManager.
*/
(function (Camera) {
var Template = (function () {
function Template(game, parent) {
this._game = game;
this._parent = parent;
}
Template.prototype.start = /**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
function () {
Template.prototype.start = function () {
};
Template.prototype.preUpdate = /**
* Pre-update is called at the start of the objects update cycle, before any other updates have taken place.
*/
function () {
Template.prototype.preUpdate = function () {
};
Template.prototype.postUpdate = /**
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
*/
function () {
Template.prototype.postUpdate = function () {
};
Template.prototype.preRender = /**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Template.prototype.preRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
};
Template.prototype.render = /**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Template.prototype.render = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
};
Template.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
Template.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
};
return Template;
})();
@ -178,13 +114,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Mirror
*
* Creates a mirror effect for a camera.
* Can mirror the camera image horizontally, vertically or both with an optional fill color overlay.
*/
(function (Camera) {
var Mirror = (function () {
function Mirror(game, parent) {
@ -199,11 +128,7 @@ var Phaser;
this._canvas.height = parent.height;
this._context = this._canvas.getContext('2d');
}
Mirror.prototype.start = /**
* This is the rectangular region to grab from the Camera used in the Mirror effect
* It is rendered to the Stage at Mirror.x/y (note the use of Stage coordinates, not World coordinates)
*/
function (x, y, region, fillColor) {
Mirror.prototype.start = function (x, y, region, fillColor) {
if (typeof fillColor === "undefined") { fillColor = 'rgba(0, 0, 100, 0.5)'; }
this.x = x;
this.y = y;
@ -216,15 +141,7 @@ var Phaser;
this._context.fillStyle = this._mirrorColor;
}
};
Mirror.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
//if (this.cls)
//{
// this._context.clearRect(0, 0, this._mirrorWidth, this._mirrorHeight);
//}
Mirror.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
this._sx = cameraX + this._mirrorX;
this._sy = cameraY + this._mirrorY;
if(this.flipX == true && this.flipY == false) {
@ -232,16 +149,7 @@ var Phaser;
} else if(this.flipY == true && this.flipX == false) {
this._sy = 0;
}
this._context.drawImage(this._game.stage.canvas, // Source Image
this._sx, // Source X (location within the source image)
this._sy, // Source Y
this._mirrorWidth, // Source Width
this._mirrorHeight, // Source Height
0, // Destination X (where on the canvas it'll be drawn)
0, // Destination Y
this._mirrorWidth, // Destination Width (always same as Source Width unless scaled)
this._mirrorHeight);
// Destination Height (always same as Source Height unless scaled)
this._context.drawImage(this._game.stage.canvas, this._sx, this._sy, this._mirrorWidth, this._mirrorHeight, 0, 0, this._mirrorWidth, this._mirrorHeight);
if(this._mirrorColor) {
this._context.fillRect(0, 0, this._mirrorWidth, this._mirrorHeight);
}
@ -267,49 +175,19 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Shadow
*
* Creates a drop-shadow effect on the camera window.
*/
(function (Camera) {
var Shadow = (function () {
function Shadow(game, parent) {
/**
* Render camera shadow or not. (default is false)
* @type {boolean}
*/
this.showShadow = false;
/**
* Color of shadow, in css color string.
* @type {string}
*/
this.shadowColor = 'rgb(0,0,0)';
/**
* Blur factor of shadow.
* @type {number}
*/
this.shadowBlur = 10;
/**
* Offset of the shadow from camera's position.
* @type {Point}
*/
this.shadowOffset = new Phaser.Point(4, 4);
this._game = game;
this._parent = parent;
}
Shadow.prototype.start = /**
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
*/
function () {
Shadow.prototype.start = function () {
};
Shadow.prototype.preRender = /**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
// Shadow
Shadow.prototype.preRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
if(this.showShadow == true) {
this._game.stage.context.shadowColor = this.shadowColor;
this._game.stage.context.shadowBlur = this.shadowBlur;
@ -317,11 +195,7 @@ var Phaser;
this._game.stage.context.shadowOffsetY = this.shadowOffset.y;
}
};
Shadow.prototype.render = /**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
*/
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
// Shadow off
Shadow.prototype.render = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
if(this.showShadow == true) {
this._game.stage.context.shadowBlur = 0;
this._game.stage.context.shadowOffsetX = 0;
@ -339,12 +213,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Scanlines
*
* Give your game that classic retro feel!
*/
(function (Camera) {
var Scanlines = (function () {
function Scanlines(game, parent) {
@ -370,12 +238,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Shake
*
* A simple camera shake effect.
*/
(function (Camera) {
var Shake = (function () {
function Shake(game, camera) {
@ -392,16 +254,7 @@ var Phaser;
Shake.SHAKE_BOTH_AXES = 0;
Shake.SHAKE_HORIZONTAL_ONLY = 1;
Shake.SHAKE_VERTICAL_ONLY = 2;
Shake.prototype.start = /**
* A simple camera shake effect.
*
* @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
* @param Duration The length in seconds that the shaking effect should last.
* @param OnComplete A function you want to run when the shake effect finishes.
* @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
* @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
*/
function (intensity, duration, onComplete, force, direction) {
Shake.prototype.start = function (intensity, duration, onComplete, force, direction) {
if (typeof intensity === "undefined") { intensity = 0.05; }
if (typeof duration === "undefined") { duration = 0.5; }
if (typeof onComplete === "undefined") { onComplete = null; }
@ -410,7 +263,6 @@ var Phaser;
if(!force && ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0))) {
return;
}
// If a shake is not already running we need to store the offsets here
if(this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0) {
this._fxShakePrevX = this._parent.x;
this._fxShakePrevY = this._parent.y;
@ -422,7 +274,6 @@ var Phaser;
this._fxShakeOffset.setTo(0, 0);
};
Shake.prototype.postUpdate = function () {
// Update the "shake" special effect
if(this._fxShakeDuration > 0) {
this._fxShakeDuration -= this._game.time.elapsed;
if(this._game.math.roundTo(this._fxShakeDuration, -2) <= 0) {
@ -435,11 +286,9 @@ var Phaser;
}
} else {
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_HORIZONTAL_ONLY)) {
//this._fxShakeOffset.x = ((this._game.math.random() * this._fxShakeIntensity * this.worldView.width * 2 - this._fxShakeIntensity * this.worldView.width) * this._zoom;
this._fxShakeOffset.x = (this._game.math.random() * this._fxShakeIntensity * this._parent.worldView.width * 2 - this._fxShakeIntensity * this._parent.worldView.width);
}
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_VERTICAL_ONLY)) {
//this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this.worldView.height * 2 - this._fxShakeIntensity * this.worldView.height) * this._zoom;
this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this._parent.worldView.height * 2 - this._fxShakeIntensity * this._parent.worldView.height);
}
}
@ -462,12 +311,6 @@ var Phaser;
var Phaser;
(function (Phaser) {
(function (FX) {
/// <reference path="../../build/phaser.d.ts" />
/**
* Phaser - FX - Camera - Fade
*
* The camera is filled with the given color and returns to normal at the given duration.
*/
(function (Camera) {
var Fade = (function () {
function Fade(game) {
@ -476,21 +319,12 @@ var Phaser;
this._fxFadeAlpha = 0;
this._game = game;
}
Fade.prototype.start = /**
* The camera is gradually filled with this color.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
function (color, duration, onComplete, force) {
Fade.prototype.start = function (color, duration, onComplete, force) {
if (typeof color === "undefined") { color = 0x000000; }
if (typeof duration === "undefined") { duration = 1; }
if (typeof onComplete === "undefined") { onComplete = null; }
if (typeof force === "undefined") { force = false; }
if(force === false && this._fxFadeAlpha > 0) {
// You can't fade again unless you force it
return;
}
if(duration <= 0) {
@ -505,7 +339,6 @@ var Phaser;
this._fxFadeComplete = onComplete;
};
Fade.prototype.postUpdate = function () {
// Update the Fade effect
if(this._fxFadeAlpha > 0) {
this._fxFadeAlpha += this._game.time.elapsed / this._fxFadeDuration;
if(this._game.math.roundTo(this._fxFadeAlpha, -2) >= 1) {
@ -517,7 +350,6 @@ var Phaser;
}
};
Fade.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
// "Fade" FX
if(this._fxFadeAlpha > 0) {
this._game.stage.context.fillStyle = this._fxFadeColor + this._fxFadeAlpha + ')';
this._game.stage.context.fillRect(cameraX, cameraY, cameraWidth, cameraHeight);

View file

@ -760,6 +760,7 @@ var Phaser;
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.
@ -3086,6 +3087,7 @@ var Phaser;
(function (Phaser) {
/// <reference path="../Game.ts" />
/// <reference path="../math/Mat3.ts" />
/// <reference path="../geom/Point.ts" />
/**
* Phaser - Components - Transform
*/
@ -3138,7 +3140,7 @@ var Phaser;
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._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;
@ -4123,7 +4125,7 @@ var Phaser;
* @return {Vec2} A Vec2.
*/
function normalRightHand(a, out) {
if (typeof out === "undefined") { out = this; }
if (typeof out === "undefined") { out = new Phaser.Vec2(); }
return out.setTo(a.y * -1, a.x);
};
Vec2Utils.normalize = /**
@ -6466,7 +6468,7 @@ var Phaser;
// 5) Iterative velocity constraints solver
this.velocitySolver(velocityIterations);
Physics.Manager.dump("Velocity Solvers", this.bodies[1]);
// 6) Intergrate position
// 6) Integrate position
for(var i = 0; i < this._bl; i++) {
if(this.bodies[i] && this.bodies[i].isDynamic && this.bodies[i].isAwake) {
this.bodies[i].updatePosition(this._delta);
@ -6597,12 +6599,15 @@ var Phaser;
__extends(Box, _super);
// Give in pixels
function Box(x, y, width, height) {
console.log('Box px', x, y, width, height);
x = Physics.Manager.pixelsToMeters(x);
y = Physics.Manager.pixelsToMeters(y);
width = Physics.Manager.pixelsToMeters(width);
height = Physics.Manager.pixelsToMeters(height);
console.log('Box m', x, y, width, height);
var hw = width * 0.5;
var hh = height * 0.5;
console.log('Box hh', hw, hh);
_super.call(this, [
{
x: -hw + x,
@ -6932,7 +6937,7 @@ var Phaser;
Physics.Manager.write('p: ' + this.position.toString());
Physics.Manager.write('xf: ' + this.transform.toString());
this.bounds.clear();
for(var i = 0; i < this.shapes.length; i++) {
for(var i = 0; i < this.shapesLength; i++) {
var shape = this.shapes[i];
shape.cacheData(this.transform);
this.bounds.addBounds(shape.bounds);
@ -13573,14 +13578,16 @@ var Phaser;
* @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.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
* @param [shapeType] The default body shape is either 0 for a Box or 1 for a Circle. See Sprite.body.addShape for custom shapes (polygons, etc)
* @returns {Sprite} The newly created sprite object.
*/
function (x, y, key, frame, shapeType) {
function (x, y, key, frame, bodyType, shapeType) {
if (typeof key === "undefined") { key = ''; }
if (typeof frame === "undefined") { frame = null; }
if (typeof bodyType === "undefined") { bodyType = Phaser.Types.BODY_DYNAMIC; }
if (typeof shapeType === "undefined") { shapeType = 0; }
return this._world.group.add(new Phaser.Sprite(this._game, x, y, key, frame, Phaser.Types.BODY_DYNAMIC, shapeType));
return this._world.group.add(new Phaser.Sprite(this._game, x, y, key, frame, bodyType, shapeType));
};
GameObjectFactory.prototype.dynamicTexture = /**
* Create a new DynamicTexture with specific size.
@ -18582,6 +18589,32 @@ var Phaser;
DebugUtils.context.fillText('cx: ' + sprite.cameraView.x + ' cy: ' + sprite.cameraView.y + ' cw: ' + sprite.cameraView.width + ' ch: ' + sprite.cameraView.height + ' cb: ' + sprite.cameraView.bottom + ' cr: ' + sprite.cameraView.right, x, y + 70);
DebugUtils.context.fillText('inCamera: ' + DebugUtils.game.renderer.inCamera(DebugUtils.game.camera, sprite), x, y + 84);
};
DebugUtils.renderPhysicsBodyInfo = /**
* 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 renderPhysicsBodyInfo(body, x, y, color) {
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillText('Body ID: ' + body.name, x, y);
DebugUtils.context.fillText('Position x: ' + body.position.x.toFixed(1) + ' y: ' + body.position.y.toFixed(1) + ' rotation: ' + body.angle.toFixed(1), x, y + 14);
DebugUtils.context.fillText('World x: ' + (body.position.x * 50).toFixed(1) + ' y: ' + (body.position.y * 50).toFixed(1), x, y + 28);
DebugUtils.context.fillText('Velocity x: ' + body.velocity.x.toFixed(1) + ' y: ' + body.velocity.y.toFixed(1), x, y + 42);
if(body.shapes[0].verts.length > 0) {
DebugUtils.context.fillText('Vert 1 x: ' + (body.shapes[0].verts[0].x * 50) + ' y: ' + (body.shapes[0].verts[0].y * 50), x, y + 56);
DebugUtils.context.fillText('Vert 2 x: ' + (body.shapes[0].verts[1].x * 50) + ' y: ' + (body.shapes[0].verts[1].y * 50), x, y + 70);
DebugUtils.context.fillText('Vert 3 x: ' + (body.shapes[0].tverts[2].x * 50) + ' y: ' + (body.shapes[0].tverts[2].y * 50), x, y + 84);
DebugUtils.context.fillText('Vert 4 x: ' + (body.shapes[0].tverts[3].x * 50) + ' y: ' + (body.shapes[0].tverts[3].y * 50), x, y + 98);
/*
DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56);
DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70);
DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84);
DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98);
*/
}
};
DebugUtils.renderSpriteBounds = function renderSpriteBounds(sprite, camera, color) {
if (typeof camera === "undefined") { camera = null; }
if (typeof color === "undefined") { color = 'rgba(0,255,0,0.2)'; }
@ -18597,15 +18630,18 @@ var Phaser;
if (typeof lineWidth === "undefined") { lineWidth = 1; }
if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.2)'; }
if (typeof sleepStyle === "undefined") { sleepStyle = 'rgba(100,100,100,0.2)'; }
for(var s = 0; s < body.shapes.length; s++) {
for(var s = 0; s < body.shapesLength; s++) {
DebugUtils.context.beginPath();
if(body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_POLY) {
var verts = body.shapes[s].tverts;
DebugUtils.context.moveTo((body.position.x + verts[0].x) * 50, (body.position.y + verts[0].y) * 50);
for(var i = 0; i < verts.length; i++) {
DebugUtils.context.lineTo((body.position.x + verts[i].x) * 50, (body.position.y + verts[i].y) * 50);
// DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.moveTo(verts[0].x * 50, verts[0].y * 50);
for(var i = 1; i < verts.length; i++) {
// DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y);
DebugUtils.context.lineTo(verts[i].x * 50, verts[i].y * 50);
}
DebugUtils.context.lineTo((body.position.x + verts[verts.length - 1].x) * 50, (body.position.y + verts[verts.length - 1].y) * 50);
// DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50);
} else if(body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_CIRCLE) {
var circle = body.shapes[s];
DebugUtils.context.arc(circle.tc.x * 50, circle.tc.y * 50, circle.radius * 50, 0, Math.PI * 2, false);
@ -19058,6 +19094,84 @@ var Phaser;
})();
Phaser.Game = Game;
})(Phaser || (Phaser = {}));
/// <reference path="Game.ts" />
/**
* Phaser - State
*
* This is a base State class which can be extended if you are creating your game using TypeScript.
*/
var Phaser;
(function (Phaser) {
var State = (function () {
/**
* State constructor
* Create a new <code>State</code>.
*/
function State(game) {
this.game = game;
this.add = game.add;
this.camera = game.camera;
this.cache = game.cache;
this.input = game.input;
this.load = game.load;
this.math = game.math;
this.motion = game.motion;
this.sound = game.sound;
this.stage = game.stage;
this.time = game.time;
this.tweens = game.tweens;
this.world = game.world;
}
State.prototype.init = // Override these in your own States
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*/
function () {
};
State.prototype.create = /**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
*/
function () {
};
State.prototype.update = /**
* Put update logic here.
*/
function () {
};
State.prototype.render = /**
* Put render operations here.
*/
function () {
};
State.prototype.paused = /**
* This method will be called when game paused.
*/
function () {
};
State.prototype.destroy = /**
* This method will be called when the state is destroyed
*/
function () {
};
return State;
})();
Phaser.State = State;
/**
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
* @param object1 The first GameObject or Group to check. If null the world.group is used.
* @param object2 The second GameObject or Group to check.
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
* @param context The context in which the callbacks will be called
* @returns {boolean} true if the objects overlap, otherwise false.
*/
//public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
// return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
//}
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
/**
@ -19400,6 +19514,206 @@ var Phaser;
Phaser.Line = Line;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/**
* Phaser - IntersectResult
*
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
*/
var Phaser;
(function (Phaser) {
var IntersectResult = (function () {
function IntersectResult() {
/**
* Did they intersect or not?
* @property result
* @type {Boolean}
*/
this.result = false;
}
IntersectResult.prototype.setTo = /**
*
* @method setTo
* @param {Number} x1
* @param {Number} y1
* @param {Number} [x2]
* @param {Number} [y2]
* @param {Number} [width]
* @param {Number} [height]
*/
function (x1, y1, x2, y2, width, height) {
if (typeof x2 === "undefined") { x2 = 0; }
if (typeof y2 === "undefined") { y2 = 0; }
if (typeof width === "undefined") { width = 0; }
if (typeof height === "undefined") { height = 0; }
this.x = x1;
this.y = y1;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.width = width;
this.height = height;
};
return IntersectResult;
})();
Phaser.IntersectResult = IntersectResult;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../math/Mat3.ts" />
/**
* 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 = {}));
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
@ -19563,161 +19877,6 @@ var Phaser;
Phaser.CircleUtils = CircleUtils;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../math/Mat3.ts" />
/**
* 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 = {}));
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
@ -19745,126 +19904,3 @@ var Phaser;
})();
Phaser.PixelUtils = PixelUtils;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/**
* Phaser - IntersectResult
*
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
*/
var Phaser;
(function (Phaser) {
var IntersectResult = (function () {
function IntersectResult() {
/**
* Did they intersect or not?
* @property result
* @type {Boolean}
*/
this.result = false;
}
IntersectResult.prototype.setTo = /**
*
* @method setTo
* @param {Number} x1
* @param {Number} y1
* @param {Number} [x2]
* @param {Number} [y2]
* @param {Number} [width]
* @param {Number} [height]
*/
function (x1, y1, x2, y2, width, height) {
if (typeof x2 === "undefined") { x2 = 0; }
if (typeof y2 === "undefined") { y2 = 0; }
if (typeof width === "undefined") { width = 0; }
if (typeof height === "undefined") { height = 0; }
this.x = x1;
this.y = y1;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.width = width;
this.height = height;
};
return IntersectResult;
})();
Phaser.IntersectResult = IntersectResult;
})(Phaser || (Phaser = {}));
/// <reference path="Game.ts" />
/**
* Phaser - State
*
* This is a base State class which can be extended if you are creating your game using TypeScript.
*/
var Phaser;
(function (Phaser) {
var State = (function () {
/**
* State constructor
* Create a new <code>State</code>.
*/
function State(game) {
this.game = game;
this.add = game.add;
this.camera = game.camera;
this.cache = game.cache;
this.input = game.input;
this.load = game.load;
this.math = game.math;
this.motion = game.motion;
this.sound = game.sound;
this.stage = game.stage;
this.time = game.time;
this.tweens = game.tweens;
this.world = game.world;
}
State.prototype.init = // Override these in your own States
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*/
function () {
};
State.prototype.create = /**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
*/
function () {
};
State.prototype.update = /**
* Put update logic here.
*/
function () {
};
State.prototype.render = /**
* Put render operations here.
*/
function () {
};
State.prototype.paused = /**
* This method will be called when game paused.
*/
function () {
};
State.prototype.destroy = /**
* This method will be called when the state is destroyed
*/
function () {
};
return State;
})();
Phaser.State = State;
/**
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
* @param object1 The first GameObject or Group to check. If null the world.group is used.
* @param object2 The second GameObject or Group to check.
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
* @param context The context in which the callbacks will be called
* @returns {boolean} true if the objects overlap, otherwise false.
*/
//public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
// return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
//}
})(Phaser || (Phaser = {}));

View file

@ -1,25 +1,21 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('atari', 'assets/sprites/atari130xe.png');
game.load.image('ball', 'assets/sprites/shinyball.png');
game.load.start();
}
var atari;
var ball;
function create() {
// Add some gravity to the world, otherwise nothing will actually happen
game.physics.gravity.setTo(0, 10);
//atari = game.add.physicsSprite(220/2, 450, 'atari');
atari = game.add.physicsSprite(320, 450, 'atari');
// We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces
atari.body.type = Phaser.Types.BODY_STATIC;
ball = game.add.physicsSprite(330, 0, 'ball', null, 0);
}
function render() {
Phaser.DebugUtils.renderPhysicsBody(atari.body);
Phaser.DebugUtils.renderPhysicsBody(ball.body);
}
})();
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
function init() {
game.load.image('atari', 'assets/sprites/atari130xe.png');
game.load.image('ball', 'assets/sprites/shinyball.png');
game.load.start();
}
var atari;
var ball;
function create() {
game.physics.gravity.setTo(0, 5);
atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC);
ball = game.add.physicsSprite(300 - 20, 0, 'ball');
}
function render() {
Phaser.DebugUtils.renderPhysicsBodyInfo(atari.body, 32, 32);
Phaser.DebugUtils.renderPhysicsBodyInfo(ball.body, 320, 32);
Phaser.DebugUtils.renderPhysicsBody(atari.body);
Phaser.DebugUtils.renderPhysicsBody(ball.body);
}
})();

View file

@ -19,19 +19,24 @@
function create() {
// Add some gravity to the world, otherwise nothing will actually happen
game.physics.gravity.setTo(0, 10);
game.physics.gravity.setTo(0, 5);
//atari = game.add.physicsSprite(220/2, 450, 'atari');
atari = game.add.physicsSprite(320, 450, 'atari');
// We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces
atari.body.type = Phaser.Types.BODY_STATIC;
atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC);
ball = game.add.physicsSprite(330, 0, 'ball', null, 0);
// atari = 220px width (110 = center x)
// ball = 32px width (16 = center x)
// Ball will be a dynamic body and fall based on gravity
ball = game.add.physicsSprite(300-20, 0, 'ball');
}
function render() {
Phaser.DebugUtils.renderPhysicsBodyInfo(atari.body, 32, 32);
Phaser.DebugUtils.renderPhysicsBodyInfo(ball.body, 320, 32);
Phaser.DebugUtils.renderPhysicsBody(atari.body);
Phaser.DebugUtils.renderPhysicsBody(ball.body);

414
build/phaser.d.ts vendored
View file

@ -6666,10 +6666,11 @@ module Phaser {
* @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.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
* @param [shapeType] The default body shape is either 0 for a Box or 1 for a Circle. See Sprite.body.addShape for custom shapes (polygons, etc)
* @returns {Sprite} The newly created sprite object.
*/
public physicsSprite(x: number, y: number, key?: string, frame?, shapeType?: number): Sprite;
public physicsSprite(x: number, y: number, key?: string, frame?, bodyType?: number, shapeType?: number): Sprite;
/**
* Create a new DynamicTexture with specific size.
*
@ -9300,6 +9301,13 @@ module Phaser {
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
static renderSpriteInfo(sprite: Sprite, x: number, y: number, color?: string): void;
/**
* 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)
*/
static renderPhysicsBodyInfo(body: Physics.Body, x: number, y: number, color?: string): void;
static renderSpriteBounds(sprite: Sprite, camera?: Camera, color?: string): void;
static renderPhysicsBody(body: Physics.Body, lineWidth?: number, fillStyle?: string, sleepStyle?: string): void;
}
@ -9543,6 +9551,110 @@ module Phaser {
}
}
/**
* Phaser - State
*
* This is a base State class which can be extended if you are creating your game using TypeScript.
*/
module Phaser {
class State {
/**
* State constructor
* Create a new <code>State</code>.
*/
constructor(game: Game);
/**
* Reference to Game.
*/
public game: Game;
/**
* Currently used camera.
* @type {Camera}
*/
public camera: Camera;
/**
* Reference to the assets cache.
* @type {Cache}
*/
public cache: Cache;
/**
* Reference to the GameObject Factory.
* @type {GameObjectFactory}
*/
public add: GameObjectFactory;
/**
* Reference to the input manager
* @type {Input}
*/
public input: Input;
/**
* Reference to the assets loader.
* @type {Loader}
*/
public load: Loader;
/**
* Reference to the math helper.
* @type {GameMath}
*/
public math: GameMath;
/**
* Reference to the motion helper.
* @type {Motion}
*/
public motion: Motion;
/**
* Reference to the sound manager.
* @type {SoundManager}
*/
public sound: SoundManager;
/**
* Reference to the stage.
* @type {Stage}
*/
public stage: Stage;
/**
* Reference to game clock.
* @type {Time}
*/
public time: Time;
/**
* Reference to the tween manager.
* @type {TweenManager}
*/
public tweens: TweenManager;
/**
* Reference to the world.
* @type {World}
*/
public world: World;
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*/
public init(): void;
/**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
*/
public create(): void;
/**
* Put update logic here.
*/
public update(): void;
/**
* Put render operations here.
*/
public render(): void;
/**
* This method will be called when game paused.
*/
public paused(): void;
/**
* This method will be called when the state is destroyed
*/
public destroy(): void;
}
}
/**
* Phaser - Components - Debug
*
*
@ -9723,6 +9835,104 @@ module Phaser {
}
}
/**
* Phaser - IntersectResult
*
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
*/
module Phaser {
class IntersectResult {
/**
* Did they intersect or not?
* @property result
* @type {Boolean}
*/
public result: bool;
/**
* @property x
* @type {Number}
*/
public x: number;
/**
* @property y
* @type {Number}
*/
public y: number;
/**
* @property x1
* @type {Number}
*/
public x1: number;
/**
* @property y1
* @type {Number}
*/
public y1: number;
/**
* @property x2
* @type {Number}
*/
public x2: number;
/**
* @property y2
* @type {Number}
*/
public y2: number;
/**
* @property width
* @type {Number}
*/
public width: number;
/**
* @property height
* @type {Number}
*/
public height: number;
/**
*
* @method setTo
* @param {Number} x1
* @param {Number} y1
* @param {Number} [x2]
* @param {Number} [y2]
* @param {Number} [width]
* @param {Number} [height]
*/
public setTo(x1: number, y1: number, x2?: number, y2?: number, width?: number, height?: number): void;
}
}
/**
* Phaser - Mat3Utils
*
* A collection of methods useful for manipulating and performing operations on Mat3 objects.
*
*/
module Phaser {
class Mat3Utils {
/**
* Transpose the values of a Mat3
**/
static transpose(source: Mat3, dest?: Mat3): Mat3;
/**
* Inverts a Mat3
**/
static invert(source: Mat3): Mat3;
/**
* Calculates the adjugate of a Mat3
**/
static adjoint(source: Mat3): Mat3;
/**
* Calculates the adjugate of a Mat3
**/
static determinant(source: Mat3): number;
/**
* Multiplies two Mat3s
**/
static multiply(source: Mat3, b: Mat3): Mat3;
static fromQuaternion(): void;
static normalFromMat4(): void;
}
}
/**
* Phaser - CircleUtils
*
* A collection of methods useful for manipulating and comparing Circle objects.
@ -9806,38 +10016,6 @@ module Phaser {
}
}
/**
* Phaser - Mat3Utils
*
* A collection of methods useful for manipulating and performing operations on Mat3 objects.
*
*/
module Phaser {
class Mat3Utils {
/**
* Transpose the values of a Mat3
**/
static transpose(source: Mat3, dest?: Mat3): Mat3;
/**
* Inverts a Mat3
**/
static invert(source: Mat3): Mat3;
/**
* Calculates the adjugate of a Mat3
**/
static adjoint(source: Mat3): Mat3;
/**
* Calculates the adjugate of a Mat3
**/
static determinant(source: Mat3): number;
/**
* Multiplies two Mat3s
**/
static multiply(source: Mat3, b: Mat3): Mat3;
static fromQuaternion(): void;
static normalFromMat4(): void;
}
}
/**
* Phaser - PixelUtils
*
* A collection of methods useful for manipulating pixels.
@ -9858,173 +10036,3 @@ module Phaser {
static getPixel(key: string, x: number, y: number): number;
}
}
/**
* Phaser - IntersectResult
*
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
*/
module Phaser {
class IntersectResult {
/**
* Did they intersect or not?
* @property result
* @type {Boolean}
*/
public result: bool;
/**
* @property x
* @type {Number}
*/
public x: number;
/**
* @property y
* @type {Number}
*/
public y: number;
/**
* @property x1
* @type {Number}
*/
public x1: number;
/**
* @property y1
* @type {Number}
*/
public y1: number;
/**
* @property x2
* @type {Number}
*/
public x2: number;
/**
* @property y2
* @type {Number}
*/
public y2: number;
/**
* @property width
* @type {Number}
*/
public width: number;
/**
* @property height
* @type {Number}
*/
public height: number;
/**
*
* @method setTo
* @param {Number} x1
* @param {Number} y1
* @param {Number} [x2]
* @param {Number} [y2]
* @param {Number} [width]
* @param {Number} [height]
*/
public setTo(x1: number, y1: number, x2?: number, y2?: number, width?: number, height?: number): void;
}
}
/**
* Phaser - State
*
* This is a base State class which can be extended if you are creating your game using TypeScript.
*/
module Phaser {
class State {
/**
* State constructor
* Create a new <code>State</code>.
*/
constructor(game: Game);
/**
* Reference to Game.
*/
public game: Game;
/**
* Currently used camera.
* @type {Camera}
*/
public camera: Camera;
/**
* Reference to the assets cache.
* @type {Cache}
*/
public cache: Cache;
/**
* Reference to the GameObject Factory.
* @type {GameObjectFactory}
*/
public add: GameObjectFactory;
/**
* Reference to the input manager
* @type {Input}
*/
public input: Input;
/**
* Reference to the assets loader.
* @type {Loader}
*/
public load: Loader;
/**
* Reference to the math helper.
* @type {GameMath}
*/
public math: GameMath;
/**
* Reference to the motion helper.
* @type {Motion}
*/
public motion: Motion;
/**
* Reference to the sound manager.
* @type {SoundManager}
*/
public sound: SoundManager;
/**
* Reference to the stage.
* @type {Stage}
*/
public stage: Stage;
/**
* Reference to game clock.
* @type {Time}
*/
public time: Time;
/**
* Reference to the tween manager.
* @type {TweenManager}
*/
public tweens: TweenManager;
/**
* Reference to the world.
* @type {World}
*/
public world: World;
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*/
public init(): void;
/**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
*/
public create(): void;
/**
* Put update logic here.
*/
public update(): void;
/**
* Put render operations here.
*/
public render(): void;
/**
* This method will be called when game paused.
*/
public paused(): void;
/**
* This method will be called when the state is destroyed
*/
public destroy(): void;
}
}

View file

@ -760,6 +760,7 @@ var Phaser;
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.
@ -3086,6 +3087,7 @@ var Phaser;
(function (Phaser) {
/// <reference path="../Game.ts" />
/// <reference path="../math/Mat3.ts" />
/// <reference path="../geom/Point.ts" />
/**
* Phaser - Components - Transform
*/
@ -3138,7 +3140,7 @@ var Phaser;
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._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;
@ -4123,7 +4125,7 @@ var Phaser;
* @return {Vec2} A Vec2.
*/
function normalRightHand(a, out) {
if (typeof out === "undefined") { out = this; }
if (typeof out === "undefined") { out = new Phaser.Vec2(); }
return out.setTo(a.y * -1, a.x);
};
Vec2Utils.normalize = /**
@ -6466,7 +6468,7 @@ var Phaser;
// 5) Iterative velocity constraints solver
this.velocitySolver(velocityIterations);
Physics.Manager.dump("Velocity Solvers", this.bodies[1]);
// 6) Intergrate position
// 6) Integrate position
for(var i = 0; i < this._bl; i++) {
if(this.bodies[i] && this.bodies[i].isDynamic && this.bodies[i].isAwake) {
this.bodies[i].updatePosition(this._delta);
@ -6597,12 +6599,15 @@ var Phaser;
__extends(Box, _super);
// Give in pixels
function Box(x, y, width, height) {
console.log('Box px', x, y, width, height);
x = Physics.Manager.pixelsToMeters(x);
y = Physics.Manager.pixelsToMeters(y);
width = Physics.Manager.pixelsToMeters(width);
height = Physics.Manager.pixelsToMeters(height);
console.log('Box m', x, y, width, height);
var hw = width * 0.5;
var hh = height * 0.5;
console.log('Box hh', hw, hh);
_super.call(this, [
{
x: -hw + x,
@ -6932,7 +6937,7 @@ var Phaser;
Physics.Manager.write('p: ' + this.position.toString());
Physics.Manager.write('xf: ' + this.transform.toString());
this.bounds.clear();
for(var i = 0; i < this.shapes.length; i++) {
for(var i = 0; i < this.shapesLength; i++) {
var shape = this.shapes[i];
shape.cacheData(this.transform);
this.bounds.addBounds(shape.bounds);
@ -13573,14 +13578,16 @@ var Phaser;
* @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.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
* @param [shapeType] The default body shape is either 0 for a Box or 1 for a Circle. See Sprite.body.addShape for custom shapes (polygons, etc)
* @returns {Sprite} The newly created sprite object.
*/
function (x, y, key, frame, shapeType) {
function (x, y, key, frame, bodyType, shapeType) {
if (typeof key === "undefined") { key = ''; }
if (typeof frame === "undefined") { frame = null; }
if (typeof bodyType === "undefined") { bodyType = Phaser.Types.BODY_DYNAMIC; }
if (typeof shapeType === "undefined") { shapeType = 0; }
return this._world.group.add(new Phaser.Sprite(this._game, x, y, key, frame, Phaser.Types.BODY_DYNAMIC, shapeType));
return this._world.group.add(new Phaser.Sprite(this._game, x, y, key, frame, bodyType, shapeType));
};
GameObjectFactory.prototype.dynamicTexture = /**
* Create a new DynamicTexture with specific size.
@ -18582,6 +18589,32 @@ var Phaser;
DebugUtils.context.fillText('cx: ' + sprite.cameraView.x + ' cy: ' + sprite.cameraView.y + ' cw: ' + sprite.cameraView.width + ' ch: ' + sprite.cameraView.height + ' cb: ' + sprite.cameraView.bottom + ' cr: ' + sprite.cameraView.right, x, y + 70);
DebugUtils.context.fillText('inCamera: ' + DebugUtils.game.renderer.inCamera(DebugUtils.game.camera, sprite), x, y + 84);
};
DebugUtils.renderPhysicsBodyInfo = /**
* 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 renderPhysicsBodyInfo(body, x, y, color) {
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
DebugUtils.context.fillStyle = color;
DebugUtils.context.fillText('Body ID: ' + body.name, x, y);
DebugUtils.context.fillText('Position x: ' + body.position.x.toFixed(1) + ' y: ' + body.position.y.toFixed(1) + ' rotation: ' + body.angle.toFixed(1), x, y + 14);
DebugUtils.context.fillText('World x: ' + (body.position.x * 50).toFixed(1) + ' y: ' + (body.position.y * 50).toFixed(1), x, y + 28);
DebugUtils.context.fillText('Velocity x: ' + body.velocity.x.toFixed(1) + ' y: ' + body.velocity.y.toFixed(1), x, y + 42);
if(body.shapes[0].verts.length > 0) {
DebugUtils.context.fillText('Vert 1 x: ' + (body.shapes[0].verts[0].x * 50) + ' y: ' + (body.shapes[0].verts[0].y * 50), x, y + 56);
DebugUtils.context.fillText('Vert 2 x: ' + (body.shapes[0].verts[1].x * 50) + ' y: ' + (body.shapes[0].verts[1].y * 50), x, y + 70);
DebugUtils.context.fillText('Vert 3 x: ' + (body.shapes[0].tverts[2].x * 50) + ' y: ' + (body.shapes[0].tverts[2].y * 50), x, y + 84);
DebugUtils.context.fillText('Vert 4 x: ' + (body.shapes[0].tverts[3].x * 50) + ' y: ' + (body.shapes[0].tverts[3].y * 50), x, y + 98);
/*
DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56);
DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70);
DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84);
DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98);
*/
}
};
DebugUtils.renderSpriteBounds = function renderSpriteBounds(sprite, camera, color) {
if (typeof camera === "undefined") { camera = null; }
if (typeof color === "undefined") { color = 'rgba(0,255,0,0.2)'; }
@ -18597,15 +18630,18 @@ var Phaser;
if (typeof lineWidth === "undefined") { lineWidth = 1; }
if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.2)'; }
if (typeof sleepStyle === "undefined") { sleepStyle = 'rgba(100,100,100,0.2)'; }
for(var s = 0; s < body.shapes.length; s++) {
for(var s = 0; s < body.shapesLength; s++) {
DebugUtils.context.beginPath();
if(body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_POLY) {
var verts = body.shapes[s].tverts;
DebugUtils.context.moveTo((body.position.x + verts[0].x) * 50, (body.position.y + verts[0].y) * 50);
for(var i = 0; i < verts.length; i++) {
DebugUtils.context.lineTo((body.position.x + verts[i].x) * 50, (body.position.y + verts[i].y) * 50);
// DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.moveTo(verts[0].x * 50, verts[0].y * 50);
for(var i = 1; i < verts.length; i++) {
// DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y);
DebugUtils.context.lineTo(verts[i].x * 50, verts[i].y * 50);
}
DebugUtils.context.lineTo((body.position.x + verts[verts.length - 1].x) * 50, (body.position.y + verts[verts.length - 1].y) * 50);
// DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50);
} else if(body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_CIRCLE) {
var circle = body.shapes[s];
DebugUtils.context.arc(circle.tc.x * 50, circle.tc.y * 50, circle.radius * 50, 0, Math.PI * 2, false);
@ -19058,6 +19094,84 @@ var Phaser;
})();
Phaser.Game = Game;
})(Phaser || (Phaser = {}));
/// <reference path="Game.ts" />
/**
* Phaser - State
*
* This is a base State class which can be extended if you are creating your game using TypeScript.
*/
var Phaser;
(function (Phaser) {
var State = (function () {
/**
* State constructor
* Create a new <code>State</code>.
*/
function State(game) {
this.game = game;
this.add = game.add;
this.camera = game.camera;
this.cache = game.cache;
this.input = game.input;
this.load = game.load;
this.math = game.math;
this.motion = game.motion;
this.sound = game.sound;
this.stage = game.stage;
this.time = game.time;
this.tweens = game.tweens;
this.world = game.world;
}
State.prototype.init = // Override these in your own States
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*/
function () {
};
State.prototype.create = /**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
*/
function () {
};
State.prototype.update = /**
* Put update logic here.
*/
function () {
};
State.prototype.render = /**
* Put render operations here.
*/
function () {
};
State.prototype.paused = /**
* This method will be called when game paused.
*/
function () {
};
State.prototype.destroy = /**
* This method will be called when the state is destroyed
*/
function () {
};
return State;
})();
Phaser.State = State;
/**
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
* @param object1 The first GameObject or Group to check. If null the world.group is used.
* @param object2 The second GameObject or Group to check.
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
* @param context The context in which the callbacks will be called
* @returns {boolean} true if the objects overlap, otherwise false.
*/
//public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
// return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
//}
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
/**
@ -19400,6 +19514,206 @@ var Phaser;
Phaser.Line = Line;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/**
* Phaser - IntersectResult
*
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
*/
var Phaser;
(function (Phaser) {
var IntersectResult = (function () {
function IntersectResult() {
/**
* Did they intersect or not?
* @property result
* @type {Boolean}
*/
this.result = false;
}
IntersectResult.prototype.setTo = /**
*
* @method setTo
* @param {Number} x1
* @param {Number} y1
* @param {Number} [x2]
* @param {Number} [y2]
* @param {Number} [width]
* @param {Number} [height]
*/
function (x1, y1, x2, y2, width, height) {
if (typeof x2 === "undefined") { x2 = 0; }
if (typeof y2 === "undefined") { y2 = 0; }
if (typeof width === "undefined") { width = 0; }
if (typeof height === "undefined") { height = 0; }
this.x = x1;
this.y = y1;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.width = width;
this.height = height;
};
return IntersectResult;
})();
Phaser.IntersectResult = IntersectResult;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../math/Mat3.ts" />
/**
* 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 = {}));
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
@ -19563,161 +19877,6 @@ var Phaser;
Phaser.CircleUtils = CircleUtils;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../math/Vec2.ts" />
/// <reference path="../math/Mat3.ts" />
/**
* 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 = {}));
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />
/// <reference path="../geom/Circle.ts" />
@ -19745,126 +19904,3 @@ var Phaser;
})();
Phaser.PixelUtils = PixelUtils;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/**
* Phaser - IntersectResult
*
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
*/
var Phaser;
(function (Phaser) {
var IntersectResult = (function () {
function IntersectResult() {
/**
* Did they intersect or not?
* @property result
* @type {Boolean}
*/
this.result = false;
}
IntersectResult.prototype.setTo = /**
*
* @method setTo
* @param {Number} x1
* @param {Number} y1
* @param {Number} [x2]
* @param {Number} [y2]
* @param {Number} [width]
* @param {Number} [height]
*/
function (x1, y1, x2, y2, width, height) {
if (typeof x2 === "undefined") { x2 = 0; }
if (typeof y2 === "undefined") { y2 = 0; }
if (typeof width === "undefined") { width = 0; }
if (typeof height === "undefined") { height = 0; }
this.x = x1;
this.y = y1;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.width = width;
this.height = height;
};
return IntersectResult;
})();
Phaser.IntersectResult = IntersectResult;
})(Phaser || (Phaser = {}));
/// <reference path="Game.ts" />
/**
* Phaser - State
*
* This is a base State class which can be extended if you are creating your game using TypeScript.
*/
var Phaser;
(function (Phaser) {
var State = (function () {
/**
* State constructor
* Create a new <code>State</code>.
*/
function State(game) {
this.game = game;
this.add = game.add;
this.camera = game.camera;
this.cache = game.cache;
this.input = game.input;
this.load = game.load;
this.math = game.math;
this.motion = game.motion;
this.sound = game.sound;
this.stage = game.stage;
this.time = game.time;
this.tweens = game.tweens;
this.world = game.world;
}
State.prototype.init = // Override these in your own States
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*/
function () {
};
State.prototype.create = /**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
*/
function () {
};
State.prototype.update = /**
* Put update logic here.
*/
function () {
};
State.prototype.render = /**
* Put render operations here.
*/
function () {
};
State.prototype.paused = /**
* This method will be called when game paused.
*/
function () {
};
State.prototype.destroy = /**
* This method will be called when the state is destroyed
*/
function () {
};
return State;
})();
Phaser.State = State;
/**
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
* @param object1 The first GameObject or Group to check. If null the world.group is used.
* @param object2 The second GameObject or Group to check.
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
* @param context The context in which the callbacks will be called
* @returns {boolean} true if the objects overlap, otherwise false.
*/
//public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
// return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
//}
})(Phaser || (Phaser = {}));