Added jsdocs.

This commit is contained in:
Richard Davey 2018-02-09 16:04:43 +00:00
parent c7a84a1f7a
commit 2434bb187a
11 changed files with 997 additions and 31 deletions

View file

@ -59,10 +59,10 @@ var Body = new Class({
this.enabled = true;
/**
* [description]
* The ImpactBody, ImpactSprite or ImpactImage object that owns this Body, if any.
*
* @name Phaser.Physics.Impact.Body#parent
* @type {null}
* @type {Phaser.Physics.Impact.ImpactBody|Phaser.Physics.Impact.ImpactImage|Phaser.Physics.Impact.ImpactSprite|null}
* @since 3.0.0
*/
this.parent;

View file

@ -1,8 +1,18 @@
// Phaser.Physics.Impact.CollisionMap
var Class = require('../../utils/Class');
var DefaultDefs = require('./DefaultDefs');
/**
* @classdesc
* [description]
*
* @class CollisionMap
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @param {integer} [tilesize=32] - [description]
* @param {array} data - [description]
*/
var CollisionMap = new Class({
initialize:
@ -11,18 +21,78 @@ var CollisionMap = new Class({
{
if (tilesize === undefined) { tilesize = 32; }
/**
* [description]
*
* @name Phaser.Physics.Impact.CollisionMap#tilesize
* @type {integer}
* @default 32
* @since 3.0.0
*/
this.tilesize = tilesize;
/**
* [description]
*
* @name Phaser.Physics.Impact.CollisionMap#data
* @type {array}
* @since 3.0.0
*/
this.data = (Array.isArray(data)) ? data : [];
/**
* [description]
*
* @name Phaser.Physics.Impact.CollisionMap#width
* @type {number}
* @since 3.0.0
*/
this.width = (Array.isArray(data)) ? data[0].length : 0;
/**
* [description]
*
* @name Phaser.Physics.Impact.CollisionMap#height
* @type {number}
* @since 3.0.0
*/
this.height = (Array.isArray(data)) ? data.length : 0;
/**
* [description]
*
* @name Phaser.Physics.Impact.CollisionMap#lastSlope
* @type {integer}
* @default 55
* @since 3.0.0
*/
this.lastSlope = 55;
/**
* [description]
*
* @name Phaser.Physics.Impact.CollisionMap#tiledef
* @type {object}
* @since 3.0.0
*/
this.tiledef = DefaultDefs;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.CollisionMap#trace
* @since 3.0.0
*
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} vx - [description]
* @param {number} vy - [description]
* @param {number} objectWidth - [description]
* @param {number} objectHeight - [description]
*
* @return {boolean} [description]
*/
trace: function (x, y, vx, vy, objectWidth, objectHeight)
{
// Set up the trace-result
@ -77,6 +147,23 @@ var CollisionMap = new Class({
return res;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.CollisionMap#step
* @since 3.0.0
*
* @param {object} res - [description]
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} vx - [description]
* @param {number} vy - [description]
* @param {number} width - [description]
* @param {number} height - [description]
* @param {number} rvx - [description]
* @param {number} rvy - [description]
* @param {number} step - [description]
*/
step: function (res, x, y, vx, vy, width, height, rvx, rvy, step)
{
var t = 0;
@ -191,6 +278,25 @@ var CollisionMap = new Class({
}
},
/**
* [description]
*
* @method Phaser.Physics.Impact.CollisionMap#checkDef
* @since 3.0.0
*
* @param {object} res - [description]
* @param {number} t - [description]
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} vx - [description]
* @param {number} vy - [description]
* @param {number} width - [description]
* @param {number} height - [description]
* @param {number} tileX - [description]
* @param {number} tileY - [description]
*
* @return {boolean} [description]
*/
checkDef: function (res, t, x, y, vx, vy, width, height, tileX, tileY)
{
var def = this.tiledef[t];

View file

@ -3,22 +3,71 @@ var ImpactBody = require('./ImpactBody');
var ImpactImage = require('./ImpactImage');
var ImpactSprite = require('./ImpactSprite');
/**
* @classdesc
* The Impact Physics Factory allows you to easily create Impact Physics enabled Game Objects.
* Objects that are created by this Factory are automatically added to the physics world.
*
* @class Factory
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.World} world - [description]
*/
var Factory = new Class({
initialize:
function Factory (world)
{
/**
* [description]
*
* @name Phaser.Physics.Impact.Factory#world
* @type {Phaser.Physics.Impact.World}
* @since 3.0.0
*/
this.world = world;
/**
* A reference to the Scene.Systems this Impact Physics instance belongs to.
*
* @name Phaser.Physics.Impact.Factory#sys
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.sys = world.scene.sys;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Factory#body
* @since 3.0.0
*
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} width - [description]
* @param {number} height - [description]
*
* @return {Phaser.Physics.Impact.ImpactBody} The ImpactBody object that was created.
*/
body: function (x, y, width, height)
{
return new ImpactBody(this.world, x, y, width, height);
},
/**
* Adds an Impact Physics Body to the given Game Object.
*
* @method Phaser.Physics.Impact.Factory#existing
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject} gameObject - [description]
*
* @return {Phaser.GameObjects.GameObject} The Game Object.
*/
existing: function (gameObject)
{
var x = gameObject.x - gameObject.frame.centerX;
@ -34,6 +83,19 @@ var Factory = new Class({
return gameObject;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.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.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {string|integer} [frame] - An optional frame from the Texture this Game Object is rendering with.
*
* @return {Phaser.Physics.Impact.ImpactImage} The ImpactImage object that was created.
*/
image: function (x, y, key, frame)
{
var image = new ImpactImage(this.world, x, y, key, frame);
@ -43,6 +105,19 @@ var Factory = new Class({
return image;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.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.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {string|integer} [frame] - An optional frame from the Texture this Game Object is rendering with.
*
* @return {Phaser.Physics.Impact.ImpactSprite} The ImpactSprite object that was created.
*/
sprite: function (x, y, key, frame)
{
var sprite = new ImpactSprite(this.world, x, y, key, frame);

View file

@ -1,5 +1,19 @@
var Clamp = require('../../math/Clamp');
/**
* [description]
*
* @function Phaser.Physics.Impact.GetVelocity
* @since 3.0.0
*
* @param {number} delta - [description]
* @param {number} vel - [description]
* @param {number} accel - [description]
* @param {number} friction - [description]
* @param {number} max - [description]
*
* @return {number} [description]
*/
var GetVelocity = function (delta, vel, accel, friction, max)
{
if (accel)

View file

@ -1,7 +1,34 @@
var Class = require('../../utils/Class');
var Components = require('./components');
/**
* @classdesc
* [description]
*
* @class ImpactBody
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @extends Phaser.Physics.Impact.Components.Acceleration
* @extends Phaser.Physics.Impact.Components.BodyScale
* @extends Phaser.Physics.Impact.Components.BodyType
* @extends Phaser.Physics.Impact.Components.Bounce
* @extends Phaser.Physics.Impact.Components.CheckAgainst
* @extends Phaser.Physics.Impact.Components.Collides
* @extends Phaser.Physics.Impact.Components.Debug
* @extends Phaser.Physics.Impact.Components.Friction
* @extends Phaser.Physics.Impact.Components.Gravity
* @extends Phaser.Physics.Impact.Components.Offset
* @extends Phaser.Physics.Impact.Components.SetGameObject
* @extends Phaser.Physics.Impact.Components.Velocity
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} width - [description]
* @param {number} height - [description]
*/
var ImpactBody = new Class({
Mixins: [
@ -21,19 +48,71 @@ var ImpactBody = new Class({
initialize:
// x/y is the top-left of the Body
function ImpactBody (world, x, y, width, height)
{
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactBody#body
* @type {Phaser.Physics.Impact.Body}
* @since 3.0.0
*/
this.body = world.create(x, y, width, height);
this.body.parent = this;
// Local references to the Body properties
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactBody#size
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.size = this.body.size;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactBody#offset
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.offset = this.body.offset;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactBody#vel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.vel = this.body.vel;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactBody#accel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.accel = this.body.accel;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactBody#friction
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.friction = this.body.friction;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactBody#maxVel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.maxVel = this.body.maxVel;
}

View file

@ -1,8 +1,55 @@
var Class = require('../../utils/Class');
var Components = require('./components');
var Image = require('../../gameobjects/image/Image');
/**
* @classdesc
* An Impact Physics Image Game Object.
*
* An Image is a light-weight Game Object useful for the display of static images in your game,
* such as logos, backgrounds, scenery or other non-animated elements. Images can have input
* events and physics bodies, or be tweened, tinted or scrolled. The main difference between an
* Image and a Sprite is that you cannot animate an Image as they do not have the Animation component.
*
* @class ImpactImage
* @extends Phaser.GameObjects.Image
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @extends Phaser.Physics.Impact.Components.Acceleration
* @extends Phaser.Physics.Impact.Components.BodyScale
* @extends Phaser.Physics.Impact.Components.BodyType
* @extends Phaser.Physics.Impact.Components.Bounce
* @extends Phaser.Physics.Impact.Components.CheckAgainst
* @extends Phaser.Physics.Impact.Components.Collides
* @extends Phaser.Physics.Impact.Components.Debug
* @extends Phaser.Physics.Impact.Components.Friction
* @extends Phaser.Physics.Impact.Components.Gravity
* @extends Phaser.Physics.Impact.Components.Offset
* @extends Phaser.Physics.Impact.Components.SetGameObject
* @extends Phaser.Physics.Impact.Components.Velocity
* @extends Phaser.GameObjects.Components.Alpha
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.Flip
* @extends Phaser.GameObjects.Components.GetBounds
* @extends Phaser.GameObjects.Components.Origin
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.ScaleMode
* @extends Phaser.GameObjects.Components.ScrollFactor
* @extends Phaser.GameObjects.Components.Size
* @extends Phaser.GameObjects.Components.Texture
* @extends Phaser.GameObjects.Components.Tint
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @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.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {string|integer} [frame] - An optional frame from the Texture this Game Object is rendering with.
*/
var ImpactImage = new Class({
Extends: Image,
@ -24,22 +71,74 @@ var ImpactImage = new Class({
initialize:
// x/y is the center of the Image / Body, just like other default Game Objects
function ImpactImage (world, x, y, texture, frame)
{
Image.call(this, world.scene, x, y, texture, frame);
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactImage#body
* @type {Phaser.Physics.Impact.Body}
* @since 3.0.0
*/
this.body = world.create(x - this.frame.centerX, y - this.frame.centerY, this.width, this.height);
this.body.parent = this;
this.body.gameObject = this;
// Local references to the Body properties
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactImage#size
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.size = this.body.size;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactImage#offset
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.offset = this.body.offset;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactImage#vel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.vel = this.body.vel;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactImage#accel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.accel = this.body.accel;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactImage#friction
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.friction = this.body.friction;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactImage#maxVel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.maxVel = this.body.maxVel;
}

View file

@ -5,17 +5,39 @@ var Merge = require('../../utils/object/Merge');
var PluginManager = require('../../plugins/PluginManager');
var World = require('./World');
// Phaser.Physics.Impact.ImpactPhysics
/**
* @classdesc
* [description]
*
* @class ImpactPhysics
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var ImpactPhysics = new Class({
initialize:
function ImpactPhysics (scene)
{
// The Scene that owns this plugin
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactPhysics#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactPhysics#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
@ -23,13 +45,42 @@ var ImpactPhysics = new Class({
scene.sys.events.once('boot', this.boot, this);
}
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactPhysics#config
* @type {object}
* @since 3.0.0
*/
this.config = this.getConfig();
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactPhysics#world
* @type {Phaser.Physics.Impact.World}
* @since 3.0.0
*/
this.world;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactPhysics#add
* @type {Phaser.Physics.Impact.Factory}
* @since 3.0.0
*/
this.add;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.ImpactPhysics#getConfig
* @since 3.0.0
*
* @return {object} [description]
*/
getConfig: function ()
{
var gameConfig = this.systems.game.config.physics;
@ -43,6 +94,12 @@ var ImpactPhysics = new Class({
return config;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.ImpactPhysics#boot
* @since 3.0.0
*/
boot: function ()
{
this.world = new World(this.scene, this.config);
@ -55,11 +112,23 @@ var ImpactPhysics = new Class({
eventEmitter.on('destroy', this.destroy, this);
},
/**
* [description]
*
* @method Phaser.Physics.Impact.ImpactPhysics#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
this.world.shutdown();
},
/**
* [description]
*
* @method Phaser.Physics.Impact.ImpactPhysics#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.world.destroy();

View file

@ -1,8 +1,59 @@
var Class = require('../../utils/Class');
var Components = require('./components');
var Sprite = require('../../gameobjects/sprite/Sprite');
/**
* @classdesc
* An Impact Physics Sprite Game Object.
*
* A Sprite Game Object is used for the display of both static and animated images in your game.
* Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled
* and animated.
*
* The main difference between a Sprite and an Image Game Object is that you cannot animate Images.
* As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation
* Component. If you do not require animation then you can safely use Images to replace Sprites in all cases.
*
* @class ImpactSprite
* @extends Phaser.GameObjects.Sprite
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @extends Phaser.Physics.Impact.Components.Acceleration
* @extends Phaser.Physics.Impact.Components.BodyScale
* @extends Phaser.Physics.Impact.Components.BodyType
* @extends Phaser.Physics.Impact.Components.Bounce
* @extends Phaser.Physics.Impact.Components.CheckAgainst
* @extends Phaser.Physics.Impact.Components.Collides
* @extends Phaser.Physics.Impact.Components.Debug
* @extends Phaser.Physics.Impact.Components.Friction
* @extends Phaser.Physics.Impact.Components.Gravity
* @extends Phaser.Physics.Impact.Components.Offset
* @extends Phaser.Physics.Impact.Components.SetGameObject
* @extends Phaser.Physics.Impact.Components.Velocity
* @extends Phaser.GameObjects.Components.Alpha
* @extends Phaser.GameObjects.Components.Animation
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.Flip
* @extends Phaser.GameObjects.Components.GetBounds
* @extends Phaser.GameObjects.Components.Origin
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.ScaleMode
* @extends Phaser.GameObjects.Components.ScrollFactor
* @extends Phaser.GameObjects.Components.Size
* @extends Phaser.GameObjects.Components.Texture
* @extends Phaser.GameObjects.Components.Tint
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @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.
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {string|integer} [frame] - An optional frame from the Texture this Game Object is rendering with.
*/
var ImpactSprite = new Class({
Extends: Sprite,
@ -24,22 +75,74 @@ var ImpactSprite = new Class({
initialize:
// x/y is the center of the Sprite / Body, just like other default Game Objects
function ImpactSprite (world, x, y, texture, frame)
{
Sprite.call(this, world.scene, x, y, texture, frame);
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactSprite#body
* @type {Phaser.Physics.Impact.Body}
* @since 3.0.0
*/
this.body = world.create(x - this.frame.centerX, y - this.frame.centerY, this.width, this.height);
this.body.parent = this;
this.body.gameObject = this;
// Local references to the Body properties
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactSprite#size
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.size = this.body.size;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactSprite#offset
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.offset = this.body.offset;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactSprite#vel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.vel = this.body.vel;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactSprite#accel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.accel = this.body.accel;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactSprite#friction
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.friction = this.body.friction;
/**
* [description]
*
* @name Phaser.Physics.Impact.ImpactSprite#maxVel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.maxVel = this.body.maxVel;
}

View file

@ -1,9 +1,17 @@
var COLLIDES = require('./COLLIDES');
var SeperateX = require('./SeperateX');
var SeperateY = require('./SeperateY');
var COLLIDES = require('./COLLIDES');
// Impact Physics Solver
/**
* Impact Physics Solver
*
* @function Phaser.Physics.Impact.Solver
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @param {Phaser.Physics.Impact.Body} bodyA - [description]
* @param {Phaser.Physics.Impact.Body} bodyB - [description]
*/
var Solver = function (world, bodyA, bodyB)
{
var weak = null;

View file

@ -1,10 +1,17 @@
// Set up the trace-result
// var res = {
// collision: {x: false, y: false, slope: false},
// pos: {x: x, y: y},
// tile: {x: 0, y: 0}
// };
/**
* Set up the trace-result
* var res = {
* collision: {x: false, y: false, slope: false},
* pos: {x: x, y: y},
* tile: {x: 0, y: 0}
* };
*
* @function Phaser.Physics.Impact.UpdateMotion
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.Body} body - [description]
* @param {object} res - [description]
*/
var UpdateMotion = function (body, res)
{
body.standing = false;

View file

@ -1,18 +1,28 @@
// Phaser.Physics.Impact.World
var Body = require('./Body');
var Class = require('../../utils/Class');
var COLLIDES = require('./COLLIDES');
var CollisionMap = require('./CollisionMap');
var EventEmitter = require('eventemitter3');
var GetFastValue = require('../../utils/object/GetFastValue');
var HasValue = require('../../utils/object/HasValue');
var Set = require('../../structs/Set');
var Solver = require('./Solver');
var TYPE = require('./TYPE');
var TILEMAP_FORMATS = require('../../tilemaps/Formats');
var HasValue = require('../../utils/object/HasValue');
var GetFastValue = require('../../utils/object/GetFastValue');
var TYPE = require('./TYPE');
/**
* @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]
*/
var World = new Class({
Extends: EventEmitter,
@ -23,30 +33,119 @@ var World = new Class({
{
EventEmitter.call(this);
/**
* [description]
*
* @name Phaser.Physics.Impact.World#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* [description]
*
* @name Phaser.Physics.Impact.World#bodies
* @type {[type]}
* @since 3.0.0
*/
this.bodies = new Set();
/**
* [description]
*
* @name Phaser.Physics.Impact.World#gravity
* @type {[type]}
* @since 3.0.0
*/
this.gravity = GetFastValue(config, 'gravity', 0);
// Spatial hash cell dimensions
/**
* [description]
*
* @name Phaser.Physics.Impact.World#cellSize
* @type {[type]}
* @since 3.0.0
*/
this.cellSize = GetFastValue(config, 'cellSize', 64);
/**
* [description]
*
* @name Phaser.Physics.Impact.World#collisionMap
* @type {[type]}
* @since 3.0.0
*/
this.collisionMap = new CollisionMap();
/**
* [description]
*
* @name Phaser.Physics.Impact.World#timeScale
* @type {[type]}
* @since 3.0.0
*/
this.timeScale = GetFastValue(config, 'timeScale', 1);
// Impacts maximum time step is 20 fps.
/**
* [description]
*
* @name Phaser.Physics.Impact.World#maxStep
* @type {[type]}
* @since 3.0.0
*/
this.maxStep = GetFastValue(config, 'maxStep', 0.05);
/**
* [description]
*
* @name Phaser.Physics.Impact.World#enabled
* @type {boolean}
* @default true
* @since 3.0.0
*/
this.enabled = true;
/**
* [description]
*
* @name Phaser.Physics.Impact.World#drawDebug
* @type {[type]}
* @since 3.0.0
*/
this.drawDebug = GetFastValue(config, 'debug', false);
/**
* [description]
*
* @name Phaser.Physics.Impact.World#debugGraphic
* @type {null}
* @since 3.0.0
*/
this.debugGraphic;
var _maxVelocity = GetFastValue(config, 'maxVelocity', 100);
/**
* [description]
*
* @name Phaser.Physics.Impact.World#defaults
* @type {[type]}
* @since 3.0.0
*/
this.defaults = {
debugShowBody: GetFastValue(config, 'debugShowBody', true),
debugShowVelocity: GetFastValue(config, 'debugShowVelocity', true),
@ -62,10 +161,37 @@ var World = new Class({
/**
* @property {object} walls - An object containing the 4 wall bodies that bound the physics world.
*/
/**
* [description]
*
* @name Phaser.Physics.Impact.World#walls
* @type {[type]}
* @since 3.0.0
*/
this.walls = { left: null, right: null, top: null, bottom: null };
/**
* [description]
*
* @name Phaser.Physics.Impact.World#delta
* @type {number}
* @default 0
* @since 3.0.0
*/
this.delta = 0;
/**
* [description]
*
* @name Phaser.Physics.Impact.World#_lastId
* @type {number}
* @private
* @default 0
* @since 3.0.0
*/
this._lastId = 0;
if (GetFastValue(config, 'setBounds', false))
@ -109,6 +235,17 @@ var World = new Class({
* @return {CollisionMap|null} The newly created CollisionMap, or null if the method failed to
* create the CollisionMap.
*/
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCollisionMap
* @since 3.0.0
*
* @param {[type]} key - [description]
* @param {[type]} tileSize - [description]
*
* @return {[type]} [description]
*/
setCollisionMap: function (key, tileSize)
{
if (typeof key === 'string')
@ -167,6 +304,17 @@ var World = new Class({
* non-colliding tile.
* @return {CollisionMap} The newly created CollisionMap.
*/
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCollisionMapFromTilemapLayer
* @since 3.0.0
*
* @param {[type]} tilemapLayer - [description]
* @param {[type]} options - [description]
*
* @return {[type]} [description]
*/
setCollisionMapFromTilemapLayer: function (tilemapLayer, options)
{
if (options === undefined) { options = {}; }
@ -236,6 +384,24 @@ var World = new Class({
* @param {boolean} [top=true] - If true will create the top bounds wall.
* @param {boolean} [bottom=true] - If true will create the bottom bounds wall.
*/
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setBounds
* @since 3.0.0
*
* @param {[type]} x - [description]
* @param {[type]} y - [description]
* @param {[type]} width - [description]
* @param {[type]} height - [description]
* @param {[type]} thickness - [description]
* @param {[type]} left - [description]
* @param {[type]} right - [description]
* @param {[type]} top - [description]
* @param {[type]} bottom - [description]
*
* @return {[type]} [description]
*/
setBounds: function (x, y, width, height, thickness, left, right, top, bottom)
{
if (x === undefined) { x = 0; }
@ -257,6 +423,19 @@ var World = new Class({
},
// position = 'left', 'right', 'top' or 'bottom'
/**
* [description]
*
* @method Phaser.Physics.Impact.World#updateWall
* @since 3.0.0
*
* @param {[type]} add - [description]
* @param {[type]} position - [description]
* @param {[type]} x - [description]
* @param {[type]} y - [description]
* @param {[type]} width - [description]
* @param {[type]} height - [description]
*/
updateWall: function (add, position, x, y, width, height)
{
var wall = this.walls[position];
@ -286,6 +465,14 @@ var World = new Class({
}
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#createDebugGraphic
* @since 3.0.0
*
* @return {[type]} [description]
*/
createDebugGraphic: function ()
{
var graphic = this.scene.sys.add.graphics({ x: 0, y: 0 });
@ -299,11 +486,32 @@ var World = new Class({
return graphic;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#getNextID
* @since 3.0.0
*
* @return {[type]} [description]
*/
getNextID: function ()
{
return this._lastId++;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#create
* @since 3.0.0
*
* @param {[type]} x - [description]
* @param {[type]} y - [description]
* @param {[type]} sizeX - [description]
* @param {[type]} sizeY - [description]
*
* @return {[type]} [description]
*/
create: function (x, y, sizeX, sizeY)
{
var body = new Body(this, x, y, sizeX, sizeY);
@ -313,11 +521,27 @@ var World = new Class({
return body;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#remove
* @since 3.0.0
*
* @param {[type]} object - [description]
*/
remove: function (object)
{
this.bodies.delete(object);
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#pause
* @since 3.0.0
*
* @return {[type]} [description]
*/
pause: function ()
{
this.enabled = false;
@ -325,6 +549,14 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#resume
* @since 3.0.0
*
* @return {[type]} [description]
*/
resume: function ()
{
this.enabled = true;
@ -332,6 +564,17 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#update
* @since 3.0.0
*
* @param {[type]} time - [description]
* @param {[type]} delta - [description]
*
* @return {[type]} [description]
*/
update: function (time, delta)
{
if (!this.enabled || this.bodies.size === 0)
@ -395,6 +638,16 @@ var World = new Class({
},
// Check the body against the spatial hash
/**
* [description]
*
* @method Phaser.Physics.Impact.World#checkHash
* @since 3.0.0
*
* @param {[type]} body - [description]
* @param {[type]} hash - [description]
* @param {[type]} size - [description]
*/
checkHash: function (body, hash, size)
{
var checked = {};
@ -437,6 +690,17 @@ var World = new Class({
}
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#checkBodies
* @since 3.0.0
*
* @param {[type]} bodyA - [description]
* @param {[type]} bodyB - [description]
*
* @return {[type]} [description]
*/
checkBodies: function (bodyA, bodyB)
{
// 2 fixed bodies won't do anything
@ -466,6 +730,16 @@ var World = new Class({
// Helpers //
// ////////////
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCollidesNever
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setCollidesNever: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -476,6 +750,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setLite
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setLite: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -486,6 +770,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setPassive
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setPassive: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -496,6 +790,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setActive
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setActive: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -506,6 +810,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setFixed
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setFixed: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -516,6 +830,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setTypeNone
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setTypeNone: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -526,6 +850,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setTypeA
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setTypeA: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -536,6 +870,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setTypeB
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setTypeB: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -546,6 +890,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setAvsB
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setAvsB: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -557,6 +911,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setBvsA
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setBvsA: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -568,6 +932,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCheckAgainstNone
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setCheckAgainstNone: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -578,6 +952,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCheckAgainstA
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setCheckAgainstA: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -588,6 +972,16 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#setCheckAgainstB
* @since 3.0.0
*
* @param {[type]} bodies - [description]
*
* @return {[type]} [description]
*/
setCheckAgainstB: function (bodies)
{
for (var i = 0; i < bodies.length; i++)
@ -598,11 +992,23 @@ var World = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
this.removeAllListeners();
},
/**
* [description]
*
* @method Phaser.Physics.Impact.World#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.removeAllListeners();