API Docs for: 0.1.0
Show:

zerk.game.engine.physics Class

Physics engine interface

Box2dWeb implementation.

Methods

_addContactListener

() protected

Registers the contact listener event handlers

_cleanup

() protected

Destroy bodies and joints schedules to be removed from the world

_createBody

(
  • entity
  • body
)
Object protected

Creates a body

Parameters:

Returns:

Object: Body handle

_createFixture

(
  • entity
  • body
  • fixture
)
Object protected

Delegate method for fixture creation

Parameters:

Returns:

Object: Fixture handle

_createFixtureCircle

(
  • entity
  • body
  • fixture
)
Object protected

Creates a circle shaped fixture

Parameters:

Returns:

Object: Fixture handle

_createFixturePolygon

(
  • entity
  • body
  • fixture
)
Object protected

Creates a polygon shaped fixture

Parameters:

Returns:

Object: Fixture handle

_createFixtureRectangle

(
  • entity
  • body
  • fixture
)
Object protected

Creates a rectangle shaped fixture

Parameters:

Returns:

Object: Fixture handle

_createJoint

(
  • entity
  • joint
)
Object protected

Delgate method for joint creation

Parameters:

Returns:

Object: Joint handle

_createJointDistance

(
  • entity
  • joint
)
Object protected

Creates a distance joint

Parameters:

Returns:

Object: Joint handle

_createJointMouse

(
  • body
  • targetX
  • targetY
)
Object protected

Creates a mouse joint

Parameters:

  • body Object

    Box2dWeb body

  • targetX Float

    Horizontal position

  • targetY Float

    Vertical position

Returns:

Object: Joint handle

_createJointRevolute

(
  • entity
  • joint
)
Object protected

Creates a revolute join

Parameters:

Returns:

Object: Joint handle

_destroyBody

(
  • entity
  • body
)
protected

Destroys a body

Parameters:

_destroyJoint

(
  • entity
  • joint
)
protected

Destroys a joint

Parameters:

_getBodyAtMouseCallback

(
  • fixture
)
Boolean protected

Callbak method for internal processing of getBodyAtMouse

Parameters:

  • fixture Object

    Box2D fixture

Returns:

Boolean:

_log

(
  • msg
)
protected

Local log method

Parameters:

  • msg String

    Log message

_onContactBegin

(
  • contact
)
protected

Contact begin event handler

Parameters:

  • contact Object

    Contact information

_onContactEnd

(
  • contact
)
protected

Contact end event handler

Parameters:

  • contact Object

    Contact information

_onContactPostSolve

(
  • contact
  • impulse
)
protected

Contact post solve event handler

Parameters:

  • contact Object

    Contact information

  • impulse Object

    Impulse information

_onContactPreSolve

(
  • contact
  • oldManifold
)
protected

Contact pre solve event handler

Parameters:

  • contact Object

    Contact information

  • oldManifold Object

_processMouseJoint

() protected

Process mouse joint

createPhysics

(
  • entity
)

Create the physics engine representation for an entity

Parameters:

dumpPhysicsData

()

Dumps elements currently contained in physics simulation to console

fireEvent

(
  • event
)
Boolen

Fire event

Parameters:

  • event String

    Event name

Returns:

Boolen: Returns false when the bubble was canceled

getBodyAtMouse

() Object

Returns body at current cursor position if present

Returns:

Object: Box2D body

getEntitiesInArea

(
  • x1
  • y1
  • x2
  • y2
)
Array

Returns an array of entities inside given area

Parameters:

  • x1 Float
  • y1 Float
  • x2 Float
  • y2 Float

Returns:

Array: Entities inside given area

init

(
  • engine
)

Class constructor

Parameters:

on

(
  • event
  • callback
  • scope
)

Register event handler

Parameters:

  • event String

    Event name

  • callback Function

    Callback function. Return false to cancel event bubble.

  • scope Object

    Scope to be used in callback function

removePhysics

(
  • entity
)

Removes the physics engine representation for an entity

Parameters:

scheduleDestroyBody

(
  • entity
  • body
)

Schedules a body to be destroyed after current simulation tick

scheduleDestroyJoint

(
  • entity
  • body
)

Schedules a join to be destroyed after current simulation tick

Parameters:

syncEntityPhysics

(
  • entity
)

Synchronize the physic simulation properties of an entity

Parameters:

tick

()

Physics engine tick

un

(
  • event
  • callback
)
Boolen

Unregister event handler

Parameters:

  • event String

    Event name

  • callback Function

    Callback function

Returns:

Boolen: Returns true on success

Properties

__destroyJointList

Array protected

List of joints to be destroyed after current simulation tick

_b2AABB

Object protected

Shortcut for Box2D.Collision.b2AABB

_b2Body

Object protected

Shortcut for Box2D.Dynamics.b2Body

_b2BodyDef

Object protected

Shortcut for Box2D.Dynamics.b2BodyDef

_b2CircleShape

Object protected

Shortcut for Box2D.Collision.Shapes.b2CircleShape

_b2ContactListener

Object protected

Shortcut for Box2D.Dynamics.b2ContactListener

_b2DebugDraw

Object protected

Shortcut for Box2D.Dynamics.b2DebugDraw

_b2DistanceJointDef

Object protected

Shortcut for Box2D.Dynamics.Joints.b2DistanceJointDef

_b2FixtureDef

Object protected

Shortcut for Box2D.Dynamics.b2FixtureDef

_b2MouseJointDef

Object protected

Shortcut for Box2D.Dynamics.Joints.b2MouseJointDef

_b2PolygonShape

Object protected

Shortcut for Box2D.Collision.Shapes.b2PolygonShape

_b2RevoluteJointDef

Object protected

Shortcut for Box2D.Dynamics.Joints.b2RevoluteJointDef

_b2Vec2

Object protected

Shortcut for Box2D.Common.Math.b2Vec2

_b2World

Object protected

Shortcut for Box2D.Dynamics.b2World

_config

Object protected

Physics configuration

_destroyBodyList

Array protected

List of bodies to be destroyed after current simulation tick

_engine

zerk.game.engine protected

Game engine

_eventListeners

Array protected

List of event handlers

_mouseJoint

Object protected

Handle for the mouse joint

_mouseJointVec

Object protected

Stores a vector for the mouse joint function

_selectedBody

Object protected

Stores the last selected body

_world

Box2D.Dynamics.b2World protected

Box2D world

Events

contactbegin

Fires when two fixtures start colliding

Event Payload:

contactend

Fires when two fixtures stop colliding

Event Payload:

contactpostsolve

Fires before two fixtures start colliding

Event Payload: