2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-11-21 16:53:36 +00:00
|
|
|
var Bodies = require('./lib/factory/Bodies');
|
2017-11-20 16:54:26 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-11-22 02:25:42 +00:00
|
|
|
var Composites = require('./lib/factory/Composites');
|
2017-11-22 16:23:47 +00:00
|
|
|
var Constraint = require('./lib/constraint/Constraint');
|
2018-03-17 18:07:05 +00:00
|
|
|
var MatterGameObject = require('./MatterGameObject');
|
2017-11-21 16:53:36 +00:00
|
|
|
var MatterImage = require('./MatterImage');
|
|
|
|
var MatterSprite = require('./MatterSprite');
|
2018-01-21 18:53:48 +00:00
|
|
|
var MatterTileBody = require('./MatterTileBody');
|
2018-02-12 13:14:50 +00:00
|
|
|
var PointerConstraint = require('./PointerConstraint');
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2018-10-22 11:12:31 +00:00
|
|
|
* The Matter Factory can create different types of bodies and them to a physics world.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @class Factory
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Physics.Matter
|
2018-02-12 13:14:50 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-22 11:12:31 +00:00
|
|
|
* @param {Phaser.Physics.Matter.World} world - The Matter World which this Factory adds to.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-20 16:54:26 +00:00
|
|
|
var Factory = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Factory (world)
|
|
|
|
{
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* The Matter World which this Factory adds to.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.Factory#world
|
|
|
|
* @type {Phaser.Physics.Matter.World}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-20 16:54:26 +00:00
|
|
|
this.world = world;
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* The Scene which this Factory's Matter World belongs to.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.Factory#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-20 16:54:26 +00:00
|
|
|
this.scene = world.scene;
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* A reference to the Scene.Systems this Matter Physics instance belongs to.
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.Factory#sys
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-20 16:54:26 +00:00
|
|
|
this.sys = world.scene.sys;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* Creates a new rigid rectangular Body and adds it to the World.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#rectangle
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-22 11:12:31 +00:00
|
|
|
* @param {number} x - The X coordinate of the center of the Body.
|
|
|
|
* @param {number} y - The Y coordinate of the center of the Body.
|
|
|
|
* @param {number} width - The width of the Body.
|
|
|
|
* @param {number} height - The height of the Body.
|
|
|
|
* @param {object} options - An object of properties to set on the Body. You can also specify a `chamfer` property to automatically adjust the body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Body} A Matter JS Body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-21 16:53:36 +00:00
|
|
|
rectangle: function (x, y, width, height, options)
|
2017-11-20 16:54:26 +00:00
|
|
|
{
|
2017-11-21 16:53:36 +00:00
|
|
|
var body = Bodies.rectangle(x, y, width, height, options);
|
|
|
|
|
|
|
|
this.world.add(body);
|
|
|
|
|
|
|
|
return body;
|
2017-11-20 16:54:26 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* Creates a new rigid trapezoidal Body and adds it to the World.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#trapezoid
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-22 11:12:31 +00:00
|
|
|
* @param {number} x - The X coordinate of the center of the Body.
|
|
|
|
* @param {number} y - The Y coordinate of the center of the Body.
|
|
|
|
* @param {number} width - The width of the trapezoid of the Body.
|
|
|
|
* @param {number} height - The height of the trapezoid of the Body.
|
|
|
|
* @param {number} slope - The slope of the trapezoid. 0 creates a rectangle, while 1 creates a triangle. Positive values make the top side shorter, while negative values make the bottom side shorter.
|
|
|
|
* @param {object} options - An object of properties to set on the Body. You can also specify a `chamfer` property to automatically adjust the body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Body} A Matter JS Body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-21 16:53:36 +00:00
|
|
|
trapezoid: function (x, y, width, height, slope, options)
|
2017-11-20 16:54:26 +00:00
|
|
|
{
|
2017-11-21 16:53:36 +00:00
|
|
|
var body = Bodies.trapezoid(x, y, width, height, slope, options);
|
|
|
|
|
|
|
|
this.world.add(body);
|
|
|
|
|
|
|
|
return body;
|
2017-11-20 16:54:26 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* Creates a new rigid circular Body and adds it to the World.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#circle
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-22 11:12:31 +00:00
|
|
|
* @param {number} x - The X coordinate of the center of the Body.
|
|
|
|
* @param {number} y - The Y coordinate of the center of the Body.
|
|
|
|
* @param {number} radius - The radius of the circle.
|
|
|
|
* @param {object} options - An object of properties to set on the Body. You can also specify a `chamfer` property to automatically adjust the body.
|
|
|
|
* @param {number} maxSides - The maximum amount of sides to use for the polygon which will approximate this circle.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Body} A Matter JS Body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-21 16:53:36 +00:00
|
|
|
circle: function (x, y, radius, options, maxSides)
|
2017-11-20 16:54:26 +00:00
|
|
|
{
|
2017-11-21 16:53:36 +00:00
|
|
|
var body = Bodies.circle(x, y, radius, options, maxSides);
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2017-11-21 16:53:36 +00:00
|
|
|
this.world.add(body);
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2017-11-21 16:53:36 +00:00
|
|
|
return body;
|
2017-11-20 16:54:26 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* Creates a new rigid polygonal Body and adds it to the World.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#polygon
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-22 11:12:31 +00:00
|
|
|
* @param {number} x - The X coordinate of the center of the Body.
|
|
|
|
* @param {number} y - The Y coordinate of the center of the Body.
|
|
|
|
* @param {number} sides - The number of sides the polygon will have.
|
|
|
|
* @param {number} radius - The "radius" of the polygon, i.e. the distance from its center to any vertex. This is also the radius of its circumcircle.
|
|
|
|
* @param {object} options - An object of properties to set on the Body. You can also specify a `chamfer` property to automatically adjust the body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Body} A Matter JS Body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-21 16:53:36 +00:00
|
|
|
polygon: function (x, y, sides, radius, options)
|
2017-11-20 16:54:26 +00:00
|
|
|
{
|
2017-11-21 16:53:36 +00:00
|
|
|
var body = Bodies.polygon(x, y, sides, radius, options);
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2017-11-21 16:53:36 +00:00
|
|
|
this.world.add(body);
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2017-11-21 16:53:36 +00:00
|
|
|
return body;
|
2017-11-20 16:54:26 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-10-22 11:12:31 +00:00
|
|
|
* Creates a body using the supplied vertices (or an array containing multiple sets of vertices) and adds it to the World.
|
|
|
|
* If the vertices are convex, they will pass through as supplied. Otherwise, if the vertices are concave, they will be decomposed. Note that this process is not guaranteed to support complex sets of vertices, e.g. ones with holes.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#fromVertices
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-10-22 11:12:31 +00:00
|
|
|
* @param {number} x - The X coordinate of the center of the Body.
|
|
|
|
* @param {number} y - The Y coordinate of the center of the Body.
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {array} vertexSets - [description]
|
|
|
|
* @param {object} options - [description]
|
2018-12-03 15:16:23 +00:00
|
|
|
* @param {boolean} flagInternal - Flag internal edges (coincident part edges)
|
|
|
|
* @param {boolean} removeCollinear - Whether Matter.js will discard collinear edges (to improve performance).
|
|
|
|
* @param {number} minimumArea - During decomposition discard parts that have an area less than this
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Body} A Matter JS Body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-21 16:53:36 +00:00
|
|
|
fromVertices: function (x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea)
|
2017-11-20 16:54:26 +00:00
|
|
|
{
|
2017-11-21 16:53:36 +00:00
|
|
|
var body = Bodies.fromVertices(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea);
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2017-11-21 16:53:36 +00:00
|
|
|
this.world.add(body);
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2017-11-21 16:53:36 +00:00
|
|
|
return body;
|
|
|
|
},
|
2017-11-20 16:54:26 +00:00
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Create a new composite containing Matter Image objects created in a grid arrangement.
|
|
|
|
* This function uses the body bounds to prevent overlaps.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#imageStack
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {string} key - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
2018-03-28 13:11:46 +00:00
|
|
|
* @param {(string|integer)} frame - An optional frame from the Texture this Game Object is rendering with. Set to `null` to skip this value.
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {number} x - The horizontal position of this composite in the world.
|
|
|
|
* @param {number} y - The vertical position of this composite in the world.
|
2018-03-19 15:01:14 +00:00
|
|
|
* @param {number} columns - The number of columns in the grid.
|
|
|
|
* @param {number} rows - The number of rows in the grid.
|
2018-03-28 13:11:46 +00:00
|
|
|
* @param {number} [columnGap=0] - The distance between each column.
|
|
|
|
* @param {number} [rowGap=0] - The distance between each row.
|
|
|
|
* @param {object} [options] - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} A Matter JS Composite Stack.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-23 16:55:28 +00:00
|
|
|
imageStack: function (key, frame, x, y, columns, rows, columnGap, rowGap, options)
|
|
|
|
{
|
|
|
|
if (columnGap === undefined) { columnGap = 0; }
|
|
|
|
if (rowGap === undefined) { rowGap = 0; }
|
|
|
|
if (options === undefined) { options = {}; }
|
|
|
|
|
|
|
|
var world = this.world;
|
|
|
|
var displayList = this.sys.displayList;
|
|
|
|
|
|
|
|
options.addToWorld = false;
|
|
|
|
|
|
|
|
var stack = Composites.stack(x, y, columns, rows, columnGap, rowGap, function (x, y)
|
|
|
|
{
|
|
|
|
var image = new MatterImage(world, x, y, key, frame, options);
|
|
|
|
|
|
|
|
displayList.add(image);
|
|
|
|
|
|
|
|
return image.body;
|
|
|
|
});
|
|
|
|
|
|
|
|
world.add(stack);
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Create a new composite containing bodies created in the callback in a grid arrangement.
|
|
|
|
* This function uses the body bounds to prevent overlaps.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#stack
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal position of this composite in the world.
|
|
|
|
* @param {number} y - The vertical position of this composite in the world.
|
2018-03-19 15:01:14 +00:00
|
|
|
* @param {number} columns - The number of columns in the grid.
|
|
|
|
* @param {number} rows - The number of rows in the grid.
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {number} columnGap - The distance between each column.
|
|
|
|
* @param {number} rowGap - The distance between each row.
|
2018-03-19 15:01:14 +00:00
|
|
|
* @param {function} callback - The callback that creates the stack.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} A new composite containing objects created in the callback.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-22 02:25:42 +00:00
|
|
|
stack: function (x, y, columns, rows, columnGap, rowGap, callback)
|
|
|
|
{
|
|
|
|
var stack = Composites.stack(x, y, columns, rows, columnGap, rowGap, callback);
|
|
|
|
|
|
|
|
this.world.add(stack);
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Create a new composite containing bodies created in the callback in a pyramid arrangement.
|
|
|
|
* This function uses the body bounds to prevent overlaps.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#pyramid
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal position of this composite in the world.
|
|
|
|
* @param {number} y - The vertical position of this composite in the world.
|
2018-03-19 15:01:14 +00:00
|
|
|
* @param {number} columns - The number of columns in the pyramid.
|
|
|
|
* @param {number} rows - The number of rows in the pyramid.
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {number} columnGap - The distance between each column.
|
|
|
|
* @param {number} rowGap - The distance between each row.
|
2018-12-03 15:16:23 +00:00
|
|
|
* @param {function} callback - The callback function to be invoked.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} A Matter JS Composite pyramid.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-27 16:29:43 +00:00
|
|
|
pyramid: function (x, y, columns, rows, columnGap, rowGap, callback)
|
|
|
|
{
|
|
|
|
var stack = Composites.pyramid(x, y, columns, rows, columnGap, rowGap, callback);
|
|
|
|
|
|
|
|
this.world.add(stack);
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Chains all bodies in the given composite together using constraints.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#chain
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @param {MatterJS.Composite} composite - [description]
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {number} xOffsetA - [description]
|
|
|
|
* @param {number} yOffsetA - [description]
|
|
|
|
* @param {number} xOffsetB - [description]
|
|
|
|
* @param {number} yOffsetB - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {object} options - [description]
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} A new composite containing objects chained together with constraints.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-27 16:29:43 +00:00
|
|
|
chain: function (composite, xOffsetA, yOffsetA, xOffsetB, yOffsetB, options)
|
|
|
|
{
|
|
|
|
return Composites.chain(composite, xOffsetA, yOffsetA, xOffsetB, yOffsetB, options);
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Connects bodies in the composite with constraints in a grid pattern, with optional cross braces.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#mesh
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @param {MatterJS.Composite} composite - [description]
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {number} columns - [description]
|
|
|
|
* @param {number} rows - [description]
|
|
|
|
* @param {boolean} crossBrace - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {object} options - [description]
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} The composite containing objects meshed together with constraints.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-27 16:29:43 +00:00
|
|
|
mesh: function (composite, columns, rows, crossBrace, options)
|
|
|
|
{
|
|
|
|
return Composites.mesh(composite, columns, rows, crossBrace, options);
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Creates a composite with a Newton's Cradle setup of bodies and constraints.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#newtonsCradle
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - [description]
|
|
|
|
* @param {number} y - [description]
|
|
|
|
* @param {number} number - [description]
|
|
|
|
* @param {number} size - [description]
|
|
|
|
* @param {number} length - [description]
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} A new composite newtonsCradle body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-27 16:29:43 +00:00
|
|
|
newtonsCradle: function (x, y, number, size, length)
|
|
|
|
{
|
|
|
|
var composite = Composites.newtonsCradle(x, y, number, size, length);
|
|
|
|
|
|
|
|
this.world.add(composite);
|
|
|
|
|
|
|
|
return composite;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Creates a composite with simple car setup of bodies and constraints.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#car
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - [description]
|
|
|
|
* @param {number} y - [description]
|
|
|
|
* @param {number} width - [description]
|
|
|
|
* @param {number} height - [description]
|
|
|
|
* @param {number} wheelSize - [description]
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} A new composite car body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-27 16:29:43 +00:00
|
|
|
car: function (x, y, width, height, wheelSize)
|
|
|
|
{
|
|
|
|
var composite = Composites.car(x, y, width, height, wheelSize);
|
|
|
|
|
|
|
|
this.world.add(composite);
|
|
|
|
|
|
|
|
return composite;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
2018-03-19 15:01:14 +00:00
|
|
|
* Creates a simple soft body like object.
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#softBody
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal position of this composite in the world.
|
|
|
|
* @param {number} y - The vertical position of this composite in the world.
|
|
|
|
* @param {number} columns - The number of columns in the Composite.
|
|
|
|
* @param {number} rows - The number of rows in the Composite.
|
|
|
|
* @param {number} columnGap - The distance between each column.
|
|
|
|
* @param {number} rowGap - The distance between each row.
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {boolean} crossBrace - [description]
|
2018-12-03 15:16:23 +00:00
|
|
|
* @param {number} particleRadius - The radius of this circlular composite.
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {object} particleOptions - [description]
|
|
|
|
* @param {object} constraintOptions - [description]
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Composite} A new composite simple soft body.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-27 16:29:43 +00:00
|
|
|
softBody: function (x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions)
|
|
|
|
{
|
|
|
|
var composite = Composites.softBody(x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions);
|
|
|
|
|
|
|
|
this.world.add(composite);
|
|
|
|
|
|
|
|
return composite;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#joint
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @param {MatterJS.Body} bodyA - [description]
|
|
|
|
* @param {MatterJS.Body} bodyB - [description]
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {number} length - [description]
|
|
|
|
* @param {number} [stiffness=1] - [description]
|
|
|
|
* @param {object} [options={}] - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Constraint} A Matter JS Constraint.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-22 16:23:47 +00:00
|
|
|
joint: function (bodyA, bodyB, length, stiffness, options)
|
|
|
|
{
|
|
|
|
return this.constraint(bodyA, bodyB, length, stiffness, options);
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#spring
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-12-03 15:16:23 +00:00
|
|
|
* @param {MatterJS.Body} bodyA - The first possible `Body` that this constraint is attached to.
|
|
|
|
* @param {MatterJS.Body} bodyB - The second possible `Body` that this constraint is attached to.
|
|
|
|
* @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`
|
|
|
|
* @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.
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {object} [options={}] - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Constraint} A Matter JS Constraint.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-22 16:23:47 +00:00
|
|
|
spring: function (bodyA, bodyB, length, stiffness, options)
|
|
|
|
{
|
|
|
|
return this.constraint(bodyA, bodyB, length, stiffness, options);
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#constraint
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @param {MatterJS.Body} bodyA - [description]
|
|
|
|
* @param {MatterJS.Body} bodyB - [description]
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {number} length - [description]
|
|
|
|
* @param {number} [stiffness=1] - [description]
|
|
|
|
* @param {object} [options={}] - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Constraint} A Matter JS Constraint.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-22 16:23:47 +00:00
|
|
|
constraint: function (bodyA, bodyB, length, stiffness, options)
|
|
|
|
{
|
|
|
|
if (stiffness === undefined) { stiffness = 1; }
|
|
|
|
if (options === undefined) { options = {}; }
|
|
|
|
|
|
|
|
options.bodyA = (bodyA.type === 'body') ? bodyA : bodyA.body;
|
|
|
|
options.bodyB = (bodyB.type === 'body') ? bodyB : bodyB.body;
|
|
|
|
options.length = length;
|
|
|
|
options.stiffness = stiffness;
|
|
|
|
|
|
|
|
var constraint = Constraint.create(options);
|
|
|
|
|
|
|
|
this.world.add(constraint);
|
|
|
|
|
|
|
|
return constraint;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#worldConstraint
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @param {MatterJS.Body} bodyB - [description]
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {number} length - [description]
|
|
|
|
* @param {number} [stiffness=1] - [description]
|
|
|
|
* @param {object} [options={}] - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Constraint} A Matter JS Constraint.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-27 16:29:43 +00:00
|
|
|
worldConstraint: function (bodyB, length, stiffness, options)
|
|
|
|
{
|
|
|
|
if (stiffness === undefined) { stiffness = 1; }
|
|
|
|
if (options === undefined) { options = {}; }
|
|
|
|
|
|
|
|
options.bodyB = (bodyB.type === 'body') ? bodyB : bodyB.body;
|
|
|
|
options.length = length;
|
|
|
|
options.stiffness = stiffness;
|
|
|
|
|
|
|
|
var constraint = Constraint.create(options);
|
|
|
|
|
|
|
|
this.world.add(constraint);
|
|
|
|
|
|
|
|
return constraint;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#mouseSpring
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {object} options - [description]
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Constraint} A Matter JS Constraint.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-23 01:45:58 +00:00
|
|
|
mouseSpring: function (options)
|
|
|
|
{
|
|
|
|
return this.pointerConstraint(options);
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#pointerConstraint
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {object} options - [description]
|
|
|
|
*
|
2018-03-29 13:24:51 +00:00
|
|
|
* @return {MatterJS.Constraint} A Matter JS Constraint.
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-23 01:45:58 +00:00
|
|
|
pointerConstraint: function (options)
|
|
|
|
{
|
2018-04-13 17:09:16 +00:00
|
|
|
if (options === undefined) { options = {}; }
|
2018-04-13 16:43:44 +00:00
|
|
|
|
|
|
|
if (!options.hasOwnProperty('render'))
|
|
|
|
{
|
|
|
|
options.render = { visible: false };
|
|
|
|
}
|
|
|
|
|
2017-11-23 01:45:58 +00:00
|
|
|
var pointerConstraint = new PointerConstraint(this.scene, this.world, options);
|
|
|
|
|
|
|
|
this.world.add(pointerConstraint.constraint);
|
|
|
|
|
|
|
|
return pointerConstraint;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#image
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal position of this Game Object in the world.
|
|
|
|
* @param {number} y - The vertical position of this Game Object in the world.
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {string} key - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
2018-03-28 13:11:46 +00:00
|
|
|
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with. Set to `null` to skip this value.
|
|
|
|
* @param {object} [options={}] - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-28 14:39:57 +00:00
|
|
|
* @return {Phaser.Physics.Matter.Image} [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-21 16:53:36 +00:00
|
|
|
image: function (x, y, key, frame, options)
|
|
|
|
{
|
|
|
|
var image = new MatterImage(this.world, x, y, key, frame, options);
|
|
|
|
|
|
|
|
this.sys.displayList.add(image);
|
|
|
|
|
|
|
|
return image;
|
2017-11-20 16:54:26 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#tileBody
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-28 14:39:57 +00:00
|
|
|
* @param {Phaser.Tilemaps.Tile} tile - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
* @param {object} options - [description]
|
|
|
|
*
|
2018-03-28 14:39:57 +00:00
|
|
|
* @return {Phaser.Physics.Matter.TileBody} [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2018-01-21 18:53:48 +00:00
|
|
|
tileBody: function (tile, options)
|
|
|
|
{
|
|
|
|
var tileBody = new MatterTileBody(this.world, tile, options);
|
|
|
|
|
|
|
|
return tileBody;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:14:50 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#sprite
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal position of this Game Object in the world.
|
|
|
|
* @param {number} y - The vertical position of this Game Object in the world.
|
2018-03-19 00:10:32 +00:00
|
|
|
* @param {string} key - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
2018-03-28 13:11:46 +00:00
|
|
|
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with. Set to `null` to skip this value.
|
|
|
|
* @param {object} [options={}] - [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*
|
2018-03-28 14:39:57 +00:00
|
|
|
* @return {Phaser.Physics.Matter.Sprite} [description]
|
2018-02-12 13:14:50 +00:00
|
|
|
*/
|
2017-11-21 16:53:36 +00:00
|
|
|
sprite: function (x, y, key, frame, options)
|
2017-11-20 16:54:26 +00:00
|
|
|
{
|
2017-11-21 16:53:36 +00:00
|
|
|
var sprite = new MatterSprite(this.world, x, y, key, frame, options);
|
2017-11-20 16:54:26 +00:00
|
|
|
|
|
|
|
this.sys.displayList.add(sprite);
|
|
|
|
this.sys.updateList.add(sprite);
|
|
|
|
|
|
|
|
return sprite;
|
2018-03-19 15:01:14 +00:00
|
|
|
},
|
|
|
|
|
2018-03-21 03:16:36 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#gameObject
|
|
|
|
* @since 3.3.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to inject the Matter Body in to.
|
|
|
|
* @param {object} options - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that had the Matter Body injected into it.
|
|
|
|
*/
|
2018-03-19 15:01:14 +00:00
|
|
|
gameObject: function (gameObject, options)
|
|
|
|
{
|
2018-03-21 03:16:36 +00:00
|
|
|
return MatterGameObject(this.world, gameObject, options);
|
2018-04-13 16:12:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys this Factory.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.Factory#destroy
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 16:12:17 +00:00
|
|
|
*/
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.world = null;
|
|
|
|
this.scene = null;
|
|
|
|
this.sys = null;
|
2017-11-20 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Factory;
|