2014-03-13 11:13:22 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A constraint that tries to keep the distance between two bodies constant.
|
|
|
|
*
|
|
|
|
* @class Phaser.Physics.P2.DistanceConstraint
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Physics.P2} world - A reference to the P2 World.
|
|
|
|
* @param {p2.Body} bodyA - First connected body.
|
|
|
|
* @param {p2.Body} bodyB - Second connected body.
|
|
|
|
* @param {number} distance - The distance to keep between the bodies.
|
2014-08-27 23:15:28 +00:00
|
|
|
* @param {Array} [localAnchorA] - The anchor point for bodyA, defined locally in bodyA frame. Defaults to [0,0].
|
|
|
|
* @param {Array} [localAnchorB] - The anchor point for bodyB, defined locally in bodyB frame. Defaults to [0,0].
|
|
|
|
* @param {object} [maxForce=Number.MAX_VALUE] - Maximum force to apply.
|
2014-03-13 11:13:22 +00:00
|
|
|
*/
|
2014-08-27 23:15:28 +00:00
|
|
|
Phaser.Physics.P2.DistanceConstraint = function (world, bodyA, bodyB, distance, localAnchorA, localAnchorB, maxForce) {
|
2014-03-13 11:13:22 +00:00
|
|
|
|
2014-03-13 13:09:33 +00:00
|
|
|
if (typeof distance === 'undefined') { distance = 100; }
|
2014-08-27 23:15:28 +00:00
|
|
|
if (typeof localAnchorA === 'undefined') { localAnchorA = [0, 0]; }
|
|
|
|
if (typeof localAnchorB === 'undefined') { localAnchorB = [0, 0]; }
|
|
|
|
if (typeof maxForce === 'undefined') { maxForce = Number.MAX_VALUE; }
|
2014-03-13 13:09:33 +00:00
|
|
|
|
2014-03-13 11:13:22 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - Local reference to game.
|
|
|
|
*/
|
|
|
|
this.game = world.game;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Physics.P2} world - Local reference to P2 World.
|
|
|
|
*/
|
|
|
|
this.world = world;
|
|
|
|
|
|
|
|
distance = world.pxm(distance);
|
|
|
|
|
2014-08-27 23:15:28 +00:00
|
|
|
localAnchorA = [ world.pxmi(localAnchorA[0]), world.pxmi(localAnchorA[1]) ];
|
|
|
|
localAnchorB = [ world.pxmi(localAnchorB[0]), world.pxmi(localAnchorB[1]) ];
|
|
|
|
|
|
|
|
var options = { distance: distance, localAnchorA: localAnchorA, localAnchorB: localAnchorB, maxForce: maxForce };
|
|
|
|
|
|
|
|
p2.DistanceConstraint.call(this, bodyA, bodyB, options);
|
2014-03-13 11:13:22 +00:00
|
|
|
|
2014-03-23 06:31:26 +00:00
|
|
|
};
|
2014-03-13 11:13:22 +00:00
|
|
|
|
|
|
|
Phaser.Physics.P2.DistanceConstraint.prototype = Object.create(p2.DistanceConstraint.prototype);
|
|
|
|
Phaser.Physics.P2.DistanceConstraint.prototype.constructor = Phaser.Physics.P2.DistanceConstraint;
|