Skip to content

Commit 6500826

Browse files
committed
Fixed worldConstraint
1 parent 4a1b969 commit 6500826

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/physics/matter-js/Factory.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var MatterSprite = require('./MatterSprite');
1515
var MatterTileBody = require('./MatterTileBody');
1616
var PointerConstraint = require('./PointerConstraint');
1717
var Vertices = require('./lib/geometry/Vertices');
18+
var Vector = require('./lib/geometry/Vector');
1819

1920
/**
2021
* @classdesc
@@ -474,19 +475,22 @@ var Factory = new Class({
474475
* @method Phaser.Physics.Matter.Factory#worldConstraint
475476
* @since 3.0.0
476477
*
477-
* @param {MatterJS.Body} bodyB - The second possible `Body` that this constraint is attached to.
478-
* @param {number} [length] - A Number that specifies the target resting length of the constraint. If not given it is calculated automatically in `Constraint.create` from initial positions of the `constraint.bodyA` and `constraint.bodyB`.
478+
* @param {number} x - The x position in the world to create the constraint at.
479+
* @param {number} y - The y position in the world to create the constraint at.
480+
* @param {MatterJS.Body} body - The Matter `Body` that this constraint is attached to.
481+
* @param {number} [length] - A number that specifies the target resting length of the constraint. If not given it is calculated automatically in `Constraint.create` from initial positions of the `constraint.bodyA` and `constraint.bodyB`.
479482
* @param {number} [stiffness=1] - A Number that specifies the stiffness of the constraint, i.e. the rate at which it returns to its resting `constraint.length`. A value of `1` means the constraint should be very stiff. A value of `0.2` means the constraint acts as a soft spring.
480483
* @param {object} [options={}] - [description]
481484
*
482485
* @return {MatterJS.Constraint} A Matter JS Constraint.
483486
*/
484-
worldConstraint: function (bodyB, length, stiffness, options)
487+
worldConstraint: function (x, y, body, length, stiffness, options)
485488
{
486489
if (stiffness === undefined) { stiffness = 1; }
487490
if (options === undefined) { options = {}; }
488491

489-
options.bodyB = (bodyB.type === 'body') ? bodyB : bodyB.body;
492+
options.pointA = Vector.create(x, y);
493+
options.bodyB = (body.type === 'body') ? body : body.body;
490494

491495
if (!isNaN(length))
492496
{

0 commit comments

Comments
 (0)