Skip to content

Commit bb29aed

Browse files
committed
Matter.Factory.constraint wouldn't allow a zero length constraint to be created due to a falsey check of the length argument. You can now set length to be any value, including zero, or leave it undefined to have it automatically calculated
1 parent 96f96a7 commit bb29aed

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
### Bug Fixes
1717

1818
* The Scale Manager would throw the error 'TypeError: this.removeFullscreenTarget is not a function' when entering full-screen mode. It would still enter fullscreen, but the error would appear in the console. Fix #4605 (thanks @darklightcode)
19-
19+
* `Tilemap.renderDebug` was calling out-dated Graphics API methods, which would cause the debug to fail (thanks @Fabadiculous)
20+
* The `Matter.Factory.constraint`, `joint` and `worldConstraint` methods wouldn't allow a zero length constraint to be created due to a falsey check of the length argument. You can now set length to be any value, including zero, or leave it undefined to have it automatically calculated (thanks @olilanz)
2021

2122

2223

src/physics/matter-js/Factory.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ var Factory = new Class({
400400
* @method Phaser.Physics.Matter.Factory#joint
401401
* @since 3.0.0
402402
*
403-
* @param {MatterJS.Body} bodyA - [description]
404-
* @param {MatterJS.Body} bodyB - [description]
405-
* @param {number} length - [description]
406-
* @param {number} [stiffness=1] - [description]
403+
* @param {MatterJS.Body} bodyA - The first possible `Body` that this constraint is attached to.
404+
* @param {MatterJS.Body} bodyB - The second possible `Body` that this constraint is attached to.
405+
* @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`.
406+
* @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.
407407
* @param {object} [options={}] - [description]
408408
*
409409
* @return {MatterJS.Constraint} A Matter JS Constraint.
@@ -421,7 +421,7 @@ var Factory = new Class({
421421
*
422422
* @param {MatterJS.Body} bodyA - The first possible `Body` that this constraint is attached to.
423423
* @param {MatterJS.Body} bodyB - The second possible `Body` that this constraint is attached to.
424-
* @param {number} length - A Number that specifies the target resting length of the constraint. It is calculated automatically in `Constraint.create` from initial positions of the `constraint.bodyA` and `constraint.bodyB`
424+
* @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`.
425425
* @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.
426426
* @param {object} [options={}] - [description]
427427
*
@@ -438,10 +438,10 @@ var Factory = new Class({
438438
* @method Phaser.Physics.Matter.Factory#constraint
439439
* @since 3.0.0
440440
*
441-
* @param {MatterJS.Body} bodyA - [description]
442-
* @param {MatterJS.Body} bodyB - [description]
443-
* @param {number} [length] - [description]
444-
* @param {number} [stiffness=1] - [description]
441+
* @param {MatterJS.Body} bodyA - The first possible `Body` that this constraint is attached to.
442+
* @param {MatterJS.Body} bodyB - The second possible `Body` that this constraint is attached to.
443+
* @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`.
444+
* @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.
445445
* @param {object} [options={}] - [description]
446446
*
447447
* @return {MatterJS.Constraint} A Matter JS Constraint.
@@ -454,7 +454,7 @@ var Factory = new Class({
454454
options.bodyA = (bodyA.type === 'body') ? bodyA : bodyA.body;
455455
options.bodyB = (bodyB.type === 'body') ? bodyB : bodyB.body;
456456

457-
if (length)
457+
if (!isNaN(length))
458458
{
459459
options.length = length;
460460
}
@@ -474,9 +474,9 @@ var Factory = new Class({
474474
* @method Phaser.Physics.Matter.Factory#worldConstraint
475475
* @since 3.0.0
476476
*
477-
* @param {MatterJS.Body} bodyB - [description]
478-
* @param {number} length - [description]
479-
* @param {number} [stiffness=1] - [description]
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`.
479+
* @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.
480480
* @param {object} [options={}] - [description]
481481
*
482482
* @return {MatterJS.Constraint} A Matter JS Constraint.
@@ -487,7 +487,12 @@ var Factory = new Class({
487487
if (options === undefined) { options = {}; }
488488

489489
options.bodyB = (bodyB.type === 'body') ? bodyB : bodyB.body;
490-
options.length = length;
490+
491+
if (!isNaN(length))
492+
{
493+
options.length = length;
494+
}
495+
491496
options.stiffness = stiffness;
492497

493498
var constraint = Constraint.create(options);

0 commit comments

Comments
 (0)