mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 22:18:29 +00:00
MatterPhysics.getConstraintLength
is a new method that will return the length of the given constraint, as this is something you cannot get from the constraint properties directly.
This commit is contained in:
parent
b8797de87a
commit
d6e0ba9b29
1 changed files with 33 additions and 0 deletions
|
@ -13,6 +13,7 @@ var Composite = require('./lib/body/Composite');
|
|||
var Composites = require('./lib/factory/Composites');
|
||||
var Constraint = require('./lib/constraint/Constraint');
|
||||
var Detector = require('./lib/collision/Detector');
|
||||
var DistanceBetween = require('../../math/distance/DistanceBetween');
|
||||
var Factory = require('./Factory');
|
||||
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||
var GetValue = require('../../utils/object/GetValue');
|
||||
|
@ -1271,6 +1272,38 @@ var MatterPhysics = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the length of the given constraint, which is the distance between the two points.
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#getConstraintLength
|
||||
* @since 3.22.0
|
||||
*
|
||||
* @param {MatterJS.Constraint} constraint - The constraint to get the length from.
|
||||
*
|
||||
* @return {number} The length of the constraint.
|
||||
*/
|
||||
getConstraintLength: function (constraint)
|
||||
{
|
||||
var aX = constraint.pointA.x;
|
||||
var aY = constraint.pointA.y;
|
||||
var bX = constraint.pointB.x;
|
||||
var bY = constraint.pointB.y;
|
||||
|
||||
if (constraint.bodyA)
|
||||
{
|
||||
aX += constraint.bodyA.position.x;
|
||||
aY += constraint.bodyA.position.y;
|
||||
}
|
||||
|
||||
if (constraint.bodyB)
|
||||
{
|
||||
bX += constraint.bodyB.position.x;
|
||||
bY += constraint.bodyB.position.y;
|
||||
}
|
||||
|
||||
return DistanceBetween(aX, aY, bX, bY);
|
||||
},
|
||||
|
||||
/**
|
||||
* The Scene that owns this plugin is shutting down.
|
||||
* We need to kill and reset all internal properties as well as stop listening to Scene events.
|
||||
|
|
Loading…
Add table
Reference in a new issue