Skip to content

Commit b25bdf3

Browse files
committed
Fixed the DistanceConstraint parameters.
1 parent 504b69f commit b25bdf3

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@ Version 2.1.0 - "Cairhien" - -in development-
6969

7070
### Updates
7171

72+
* Updated to the latest build of [p2.js](https://github.com/schteppe/p2.js/commit/d1c7a340c42e4d5d1d939fba5fd13c5e49d6abd2)
7273
* TypeScript definition updates to help fix for the `noimplicitany` option (thanks @Waog #1088)
7374
* All of the Pixi geom classes have been removed from the build file as they aren't needed (the Phaser.Geom classes overwrite them), saving some space in the process.
7475

76+
### p2.js changes
77+
78+
* DistanceConstraint signature changed to take the new localAnchors.
79+
*
80+
7581
### New Features
7682

7783
* Device will now detect for Kindle and PS Vita (thanks @lucbloom)

src/physics/p2/DistanceConstraint.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
* @param {p2.Body} bodyA - First connected body.
1515
* @param {p2.Body} bodyB - Second connected body.
1616
* @param {number} distance - The distance to keep between the bodies.
17-
* @param {number} [maxForce] - The maximum force that should be applied to constrain the bodies.
17+
* @param {Array} [localAnchorA] - The anchor point for bodyA, defined locally in bodyA frame. Defaults to [0,0].
18+
* @param {Array} [localAnchorB] - The anchor point for bodyB, defined locally in bodyB frame. Defaults to [0,0].
19+
* @param {object} [maxForce=Number.MAX_VALUE] - Maximum force to apply.
1820
*/
19-
Phaser.Physics.P2.DistanceConstraint = function (world, bodyA, bodyB, distance, maxForce) {
21+
Phaser.Physics.P2.DistanceConstraint = function (world, bodyA, bodyB, distance, localAnchorA, localAnchorB, maxForce) {
2022

2123
if (typeof distance === 'undefined') { distance = 100; }
24+
if (typeof localAnchorA === 'undefined') { localAnchorA = [0, 0]; }
25+
if (typeof localAnchorB === 'undefined') { localAnchorB = [0, 0]; }
26+
if (typeof maxForce === 'undefined') { maxForce = Number.MAX_VALUE; }
2227

2328
/**
2429
* @property {Phaser.Game} game - Local reference to game.
@@ -32,7 +37,12 @@ Phaser.Physics.P2.DistanceConstraint = function (world, bodyA, bodyB, distance,
3237

3338
distance = world.pxm(distance);
3439

35-
p2.DistanceConstraint.call(this, bodyA, bodyB, distance, {maxForce: maxForce});
40+
localAnchorA = [ world.pxmi(localAnchorA[0]), world.pxmi(localAnchorA[1]) ];
41+
localAnchorB = [ world.pxmi(localAnchorB[0]), world.pxmi(localAnchorB[1]) ];
42+
43+
var options = { distance: distance, localAnchorA: localAnchorA, localAnchorB: localAnchorB, maxForce: maxForce };
44+
45+
p2.DistanceConstraint.call(this, bodyA, bodyB, options);
3646

3747
};
3848

0 commit comments

Comments
 (0)