phaser/src/physics/p2/LockConstraint.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-03-13 12:14:14 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2015-02-25 03:36:23 +00:00
* @copyright 2015 Photon Storm Ltd.
2014-03-13 12:14:14 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Locks the relative position between two bodies.
2014-03-13 12:14:14 +00:00
*
* @class Phaser.Physics.P2.LockConstraint
* @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 {Array} [offset] - The offset of bodyB in bodyA's frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param {number} [angle=0] - The angle of bodyB in bodyA's frame.
* @param {number} [maxForce] - The maximum force that should be applied to constrain the bodies.
2014-03-13 12:14:14 +00:00
*/
Phaser.Physics.P2.LockConstraint = function (world, bodyA, bodyB, offset, angle, maxForce) {
2014-03-13 12:14:14 +00:00
if (offset === undefined) { offset = [0, 0]; }
if (angle === undefined) { angle = 0; }
if (maxForce === undefined) { maxForce = Number.MAX_VALUE; }
2014-03-13 12:14:14 +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;
offset = [ world.pxm(offset[0]), world.pxm(offset[1]) ];
var options = { localOffsetB: offset, localAngleB: angle, maxForce: maxForce };
2014-03-13 12:14:14 +00:00
p2.LockConstraint.call(this, bodyA, bodyB, options);
2014-03-23 06:31:26 +00:00
};
2014-03-13 12:14:14 +00:00
Phaser.Physics.P2.LockConstraint.prototype = Object.create(p2.LockConstraint.prototype);
Phaser.Physics.P2.LockConstraint.prototype.constructor = Phaser.Physics.P2.LockConstraint;