UNPKG

matter-js

Version:

a 2D rigid body physics engine for the web

148 lines (126 loc) 3.86 kB
/** * The `Matter.World` module contains methods for creating and manipulating the world composite. * A `Matter.World` is a `Matter.Composite` body, which is a collection of `Matter.Body`, `Matter.Constraint` and other `Matter.Composite`. * A `Matter.World` has a few additional properties including `gravity` and `bounds`. * It is important to use the functions in the `Matter.Composite` module to modify the world composite, rather than directly modifying its properties. * There are also a few methods here that alias those in `Matter.Composite` for easier readability. * * See the included usage [examples](https://github.com/liabru/matter-js/tree/master/examples). * * @class World * @extends Composite */ var World = {}; module.exports = World; var Composite = require('./Composite'); var Constraint = require('../constraint/Constraint'); var Common = require('../core/Common'); (function() { /** * Creates a new world composite. The options parameter is an object that specifies any properties you wish to override the defaults. * See the properties section below for detailed information on what you can pass via the `options` object. * @method create * @constructor * @param {} options * @return {world} A new world */ World.create = function(options) { var composite = Composite.create(); var defaults = { label: 'World', gravity: { x: 0, y: 1, scale: 0.001 }, bounds: { min: { x: -Infinity, y: -Infinity }, max: { x: Infinity, y: Infinity } } }; return Common.extend(composite, defaults, options); }; /* * * Properties Documentation * */ /** * The gravity to apply on the world. * * @property gravity * @type object */ /** * The gravity x component. * * @property gravity.x * @type object * @default 0 */ /** * The gravity y component. * * @property gravity.y * @type object * @default 1 */ /** * The gravity scale factor. * * @property gravity.scale * @type object * @default 0.001 */ /** * A `Bounds` object that defines the world bounds for collision detection. * * @property bounds * @type bounds * @default { min: { x: -Infinity, y: -Infinity }, max: { x: Infinity, y: Infinity } } */ // World is a Composite body // see src/module/Outro.js for these aliases: /** * An alias for Composite.add * @method add * @param {world} world * @param {} object * @return {composite} The original world with the objects added */ /** * An alias for Composite.remove * @method remove * @param {world} world * @param {} object * @param {boolean} [deep=false] * @return {composite} The original world with the objects removed */ /** * An alias for Composite.clear * @method clear * @param {world} world * @param {boolean} keepStatic */ /** * An alias for Composite.addComposite * @method addComposite * @param {world} world * @param {composite} composite * @return {world} The original world with the objects from composite added */ /** * An alias for Composite.addBody * @method addBody * @param {world} world * @param {body} body * @return {world} The original world with the body added */ /** * An alias for Composite.addConstraint * @method addConstraint * @param {world} world * @param {constraint} constraint * @return {world} The original world with the constraint added */ })();