Fixed the RevoluteConstraint worldPivot and moved it to the end of the signature to minimise code changes.

This commit is contained in:
photonstorm 2014-08-28 01:14:59 +01:00
parent aeb82dbee9
commit c87aa5103d
3 changed files with 12 additions and 6 deletions

View file

@ -94,7 +94,7 @@ Version 2.1.0 - "Cairhien" - -in development-
### p2.js 0.6.0 Changes and New Features
* DistanceConstraint signature changed to take the new localAnchors.
* RevoluteConstraint signature changed to include worldPivot
* RevoluteConstraint signature changed to include worldPivot.
* P2.Body now uses the new Body.type value instead of Body.motionState, however as P2.Body already have a property called `type` we have left the `motionState` getter/setter in for now.
* World.enableBodySleeping has been removed and replaced with World.sleepMode.
* Phaser P2.Springs are now LinearSprings by default.

View file

@ -16,13 +16,13 @@
* @param {Float32Array} pivotA - The point relative to the center of mass of bodyA which bodyA is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param {p2.Body} bodyB - Second connected body.
* @param {Float32Array} pivotB - The point relative to the center of mass of bodyB which bodyB is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param {Float32Array} [worldPivot] - A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
* @param {number} [maxForce=0] - The maximum force that should be applied to constrain the bodies.
* @param {Float32Array} [worldPivot=null] - A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
*/
Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pivotB, worldPivot, maxForce) {
Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot) {
if (typeof worldPivot === 'undefined') { worldPivot = null; }
if (typeof maxForce === 'undefined') { maxForce = Number.MAX_VALUE; }
if (typeof worldPivot === 'undefined') { worldPivot = null; }
/**
* @property {Phaser.Game} game - Local reference to game.
@ -37,6 +37,11 @@ Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pi
pivotA = [ world.pxmi(pivotA[0]), world.pxmi(pivotA[1]) ];
pivotB = [ world.pxmi(pivotB[0]), world.pxmi(pivotB[1]) ];
if (worldPivot)
{
worldPivot = [ world.pxmi(worldPivot[0]), world.pxmi(worldPivot[1]) ];
}
var options = { worldPivot: worldPivot, localPivotA: pivotA, localPivotB: pivotB, maxForce: maxForce };
p2.RevoluteConstraint.call(this, bodyA, bodyB, options);

View file

@ -856,9 +856,10 @@ Phaser.Physics.P2.prototype = {
* @param {Phaser.Sprite|Phaser.Physics.P2.Body|p2.Body} bodyB - Second connected body.
* @param {Array} pivotB - The point relative to the center of mass of bodyB which bodyB is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param {number} [maxForce=0] - The maximum force that should be applied to constrain the bodies.
* @param {Float32Array} [worldPivot=null] - A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
* @return {Phaser.Physics.P2.RevoluteConstraint} The constraint
*/
createRevoluteConstraint: function (bodyA, pivotA, bodyB, pivotB, maxForce) {
createRevoluteConstraint: function (bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot) {
bodyA = this.getBody(bodyA);
bodyB = this.getBody(bodyB);
@ -869,7 +870,7 @@ Phaser.Physics.P2.prototype = {
}
else
{
return this.addConstraint(new Phaser.Physics.P2.RevoluteConstraint(this, bodyA, pivotA, bodyB, pivotB, maxForce));
return this.addConstraint(new Phaser.Physics.P2.RevoluteConstraint(this, bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot));
}
},