Brand new physics system finally (mostly) working. Some poly issues to resolve, but it's running well.

This commit is contained in:
Richard Davey 2013-06-18 19:37:09 +01:00
parent 0a7513240a
commit 829a1b00e4
14 changed files with 684 additions and 232 deletions

View file

@ -53,6 +53,11 @@ module Phaser {
this.activePointer = this.mousePointer;
this.currentPointers = 0;
this.hitCanvas = <HTMLCanvasElement> document.createElement('canvas');
this.hitCanvas.width = 1;
this.hitCanvas.height = 1;
this.hitContext = this.hitCanvas.getContext('2d');
}
/**
@ -60,6 +65,18 @@ module Phaser {
*/
private _game: Game;
/**
* A 1x1 sized canvas used for pixel-perfect checks
* @type {HTMLCanvasElement}
*/
public hitCanvas: HTMLCanvasElement;
/**
* The context of the 1x1 pixel check canvas
* @type {CanvasRenderingContext2D}
*/
public hitContext: CanvasRenderingContext2D;
/**
* A vector object representing the previous position of the Pointer.
* @property vector
@ -961,6 +978,14 @@ module Phaser {
return Vec2Utils.angle(pointer1.position, pointer2.position);
}
public pixelPerfectCheck(sprite: Phaser.Sprite, pointer: Phaser.Pointer, alpha: number = 255): bool {
this.hitContext.clearRect(0, 0, 1, 1);
return true;
}
}
}

View file

@ -8,6 +8,11 @@
/// <reference path="Bounds.ts" />
/// <reference path="Space.ts" />
/// <reference path="shapes/IShape.ts" />
/// <reference path="shapes/Triangle.ts" />
/// <reference path="shapes/Circle.ts" />
/// <reference path="shapes/Box.ts" />
/// <reference path="shapes/Poly.ts" />
/// <reference path="shapes/Segment.ts" />
/**
* Phaser - Advanced Physics - Body
@ -29,12 +34,12 @@ module Phaser.Physics.Advanced {
{
this.sprite = sprite;
this.game = sprite.game;
this.position = new Phaser.Vec2(sprite.x, sprite.y);
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.y));
this.angle = sprite.rotation;
}
else
{
this.position = new Phaser.Vec2(x, y);
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(x), Phaser.Physics.Advanced.Manager.pixelsToMeters(y));
this.angle = 0;
}
@ -64,6 +69,8 @@ module Phaser.Physics.Advanced {
}
private _tempVec2: Phaser.Vec2 = new Phaser.Vec2;
/**
* Reference to Phaser.Game
*/
@ -139,6 +146,11 @@ module Phaser.Physics.Advanced {
// Bounds of all shapes
public bounds: Bounds;
public mass: number;
public massInverted: number;
public inertia: number;
public inertiaInverted: number;
public fixedRotation = false;
public categoryBits = 0x0001;
public maskBits = 0xFFFF;
@ -195,6 +207,62 @@ module Phaser.Physics.Advanced {
}
public addPoly(verts, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Poly {
var poly: Phaser.Physics.Advanced.Shapes.Poly = new Phaser.Physics.Advanced.Shapes.Poly(verts);
poly.elasticity = elasticity;
poly.friction = friction;
poly.density = density;
this.addShape(poly);
this.resetMassData();
return poly;
}
public addTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Triangle {
var tri: Phaser.Physics.Advanced.Shapes.Triangle = new Phaser.Physics.Advanced.Shapes.Triangle(x1, y1, x2, y2, x3, y3);
tri.elasticity = elasticity;
tri.friction = friction;
tri.density = density;
this.addShape(tri);
this.resetMassData();
return tri;
}
public addBox(x: number, y: number, width: number, height: number, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Box {
var box: Phaser.Physics.Advanced.Shapes.Box = new Phaser.Physics.Advanced.Shapes.Box(x, y, width, height);
box.elasticity = elasticity;
box.friction = friction;
box.density = density;
this.addShape(box);
this.resetMassData();
return box;
}
public addCircle(radius: number, x?: number = 0, y?: number = 0, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Circle {
var circle: Phaser.Physics.Advanced.Shapes.Circle = new Phaser.Physics.Advanced.Shapes.Circle(radius, x, y);
circle.elasticity = elasticity;
circle.friction = friction;
circle.density = density;
this.addShape(circle);
this.resetMassData();
return circle;
}
public addShape(shape) {
// Check not already part of this body
@ -218,10 +286,6 @@ module Phaser.Physics.Advanced {
}
public mass: number;
public massInverted: number;
public inertia: number;
public inertiaInverted: number;
private setMass(mass) {
@ -381,7 +445,6 @@ module Phaser.Physics.Advanced {
}
private _tempVec2: Phaser.Vec2 = new Phaser.Vec2;
public updateVelocity(gravity, dt, damping) {

View file

@ -71,6 +71,22 @@ module Phaser.Physics.Advanced {
}
public get x(): number {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.x);
}
public get y(): number {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.y);
}
public get width(): number {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.x - this.mins.x);
}
public get height(): number {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.y - this.mins.y);
}
public isEmpty(): bool {
return (this.mins.x > this.maxs.x || this.mins.y > this.maxs.y);
}

View file

@ -560,6 +560,7 @@ module Phaser.Physics.Advanced {
//stats.timeCollision = Date.now() - t0;
return newContactSolverArr;
}
public initSolver(dt, dt_inv, warmStarting) {

View file

@ -26,10 +26,10 @@ module Phaser.Physics.Advanced.Shapes {
var hh = height * 0.5;
super([
new Phaser.Vec2(-hw + x, +hh + y),
new Phaser.Vec2(-hw + x, -hh + y),
new Phaser.Vec2(+hw + x, -hh + y),
new Phaser.Vec2(+hw + x, +hh + y)
{ x: -hw + x, y: +hh + y },
{ x: -hw + x, y: -hh + y },
{ x: +hw + x, y: -hh + y },
{ x: +hw + x, y: +hh + y }
]);
}

View file

@ -18,6 +18,10 @@ module Phaser.Physics.Advanced.Shapes {
super(Manager.SHAPE_TYPE_CIRCLE);
x = Manager.pixelsToMeters(x);
y = Manager.pixelsToMeters(y);
radius = Manager.pixelsToMeters(radius);
this.center = new Phaser.Vec2(x, y);
this.radius = radius;
this.tc = new Phaser.Vec2;

View file

@ -14,7 +14,9 @@ module Phaser.Physics.Advanced.Shapes {
export class Poly extends Phaser.Physics.Advanced.Shape implements IShape {
constructor(verts?:Phaser.Vec2[]) {
// Verts is an optional array of objects, the objects must have public x and y properties which will be used
// to seed this polygon (i.e. Vec2 objects, or just straight JS objects) and must wind COUNTER clockwise
constructor(verts?) {
super(Manager.SHAPE_TYPE_POLY);
@ -28,7 +30,7 @@ module Phaser.Physics.Advanced.Shapes {
{
for (var i = 0; i < verts.length; i++)
{
this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
this.verts[i] = new Phaser.Vec2(verts[i].x, verts[i].y);
this.tverts[i] = this.verts[i];
this.tplanes[i] = {};
@ -91,6 +93,7 @@ module Phaser.Physics.Advanced.Shapes {
this.convexity = false;
}
}
}
public duplicate() {
@ -138,7 +141,7 @@ module Phaser.Physics.Advanced.Shapes {
var numVerts = this.verts.length;
//console.log('shapePoly cacheData', numVerts);
console.log('Poly cacheData', numVerts, this.body.name);
if (numVerts == 0)
{

View file

@ -14,9 +14,16 @@ module Phaser.Physics.Advanced.Shapes {
export class Triangle extends Phaser.Physics.Advanced.Shapes.Poly {
constructor(p1, p2, p3) {
constructor(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) {
super( [ new Phaser.Vec2(p1.x, p1.y), new Phaser.Vec2(p2.x, p2.y), new Phaser.Vec2(p3.x, p3.y) ] );
x1 = Manager.pixelsToMeters(x1);
y1 = Manager.pixelsToMeters(y1);
x2 = Manager.pixelsToMeters(x2);
y2 = Manager.pixelsToMeters(y2);
x3 = Manager.pixelsToMeters(x3);
y3 = Manager.pixelsToMeters(y3);
super([{ x: x1, y: y1 }, { x: x2, y: y2 }, { x: x3, y: y3 }]);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -16057,6 +16057,10 @@ var Phaser;
this.camera = this._game.camera;
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');
}
Input.MOUSE_OVERRIDES_TOUCH = 0;
Input.TOUCH_OVERRIDES_MOUSE = 1;
@ -16495,7 +16499,16 @@ var Phaser;
return Input;
})();
Phaser.Input = Input;
})(Phaser || (Phaser = {}));
/*
public pixelPerfectCheck(sprite: Phaser.Sprite, pointer: Phaser.Pointer, alpha: number = 255): bool {
this.hitContext.clearRect(0, 0, 1, 1);
return true;
}
*/
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../cameras/Camera.ts" />
/// <reference path="IRenderer.ts" />
@ -19387,6 +19400,34 @@ var Phaser;
this.maxs.setTo(-999999, -999999);
return this;
};
Object.defineProperty(Bounds.prototype, "x", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.x);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Bounds.prototype, "y", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.y);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Bounds.prototype, "width", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.x - this.mins.x);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Bounds.prototype, "height", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.y - this.mins.y);
},
enumerable: true,
configurable: true
});
Bounds.prototype.isEmpty = function () {
return (this.mins.x > this.maxs.x || this.mins.y > this.maxs.y);
};
@ -19845,6 +19886,9 @@ var Phaser;
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
_super.call(this, Advanced.Manager.SHAPE_TYPE_CIRCLE);
x = Advanced.Manager.pixelsToMeters(x);
y = Advanced.Manager.pixelsToMeters(y);
radius = Advanced.Manager.pixelsToMeters(radius);
this.center = new Phaser.Vec2(x, y);
this.radius = radius;
this.tc = new Phaser.Vec2();
@ -19923,6 +19967,8 @@ var Phaser;
(function (Shapes) {
var Poly = (function (_super) {
__extends(Poly, _super);
// Verts is an optional array of objects, the objects must have public x and y properties which will be used
// to seed this polygon (i.e. Vec2 objects, or just straight JS objects) and must wind COUNTER clockwise
function Poly(verts) {
_super.call(this, Advanced.Manager.SHAPE_TYPE_POLY);
this.verts = [];
@ -19931,7 +19977,7 @@ var Phaser;
this.tplanes = [];
if(verts) {
for(var i = 0; i < verts.length; i++) {
this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
this.verts[i] = new Phaser.Vec2(verts[i].x, verts[i].y);
this.tverts[i] = this.verts[i];
this.tplanes[i] = {
};
@ -20004,7 +20050,7 @@ var Phaser;
Poly.prototype.cacheData = function (xf) {
this.bounds.clear();
var numVerts = this.verts.length;
//console.log('shapePoly cacheData', numVerts);
console.log('Poly cacheData', numVerts, this.body.name);
if(numVerts == 0) {
return;
}
@ -21156,6 +21202,109 @@ var Phaser;
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Triangle = (function (_super) {
__extends(Triangle, _super);
function Triangle(x1, y1, x2, y2, x3, y3) {
x1 = Advanced.Manager.pixelsToMeters(x1);
y1 = Advanced.Manager.pixelsToMeters(y1);
x2 = Advanced.Manager.pixelsToMeters(x2);
y2 = Advanced.Manager.pixelsToMeters(y2);
x3 = Advanced.Manager.pixelsToMeters(x3);
y3 = Advanced.Manager.pixelsToMeters(y3);
_super.call(this, [
{
x: x1,
y: y1
},
{
x: x2,
y: y2
},
{
x: x3,
y: y3
}
]);
}
return Triangle;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Triangle = Triangle;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Box
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Box = (function (_super) {
__extends(Box, _super);
// Give in pixels
function Box(x, y, width, height) {
x = Advanced.Manager.pixelsToMeters(x);
y = Advanced.Manager.pixelsToMeters(y);
width = Advanced.Manager.pixelsToMeters(width);
height = Advanced.Manager.pixelsToMeters(height);
var hw = width * 0.5;
var hh = height * 0.5;
_super.call(this, [
{
x: -hw + x,
y: +hh + y
},
{
x: -hw + x,
y: -hh + y
},
{
x: +hw + x,
y: -hh + y
},
{
x: +hw + x,
y: +hh + y
}
]);
}
return Box;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Box = Box;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
/// <reference path="../../math/Vec2.ts" />
@ -21168,6 +21317,11 @@ var Phaser;
/// <reference path="Bounds.ts" />
/// <reference path="Space.ts" />
/// <reference path="shapes/IShape.ts" />
/// <reference path="shapes/Triangle.ts" />
/// <reference path="shapes/Circle.ts" />
/// <reference path="shapes/Box.ts" />
/// <reference path="shapes/Poly.ts" />
/// <reference path="shapes/Segment.ts" />
/**
* Phaser - Advanced Physics - Body
*
@ -21178,6 +21332,7 @@ var Phaser;
function Body(sprite, type, x, y) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
this._tempVec2 = new Phaser.Vec2();
// Shapes
this.shapes = [];
// Joints
@ -21188,17 +21343,16 @@ var Phaser;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
this._tempVec2 = new Phaser.Vec2();
this.id = Phaser.Physics.Advanced.Manager.bodyCounter++;
this.name = 'body' + this.id;
this.type = type;
if(sprite) {
this.sprite = sprite;
this.game = sprite.game;
this.position = new Phaser.Vec2(sprite.x, sprite.y);
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.y));
this.angle = sprite.rotation;
} else {
this.position = new Phaser.Vec2(x, y);
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(x), Phaser.Physics.Advanced.Manager.pixelsToMeters(y));
this.angle = 0;
}
this.transform = new Phaser.Transform(this.position, this.angle);
@ -21270,6 +21424,56 @@ var Phaser;
this.type = type;
this.awake(true);
};
Body.prototype.addPoly = function (verts, elasticity, friction, density) {
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var poly = new Phaser.Physics.Advanced.Shapes.Poly(verts);
poly.elasticity = elasticity;
poly.friction = friction;
poly.density = density;
this.addShape(poly);
this.resetMassData();
return poly;
};
Body.prototype.addTriangle = function (x1, y1, x2, y2, x3, y3, elasticity, friction, density) {
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var tri = new Phaser.Physics.Advanced.Shapes.Triangle(x1, y1, x2, y2, x3, y3);
tri.elasticity = elasticity;
tri.friction = friction;
tri.density = density;
this.addShape(tri);
this.resetMassData();
return tri;
};
Body.prototype.addBox = function (x, y, width, height, elasticity, friction, density) {
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var box = new Phaser.Physics.Advanced.Shapes.Box(x, y, width, height);
box.elasticity = elasticity;
box.friction = friction;
box.density = density;
this.addShape(box);
this.resetMassData();
return box;
};
Body.prototype.addCircle = function (radius, x, y, elasticity, friction, density) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var circle = new Phaser.Physics.Advanced.Shapes.Circle(radius, x, y);
circle.elasticity = elasticity;
circle.friction = friction;
circle.density = density;
this.addShape(circle);
this.resetMassData();
return circle;
};
Body.prototype.addShape = function (shape) {
// Check not already part of this body
shape.body = this;
@ -21524,82 +21728,6 @@ var Phaser;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Box
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Box = (function (_super) {
__extends(Box, _super);
// Give in pixels
function Box(x, y, width, height) {
x = Advanced.Manager.pixelsToMeters(x);
y = Advanced.Manager.pixelsToMeters(y);
width = Advanced.Manager.pixelsToMeters(width);
height = Advanced.Manager.pixelsToMeters(height);
var hw = width * 0.5;
var hh = height * 0.5;
_super.call(this, [
new Phaser.Vec2(-hw + x, +hh + y),
new Phaser.Vec2(-hw + x, -hh + y),
new Phaser.Vec2(+hw + x, -hh + y),
new Phaser.Vec2(+hw + x, +hh + y)
]);
}
return Box;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Box = Box;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Triangle = (function (_super) {
__extends(Triangle, _super);
function Triangle(p1, p2, p3) {
_super.call(this, [
new Phaser.Vec2(p1.x, p1.y),
new Phaser.Vec2(p2.x, p2.y),
new Phaser.Vec2(p3.x, p3.y)
]);
}
return Triangle;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Triangle = Triangle;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />

View file

@ -15,32 +15,63 @@
var physics;
var circle;
var walls;
var ground;
var t;
function create() {
atari = game.add.sprite(200, 100, 'atari');
// need to get the physics bounds around the sprite center, regardless of origin
atari.transform.origin.setTo(0.5, 0.5);
//card = game.add.sprite(500, 300, 'card');
physics = new Phaser.Physics.Advanced.Manager(game);
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_KINETIC);
walls.game = game;
walls.addBox(500, 500, 500, 20);
walls.addBox(100, 250, 250, 20);
walls.transform.setRotation(game.math.degreesToRadians(3));
//walls.fixedRotation = true;
// position is in relation to the containing body! don't forget this
ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
//ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(-10.04, 7.68, 0.4, 14.56));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(10.04, 7.68, 0.4, 14.56));
walls.resetMassData();
//walls.resetMassData();
physics.space.addBody(walls);
// Add a circle
circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, physics.pixelsToMeters(300), physics.pixelsToMeters(200));
circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 100, 200);
circle.game = game;
var shape = new Phaser.Physics.Advanced.Shapes.Circle(0.4, 0, 0);
shape.elasticity = 0.8;
shape.friction = 1;
shape.density = 1;
circle.addShape(shape);
circle.resetMassData();
circle.addCircle(32, 0, 0, 0.8);
physics.space.addBody(circle);
t = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_KINETIC, 500, 400);
t.game = game;
//t.addCircle(32, 0, 0, 0.8);
//t.addTriangle(0, 0, 1, 1, 2, 2);
t.addPoly([
{
x: -0.8,
y: 0.48
},
{
x: -0.8,
y: 0
},
{
x: 0.8,
y: 0
},
{
x: 0.8,
y: 0.32
},
{
x: 0,
y: 0.84
},
{
x: -0.56,
y: 0.84
}
], 0.5, 1, 6);
physics.space.addBody(t);
}
function update() {
physics.update();
@ -71,6 +102,10 @@
//console.log(circle.velocity.x, circle.velocity.y);
//console.log('p', circle.position.x, circle.position.y);
}
function renderBounds(body) {
game.stage.context.fillStyle = 'rgba(0,255,200,0.2)';
game.stage.context.fillRect(body.bounds.x, body.bounds.y, body.bounds.width, body.bounds.height);
}
function renderCircle(shape) {
game.stage.context.beginPath();
game.stage.context.arc(shape.tc.x * 50, shape.tc.y * 50, shape.radius * 50, 0, Math.PI * 2, false);
@ -99,6 +134,11 @@
game.stage.context.fillText('x: ' + circle.position.x + ' y: ' + circle.position.y, 32, 32);
game.stage.context.fillText('vx: ' + circle.velocity.x + ' vy: ' + circle.velocity.y, 32, 64);
renderCircle(circle.shapes[0]);
renderBounds(circle);
drawPolygon(game.stage.context, walls.shapes[0], 1, 'rgb(0,255,255)');
drawPolygon(game.stage.context, walls.shapes[1], 1, 'rgb(0,255,255)');
//renderCircle(t.shapes[0]);
drawPolygon(game.stage.context, t.shapes[0], 1, 'rgb(255,255,255)');
renderBounds(t);
}
})();

View file

@ -21,45 +21,50 @@
var physics: Phaser.Physics.Advanced.Manager;
var circle: Phaser.Physics.Advanced.Body;
var walls: Phaser.Physics.Advanced.Body;
var ground: Phaser.Physics.Advanced.Shapes.Box;
var t: Phaser.Physics.Advanced.Body;
function create() {
atari = game.add.sprite(200, 100, 'atari');
// need to get the physics bounds around the sprite center, regardless of origin
atari.transform.origin.setTo(0.5, 0.5);
//card = game.add.sprite(500, 300, 'card');
physics = new Phaser.Physics.Advanced.Manager(game);
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_KINETIC);
walls.game = game;
walls.addBox(500, 500, 500, 20);
walls.addBox(100, 250, 250, 20);
walls.transform.setRotation(game.math.degreesToRadians(3));
//walls.fixedRotation = true;
// position is in relation to the containing body! don't forget this
ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
//ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(-10.04, 7.68, 0.4, 14.56));
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(10.04, 7.68, 0.4, 14.56));
walls.resetMassData();
//walls.resetMassData();
physics.space.addBody(walls);
// Add a circle
circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, physics.pixelsToMeters(300), physics.pixelsToMeters(200));
circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 100, 200);
circle.game = game;
var shape = new Phaser.Physics.Advanced.Shapes.Circle(0.4, 0, 0);
shape.elasticity = 0.8;
shape.friction = 1;
shape.density = 1;
circle.addShape(shape);
circle.resetMassData();
circle.addCircle(32, 0, 0, 0.8);
physics.space.addBody(circle);
t = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_KINETIC, 500, 400);
t.game = game;
//t.addCircle(32, 0, 0, 0.8);
//t.addTriangle(0, 0, 1, 1, 2, 2);
t.addPoly([{ x: -0.8, y: 0.48 }, { x: -0.8, y: 0 }, { x: 0.8, y: 0 }, { x: 0.8, y: 0.32 }, { x: 0, y: 0.84 }, { x: -0.56, y: 0.84 }], 0.5, 1, 6);
physics.space.addBody(t);
}
function update() {
@ -106,6 +111,14 @@
//console.log('p', circle.position.x, circle.position.y);
}
function renderBounds(body: Phaser.Physics.Advanced.Body) {
game.stage.context.fillStyle = 'rgba(0,255,200,0.2)';
game.stage.context.fillRect(body.bounds.x, body.bounds.y, body.bounds.width, body.bounds.height);
}
function renderCircle(shape) {
game.stage.context.beginPath();
@ -152,8 +165,14 @@
game.stage.context.fillText('vx: ' + circle.velocity.x + ' vy: ' + circle.velocity.y, 32, 64);
renderCircle(circle.shapes[0]);
renderBounds(circle);
drawPolygon(game.stage.context, walls.shapes[0], 1, 'rgb(0,255,255)');
drawPolygon(game.stage.context, walls.shapes[1], 1, 'rgb(0,255,255)');
//renderCircle(t.shapes[0]);
drawPolygon(game.stage.context, t.shapes[0], 1, 'rgb(255,255,255)');
renderBounds(t);
}

70
build/phaser.d.ts vendored
View file

@ -8473,6 +8473,16 @@ module Phaser {
*/
private _game;
/**
* A 1x1 sized canvas used for pixel-perfect checks
* @type {HTMLCanvasElement}
*/
public hitCanvas: HTMLCanvasElement;
/**
* The context of the 1x1 pixel check canvas
* @type {CanvasRenderingContext2D}
*/
public hitContext: CanvasRenderingContext2D;
/**
* A vector object representing the previous position of the Pointer.
* @property vector
* @type {Vec2}
@ -9668,6 +9678,10 @@ module Phaser.Physics.Advanced {
public setTo(mins: Vec2, maxs: Vec2): void;
public copy(b: Bounds): Bounds;
public clear(): Bounds;
public x : number;
public y : number;
public width : number;
public height : number;
public isEmpty(): bool;
public getPerimeter(): number;
public addPoint(p: Vec2): Bounds;
@ -9792,7 +9806,7 @@ module Phaser.Physics.Advanced.Shapes {
*/
module Phaser.Physics.Advanced.Shapes {
class Poly extends Shape implements IShape {
constructor(verts?: Vec2[]);
constructor(verts?);
public verts: Vec2[];
public planes;
public tverts;
@ -9938,6 +9952,26 @@ module Phaser.Physics.Advanced {
}
}
/**
* Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
module Phaser.Physics.Advanced.Shapes {
class Triangle extends Poly {
constructor(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number);
}
}
/**
* Phaser - Advanced Physics - Shapes - Box
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
module Phaser.Physics.Advanced.Shapes {
class Box extends Poly {
constructor(x, y, width, height);
}
}
/**
* Phaser - Advanced Physics - Body
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
@ -9945,6 +9979,7 @@ module Phaser.Physics.Advanced {
module Phaser.Physics.Advanced {
class Body {
constructor(sprite: Sprite, type: number, x?: number, y?: number);
private _tempVec2;
/**
* Reference to Phaser.Game
*/
@ -9986,6 +10021,10 @@ module Phaser.Physics.Advanced {
public joints: IJoint[];
public jointHash: {};
public bounds: Bounds;
public mass: number;
public massInverted: number;
public inertia: number;
public inertiaInverted: number;
public fixedRotation: bool;
public categoryBits: number;
public maskBits: number;
@ -9997,12 +10036,12 @@ module Phaser.Physics.Advanced {
public isKinetic : bool;
public isDynamic : bool;
public setType(type: number): void;
public addPoly(verts, elasticity?: number, friction?: number, density?: number): Shapes.Poly;
public addTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, elasticity?: number, friction?: number, density?: number): Shapes.Triangle;
public addBox(x: number, y: number, width: number, height: number, elasticity?: number, friction?: number, density?: number): Shapes.Box;
public addCircle(radius: number, x?: number, y?: number, elasticity?: number, friction?: number, density?: number): Shapes.Circle;
public addShape(shape);
public removeShape(shape): void;
public mass: number;
public massInverted: number;
public inertia: number;
public inertiaInverted: number;
private setMass(mass);
private setInertia(inertia);
public setTransform(pos, angle): void;
@ -10015,7 +10054,6 @@ module Phaser.Physics.Advanced {
public resetMassData(): void;
public resetJointAnchors(): void;
public cacheData(): void;
private _tempVec2;
public updateVelocity(gravity, dt, damping): void;
public updatePosition(dt): void;
public resetForce(): void;
@ -10031,26 +10069,6 @@ module Phaser.Physics.Advanced {
}
}
/**
* Phaser - Advanced Physics - Shapes - Box
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
module Phaser.Physics.Advanced.Shapes {
class Box extends Poly {
constructor(x, y, width, height);
}
}
/**
* Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
module Phaser.Physics.Advanced.Shapes {
class Triangle extends Poly {
constructor(p1, p2, p3);
}
}
/**
* Phaser - PixelUtils
*
* A collection of methods useful for manipulating pixels.

View file

@ -16057,6 +16057,10 @@ var Phaser;
this.camera = this._game.camera;
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');
}
Input.MOUSE_OVERRIDES_TOUCH = 0;
Input.TOUCH_OVERRIDES_MOUSE = 1;
@ -16495,7 +16499,16 @@ var Phaser;
return Input;
})();
Phaser.Input = Input;
})(Phaser || (Phaser = {}));
/*
public pixelPerfectCheck(sprite: Phaser.Sprite, pointer: Phaser.Pointer, alpha: number = 255): bool {
this.hitContext.clearRect(0, 0, 1, 1);
return true;
}
*/
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../cameras/Camera.ts" />
/// <reference path="IRenderer.ts" />
@ -19387,6 +19400,34 @@ var Phaser;
this.maxs.setTo(-999999, -999999);
return this;
};
Object.defineProperty(Bounds.prototype, "x", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.x);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Bounds.prototype, "y", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.y);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Bounds.prototype, "width", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.x - this.mins.x);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Bounds.prototype, "height", {
get: function () {
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.y - this.mins.y);
},
enumerable: true,
configurable: true
});
Bounds.prototype.isEmpty = function () {
return (this.mins.x > this.maxs.x || this.mins.y > this.maxs.y);
};
@ -19845,6 +19886,9 @@ var Phaser;
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
_super.call(this, Advanced.Manager.SHAPE_TYPE_CIRCLE);
x = Advanced.Manager.pixelsToMeters(x);
y = Advanced.Manager.pixelsToMeters(y);
radius = Advanced.Manager.pixelsToMeters(radius);
this.center = new Phaser.Vec2(x, y);
this.radius = radius;
this.tc = new Phaser.Vec2();
@ -19923,6 +19967,8 @@ var Phaser;
(function (Shapes) {
var Poly = (function (_super) {
__extends(Poly, _super);
// Verts is an optional array of objects, the objects must have public x and y properties which will be used
// to seed this polygon (i.e. Vec2 objects, or just straight JS objects) and must wind COUNTER clockwise
function Poly(verts) {
_super.call(this, Advanced.Manager.SHAPE_TYPE_POLY);
this.verts = [];
@ -19931,7 +19977,7 @@ var Phaser;
this.tplanes = [];
if(verts) {
for(var i = 0; i < verts.length; i++) {
this.verts[i] = Phaser.Vec2Utils.clone(verts[i]);
this.verts[i] = new Phaser.Vec2(verts[i].x, verts[i].y);
this.tverts[i] = this.verts[i];
this.tplanes[i] = {
};
@ -20004,7 +20050,7 @@ var Phaser;
Poly.prototype.cacheData = function (xf) {
this.bounds.clear();
var numVerts = this.verts.length;
//console.log('shapePoly cacheData', numVerts);
console.log('Poly cacheData', numVerts, this.body.name);
if(numVerts == 0) {
return;
}
@ -21156,6 +21202,109 @@ var Phaser;
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Triangle = (function (_super) {
__extends(Triangle, _super);
function Triangle(x1, y1, x2, y2, x3, y3) {
x1 = Advanced.Manager.pixelsToMeters(x1);
y1 = Advanced.Manager.pixelsToMeters(y1);
x2 = Advanced.Manager.pixelsToMeters(x2);
y2 = Advanced.Manager.pixelsToMeters(y2);
x3 = Advanced.Manager.pixelsToMeters(x3);
y3 = Advanced.Manager.pixelsToMeters(y3);
_super.call(this, [
{
x: x1,
y: y1
},
{
x: x2,
y: y2
},
{
x: x3,
y: y3
}
]);
}
return Triangle;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Triangle = Triangle;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Box
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Box = (function (_super) {
__extends(Box, _super);
// Give in pixels
function Box(x, y, width, height) {
x = Advanced.Manager.pixelsToMeters(x);
y = Advanced.Manager.pixelsToMeters(y);
width = Advanced.Manager.pixelsToMeters(width);
height = Advanced.Manager.pixelsToMeters(height);
var hw = width * 0.5;
var hh = height * 0.5;
_super.call(this, [
{
x: -hw + x,
y: +hh + y
},
{
x: -hw + x,
y: -hh + y
},
{
x: +hw + x,
y: -hh + y
},
{
x: +hw + x,
y: +hh + y
}
]);
}
return Box;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Box = Box;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
/// <reference path="../../math/Vec2.ts" />
@ -21168,6 +21317,11 @@ var Phaser;
/// <reference path="Bounds.ts" />
/// <reference path="Space.ts" />
/// <reference path="shapes/IShape.ts" />
/// <reference path="shapes/Triangle.ts" />
/// <reference path="shapes/Circle.ts" />
/// <reference path="shapes/Box.ts" />
/// <reference path="shapes/Poly.ts" />
/// <reference path="shapes/Segment.ts" />
/**
* Phaser - Advanced Physics - Body
*
@ -21178,6 +21332,7 @@ var Phaser;
function Body(sprite, type, x, y) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
this._tempVec2 = new Phaser.Vec2();
// Shapes
this.shapes = [];
// Joints
@ -21188,17 +21343,16 @@ var Phaser;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
this._tempVec2 = new Phaser.Vec2();
this.id = Phaser.Physics.Advanced.Manager.bodyCounter++;
this.name = 'body' + this.id;
this.type = type;
if(sprite) {
this.sprite = sprite;
this.game = sprite.game;
this.position = new Phaser.Vec2(sprite.x, sprite.y);
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.y));
this.angle = sprite.rotation;
} else {
this.position = new Phaser.Vec2(x, y);
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(x), Phaser.Physics.Advanced.Manager.pixelsToMeters(y));
this.angle = 0;
}
this.transform = new Phaser.Transform(this.position, this.angle);
@ -21270,6 +21424,56 @@ var Phaser;
this.type = type;
this.awake(true);
};
Body.prototype.addPoly = function (verts, elasticity, friction, density) {
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var poly = new Phaser.Physics.Advanced.Shapes.Poly(verts);
poly.elasticity = elasticity;
poly.friction = friction;
poly.density = density;
this.addShape(poly);
this.resetMassData();
return poly;
};
Body.prototype.addTriangle = function (x1, y1, x2, y2, x3, y3, elasticity, friction, density) {
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var tri = new Phaser.Physics.Advanced.Shapes.Triangle(x1, y1, x2, y2, x3, y3);
tri.elasticity = elasticity;
tri.friction = friction;
tri.density = density;
this.addShape(tri);
this.resetMassData();
return tri;
};
Body.prototype.addBox = function (x, y, width, height, elasticity, friction, density) {
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var box = new Phaser.Physics.Advanced.Shapes.Box(x, y, width, height);
box.elasticity = elasticity;
box.friction = friction;
box.density = density;
this.addShape(box);
this.resetMassData();
return box;
};
Body.prototype.addCircle = function (radius, x, y, elasticity, friction, density) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
if (typeof elasticity === "undefined") { elasticity = 1; }
if (typeof friction === "undefined") { friction = 1; }
if (typeof density === "undefined") { density = 1; }
var circle = new Phaser.Physics.Advanced.Shapes.Circle(radius, x, y);
circle.elasticity = elasticity;
circle.friction = friction;
circle.density = density;
this.addShape(circle);
this.resetMassData();
return circle;
};
Body.prototype.addShape = function (shape) {
// Check not already part of this body
shape.body = this;
@ -21524,82 +21728,6 @@ var Phaser;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Box
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Box = (function (_super) {
__extends(Box, _super);
// Give in pixels
function Box(x, y, width, height) {
x = Advanced.Manager.pixelsToMeters(x);
y = Advanced.Manager.pixelsToMeters(y);
width = Advanced.Manager.pixelsToMeters(width);
height = Advanced.Manager.pixelsToMeters(height);
var hw = width * 0.5;
var hh = height * 0.5;
_super.call(this, [
new Phaser.Vec2(-hw + x, +hh + y),
new Phaser.Vec2(-hw + x, -hh + y),
new Phaser.Vec2(+hw + x, -hh + y),
new Phaser.Vec2(+hw + x, +hh + y)
]);
}
return Box;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Box = Box;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
(function (Physics) {
(function (Advanced) {
/// <reference path="../../../math/Vec2.ts" />
/// <reference path="../Manager.ts" />
/// <reference path="../Body.ts" />
/// <reference path="Shape.ts" />
/// <reference path="Poly.ts" />
/**
* Phaser - Advanced Physics - Shapes - Triangle
*
* Based on the work Ju Hyung Lee started in JS PhyRus.
*/
(function (Shapes) {
var Triangle = (function (_super) {
__extends(Triangle, _super);
function Triangle(p1, p2, p3) {
_super.call(this, [
new Phaser.Vec2(p1.x, p1.y),
new Phaser.Vec2(p2.x, p2.y),
new Phaser.Vec2(p3.x, p3.y)
]);
}
return Triangle;
})(Phaser.Physics.Advanced.Shapes.Poly);
Shapes.Triangle = Triangle;
})(Advanced.Shapes || (Advanced.Shapes = {}));
var Shapes = Advanced.Shapes;
})(Physics.Advanced || (Physics.Advanced = {}));
var Advanced = Physics.Advanced;
})(Phaser.Physics || (Phaser.Physics = {}));
var Physics = Phaser.Physics;
})(Phaser || (Phaser = {}));
/// <reference path="../Game.ts" />
/// <reference path="../geom/Point.ts" />
/// <reference path="../geom/Rectangle.ts" />