diff --git a/Phaser/physics/advanced/Body.ts b/Phaser/physics/advanced/Body.ts
index f974005d..b35ec1da 100644
--- a/Phaser/physics/advanced/Body.ts
+++ b/Phaser/physics/advanced/Body.ts
@@ -17,17 +17,24 @@ module Phaser.Physics.Advanced {
export class Body {
- constructor(sprite: Phaser.Sprite, type: number) {
-
- this.sprite = sprite;
- this.game = sprite.game;
+ constructor(sprite: Phaser.Sprite, type: number, x?: number = 0, y?: number = 0) {
this.id = Phaser.Physics.Advanced.Manager.bodyCounter++;
this.name = 'body' + this.id;
this.type = type;
- this.position = new Phaser.Vec2(sprite.x, sprite.y);
- this.angle = sprite.rotation;
+ if (sprite)
+ {
+ this.sprite = sprite;
+ this.game = sprite.game;
+ this.position = new Phaser.Vec2(sprite.x, sprite.y);
+ this.angle = sprite.rotation;
+ }
+ else
+ {
+ this.position = new Phaser.Vec2(x, y);
+ this.angle = 0;
+ }
this.transform = new Phaser.Transform(this.position, this.angle);
this.centroid = new Phaser.Vec2;
@@ -136,8 +143,22 @@ module Phaser.Physics.Advanced {
public stepCount = 0;
public space: Space;
- // duplicate = Util function
- // serialize = Util function
+ /*
+ public duplicate() {
+
+ var body = new Body(this.type, this.transform.t, this.angle);
+
+ for (var i = 0; i < this.shapes.length; i++)
+ {
+ body.addShape(this.shapes[i].duplicate());
+ }
+
+ body.resetMassData();
+
+ return body;
+
+ }
+ */
public get isDisabled(): bool {
return this.type == Phaser.Types.BODY_DISABLED ? true : false;
@@ -274,6 +295,8 @@ module Phaser.Physics.Advanced {
var mass = shape.area() * shape.density;
var inertia = shape.inertia(mass);
+ console.log('rmd', centroid, shape);
+
totalMassCentroid.multiplyAddByScalar(centroid, mass);
totalMass += mass;
totalInertia += inertia;
@@ -335,7 +358,7 @@ module Phaser.Physics.Advanced {
}
- private _tempVec2: Phaser.Vec2;
+ private _tempVec2: Phaser.Vec2 = new Phaser.Vec2;
public updateVelocity(gravity, dt, damping) {
diff --git a/Phaser/physics/advanced/Manager.ts b/Phaser/physics/advanced/Manager.ts
index 7aa5f976..c4b779df 100644
--- a/Phaser/physics/advanced/Manager.ts
+++ b/Phaser/physics/advanced/Manager.ts
@@ -17,6 +17,8 @@ module Phaser.Physics.Advanced {
this.game = game;
+ this.space = new Space();
+
Manager.collision = new Collision();
}
@@ -59,6 +61,92 @@ module Phaser.Physics.Advanced {
public static bodyCounter: number = 0;
public static jointCounter: number = 0;
public static shapeCounter: number = 0;
+
+ public space: Space;
+ public lastTime: number = 0;
+ public frameRateHz: number = 60;
+ public timeDelta: number = 0;
+ public paused: bool = false;
+ public step: bool = false; // step through the simulation (i.e. per click)
+ public velocityIterations: number = 8;
+ public positionIterations: number = 4;
+ public allowSleep: bool = true;
+ public warmStarting: bool = true;
+
+ public update() {
+
+ var time = Date.now();
+ var frameTime = (time - this.lastTime) / 1000;
+ this.lastTime = time;
+
+ // if rAf - why?
+ frameTime = Math.floor(frameTime * 60 + 0.5) / 60;
+
+ //if (!mouseDown)
+ //{
+ // var p = canvasToWorld(mousePosition);
+ // var body = space.findBodyByPoint(p);
+ // //domCanvas.style.cursor = body ? "pointer" : "default";
+ //}
+
+ if (!this.paused || this.step)
+ {
+ var h = 1 / this.frameRateHz;
+
+ this.timeDelta += frameTime;
+
+ if (this.step)
+ {
+ this.step = false;
+ this.timeDelta = h;
+ }
+
+ for (var maxSteps = 4; maxSteps > 0 && this.timeDelta >= h; maxSteps--)
+ {
+ this.space.step(h, this.velocityIterations, this.positionIterations, this.warmStarting, this.allowSleep);
+ this.timeDelta -= h;
+ }
+
+ if (this.timeDelta > h)
+ {
+ this.timeDelta = 0;
+ }
+
+ //if (sceneIndex < demoArr.length)
+ //{
+ // demo = demoArr[sceneIndex];
+ // demo.runFrame();
+ //}
+ }
+
+ //frameCount++;
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
public static pixelsToMeters(value: number): number {
return value * 0.02;
@@ -81,7 +169,7 @@ module Phaser.Physics.Advanced {
}
public static inertiaForCircle(mass, center, radius_outer, radius_inner) {
- return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthsq());
+ return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthSq());
}
public static areaForSegment(a, b, radius) {
diff --git a/Phaser/physics/advanced/Shape.ts b/Phaser/physics/advanced/Shape.ts
index 9061a800..5af9f73e 100644
--- a/Phaser/physics/advanced/Shape.ts
+++ b/Phaser/physics/advanced/Shape.ts
@@ -3,6 +3,7 @@
///
///
///
+///
/**
* Phaser - Advanced Physics - Shape
@@ -23,7 +24,7 @@ module Phaser.Physics.Advanced {
this.friction = 1.0;
this.density = 1;
- //this.bounds = new Bounds;
+ this.bounds = new Bounds;
}
@@ -40,7 +41,7 @@ module Phaser.Physics.Advanced {
public density: number;
// Axis-aligned bounding box
- public bounds;
+ public bounds: Bounds;
}
diff --git a/Phaser/physics/advanced/ShapeCircle.ts b/Phaser/physics/advanced/ShapeCircle.ts
index 680f52c5..f0b97f26 100644
--- a/Phaser/physics/advanced/ShapeCircle.ts
+++ b/Phaser/physics/advanced/ShapeCircle.ts
@@ -56,7 +56,7 @@ module Phaser.Physics.Advanced {
}
public centroid() {
- //return this.center.duplicate();
+ return Phaser.Vec2Utils.clone(this.center);
}
public inertia(mass) {
@@ -66,8 +66,8 @@ module Phaser.Physics.Advanced {
public cacheData(xf) {
this.tc = xf.transform(this.center);
- this.bounds.mins.set(this.tc.x - this.radius, this.tc.y - this.radius);
- this.bounds.maxs.set(this.tc.x + this.radius, this.tc.y + this.radius);
+ this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
+ this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
}
public pointQuery(p) {
diff --git a/Phaser/physics/advanced/ShapeSegment.ts b/Phaser/physics/advanced/ShapeSegment.ts
index 4359eb93..71703947 100644
--- a/Phaser/physics/advanced/ShapeSegment.ts
+++ b/Phaser/physics/advanced/ShapeSegment.ts
@@ -116,8 +116,8 @@ module Phaser.Physics.Advanced {
t = this.ta.y;
}
- this.bounds.mins.set(l - this.radius, b - this.radius);
- this.bounds.maxs.set(r + this.radius, t + this.radius);
+ this.bounds.mins.setTo(l - this.radius, b - this.radius);
+ this.bounds.maxs.setTo(r + this.radius, t + this.radius);
}
diff --git a/Tests/phaser.js b/Tests/phaser.js
index fb07542c..3b388a4f 100644
--- a/Tests/phaser.js
+++ b/Tests/phaser.js
@@ -19112,7 +19112,18 @@ var Phaser;
(function (Advanced) {
var Manager = (function () {
function Manager(game) {
+ this.lastTime = 0;
+ this.frameRateHz = 60;
+ this.timeDelta = 0;
+ this.paused = false;
+ this.step = false;
+ // step through the simulation (i.e. per click)
+ this.velocityIterations = 8;
+ this.positionIterations = 4;
+ this.allowSleep = true;
+ this.warmStarting = true;
this.game = game;
+ this.space = new Advanced.Space();
Manager.collision = new Advanced.Collision();
}
Manager.SHAPE_TYPE_CIRCLE = 0;
@@ -19141,6 +19152,40 @@ var Phaser;
Manager.bodyCounter = 0;
Manager.jointCounter = 0;
Manager.shapeCounter = 0;
+ Manager.prototype.update = function () {
+ var time = Date.now();
+ var frameTime = (time - this.lastTime) / 1000;
+ this.lastTime = time;
+ // if rAf - why?
+ frameTime = Math.floor(frameTime * 60 + 0.5) / 60;
+ //if (!mouseDown)
+ //{
+ // var p = canvasToWorld(mousePosition);
+ // var body = space.findBodyByPoint(p);
+ // //domCanvas.style.cursor = body ? "pointer" : "default";
+ //}
+ if(!this.paused || this.step) {
+ var h = 1 / this.frameRateHz;
+ this.timeDelta += frameTime;
+ if(this.step) {
+ this.step = false;
+ this.timeDelta = h;
+ }
+ for(var maxSteps = 4; maxSteps > 0 && this.timeDelta >= h; maxSteps--) {
+ this.space.step(h, this.velocityIterations, this.positionIterations, this.warmStarting, this.allowSleep);
+ this.timeDelta -= h;
+ }
+ if(this.timeDelta > h) {
+ this.timeDelta = 0;
+ }
+ //if (sceneIndex < demoArr.length)
+ //{
+ // demo = demoArr[sceneIndex];
+ // demo.runFrame();
+ //}
+ }
+ //frameCount++;
+ };
Manager.pixelsToMeters = function pixelsToMeters(value) {
return value * 0.02;
};
@@ -19157,7 +19202,7 @@ var Phaser;
return Math.PI * (radius_outer * radius_outer - radius_inner * radius_inner);
};
Manager.inertiaForCircle = function inertiaForCircle(mass, center, radius_outer, radius_inner) {
- return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthsq());
+ return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthSq());
};
Manager.areaForSegment = function areaForSegment(a, b, radius) {
return radius * (Math.PI * radius + 2 * Phaser.Vec2Utils.distance(a, b));
@@ -19432,6 +19477,7 @@ var Phaser;
///
///
///
+ ///
/**
* Phaser - Advanced Physics - Shape
*
@@ -19445,8 +19491,8 @@ var Phaser;
this.elasticity = 0.0;
this.friction = 1.0;
this.density = 1;
- //this.bounds = new Bounds;
- }
+ this.bounds = new Advanced.Bounds();
+ }
return Shape;
})();
Advanced.Shape = Shape;
@@ -19780,15 +19826,15 @@ var Phaser;
return Advanced.Manager.areaForCircle(this.radius, 0);
};
ShapeCircle.prototype.centroid = function () {
- //return this.center.duplicate();
- };
+ return Phaser.Vec2Utils.clone(this.center);
+ };
ShapeCircle.prototype.inertia = function (mass) {
return Advanced.Manager.inertiaForCircle(mass, this.center, this.radius, 0);
};
ShapeCircle.prototype.cacheData = function (xf) {
this.tc = xf.transform(this.center);
- this.bounds.mins.set(this.tc.x - this.radius, this.tc.y - this.radius);
- this.bounds.maxs.set(this.tc.x + this.radius, this.tc.y + this.radius);
+ this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
+ this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
};
ShapeCircle.prototype.pointQuery = function (p) {
//return vec2.distsq(this.tc, p) < (this.r * this.r);
@@ -20731,7 +20777,9 @@ var Phaser;
*/
(function (Advanced) {
var Body = (function () {
- function Body(sprite, type) {
+ function Body(sprite, type, x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
// Shapes
this.shapes = [];
// Joints
@@ -20742,13 +20790,19 @@ var Phaser;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
- this.sprite = sprite;
- this.game = sprite.game;
+ this._tempVec2 = new Phaser.Vec2();
this.id = Phaser.Physics.Advanced.Manager.bodyCounter++;
this.name = 'body' + this.id;
this.type = type;
- this.position = new Phaser.Vec2(sprite.x, sprite.y);
- this.angle = sprite.rotation;
+ if(sprite) {
+ this.sprite = sprite;
+ this.game = sprite.game;
+ this.position = new Phaser.Vec2(sprite.x, sprite.y);
+ this.angle = sprite.rotation;
+ } else {
+ this.position = new Phaser.Vec2(x, y);
+ this.angle = 0;
+ }
this.transform = new Phaser.Transform(this.position, this.angle);
this.centroid = new Phaser.Vec2();
this.velocity = new Phaser.Vec2();
@@ -20770,8 +20824,22 @@ var Phaser;
this.stepCount = 0;
}
Object.defineProperty(Body.prototype, "isDisabled", {
- get: // duplicate = Util function
- // serialize = Util function
+ get: /*
+ public duplicate() {
+
+ var body = new Body(this.type, this.transform.t, this.angle);
+
+ for (var i = 0; i < this.shapes.length; i++)
+ {
+ body.addShape(this.shapes[i].duplicate());
+ }
+
+ body.resetMassData();
+
+ return body;
+
+ }
+ */
function () {
return this.type == Phaser.Types.BODY_DISABLED ? true : false;
},
@@ -20875,6 +20943,7 @@ var Phaser;
var centroid = shape.centroid();
var mass = shape.area() * shape.density;
var inertia = shape.inertia(mass);
+ console.log('rmd', centroid, shape);
totalMassCentroid.multiplyAddByScalar(centroid, mass);
totalMass += mass;
totalInertia += inertia;
@@ -21357,8 +21426,8 @@ var Phaser;
b = this.tb.y;
t = this.ta.y;
}
- this.bounds.mins.set(l - this.radius, b - this.radius);
- this.bounds.maxs.set(r + this.radius, t + this.radius);
+ this.bounds.mins.setTo(l - this.radius, b - this.radius);
+ this.bounds.maxs.setTo(r + this.radius, t + this.radius);
};
ShapeSegment.prototype.pointQuery = function (p) {
if(!this.bounds.containPoint(p)) {
diff --git a/Tests/physics/body1.js b/Tests/physics/body1.js
index 4bda2968..14b00b1c 100644
--- a/Tests/physics/body1.js
+++ b/Tests/physics/body1.js
@@ -1,5 +1,7 @@
///
///
+///
+///
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
function init() {
@@ -9,16 +11,37 @@
}
var atari;
var card;
+ var physics;
+ var circle;
function create() {
- atari = game.add.sprite(200, 310, 'atari');
+ atari = game.add.sprite(200, 100, 'atari');
//card = game.add.sprite(500, 300, 'card');
- var body = new Phaser.Physics.Advanced.Body(atari, Phaser.Types.BODY_DYNAMIC);
- var body2 = new Phaser.Physics.Advanced.Body(atari, Phaser.Types.BODY_DYNAMIC);
- console.log(body);
- console.log(body2);
+ physics = new Phaser.Physics.Advanced.Manager(game);
+ var walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
+ walls.game = game;
+ 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();
+ physics.space.addBody(walls);
+ // Add a circle
+ circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 4, 4);
+ circle.game = game;
+ var shape = new Phaser.Physics.Advanced.ShapeCircle(0.4, 0, 0);
+ shape.elasticity = 0.5;
+ shape.friction = 1.0;
+ shape.density = 1;
+ circle.addShape(shape);
+ circle.resetMassData();
+ physics.space.addBody(circle);
}
function update() {
+ physics.update();
}
function render() {
+ game.stage.context.fillStyle = 'rgb(255,255,0)';
+ 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);
}
})();
diff --git a/Tests/physics/body1.ts b/Tests/physics/body1.ts
index b886eb15..940b453f 100644
--- a/Tests/physics/body1.ts
+++ b/Tests/physics/body1.ts
@@ -1,5 +1,7 @@
///
///
+///
+///
(function () {
@@ -15,24 +17,53 @@
var atari: Phaser.Sprite;
var card: Phaser.Sprite;
+ var physics: Phaser.Physics.Advanced.Manager;
+ var circle: Phaser.Physics.Advanced.Body;
function create() {
- atari = game.add.sprite(200, 310, 'atari');
+ atari = game.add.sprite(200, 100, 'atari');
//card = game.add.sprite(500, 300, 'card');
- var body = new Phaser.Physics.Advanced.Body(atari, Phaser.Types.BODY_DYNAMIC);
+ physics = new Phaser.Physics.Advanced.Manager(game);
- //body.
+ var walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
+ walls.game = game;
- console.log(body);
+ 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();
+
+ physics.space.addBody(walls);
+
+ // Add a circle
+
+ circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 4, 4);
+ circle.game = game;
+
+ var shape = new Phaser.Physics.Advanced.ShapeCircle(0.4, 0, 0);
+ shape.elasticity = 0.5;
+ shape.friction = 1.0;
+ shape.density = 1;
+ circle.addShape(shape);
+ circle.resetMassData();
+
+ physics.space.addBody(circle);
}
function update() {
+ physics.update();
}
function render() {
+
+ game.stage.context.fillStyle = 'rgb(255,255,0)';
+ 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);
+
}
})();
diff --git a/build/phaser.d.ts b/build/phaser.d.ts
index 722e1bce..ab8a9bcd 100644
--- a/build/phaser.d.ts
+++ b/build/phaser.d.ts
@@ -9610,6 +9610,17 @@ module Phaser.Physics.Advanced {
static bodyCounter: number;
static jointCounter: number;
static shapeCounter: number;
+ public space: Space;
+ public lastTime: number;
+ public frameRateHz: number;
+ public timeDelta: number;
+ public paused: bool;
+ public step: bool;
+ public velocityIterations: number;
+ public positionIterations: number;
+ public allowSleep: bool;
+ public warmStarting: bool;
+ public update(): void;
static pixelsToMeters(value: number): number;
static metersToPixels(value: number): number;
static p2m(value: number): number;
@@ -9671,7 +9682,7 @@ module Phaser.Physics.Advanced {
public elasticity: number;
public friction: number;
public density: number;
- public bounds;
+ public bounds: Bounds;
}
}
/**
@@ -9730,7 +9741,7 @@ module Phaser.Physics.Advanced {
public transform(xf): void;
public untransform(xf): void;
public area(): number;
- public centroid(): void;
+ public centroid(): Vec2;
public inertia(mass): number;
public cacheData(xf): void;
public pointQuery(p): bool;
@@ -9838,7 +9849,7 @@ module Phaser.Physics.Advanced {
*/
module Phaser.Physics.Advanced {
class Body {
- constructor(sprite: Sprite, type: number);
+ constructor(sprite: Sprite, type: number, x?: number, y?: number);
/**
* Reference to Phaser.Game
*/
diff --git a/build/phaser.js b/build/phaser.js
index fb07542c..3b388a4f 100644
--- a/build/phaser.js
+++ b/build/phaser.js
@@ -19112,7 +19112,18 @@ var Phaser;
(function (Advanced) {
var Manager = (function () {
function Manager(game) {
+ this.lastTime = 0;
+ this.frameRateHz = 60;
+ this.timeDelta = 0;
+ this.paused = false;
+ this.step = false;
+ // step through the simulation (i.e. per click)
+ this.velocityIterations = 8;
+ this.positionIterations = 4;
+ this.allowSleep = true;
+ this.warmStarting = true;
this.game = game;
+ this.space = new Advanced.Space();
Manager.collision = new Advanced.Collision();
}
Manager.SHAPE_TYPE_CIRCLE = 0;
@@ -19141,6 +19152,40 @@ var Phaser;
Manager.bodyCounter = 0;
Manager.jointCounter = 0;
Manager.shapeCounter = 0;
+ Manager.prototype.update = function () {
+ var time = Date.now();
+ var frameTime = (time - this.lastTime) / 1000;
+ this.lastTime = time;
+ // if rAf - why?
+ frameTime = Math.floor(frameTime * 60 + 0.5) / 60;
+ //if (!mouseDown)
+ //{
+ // var p = canvasToWorld(mousePosition);
+ // var body = space.findBodyByPoint(p);
+ // //domCanvas.style.cursor = body ? "pointer" : "default";
+ //}
+ if(!this.paused || this.step) {
+ var h = 1 / this.frameRateHz;
+ this.timeDelta += frameTime;
+ if(this.step) {
+ this.step = false;
+ this.timeDelta = h;
+ }
+ for(var maxSteps = 4; maxSteps > 0 && this.timeDelta >= h; maxSteps--) {
+ this.space.step(h, this.velocityIterations, this.positionIterations, this.warmStarting, this.allowSleep);
+ this.timeDelta -= h;
+ }
+ if(this.timeDelta > h) {
+ this.timeDelta = 0;
+ }
+ //if (sceneIndex < demoArr.length)
+ //{
+ // demo = demoArr[sceneIndex];
+ // demo.runFrame();
+ //}
+ }
+ //frameCount++;
+ };
Manager.pixelsToMeters = function pixelsToMeters(value) {
return value * 0.02;
};
@@ -19157,7 +19202,7 @@ var Phaser;
return Math.PI * (radius_outer * radius_outer - radius_inner * radius_inner);
};
Manager.inertiaForCircle = function inertiaForCircle(mass, center, radius_outer, radius_inner) {
- return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthsq());
+ return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthSq());
};
Manager.areaForSegment = function areaForSegment(a, b, radius) {
return radius * (Math.PI * radius + 2 * Phaser.Vec2Utils.distance(a, b));
@@ -19432,6 +19477,7 @@ var Phaser;
///
///
///
+ ///
/**
* Phaser - Advanced Physics - Shape
*
@@ -19445,8 +19491,8 @@ var Phaser;
this.elasticity = 0.0;
this.friction = 1.0;
this.density = 1;
- //this.bounds = new Bounds;
- }
+ this.bounds = new Advanced.Bounds();
+ }
return Shape;
})();
Advanced.Shape = Shape;
@@ -19780,15 +19826,15 @@ var Phaser;
return Advanced.Manager.areaForCircle(this.radius, 0);
};
ShapeCircle.prototype.centroid = function () {
- //return this.center.duplicate();
- };
+ return Phaser.Vec2Utils.clone(this.center);
+ };
ShapeCircle.prototype.inertia = function (mass) {
return Advanced.Manager.inertiaForCircle(mass, this.center, this.radius, 0);
};
ShapeCircle.prototype.cacheData = function (xf) {
this.tc = xf.transform(this.center);
- this.bounds.mins.set(this.tc.x - this.radius, this.tc.y - this.radius);
- this.bounds.maxs.set(this.tc.x + this.radius, this.tc.y + this.radius);
+ this.bounds.mins.setTo(this.tc.x - this.radius, this.tc.y - this.radius);
+ this.bounds.maxs.setTo(this.tc.x + this.radius, this.tc.y + this.radius);
};
ShapeCircle.prototype.pointQuery = function (p) {
//return vec2.distsq(this.tc, p) < (this.r * this.r);
@@ -20731,7 +20777,9 @@ var Phaser;
*/
(function (Advanced) {
var Body = (function () {
- function Body(sprite, type) {
+ function Body(sprite, type, x, y) {
+ if (typeof x === "undefined") { x = 0; }
+ if (typeof y === "undefined") { y = 0; }
// Shapes
this.shapes = [];
// Joints
@@ -20742,13 +20790,19 @@ var Phaser;
this.categoryBits = 0x0001;
this.maskBits = 0xFFFF;
this.stepCount = 0;
- this.sprite = sprite;
- this.game = sprite.game;
+ this._tempVec2 = new Phaser.Vec2();
this.id = Phaser.Physics.Advanced.Manager.bodyCounter++;
this.name = 'body' + this.id;
this.type = type;
- this.position = new Phaser.Vec2(sprite.x, sprite.y);
- this.angle = sprite.rotation;
+ if(sprite) {
+ this.sprite = sprite;
+ this.game = sprite.game;
+ this.position = new Phaser.Vec2(sprite.x, sprite.y);
+ this.angle = sprite.rotation;
+ } else {
+ this.position = new Phaser.Vec2(x, y);
+ this.angle = 0;
+ }
this.transform = new Phaser.Transform(this.position, this.angle);
this.centroid = new Phaser.Vec2();
this.velocity = new Phaser.Vec2();
@@ -20770,8 +20824,22 @@ var Phaser;
this.stepCount = 0;
}
Object.defineProperty(Body.prototype, "isDisabled", {
- get: // duplicate = Util function
- // serialize = Util function
+ get: /*
+ public duplicate() {
+
+ var body = new Body(this.type, this.transform.t, this.angle);
+
+ for (var i = 0; i < this.shapes.length; i++)
+ {
+ body.addShape(this.shapes[i].duplicate());
+ }
+
+ body.resetMassData();
+
+ return body;
+
+ }
+ */
function () {
return this.type == Phaser.Types.BODY_DISABLED ? true : false;
},
@@ -20875,6 +20943,7 @@ var Phaser;
var centroid = shape.centroid();
var mass = shape.area() * shape.density;
var inertia = shape.inertia(mass);
+ console.log('rmd', centroid, shape);
totalMassCentroid.multiplyAddByScalar(centroid, mass);
totalMass += mass;
totalInertia += inertia;
@@ -21357,8 +21426,8 @@ var Phaser;
b = this.tb.y;
t = this.ta.y;
}
- this.bounds.mins.set(l - this.radius, b - this.radius);
- this.bounds.maxs.set(r + this.radius, t + this.radius);
+ this.bounds.mins.setTo(l - this.radius, b - this.radius);
+ this.bounds.maxs.setTo(r + this.radius, t + this.radius);
};
ShapeSegment.prototype.pointQuery = function (p) {
if(!this.bounds.containPoint(p)) {