Skip to content

Commit c87aa51

Browse files
committed
Fixed the RevoluteConstraint worldPivot and moved it to the end of the signature to minimise code changes.
1 parent aeb82db commit c87aa51

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Version 2.1.0 - "Cairhien" - -in development-
9494
### p2.js 0.6.0 Changes and New Features
9595

9696
* DistanceConstraint signature changed to take the new localAnchors.
97-
* RevoluteConstraint signature changed to include worldPivot
97+
* RevoluteConstraint signature changed to include worldPivot.
9898
* 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.
9999
* World.enableBodySleeping has been removed and replaced with World.sleepMode.
100100
* Phaser P2.Springs are now LinearSprings by default.

src/physics/p2/RevoluteConstraint.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
* @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].
1717
* @param {p2.Body} bodyB - Second connected body.
1818
* @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].
19-
* @param {Float32Array} [worldPivot] - A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
2019
* @param {number} [maxForce=0] - The maximum force that should be applied to constrain the bodies.
20+
* @param {Float32Array} [worldPivot=null] - A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
2121
*/
22-
Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pivotB, worldPivot, maxForce) {
22+
Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot) {
2323

24-
if (typeof worldPivot === 'undefined') { worldPivot = null; }
2524
if (typeof maxForce === 'undefined') { maxForce = Number.MAX_VALUE; }
25+
if (typeof worldPivot === 'undefined') { worldPivot = null; }
2626

2727
/**
2828
* @property {Phaser.Game} game - Local reference to game.
@@ -37,6 +37,11 @@ Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pi
3737
pivotA = [ world.pxmi(pivotA[0]), world.pxmi(pivotA[1]) ];
3838
pivotB = [ world.pxmi(pivotB[0]), world.pxmi(pivotB[1]) ];
3939

40+
if (worldPivot)
41+
{
42+
worldPivot = [ world.pxmi(worldPivot[0]), world.pxmi(worldPivot[1]) ];
43+
}
44+
4045
var options = { worldPivot: worldPivot, localPivotA: pivotA, localPivotB: pivotB, maxForce: maxForce };
4146

4247
p2.RevoluteConstraint.call(this, bodyA, bodyB, options);

src/physics/p2/World.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,10 @@ Phaser.Physics.P2.prototype = {
856856
* @param {Phaser.Sprite|Phaser.Physics.P2.Body|p2.Body} bodyB - Second connected body.
857857
* @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].
858858
* @param {number} [maxForce=0] - The maximum force that should be applied to constrain the bodies.
859+
* @param {Float32Array} [worldPivot=null] - A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
859860
* @return {Phaser.Physics.P2.RevoluteConstraint} The constraint
860861
*/
861-
createRevoluteConstraint: function (bodyA, pivotA, bodyB, pivotB, maxForce) {
862+
createRevoluteConstraint: function (bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot) {
862863

863864
bodyA = this.getBody(bodyA);
864865
bodyB = this.getBody(bodyB);
@@ -869,7 +870,7 @@ Phaser.Physics.P2.prototype = {
869870
}
870871
else
871872
{
872-
return this.addConstraint(new Phaser.Physics.P2.RevoluteConstraint(this, bodyA, pivotA, bodyB, pivotB, maxForce));
873+
return this.addConstraint(new Phaser.Physics.P2.RevoluteConstraint(this, bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot));
873874
}
874875

875876
},

0 commit comments

Comments
 (0)