API Docs for: 0.1.0
Show:

zerk.game.engine.system.physics.box2d Class

Box2D Physics System

Box2dWeb implementation.

Methods

__setBodyKinematic

(
  • bodyKey
)
protected

Sets given body to be kinematic

Parameters:

  • bodyKey String

__setLinearVelocity

(
  • bodyKey
  • degrees
  • power
)
protected

Sets the linear velocity of given body

Parameters:

  • bodyKey String
  • degrees Integer
  • power Integer

_addContactListener

() protected

Registers the contact listener event handlers

_bodyApplyImpulse

(
  • bodyKey
  • degrees
  • power
)
protected

Applies an impulse to given body

Parameters:

  • bodyKey String
  • degrees Integer
  • power Integer

_cleanup

() protected

Destroy bodies and joints schedules to be removed from the world

_createBody

(
  • entity
  • body
)
Object protected

Creates a body

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • body zerk.game.engine.system.physics.box2d.body

    Body

Returns:

Object: Body handle

_createFixture

(
  • entity
  • body
  • fixture
)
Object protected

Delegate method for fixture creation

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • body zerk.game.engine.system.physics.box2d.body

    Body

  • fixture zerk.game.engine.system.physics.box2d.fixture

    Fixture

Returns:

Object: Fixture handle

_createFixtureCircle

(
  • entity
  • body
  • fixture
)
Object protected

Creates a circle shaped fixture

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • body zerk.game.engine.system.physics.box2d.body

    Body

  • fixture zerk.game.engine.system.physics.box2d.fixture

    Fixture

Returns:

Object: Fixture handle

_createFixturePolygon

(
  • entity
  • body
  • fixture
)
Object protected

Creates a polygon shaped fixture

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • body zerk.game.engine.system.physics.box2d.body

    Body

  • fixture zerk.game.engine.system.physics.box2d.fixture

    Fixture

Returns:

Object: Fixture handle

_createFixtureRectangle

(
  • entity
  • body
  • fixture
)
Object protected

Creates a rectangle shaped fixture

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • body zerk.game.engine.system.physics.box2d.body

    Body

  • fixture zerk.game.engine.system.physics.box2d.fixture

    Fixture

Returns:

Object: Fixture handle

_createJoint

(
  • entity
  • joint
)
Object protected

Delgate method for joint creation

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • joint zerk.game.engine.system.physics.box2d.joint

    Joint

Returns:

Object: Joint handle

_createJointDistance

(
  • entity
  • joint
)
Object protected

Creates a distance joint

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • joint zerk.game.engine.system.physics.box2d.joint

    Joint

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:

  • entity zerk.game.engine.entity

    Entity

  • joint zerk.game.engine.system.physics.box2d.joint

    Joint

Returns:

Object: Joint handle

_createPhysics

(
  • entity
)
protected

Creates the physics representation for given entity

Parameters:

_destroyBody

(
  • bodyKey
)
protected

Destroys given body

Parameters:

  • bodyKey String

_destroyBody

(
  • entity
  • body
)
protected

Destroys a body

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • body zerk.game.engine.system.physics.box2d.body

    Body

_destroyJoint

(
  • entity
  • joint
)
protected

Destroys a joint

Parameters:

  • entity zerk.game.engine.entity

    Entity

  • joint zerk.game.engine.system.physics.box2d.joint

    Joint

_getBodyAtMouseCallback

(
  • fixture
)
Boolean protected

Callbak method for internal processing of getBodyAtMouse

Parameters:

  • fixture Object

    Box2D fixture

Returns:

Boolean:

_getBodyLinearVelocity

(
  • bodyKey
)
Object protected

Returns the linear velocity of given body

Parameters:

  • bodyKey String

Returns:

Object:

_getBodyPosition

(
  • bodyKey
)
Object protected

Returns position of given body

Parameters:

  • bodyKey String

Returns:

Object: Position

_getConfigDefaults

() Object protected

Returns the configuration defaults of the system

Returns:

Object: Default configuration

_getSystem

(
  • name
)
zerk.game.engine.system protected

Returns system by given name

This method is used to communicate with other systems.

Parameters:

  • name String

    System name

Returns:

zerk.game.engine.system: System instance

_log

(
  • message
  • severity
)
protected

Local log method

Parameters:

  • message String

    Log message

  • severity Integer

    Log severity

_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

_removePhysics

(
  • entity
)
protected

Removes the physics representation for given entity

Parameters:

_scheduleDestroyBody

(
  • entity
  • body
)

Schedules a body to be destroyed after current simulation tick

Parameters:

  • entity zerk.game.engine.entity
  • body zerk.game.engine.system.physics.box2d.body

_scheduleDestroyJoint

(
  • entity
  • body
)

Schedules a join to be destroyed after current simulation tick

Parameters:

  • entity zerk.game.engine.entity
  • body zerk.game.engine.system.physics.box2d.join

_setBodyMoveable

(
  • bodyKey
  • moveable
)
protected

Sets whether given body is moveable

Parameters:

  • bodyKey String
  • moveable Boolean

_setBodyPosition

(
  • bodyKey
  • position
)
protected

Sets the position of given body

Parameters:

  • bodyKey String
  • position Object

_setBodySleepingAllowed

(
  • bodyKey
  • allowed
)
protected

Sets whether given body is allowed to sleep

Parameters:

  • bodyKey String
  • allowed Boolean

_tick

() protected

Fires every tick

addEntity

(
  • entity
)

Adds an entity to the system

Parameters:

createPhysics

(
  • entity
)

Create the physics engine representation for an entity

Parameters:

  • entity zerk.game.engine.entity

    Entity

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

getName

() String

Returns the name of the system

Returns:

String: System name

getPriority

() Integer

Returns the priority of the system

Returns:

Integer: System priority

getThread

() String

Returns the thread the systems runs in

Returns:

String: Thread name

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

removeEntity

(
  • entity
)

Removes an entity from the system

Parameters:

removePhysics

(
  • entity
)

Removes the physics engine representation for an entity

Parameters:

  • entity zerk.game.engine.entity

    Entity

start

()

Starts the system

stop

()

Stops the system

syncEntityPhysics

(
  • entity
)

Synchronize the physic simulation properties of an entity

Parameters:

  • entity zerk.game.engine.entity

    Entity

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

update

()

Updates the system

useComponent

(
  • name
)
Boolean

Returns true when the system is interested in given component

Parameters:

  • name String

    Component name

Returns:

Boolean: True when the system is intereseted in given component

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

Engine instance

Back reference to the engine instance.

_entities

Array protected

Entities register

Entities that this system is interested in.

_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

_name

String protected

Name of the system

_priority

Integer protected

Priority of this system

Priorities handle the order in which systems are processed.

_selectedBody

Object protected

Stores the last selected body

_thread

String protected

Thread that runs this system

_world

Box2D.Dynamics.b2World protected

Box2D world

Events

contactbegin

Fires when two fixtures start colliding

Event Payload:

  • sourceFixture zerk.game.engine.system.physics.box2d.fixture

    Source fixture

  • targetFixture zerk.game.engine.system.physics.box2d.fixture

    Target fixture

contactend

Fires when two fixtures stop colliding

Event Payload:

  • sourceFixture zerk.game.engine.system.physics.box2d.fixture

    Source fixture

  • targetFixture zerk.game.engine.system.physics.box2d.fixture

    Target fixture

contactpostsolve

Fires before two fixtures start colliding

Event Payload:

  • sourceFixture zerk.game.engine.system.physics.box2d.fixture

    Source fixture

  • targetFixture zerk.game.engine.system.physics.box2d.fixture

    Target fixture

  • impulse Object