zerk.game.engine.system.physics.box2d Class
Box2D Physics System
Box2dWeb implementation.
Item Index
Methods
- __setBodyKinematic
- __setLinearVelocity
- _addContactListener
- _bodyApplyImpulse
- _cleanup
- _createBody
- _createFixture
- _createFixtureCircle
- _createFixturePolygon
- _createFixtureRectangle
- _createJoint
- _createJointDistance
- _createJointMouse
- _createJointRevolute
- _createPhysics
- _destroyBody
- _destroyBody
- _destroyJoint
- _getBodyAtMouseCallback
- _getBodyLinearVelocity
- _getBodyPosition
- _getConfigDefaults
- _getSystem
- _log
- _onContactBegin
- _onContactEnd
- _onContactPostSolve
- _onContactPreSolve
- _processMouseJoint
- _removePhysics
- _scheduleDestroyBody
- _scheduleDestroyJoint
- _setBodyMoveable
- _setBodyPosition
- _setBodySleepingAllowed
- _tick
- addEntity
- createPhysics
- dumpPhysicsData
- fireEvent
- getBodyAtMouse
- getEntitiesInArea
- getName
- getPriority
- getThread
- init
- on
- removeEntity
- removePhysics
- start
- stop
- syncEntityPhysics
- tick
- un
- update
- useComponent
Properties
- __destroyJointList
- _b2AABB
- _b2Body
- _b2BodyDef
- _b2CircleShape
- _b2ContactListener
- _b2DebugDraw
- _b2DistanceJointDef
- _b2FixtureDef
- _b2MouseJointDef
- _b2PolygonShape
- _b2RevoluteJointDef
- _b2Vec2
- _b2World
- _config
- _destroyBodyList
- _engine
- _entities
- _eventListeners
- _mouseJoint
- _mouseJointVec
- _name
- _priority
- _selectedBody
- _thread
- _world
Methods
__setBodyKinematic
-
bodyKey
Sets given body to be kinematic
Parameters:
-
bodyKey
String
__setLinearVelocity
-
bodyKey
-
degrees
-
power
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
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
Creates a body
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.system.physics.box2d.bodyBody
Returns:
_createFixture
-
entity
-
body
-
fixture
Delegate method for fixture creation
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.system.physics.box2d.bodyBody
-
fixture
zerk.game.engine.system.physics.box2d.fixtureFixture
Returns:
_createFixtureCircle
-
entity
-
body
-
fixture
Creates a circle shaped fixture
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.system.physics.box2d.bodyBody
-
fixture
zerk.game.engine.system.physics.box2d.fixtureFixture
Returns:
_createFixturePolygon
-
entity
-
body
-
fixture
Creates a polygon shaped fixture
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.system.physics.box2d.bodyBody
-
fixture
zerk.game.engine.system.physics.box2d.fixtureFixture
Returns:
_createFixtureRectangle
-
entity
-
body
-
fixture
Creates a rectangle shaped fixture
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.system.physics.box2d.bodyBody
-
fixture
zerk.game.engine.system.physics.box2d.fixtureFixture
Returns:
_createJoint
-
entity
-
joint
Delgate method for joint creation
Parameters:
-
entity
zerk.game.engine.entityEntity
-
joint
zerk.game.engine.system.physics.box2d.jointJoint
Returns:
_createJointDistance
-
entity
-
joint
Creates a distance joint
Parameters:
-
entity
zerk.game.engine.entityEntity
-
joint
zerk.game.engine.system.physics.box2d.jointJoint
Returns:
_createJointMouse
-
body
-
targetX
-
targetY
Creates a mouse joint
Parameters:
-
body
ObjectBox2dWeb body
-
targetX
FloatHorizontal position
-
targetY
FloatVertical position
Returns:
_createJointRevolute
-
entity
-
joint
Creates a revolute join
Parameters:
-
entity
zerk.game.engine.entityEntity
-
joint
zerk.game.engine.system.physics.box2d.jointJoint
Returns:
_createPhysics
-
entity
Creates the physics representation for given entity
Parameters:
-
entity
config.entityEntity state
_destroyBody
-
bodyKey
Destroys given body
Parameters:
-
bodyKey
String
_destroyBody
-
entity
-
body
Destroys a body
Parameters:
-
entity
zerk.game.engine.entityEntity
-
body
zerk.game.engine.system.physics.box2d.bodyBody
_destroyJoint
-
entity
-
joint
Destroys a joint
Parameters:
-
entity
zerk.game.engine.entityEntity
-
joint
zerk.game.engine.system.physics.box2d.jointJoint
_getBodyAtMouseCallback
-
fixture
Callbak method for internal processing of getBodyAtMouse
Parameters:
-
fixture
ObjectBox2D fixture
Returns:
_getBodyLinearVelocity
-
bodyKey
Returns the linear velocity of given body
Parameters:
-
bodyKey
String
Returns:
_getBodyPosition
-
bodyKey
Returns position of given body
Parameters:
-
bodyKey
String
Returns:
_getConfigDefaults
()
Object
protected
Returns the configuration defaults of the system
Returns:
_getSystem
-
name
Returns system by given name
This method is used to communicate with other systems.
Parameters:
-
name
StringSystem name
Returns:
_log
-
message
-
severity
Local log method
Parameters:
-
message
StringLog message
-
severity
IntegerLog severity
_onContactBegin
-
contact
Contact begin event handler
Parameters:
-
contact
ObjectContact information
_onContactEnd
-
contact
Contact end event handler
Parameters:
-
contact
ObjectContact information
_onContactPostSolve
-
contact
-
impulse
Contact post solve event handler
Parameters:
-
contact
ObjectContact information
-
impulse
ObjectImpulse information
_onContactPreSolve
-
contact
-
oldManifold
Contact pre solve event handler
Parameters:
-
contact
ObjectContact information
-
oldManifold
Object
_processMouseJoint
()
protected
Process mouse joint
_removePhysics
-
entity
Removes the physics representation for given entity
Parameters:
-
entity
config.entityEntity state
_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
Sets whether given body is moveable
Parameters:
-
bodyKey
String -
moveable
Boolean
_setBodyPosition
-
bodyKey
-
position
Sets the position of given body
Parameters:
-
bodyKey
String -
position
Object
_setBodySleepingAllowed
-
bodyKey
-
allowed
Sets whether given body is allowed to sleep
Parameters:
-
bodyKey
String -
allowed
Boolean
_tick
()
protected
Fires every tick
createPhysics
-
entity
Create the physics engine representation for an entity
Parameters:
-
entity
zerk.game.engine.entityEntity
dumpPhysicsData
()
Dumps elements currently contained in physics simulation to console
fireEvent
-
event
Fire event
Parameters:
-
event
StringEvent name
Returns:
getBodyAtMouse
()
Object
Returns body at current cursor position if present
Returns:
getEntitiesInArea
-
x1
-
y1
-
x2
-
y2
Returns an array of entities inside given area
Parameters:
-
x1
Float -
y1
Float -
x2
Float -
y2
Float
Returns:
getName
()
String
Returns the name of the system
Returns:
getPriority
()
Integer
Returns the priority of the system
Returns:
getThread
()
String
Returns the thread the systems runs in
Returns:
on
-
event
-
callback
-
scope
Register event handler
Parameters:
-
event
StringEvent name
-
callback
FunctionCallback function. Return false to cancel event bubble.
-
scope
ObjectScope to be used in callback function
removeEntity
-
entity
Removes an entity from the system
Parameters:
-
entity
config.entityEntity state
removePhysics
-
entity
Removes the physics engine representation for an entity
Parameters:
-
entity
zerk.game.engine.entityEntity
start
()
Starts the system
stop
()
Stops the system
syncEntityPhysics
-
entity
Synchronize the physic simulation properties of an entity
Parameters:
-
entity
zerk.game.engine.entityEntity
tick
()
Physics engine tick
un
-
event
-
callback
Unregister event handler
Parameters:
-
event
StringEvent name
-
callback
FunctionCallback function
Returns:
update
()
Updates the system
useComponent
-
name
Returns true when the system is interested in given component
Parameters:
-
name
StringComponent name
Returns:
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
_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.fixtureSource fixture
-
targetFixture
zerk.game.engine.system.physics.box2d.fixtureTarget fixture
contactend
Fires when two fixtures stop colliding
Event Payload:
-
sourceFixture
zerk.game.engine.system.physics.box2d.fixtureSource fixture
-
targetFixture
zerk.game.engine.system.physics.box2d.fixtureTarget fixture
contactpostsolve
Fires before two fixtures start colliding
Event Payload:
-
sourceFixture
zerk.game.engine.system.physics.box2d.fixtureSource fixture
-
targetFixture
zerk.game.engine.system.physics.box2d.fixtureTarget fixture
-
impulse
Object