Class Index | File Index

Classes


Class R.physics.Simulation


Extends R.engine.BaseObject.
A representation of a physical world. This object is used to introduce Box2dWeb physics into your game by creating a world which supports the physical structures provided by Box2dWeb. You will need to create an R.physics.Simulation before you can utilize physics in a game.

See either "/demos/physics/" or "/demos/physics2" for examples of utilizing the R.physics.Simulation object with rigid body components.
Defined in: simulation.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
R.physics.Simulation(name, viewport, gravity)
Create a physical world for Box2dJS
Field Summary
Field Attributes Field Name and Description
 
The default number of integrations per frame
 
The world is updated at 60Hz, or 1/60th of a second.
 
The size of the world in meters
Method Summary
Method Attributes Method Name and Description
 
addSimpleBoxBody(pos, extents, properties)
Add a simple box body to the simulation.
 
addSimpleCircleBody(pos, radius, properties)
Add a simple circle body to the simulation.
 
Query the world within the given rectangle returning all of the bodies found.
 
Query the world for the body that lies at the given point.
 
Get the class name as a string.
 
Get the number of integrations per frame.
 
setIntegrations(integrations)
Set the number of integrations per frame.
Methods borrowed from class R.engine.BaseObject:
addEvent, addEvents, destroy, getElement, jQ, release, removeEvent, setElement, triggerEvent, update
Methods borrowed from class R.engine.PooledObject:
clearObjectDataModel, getId, getName, getObjectDataModel, getProperties, isDestroyed, setName, setObjectDataModel, toString, toXML
Class Detail
R.physics.Simulation(name, viewport, gravity)
Create a physical world for Box2dJS
Parameters:
name
{String} The name of the object
viewport
{R.math.Rectangle2D} Your rendering context's viewport
gravity Optional
{R.math.Vector2D} The world's gravity vector. default: [0, 650]
Field Detail
DEFAULT_INTEGRATIONS
The default number of integrations per frame

FIXED_TIMESTEP
The world is updated at 60Hz, or 1/60th of a second. This time step is ideal so that objects do not jitter. Changing this value can result in some truly odd behavior in the simulation.

WORLD_SIZE
The size of the world in meters
Method Detail
{Box2D.Dynamics.b2Body} addSimpleBoxBody(pos, extents, properties)
Add a simple box body to the simulation. The body doesn't have a visual representation, but exists in the simulation and can be interacted with.
Parameters:
pos
{R.math.Point2D} The position where the body's top/left is located
extents
{R.math.Point2D} The width and height of the body
properties
{Object} An object with up to three properties:
  • restitution - The bounciness of the body
  • friction - Friction against this body
  • density - The density of the object (default: 0)
  • isStatic - false for a dynamic body (default: true)
Returns:
{Box2D.Dynamics.b2Body} A Box2dWeb body definition object representing the box

{b2BodyDef} addSimpleCircleBody(pos, radius, properties)
Add a simple circle body to the simulation. The body doesn't have a visual representation, but exists in the simulation and can be interacted with.
Parameters:
pos
{Point2D} The position where the body's center is located
radius
{Point2D} The radius of the circle body
properties
{Object} An object with up to three properties:
  • restitution - The bounciness of the body
  • friction - Friction against this body
  • density - The density of the object (default: 0)
  • isStatic - false for a dynamic body (default: true)
Returns:
{b2BodyDef} A Box2D-JS body definition object representing the circle

{Array} getBodiesInArea(rect)
Query the world within the given rectangle returning all of the bodies found.
Parameters:
rect
{R.math.Rectangle2D} The area to query
Returns:
{Array} An array of Box2D.Dynamics.b2Body objects

{Box2D.Dynamics.b2Body} getBodyAtPoint(point)
Query the world for the body that lies at the given point.
Parameters:
point
{R.math.Point2D} The point to query
Returns:
{Box2D.Dynamics.b2Body} The body found, or null

{String} getClassName()
Get the class name as a string.
Returns:
{String} "R.physics.Simulation"

{Number} getIntegrations()
Get the number of integrations per frame.
Returns:
{Number}

setIntegrations(integrations)
Set the number of integrations per frame. A higher number will result in more accurate collisions, but will result in slower performance.
Parameters:
integrations
{Number} The number of integrations per frame

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Mar 18 2013 16:09:19 GMT-0400 (EDT)