Class: Physics

Phaser. Physics

Phaser.Physics

new Physics(game, physicsConfig)

The Physics Manager is responsible for looking after all of the running physics systems. Phaser supports 3 physics systems: Arcade Physics, P2 and Ninja Physics (with Box2D and Chipmunk in development) Game Objects can belong to only 1 physics system, but you can have multiple systems active in a single game.

For example you could have P2 managing a polygon-built terrain landscape that an vehicle drives over, while it could be firing bullets that use the faster (due to being much simpler) Arcade Physics system.

Parameters:
Name Type Argument Default Description
game Phaser.Game

A reference to the currently running game.

physicsConfig object <optional>
null

A physics configuration object to pass to the Physics world on creation.

Source:

Classes

Arcade
Ninja
P2

Members

<static, constant> ARCADE :number

Type:
  • number
Source:

<static, constant> BOX2D :number

Type:
  • number
Source:

<static, constant> CHIPMUNK :number

Type:
  • number
Source:

<static, constant> NINJA :number

Type:
  • number
Source:

<static, constant> P2JS :number

Type:
  • number
Source:

arcade

Properties:
Name Type Description
arcade Phaser.Physics.Arcade

The Arcade Physics system.

Source:

box2d

Properties:
Name Type Description
box2d Phaser.Physics.Box2D

The Box2D Physics system (to be done).

Source:

chipmunk

Properties:
Name Type Description
chipmunk Phaser.Physics.Chipmunk

The Chipmunk Physics system (to be done).

Source:

config

Properties:
Name Type Description
config object

The physics configuration object as passed to the game on creation.

Source:

game

Properties:
Name Type Description
game Phaser.Game

Local reference to game.

Source:

ninja

Properties:
Name Type Description
ninja Phaser.Physics.Ninja

The N+ Ninja Physics System.

Source:

p2

Properties:
Name Type Description
p2 Phaser.Physics.P2

The P2.JS Physics system.

Source:

Methods

<protected> clear()

Clears down all active physics systems. This doesn't destroy them, it just clears them of objects and is called when the State changes.

Source:

destroy()

Destroys all active physics systems. Usually only called on a Game Shutdown, not on a State swap.

Source:

enable(object, system, debug)

This will create a default physics body on the given game object or array of objects. A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. It can be for any of the physics systems that have been started:

Phaser.Physics.Arcade - A light weight AABB based collision system with basic separation. Phaser.Physics.P2JS - A full-body advanced physics system supporting multiple object shapes, polygon loading, contact materials, springs and constraints. Phaser.Physics.NINJA - A port of Metanet Softwares N+ physics system. Advanced AABB and Circle vs. Tile collision. Phaser.Physics.BOX2D and Phaser.Physics.CHIPMUNK are still in development.

If you require more control over what type of body is created, for example to create a Ninja Physics Circle instead of the default AABB, then see the individual physics systems enable methods instead of using this generic one.

Parameters:
Name Type Argument Default Description
object object | array

The game object to create the physics body on. Can also be an array of objects, a body will be created on every object in the array.

system number <optional>
Phaser.Physics.ARCADE

The physics system that will be used to create the body. Defaults to Arcade Physics.

debug boolean <optional>
false

Enable the debug drawing for this body. Defaults to false.

Source:

parseConfig()

Parses the Physics Configuration object passed to the Game constructor and starts any physics systems specified within.

Source:

<protected> preUpdate()

preUpdate checks.

Source:

setBoundsToWorld(left, right, top, bottom, setCollisionGroup)

Sets the bounds of the Physics world to match the Game.World dimensions. You can optionally set which 'walls' to create: left, right, top or bottom.

Parameters:
Name Type Argument Default Description
left boolean <optional>
true

If true will create the left bounds wall.

right boolean <optional>
true

If true will create the right bounds wall.

top boolean <optional>
true

If true will create the top bounds wall.

bottom boolean <optional>
true

If true will create the bottom bounds wall.

setCollisionGroup boolean <optional>
true

If true the Bounds will be set to use its own Collision Group.

Source:

<protected> setBoundsToWorld()

Updates the physics bounds to match the world dimensions.

Source:

setWorldMaterial(material, left, right, top, bottom)

Sets the given material against the 4 bounds of this World.

Parameters:
Name Type Argument Default Description
material Phaser.Physics.P2.Material

The material to set.

left boolean <optional>
true

If true will set the material on the left bounds wall.

right boolean <optional>
true

If true will set the material on the right bounds wall.

top boolean <optional>
true

If true will set the material on the top bounds wall.

bottom boolean <optional>
true

If true will set the material on the bottom bounds wall.

Source:

startSystem(The)

This will create an instance of the requested physics simulation. Phaser.Physics.Arcade is running by default, but all others need activating directly. You can start the following physics systems: Phaser.Physics.P2JS - A full-body advanced physics system by Stefan Hedman. Phaser.Physics.NINJA - A port of Metanet Softwares N+ physics system. Phaser.Physics.BOX2D and Phaser.Physics.CHIPMUNK are still in development.

Parameters:
Name Type Description
The number

physics system to start.

Source:

<protected> update()

Updates all running physics systems.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Mon Mar 24 2014 12:38:47 GMT-0000 (GMT) using the DocStrap template.