phaser/src/physics/impact/World.js

980 lines
27 KiB
JavaScript
Raw Normal View History

var Body = require('./Body');
2017-06-21 23:47:35 +00:00
var Class = require('../../utils/Class');
var COLLIDES = require('./COLLIDES');
var CollisionMap = require('./CollisionMap');
var EventEmitter = require('eventemitter3');
var GetFastValue = require('../../utils/object/GetFastValue');
2018-02-09 16:04:43 +00:00
var HasValue = require('../../utils/object/HasValue');
2017-06-21 23:47:35 +00:00
var Set = require('../../structs/Set');
var Solver = require('./Solver');
2018-02-07 17:10:01 +00:00
var TILEMAP_FORMATS = require('../../tilemaps/Formats');
2018-02-09 16:04:43 +00:00
var TYPE = require('./TYPE');
2017-06-21 23:47:35 +00:00
2018-02-09 16:04:43 +00:00
/**
* @classdesc
* [description]
*
* @class World
* @extends Phaser.Physics.Impact.EventEmitter
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
* @param {object} config - [description]
*/
2017-06-21 23:47:35 +00:00
var World = new Class({
Extends: EventEmitter,
2017-06-21 23:47:35 +00:00
initialize:
function World (scene, config)
2017-06-21 23:47:35 +00:00
{
EventEmitter.call(this);
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
2017-08-16 15:30:28 +00:00
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#bodies
2018-02-09 16:52:08 +00:00
* @type {Phaser.Structs.Set}
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
2017-06-22 01:40:10 +00:00
this.bodies = new Set();
2017-06-21 23:47:35 +00:00
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#gravity
2018-02-09 16:52:08 +00:00
* @type {number}
* @default 0
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
this.gravity = GetFastValue(config, 'gravity', 0);
2017-06-21 23:47:35 +00:00
2018-02-09 16:04:43 +00:00
/**
2018-02-09 16:52:08 +00:00
* Spatial hash cell dimensions
2018-02-09 16:04:43 +00:00
*
* @name Phaser.Physics.Impact.World#cellSize
2018-02-09 16:52:08 +00:00
* @type {integer}
* @default 64
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
this.cellSize = GetFastValue(config, 'cellSize', 64);
2017-06-22 01:40:10 +00:00
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#collisionMap
2018-02-09 16:52:08 +00:00
* @type {Phaser.Physics.Impact.CollisionMap}
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
2017-06-22 01:40:10 +00:00
this.collisionMap = new CollisionMap();
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#timeScale
2018-02-09 16:52:08 +00:00
* @type {float}
* @default 1
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
this.timeScale = GetFastValue(config, 'timeScale', 1);
2017-08-16 15:30:28 +00:00
2018-02-09 16:04:43 +00:00
/**
2018-02-09 16:52:08 +00:00
* Impacts maximum time step is 20 fps.
2018-02-09 16:04:43 +00:00
*
* @name Phaser.Physics.Impact.World#maxStep
2018-02-09 16:52:08 +00:00
* @type {number}
* @default 0.05
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
this.maxStep = GetFastValue(config, 'maxStep', 0.05);
2017-08-16 15:30:28 +00:00
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#enabled
* @type {boolean}
* @default true
* @since 3.0.0
*/
2017-08-16 15:30:28 +00:00
this.enabled = true;
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#drawDebug
2018-02-09 16:52:08 +00:00
* @type {boolean}
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
this.drawDebug = GetFastValue(config, 'debug', false);
2017-08-16 16:16:23 +00:00
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#debugGraphic
2018-02-09 16:52:08 +00:00
* @type {Phaser.GameObjects.Graphics}
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
2017-08-16 16:16:23 +00:00
this.debugGraphic;
var _maxVelocity = GetFastValue(config, 'maxVelocity', 100);
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#defaults
2018-02-09 16:52:08 +00:00
* @type {object}
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
this.defaults = {
debugShowBody: GetFastValue(config, 'debugShowBody', true),
debugShowVelocity: GetFastValue(config, 'debugShowVelocity', true),
bodyDebugColor: GetFastValue(config, 'debugBodyColor', 0xff00ff),
velocityDebugColor: GetFastValue(config, 'debugVelocityColor', 0x00ff00),
maxVelocityX: GetFastValue(config, 'maxVelocityX', _maxVelocity),
maxVelocityY: GetFastValue(config, 'maxVelocityY', _maxVelocity),
minBounceVelocity: GetFastValue(config, 'minBounceVelocity', 40),
gravityFactor: GetFastValue(config, 'gravityFactor', 1),
bounciness: GetFastValue(config, 'bounciness', 0)
};
2017-08-17 00:21:12 +00:00
/**
2018-02-09 16:52:08 +00:00
* An object containing the 4 wall bodies that bound the physics world.
2018-02-09 16:04:43 +00:00
*
* @name Phaser.Physics.Impact.World#walls
2018-02-09 16:52:08 +00:00
* @type {object}
2018-02-09 16:04:43 +00:00
* @since 3.0.0
*/
2017-08-17 00:21:12 +00:00
this.walls = { left: null, right: null, top: null, bottom: null };
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#delta
* @type {number}
* @default 0
* @since 3.0.0
*/
this.delta = 0;
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @name Phaser.Physics.Impact.World#_lastId
* @type {number}
* @private
* @default 0
* @since 3.0.0
*/
this._lastId = 0;
2017-08-16 16:16:23 +00:00
if (GetFastValue(config, 'setBounds', false))
{
var boundsConfig = config['setBounds'];
if (typeof boundsConfig === 'boolean')
{
this.setBounds();
}
else
{
var x = GetFastValue(boundsConfig, 'x', 0);
var y = GetFastValue(boundsConfig, 'y', 0);
var width = GetFastValue(boundsConfig, 'width', scene.sys.game.config.width);
var height = GetFastValue(boundsConfig, 'height', scene.sys.game.config.height);
var thickness = GetFastValue(boundsConfig, 'thickness', 64);
var left = GetFastValue(boundsConfig, 'left', true);
var right = GetFastValue(boundsConfig, 'right', true);
var top = GetFastValue(boundsConfig, 'top', true);
var bottom = GetFastValue(boundsConfig, 'bottom', true);
this.setBounds(x, y, width, height, thickness, left, right, top, bottom);
}
}
if (this.drawDebug)
2017-08-16 16:16:23 +00:00
{
this.createDebugGraphic();
}
},
/**
2018-02-09 16:52:08 +00:00
* Sets the collision map for the world either from a Weltmeister JSON level in the cache or from
* a 2D array. If loading from a Weltmeister level, the map must have a layer called "collision".
2018-02-09 16:04:43 +00:00
*
* @method Phaser.Physics.Impact.World#setCollisionMap
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {string|integer[][]} key - Either a string key that corresponds to a Weltmeister level
* in the cache, or a 2D array of collision IDs.
* @param {integer} tileSize - The size of a tile. This is optional if loading from a Weltmeister
* level in the cache.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {CollisionMap|null} The newly created CollisionMap, or null if the method failed to
* create the CollisionMap.
2018-02-09 16:04:43 +00:00
*/
setCollisionMap: function (key, tileSize)
2017-08-18 15:47:10 +00:00
{
if (typeof key === 'string')
{
var tilemapData = this.scene.cache.tilemap.get(key);
if (!tilemapData || tilemapData.format !== TILEMAP_FORMATS.WELTMEISTER)
{
console.warn('The specified key does not correspond to a Weltmeister tilemap: ' + key);
return null;
}
var layers = tilemapData.data.layer;
var collisionLayer;
for (var i = 0; i < layers.length; i++)
{
if (layers[i].name === 'collision')
{
collisionLayer = layers[i];
break;
}
}
if (tileSize === undefined) { tileSize = collisionLayer.tilesize; }
this.collisionMap = new CollisionMap(tileSize, collisionLayer.data);
}
else if (Array.isArray(key))
{
this.collisionMap = new CollisionMap(tileSize, key);
}
else
{
console.warn('Invalid Weltmeister collision map data: ' + key);
}
2017-08-18 15:47:10 +00:00
return this.collisionMap;
2017-08-18 15:47:10 +00:00
},
/**
2018-02-09 16:52:08 +00:00
* Sets the collision map for the world from a tilemap layer. Only tiles that are marked as
* colliding will be used. You can specify the mapping from tiles to slope IDs in a couple of
* ways. The easiest is to use Tiled and the slopeTileProperty option. Alternatively, you can
* manually create a slopeMap that stores the mapping between tile indices and slope IDs.
2018-02-09 16:04:43 +00:00
*
* @method Phaser.Physics.Impact.World#setCollisionMapFromTilemapLayer
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {StaticTilemapLayer|DynamicTilemapLayer} tilemapLayer - The tilemap layer to use.
* @param {object} [options] - Options for controlling the mapping from tiles to slope IDs.
* @param {string} [options.slopeTileProperty=null] - Slope IDs can be stored on tiles directly
* using Tiled's tileset editor. If a tile has a property with the given slopeTileProperty string
* name, the value of that property for the tile will be used for its slope mapping. E.g. a 45
* degree slope upward could be given a "slope" property with a value of 2.
* @param {object} [options.slopeMap=null] - A tile index to slope definition map.
* @param {integer} [options.defaultCollidingSlope=null] - If specified, the default slope ID to
* assign to a colliding tile. If not specified, the tile's index is used.
* @param {integer} [options.defaultNonCollidingSlope=0] - The default slope ID to assign to a
* non-colliding tile.
*
* @return {Phaser.Physics.Impact.CollisionMap} The newly created CollisionMap.
2018-02-09 16:04:43 +00:00
*/
setCollisionMapFromTilemapLayer: function (tilemapLayer, options)
{
if (options === undefined) { options = {}; }
var slopeProperty = GetFastValue(options, 'slopeProperty', null);
var slopeMap = GetFastValue(options, 'slopeMap', null);
var collidingSlope = GetFastValue(options, 'defaultCollidingSlope', null);
var nonCollidingSlope = GetFastValue(options, 'defaultNonCollidingSlope', 0);
var layerData = tilemapLayer.layer;
var tileSize = layerData.baseTileWidth;
var collisionData = [];
for (var ty = 0; ty < layerData.height; ty++)
{
collisionData[ty] = [];
for (var tx = 0; tx < layerData.width; tx++)
{
var tile = layerData.data[ty][tx];
if (tile && tile.collides)
{
if (slopeProperty !== null && HasValue(tile.properties, slopeProperty))
{
collisionData[ty][tx] = parseInt(tile.properties[slopeProperty], 10);
}
else if (slopeMap !== null && HasValue(slopeMap, tile.index))
{
collisionData[ty][tx] = slopeMap[tile.index];
}
else if (collidingSlope !== null)
{
collisionData[ty][tx] = collidingSlope;
}
else
{
collisionData[ty][tx] = tile.index;
}
}
else
{
collisionData[ty][tx] = nonCollidingSlope;
}
}
}
this.collisionMap = new CollisionMap(tileSize, collisionData);
return this.collisionMap;
},
2017-08-17 00:21:12 +00:00
/**
2018-02-09 16:52:08 +00:00
* Sets the bounds of the Physics world to match the given world pixel dimensions.
* You can optionally set which 'walls' to create: left, right, top or bottom.
* If none of the walls are given it will default to use the walls settings it had previously.
* I.e. if you previously told it to not have the left or right walls, and you then adjust the world size
* the newly created bounds will also not have the left and right walls.
* Explicitly state them in the parameters to override this.
2018-02-09 16:04:43 +00:00
*
* @method Phaser.Physics.Impact.World#setBounds
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {number} [x] - The x coordinate of the top-left corner of the bounds.
* @param {number} [y] - The y coordinate of the top-left corner of the bounds.
* @param {number} [width] - The width of the bounds.
* @param {number} [height] - The height of the bounds.
* @param {number} [thickness=64] - [description]
* @param {boolean} [left=true] - If true will create the left bounds wall.
* @param {boolean} [right=true] - If true will create the right bounds wall.
* @param {boolean} [top=true] - If true will create the top bounds wall.
* @param {boolean} [bottom=true] - If true will create the bottom bounds wall.
*
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-17 00:21:12 +00:00
setBounds: function (x, y, width, height, thickness, left, right, top, bottom)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (width === undefined) { width = this.scene.sys.game.config.width; }
if (height === undefined) { height = this.scene.sys.game.config.height; }
if (thickness === undefined) { thickness = 64; }
if (left === undefined) { left = true; }
if (right === undefined) { right = true; }
if (top === undefined) { top = true; }
if (bottom === undefined) { bottom = true; }
this.updateWall(left, 'left', x - thickness, y, thickness, height);
this.updateWall(right, 'right', x + width, y, thickness, height);
this.updateWall(top, 'top', x, y - thickness, width, thickness);
this.updateWall(bottom, 'bottom', x, y + height, width, thickness);
return this;
},
2018-02-09 16:04:43 +00:00
/**
2018-02-09 16:52:08 +00:00
* position = 'left', 'right', 'top' or 'bottom'
2018-02-09 16:04:43 +00:00
*
* @method Phaser.Physics.Impact.World#updateWall
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {boolean} add - [description]
* @param {string} position - [description]
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} width - [description]
* @param {number} height - [description]
2018-02-09 16:04:43 +00:00
*/
2017-08-17 00:21:12 +00:00
updateWall: function (add, position, x, y, width, height)
{
var wall = this.walls[position];
if (add)
{
if (wall)
{
wall.resetSize(x, y, width, height);
2017-08-17 00:21:12 +00:00
}
else
{
this.walls[position] = this.create(x, y, width, height);
2017-08-17 01:07:03 +00:00
this.walls[position].name = position;
2017-08-17 00:21:12 +00:00
this.walls[position].gravityFactor = 0;
this.walls[position].collides = COLLIDES.FIXED;
}
}
else
{
if (wall)
{
this.bodies.remove(wall);
}
this.walls[position] = null;
}
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#createDebugGraphic
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.GameObjects.Graphics} [description]
2018-02-09 16:04:43 +00:00
*/
2017-08-16 16:16:23 +00:00
createDebugGraphic: function ()
{
var graphic = this.scene.sys.add.graphics({ x: 0, y: 0 });
2017-08-16 16:16:23 +00:00
2018-02-09 16:52:08 +00:00
graphic.setDepth(Number.MAX_VALUE);
2017-08-16 16:27:15 +00:00
2017-08-16 16:16:23 +00:00
this.debugGraphic = graphic;
this.drawDebug = true;
return graphic;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#getNextID
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @return {integer} [description]
2018-02-09 16:04:43 +00:00
*/
getNextID: function ()
{
return this._lastId++;
2017-06-21 23:47:35 +00:00
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#create
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} sizeX - [description]
* @param {number} sizeY - [description]
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.Body} The Body that was added to this World.
2018-02-09 16:04:43 +00:00
*/
2017-06-22 01:40:10 +00:00
create: function (x, y, sizeX, sizeY)
2017-06-21 23:47:35 +00:00
{
2017-06-22 01:40:10 +00:00
var body = new Body(this, x, y, sizeX, sizeY);
2017-06-21 23:47:35 +00:00
this.bodies.set(body);
return body;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#remove
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body} object - The Body to remove from this World.
2018-02-09 16:04:43 +00:00
*/
2017-12-02 04:04:30 +00:00
remove: function (object)
{
this.bodies.delete(object);
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#pause
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 15:30:28 +00:00
pause: function ()
{
this.enabled = false;
2018-02-09 16:52:08 +00:00
this.emit('pause');
2017-08-16 15:30:28 +00:00
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#resume
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 15:30:28 +00:00
resume: function ()
{
this.enabled = true;
2018-02-09 16:52:08 +00:00
this.emit('resume');
2017-08-16 15:30:28 +00:00
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#update
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {number} time - [description]
* @param {number} delta - [description]
2018-02-09 16:04:43 +00:00
*/
2017-06-21 23:47:35 +00:00
update: function (time, delta)
{
2017-08-16 15:30:28 +00:00
if (!this.enabled || this.bodies.size === 0)
2017-06-21 23:47:35 +00:00
{
return;
}
2017-08-16 15:30:28 +00:00
// Impact uses a divided delta value that is clamped to the maxStep (20fps) maximum
2017-11-08 17:17:58 +00:00
var clampedDelta = Math.min(delta / 1000, this.maxStep) * this.timeScale;
this.delta = clampedDelta;
2017-06-21 23:47:35 +00:00
2017-08-16 15:30:28 +00:00
// Update all active bodies
2017-06-21 23:47:35 +00:00
var i;
var body;
var bodies = this.bodies.entries;
var len = bodies.length;
var hash = {};
var size = this.cellSize;
for (i = 0; i < len; i++)
2017-06-27 14:24:49 +00:00
{
body = bodies[i];
2017-06-21 23:47:35 +00:00
if (body.enabled)
{
2017-11-08 17:17:58 +00:00
body.update(clampedDelta);
2017-06-21 23:47:35 +00:00
}
}
2017-06-21 23:47:35 +00:00
2017-08-17 02:15:02 +00:00
// Run collision against them all now they're in the new positions from the update
2017-06-21 23:47:35 +00:00
for (i = 0; i < len; i++)
2017-06-21 23:47:35 +00:00
{
body = bodies[i];
2017-06-21 23:47:35 +00:00
if (!body.skipHash())
2017-06-21 23:47:35 +00:00
{
this.checkHash(body, hash, size);
}
}
if (this.drawDebug)
{
var graphics = this.debugGraphic;
graphics.clear();
for (i = 0; i < len; i++)
{
body = bodies[i];
if (body.willDrawDebug())
{
body.drawDebug(graphics);
}
}
}
2017-06-21 23:47:35 +00:00
},
2018-02-09 16:04:43 +00:00
/**
2018-02-09 16:52:08 +00:00
* Check the body against the spatial hash.
2018-02-09 16:04:43 +00:00
*
* @method Phaser.Physics.Impact.World#checkHash
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body} body - [description]
* @param {object} hash - [description]
* @param {number} size - [description]
2018-02-09 16:04:43 +00:00
*/
2017-06-21 23:47:35 +00:00
checkHash: function (body, hash, size)
{
var checked = {};
2017-06-21 23:47:35 +00:00
var xmin = Math.floor(body.pos.x / size);
var ymin = Math.floor(body.pos.y / size);
var xmax = Math.floor((body.pos.x + body.size.x) / size) + 1;
var ymax = Math.floor((body.pos.y + body.size.y) / size) + 1;
for (var x = xmin; x < xmax; x++)
{
for (var y = ymin; y < ymax; y++)
{
if (!hash[x])
{
hash[x] = {};
2017-06-23 17:08:22 +00:00
hash[x][y] = [ body ];
2017-06-21 23:47:35 +00:00
}
else if (!hash[x][y])
{
2017-06-23 17:08:22 +00:00
hash[x][y] = [ body ];
2017-06-21 23:47:35 +00:00
}
else
{
var cell = hash[x][y];
for (var c = 0; c < cell.length; c++)
{
if (body.touches(cell[c]) && !checked[cell[c].id])
{
checked[cell[c].id] = true;
this.checkBodies(body, cell[c]);
}
}
cell.push(body);
}
}
}
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#checkBodies
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body} bodyA - [description]
* @param {Phaser.Physics.Impact.Body} bodyB - [description]
2018-02-09 16:04:43 +00:00
*/
2017-06-21 23:47:35 +00:00
checkBodies: function (bodyA, bodyB)
{
2017-08-17 03:06:08 +00:00
// 2 fixed bodies won't do anything
if (bodyA.collides === COLLIDES.FIXED && bodyB.collides === COLLIDES.FIXED)
{
return;
}
2017-06-21 23:47:35 +00:00
// bitwise checks
if (bodyA.checkAgainst & bodyB.type)
{
bodyA.check(bodyB);
}
2017-06-21 23:47:35 +00:00
if (bodyB.checkAgainst & bodyA.type)
{
bodyB.check(bodyA);
}
2017-06-21 23:47:35 +00:00
if (bodyA.collides && bodyB.collides && bodyA.collides + bodyB.collides > COLLIDES.ACTIVE)
{
Solver(this, bodyA, bodyB);
}
2017-08-16 00:20:35 +00:00
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCollidesNever
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the collides value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setCollidesNever: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].collides = COLLIDES.NEVER;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setLite
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the collides value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setLite: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].collides = COLLIDES.LITE;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setPassive
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the collides value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setPassive: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].collides = COLLIDES.PASSIVE;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setActive
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the collides value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setActive: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].collides = COLLIDES.ACTIVE;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setFixed
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the collides value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setFixed: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].collides = COLLIDES.FIXED;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setTypeNone
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setTypeNone: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].type = TYPE.NONE;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setTypeA
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setTypeA: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].type = TYPE.A;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setTypeB
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setTypeB: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].type = TYPE.B;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setAvsB
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setAvsB: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].type = TYPE.A;
bodies[i].checkAgainst = TYPE.B;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setBvsA
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setBvsA: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].type = TYPE.B;
bodies[i].checkAgainst = TYPE.A;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCheckAgainstNone
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setCheckAgainstNone: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].checkAgainst = TYPE.NONE;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCheckAgainstA
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setCheckAgainstA: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].checkAgainst = TYPE.A;
}
return this;
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCheckAgainstB
* @since 3.0.0
*
2018-02-09 16:52:08 +00:00
* @param {Phaser.Physics.Impact.Body[]} bodies - An Array of Impact Bodies to set the type value on.
2018-02-09 16:04:43 +00:00
*
2018-02-09 16:52:08 +00:00
* @return {Phaser.Physics.Impact.World} This World object.
2018-02-09 16:04:43 +00:00
*/
2017-08-16 00:20:35 +00:00
setCheckAgainstB: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
{
bodies[i].checkAgainst = TYPE.B;
}
return this;
2017-08-16 16:16:23 +00:00
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
this.removeAllListeners();
},
2018-02-09 16:04:43 +00:00
/**
* [description]
*
* @method Phaser.Physics.Impact.World#destroy
* @since 3.0.0
*/
2017-08-16 16:16:23 +00:00
destroy: function ()
{
this.removeAllListeners();
2017-08-16 16:16:23 +00:00
this.scene = null;
2017-08-16 16:16:23 +00:00
this.bodies.clear();
this.bodies = null;
this.collisionMap = null;
2017-06-21 23:47:35 +00:00
}
});
module.exports = World;