mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 14:08:28 +00:00
Added jsdocs
This commit is contained in:
parent
e448ec59f0
commit
eaca4eb462
3 changed files with 398 additions and 36 deletions
|
@ -118,7 +118,7 @@ var ImpactPhysics = new Class({
|
|||
* @method Phaser.Physics.Impact.ImpactPhysics#pause
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
* @return {Phaser.Physics.Impact.World} The Impact World object.
|
||||
*/
|
||||
pause: function ()
|
||||
{
|
||||
|
@ -131,7 +131,7 @@ var ImpactPhysics = new Class({
|
|||
* @method Phaser.Physics.Impact.ImpactPhysics#resume
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
* @return {Phaser.Physics.Impact.World} The Impact World object.
|
||||
*/
|
||||
resume: function ()
|
||||
{
|
||||
|
|
|
@ -10,19 +10,39 @@ var Plugin = require('./lib/core/Plugin');
|
|||
var PluginManager = require('../../plugins/PluginManager');
|
||||
var World = require('./World');
|
||||
|
||||
// Phaser.Physics.Matter.MatterPhysics
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
*
|
||||
* @class MatterPhysics
|
||||
* @memberOf Phaser.Physics.Matter
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Scene} scene - [description]
|
||||
*/
|
||||
var MatterPhysics = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
// Referenced from the Scene PhysicsManager as `system`
|
||||
|
||||
function MatterPhysics (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.MatterPhysics#scene
|
||||
* @type {Phaser.Scene}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.scene = scene;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.MatterPhysics#systems
|
||||
* @type {Phaser.Scenes.Systems}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.systems = scene.sys;
|
||||
|
||||
if (!scene.sys.settings.isBooted)
|
||||
|
@ -30,13 +50,42 @@ var MatterPhysics = new Class({
|
|||
scene.sys.events.once('boot', this.boot, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.MatterPhysics#config
|
||||
* @type {object}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.config = this.getConfig();
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.MatterPhysics#world
|
||||
* @type {Phaser.Physics.Matter.World}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.world;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.MatterPhysics#add
|
||||
* @type {Phaser.Physics.Matter.Factory}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.add;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#getConfig
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {object} [description]
|
||||
*/
|
||||
getConfig: function ()
|
||||
{
|
||||
var gameConfig = this.systems.game.config.physics;
|
||||
|
@ -50,6 +99,12 @@ var MatterPhysics = new Class({
|
|||
return config;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#boot
|
||||
* @since 3.0.0
|
||||
*/
|
||||
boot: function ()
|
||||
{
|
||||
var config = this.config;
|
||||
|
@ -79,6 +134,12 @@ var MatterPhysics = new Class({
|
|||
eventEmitter.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#enableAttractorPlugin
|
||||
* @since 3.0.0
|
||||
*/
|
||||
enableAttractorPlugin: function ()
|
||||
{
|
||||
Plugin.register(MatterAttractors);
|
||||
|
@ -87,6 +148,12 @@ var MatterPhysics = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#enableWrapPlugin
|
||||
* @since 3.0.0
|
||||
*/
|
||||
enableWrapPlugin: function ()
|
||||
{
|
||||
Plugin.register(MatterWrap);
|
||||
|
@ -95,11 +162,49 @@ var MatterPhysics = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#pause
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} The Matter World object.
|
||||
*/
|
||||
pause: function ()
|
||||
{
|
||||
return this.world.pause();
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#resume
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} The Matter World object.
|
||||
*/
|
||||
resume: function ()
|
||||
{
|
||||
return this.world.resume();
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#shutdown
|
||||
* @since 3.0.0
|
||||
*/
|
||||
shutdown: function ()
|
||||
{
|
||||
this.world.shutdown();
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.MatterPhysics#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.world.destroy();
|
||||
|
|
|
@ -12,6 +12,19 @@ var MatterEvents = require('./lib/core/Events');
|
|||
var MatterWorld = require('./lib/body/World');
|
||||
var MatterTileBody = require('./MatterTileBody');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
*
|
||||
* @class World
|
||||
* @extends Phaser.Physics.Matter.EventEmitter
|
||||
* @memberOf Phaser.Physics.Matter
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Scene} scene - [description]
|
||||
* @param {object} config - [description]
|
||||
*/
|
||||
var World = new Class({
|
||||
|
||||
Extends: EventEmitter,
|
||||
|
@ -22,10 +35,31 @@ var World = new Class({
|
|||
{
|
||||
EventEmitter.call(this);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#scene
|
||||
* @type {Phaser.Scene}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.scene = scene;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#engine
|
||||
* @type {[type]}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.engine = Engine.create(config);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#localWorld
|
||||
* @type {[type]}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.localWorld = this.engine.world;
|
||||
|
||||
var gravity = GetValue(config, 'gravity', null);
|
||||
|
@ -36,8 +70,12 @@ var World = new Class({
|
|||
}
|
||||
|
||||
/**
|
||||
* @property {object} walls - An object containing the 4 wall bodies that bound the physics world.
|
||||
*/
|
||||
* An object containing the 4 wall bodies that bound the physics world.
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#walls
|
||||
* @type {[type]}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.walls = { left: null, right: null, top: null, bottom: null };
|
||||
|
||||
if (GetFastValue(config, 'setBounds', false))
|
||||
|
@ -64,12 +102,42 @@ var World = new Class({
|
|||
}
|
||||
}
|
||||
|
||||
this.isPaused = GetValue(config, 'isPaused', false);
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#enabled
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.enabled = GetValue(config, 'enabled', true);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#drawDebug
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.drawDebug = GetValue(config, 'debug', false);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#debugGraphic
|
||||
* @type {Phaser.GameObjects.Graphics}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.debugGraphic;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Physics.Matter.World#defaults
|
||||
* @type {object}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.defaults = {
|
||||
debugShowBody: GetValue(config, 'debugShowBody', true),
|
||||
debugShowStaticBody: GetValue(config, 'debugShowStaticBody', true),
|
||||
|
@ -87,6 +155,12 @@ var World = new Class({
|
|||
this.setEventsProxy();
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#setEventsProxy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
setEventsProxy: function ()
|
||||
{
|
||||
var _this = this;
|
||||
|
@ -154,23 +228,28 @@ var World = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @method Phaser.Physics.P2#setBounds
|
||||
* @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 {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.
|
||||
*/
|
||||
* 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.
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#setBounds
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @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=128] - The thickness of each wall, in pixels.
|
||||
* @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.Matter.World} This Matter World object.
|
||||
*/
|
||||
setBounds: function (x, y, width, height, thickness, left, right, top, bottom)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
|
@ -192,6 +271,19 @@ var World = new Class({
|
|||
},
|
||||
|
||||
// position = 'left', 'right', 'top' or 'bottom'
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.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];
|
||||
|
@ -220,6 +312,14 @@ var World = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#createDebugGraphic
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.GameObjects.Graphics} [description]
|
||||
*/
|
||||
createDebugGraphic: function ()
|
||||
{
|
||||
var graphic = this.scene.sys.add.graphics({ x: 0, y: 0 });
|
||||
|
@ -233,6 +333,14 @@ var World = new Class({
|
|||
return graphic;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#disableGravity
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
disableGravity: function ()
|
||||
{
|
||||
this.localWorld.gravity.x = 0;
|
||||
|
@ -242,6 +350,18 @@ var World = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#setGravity
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} [x=0] - [description]
|
||||
* @param {number} [y] - [description]
|
||||
* @param {number} [scale] - [description]
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
setGravity: function (x, y, scale)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
|
@ -258,6 +378,20 @@ var World = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#create
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
* @param {[type]} width - [description]
|
||||
* @param {[type]} height - [description]
|
||||
* @param {[type]} options - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
create: function (x, y, width, height, options)
|
||||
{
|
||||
var body = Bodies.rectangle(x, y, width, height, options);
|
||||
|
@ -268,6 +402,16 @@ var World = new Class({
|
|||
},
|
||||
|
||||
// object can be single or an array, and can be a body, composite or constraint
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#add
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} object - [description]
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
add: function (object)
|
||||
{
|
||||
MatterWorld.add(this.localWorld, object);
|
||||
|
@ -275,6 +419,17 @@ var World = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#remove
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} object - [description]
|
||||
* @param {boolean} deep - [description]
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
remove: function (object, deep)
|
||||
{
|
||||
var body = (object.body) ? object.body : object;
|
||||
|
@ -284,6 +439,17 @@ var World = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#removeConstraint
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} constraint - [description]
|
||||
* @param {boolean} deep - [description]
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
removeConstraint: function (constraint, deep)
|
||||
{
|
||||
Composite.remove(this.localWorld, constraint, deep);
|
||||
|
@ -302,7 +468,8 @@ var World = new Class({
|
|||
* An array of tiles.
|
||||
* @param {object} [options] - Options to be passed to the MatterTileBody constructor. See
|
||||
* Phaser.Physics.Matter.TileBody.
|
||||
* @return {this}
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
convertTilemapLayer: function (tilemapLayer, options)
|
||||
{
|
||||
|
@ -326,7 +493,8 @@ var World = new Class({
|
|||
* @param {Phaser.GameObjects.Tile[]} tiles - An array of tiles.
|
||||
* @param {object} [options] - Options to be passed to the MatterTileBody constructor. See
|
||||
* Phaser.Physics.Matter.TileBody.
|
||||
* @return {this}
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
convertTiles: function (tiles, options)
|
||||
{
|
||||
|
@ -343,28 +511,93 @@ var World = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#nextGroup
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} isNonColliding - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
nextGroup: function (isNonColliding)
|
||||
{
|
||||
return MatterBody.nextGroup(isNonColliding);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#nextCategory
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
nextCategory: function ()
|
||||
{
|
||||
return MatterBody.nextCategory();
|
||||
},
|
||||
|
||||
update: function (time, delta)
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#pause
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
pause: function ()
|
||||
{
|
||||
if (this.isPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.enabled = false;
|
||||
|
||||
var correction = 1;
|
||||
this.emit('pause');
|
||||
|
||||
Engine.update(this.engine, delta, correction);
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#resume
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Physics.Matter.World} This Matter World object.
|
||||
*/
|
||||
resume: function ()
|
||||
{
|
||||
this.enabled = true;
|
||||
|
||||
this.emit('resume');
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} time - [description]
|
||||
* @param {number} delta - [description]
|
||||
*/
|
||||
update: function (time, delta)
|
||||
{
|
||||
if (this.enabled)
|
||||
{
|
||||
var correction = 1;
|
||||
|
||||
Engine.update(this.engine, delta, correction);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#postUpdate
|
||||
* @since 3.0.0
|
||||
*/
|
||||
postUpdate: function ()
|
||||
{
|
||||
if (!this.drawDebug)
|
||||
|
@ -407,6 +640,17 @@ var World = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#fromPath
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} path - [description]
|
||||
* @param {[type]} points - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
fromPath: function (path, points)
|
||||
{
|
||||
if (points === undefined) { points = []; }
|
||||
|
@ -421,12 +665,25 @@ var World = new Class({
|
|||
return points;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#shutdown
|
||||
* @since 3.0.0
|
||||
*/
|
||||
shutdown: function ()
|
||||
{
|
||||
MatterWorld.clear(this.localWorld, false);
|
||||
|
||||
Engine.clear(this.engine);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Physics.Matter.World#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.shutdown();
|
||||
|
|
Loading…
Add table
Reference in a new issue