Packagecitrus.objects
Classpublic class Box2DPhysicsObject
InheritanceBox2DPhysicsObject Inheritance APhysicsObject Inheritance CitrusObject Inheritance Object
Implements ISpriteView, IBox2DPhysicsObject
Subclasses Bridge, Crate, Enemy, FluidBox, Hero, Hills, Missile, Platform, Pool, Reward, RewardBox, Rope, Sensor

You should extend this class to take advantage of Box2D. This class provides template methods for defining and creating Box2D bodies, fixtures, shapes, and joints. If you are not familiar with Box2D, you should first learn about it via the Box2D Manual.



Public Properties
 PropertyDefined By
 Inheritedanimation : String
Animations management works the same way than label whether it uses MovieClip, SpriteSheet or whatever.
APhysicsObject
 Inheritedart : ICitrusArt
[read-only]
APhysicsObject
  beginContactCallEnabled : Boolean
This flag determines if the handleBeginContact method is called or not.
Box2DPhysicsObject
  body : b2Body
[read-only] A direct reference to the Box2D body associated with this object.
Box2DPhysicsObject
  depth : Number
[read-only] No depth in a 2D Physics world.
Box2DPhysicsObject
  endContactCallEnabled : Boolean
This flag determines if the handleEndContact method is called or not.
Box2DPhysicsObject
 Inheritedgroup : uint
The group is similar to a z-index sorting.
APhysicsObject
  height : Number
This can only be set in the constructor parameters.
Box2DPhysicsObject
 InheritedhideParamWarnings : Boolean = false
[static]
CitrusObject
 InheritedID : uint
[read-only]
CitrusObject
 Inheritedinverted : Boolean
[read-only] Used to invert the view on the y-axis, number of animations friendly!
APhysicsObject
 Inheritedkill : Boolean = false
Set it to true if you want to remove, clean and destroy the object.
CitrusObject
 Inheritedname : String
A name to identify easily an objet.
CitrusObject
 InheritedoffsetX : Number
offsetX allows to move graphics on x axis compared to their initial point.
APhysicsObject
 InheritedoffsetY : Number
offsetY allows to move graphics on y axis compared to their initial point.
APhysicsObject
 InheritedparallaxX : Number
APhysicsObject
 InheritedparallaxY : Number
APhysicsObject
  points : Array
Used to define vertices' x and y points.
Box2DPhysicsObject
  postContactCallEnabled : Boolean
This flag determines if the handlePostSolve method is called or not.
Box2DPhysicsObject
  preContactCallEnabled : Boolean
This flag determines if the handlePreSolve method is called or not.
Box2DPhysicsObject
  radius : Number
This can only be set in the constructor parameters.
Box2DPhysicsObject
 Inheritedregistration : String
Flash registration point is topLeft, whereas physics engine use mostly center.
APhysicsObject
  rotation : Number
Box2DPhysicsObject
 Inheritedtouchable : Boolean
APhysicsObject
 Inheritedtype : String = classicObject
Added to the CE's render list via the State and the add method.
CitrusObject
 InheritedupdateCallEnabled : Boolean = false
This property prevent the update method to be called by the enter frame, it will save performances.
CitrusObject
  velocity : Array
Box2DPhysicsObject
 Inheritedview : *
The view can be a class, a string to a file, or a display object.
APhysicsObject
 Inheritedvisible : Boolean
You can easily change if an object is visible or not.
APhysicsObject
  width : Number
This can only be set in the constructor parameters.
Box2DPhysicsObject
  x : Number
Box2DPhysicsObject
  y : Number
Box2DPhysicsObject
  z : Number
[read-only]
Box2DPhysicsObject
Protected Properties
 PropertyDefined By
 Inherited_animation : String
APhysicsObject
 Inherited_art : ICitrusArt
APhysicsObject
  _beginContactCallEnabled : Boolean = false
Box2DPhysicsObject
  _body : b2Body
Box2DPhysicsObject
  _bodyDef : b2BodyDef
Box2DPhysicsObject
  _box2D : Box2D
Box2DPhysicsObject
 Inherited_ce : CitrusEngine
CitrusObject
  _endContactCallEnabled : Boolean = false
Box2DPhysicsObject
  _fixture : b2Fixture
Box2DPhysicsObject
  _fixtureDef : b2FixtureDef
Box2DPhysicsObject
  _height : Number = 1
Box2DPhysicsObject
 Inherited_initialized : Boolean = false
CitrusObject
 Inherited_inverted : Boolean = false
APhysicsObject
 Inherited_parallaxX : Number = 1
APhysicsObject
 Inherited_parallaxY : Number = 1
APhysicsObject
 Inherited_params : Object
CitrusObject
  _postContactCallEnabled : Boolean = false
Box2DPhysicsObject
  _preContactCallEnabled : Boolean = false
Box2DPhysicsObject
 Inherited_radius : Number = 0
APhysicsObject
 Inherited_rotation : Number = 0
APhysicsObject
  _shape : b2Shape
Box2DPhysicsObject
 Inherited_timeDelta : Number
The time elasped between two update call.
CitrusObject
 Inherited_touchable : Boolean = false
APhysicsObject
  _vertices : Array
Box2DPhysicsObject
 Inherited_view : *
APhysicsObject
 Inherited_visible : Boolean = true
APhysicsObject
  _width : Number = 1
Box2DPhysicsObject
 Inherited_x : Number = 0
APhysicsObject
 Inherited_y : Number = 0
APhysicsObject
 Inherited_z : Number = 0
APhysicsObject
Public Methods
 MethodDefined By
  
Box2DPhysicsObject(name:String, params:Object = null)
Creates an instance of a Box2DPhysicsObject.
Box2DPhysicsObject
  
addPhysics():void
[override] All your init physics code must be added in this method, no physics code into the constructor.
Box2DPhysicsObject
  
destroy():void
[override]
Box2DPhysicsObject
 Inherited
This method doesn't depend of your application enter frame.
APhysicsObject
  
[override]
Box2DPhysicsObject
 Inherited
called when the art changes.
APhysicsObject
 Inherited
handleArtReady(citrusArt:ICitrusArt):void
called when the art is created (and loaded if loading is required)
APhysicsObject
  
handleBeginContact(contact:b2Contact):void
Override this method to handle the begin contact collision.
Box2DPhysicsObject
  
handleEndContact(contact:b2Contact):void
Override this method to handle the end contact collision.
Box2DPhysicsObject
  
handlePostSolve(contact:b2Contact, impulse:b2ContactImpulse):void
Override this method if you want to perform some actions after the collision.
Box2DPhysicsObject
  
handlePreSolve(contact:b2Contact, oldManifold:b2Manifold):void
Override this method if you want to perform some actions before the collision (deactivate).
Box2DPhysicsObject
 Inherited
initialize(poolObjectParams:Object = null):void
Call in the constructor if the Object is added via the State and the add method.
CitrusObject
 Inherited
setParams(object:Object, params:Object):void
The initialize method usually calls this.
CitrusObject
 Inherited
toString():String
CitrusObject
 Inherited
update(timeDelta:Number):void
[override] You should override this method to extend the functionality of your physics object.
APhysicsObject
Protected Methods
 MethodDefined By
  
Box2DPhysicsObject
  
createBody():void
This method will often need to be overridden to customize the Box2D body object.
Box2DPhysicsObject
  
This method will often need to be overridden to customize the Box2D fixture object.
Box2DPhysicsObject
  
This method will often need to be overridden to customize the Box2D joint object.
Box2DPhysicsObject
  
This method will often need to be overridden to customize the Box2D shape object.
Box2DPhysicsObject
  
defineBody():void
This method will often need to be overridden to provide additional definition to the Box2D body object.
Box2DPhysicsObject
  
This method will often need to be overridden to provide additional definition to the Box2D fixture object.
Box2DPhysicsObject
  
This method will often need to be overridden to provide additional definition to the Box2D joint object.
Box2DPhysicsObject
Property Detail
_beginContactCallEnabledproperty
protected var _beginContactCallEnabled:Boolean = false

_bodyproperty 
protected var _body:b2Body

_bodyDefproperty 
protected var _bodyDef:b2BodyDef

_box2Dproperty 
protected var _box2D:Box2D

_endContactCallEnabledproperty 
protected var _endContactCallEnabled:Boolean = false

_fixtureproperty 
protected var _fixture:b2Fixture

_fixtureDefproperty 
protected var _fixtureDef:b2FixtureDef

_heightproperty 
protected var _height:Number = 1

_postContactCallEnabledproperty 
protected var _postContactCallEnabled:Boolean = false

_preContactCallEnabledproperty 
protected var _preContactCallEnabled:Boolean = false

_shapeproperty 
protected var _shape:b2Shape

_verticesproperty 
protected var _vertices:Array

_widthproperty 
protected var _width:Number = 1

beginContactCallEnabledproperty 
beginContactCallEnabled:Boolean

This flag determines if the handleBeginContact method is called or not. Default is false, it saves some performances.


Implementation
    public function get beginContactCallEnabled():Boolean
    public function set beginContactCallEnabled(value:Boolean):void
bodyproperty 
body:b2Body  [read-only]

A direct reference to the Box2D body associated with this object.


Implementation
    public function get body():b2Body
depthproperty 
depth:Number  [read-only]

No depth in a 2D Physics world.


Implementation
    public function get depth():Number
endContactCallEnabledproperty 
endContactCallEnabled:Boolean

This flag determines if the handleEndContact method is called or not. Default is false, it saves some performances.


Implementation
    public function get endContactCallEnabled():Boolean
    public function set endContactCallEnabled(value:Boolean):void
heightproperty 
height:Number

This can only be set in the constructor parameters.


Implementation
    public function get height():Number
    public function set height(value:Number):void
pointsproperty 
public var points:Array

Used to define vertices' x and y points.

postContactCallEnabledproperty 
postContactCallEnabled:Boolean

This flag determines if the handlePostSolve method is called or not. Default is false, it saves some performances.


Implementation
    public function get postContactCallEnabled():Boolean
    public function set postContactCallEnabled(value:Boolean):void
preContactCallEnabledproperty 
preContactCallEnabled:Boolean

This flag determines if the handlePreSolve method is called or not. Default is false, it saves some performances.


Implementation
    public function get preContactCallEnabled():Boolean
    public function set preContactCallEnabled(value:Boolean):void
radiusproperty 
radius:Number

This can only be set in the constructor parameters.


Implementation
    public function get radius():Number
    public function set radius(value:Number):void
rotationproperty 
rotation:Number


Implementation
    public function get rotation():Number
    public function set rotation(value:Number):void
velocityproperty 
velocity:Array


Implementation
    public function get velocity():Array
    public function set velocity(value:Array):void
widthproperty 
width:Number

This can only be set in the constructor parameters.


Implementation
    public function get width():Number
    public function set width(value:Number):void
xproperty 
x:Number


Implementation
    public function get x():Number
    public function set x(value:Number):void
yproperty 
y:Number


Implementation
    public function get y():Number
    public function set y(value:Number):void
zproperty 
z:Number  [read-only]


Implementation
    public function get z():Number
Constructor Detail
Box2DPhysicsObject()Constructor
public function Box2DPhysicsObject(name:String, params:Object = null)

Creates an instance of a Box2DPhysicsObject. Natively, this object does not default to any graphical representation, so you will need to set the "view" property in the params parameter.

Parameters
name:String
 
params:Object (default = null)
Method Detail
_createVerticesFromPoint()method
protected function _createVerticesFromPoint():void

addPhysics()method 
override public function addPhysics():void

All your init physics code must be added in this method, no physics code into the constructor. It's automatically called when the object is added to the state.

You'll notice that the Box2DPhysicsObject's initialize method calls a bunch of functions that start with "define" and "create". This is how the Box2D objects are created. You should override these methods in your own Box2DPhysicsObject implementation if you need additional Box2D functionality. Please see provided examples of classes that have overridden the Box2DPhysicsObject.

createBody()method 
protected function createBody():void

This method will often need to be overridden to customize the Box2D body object.

createFixture()method 
protected function createFixture():void

This method will often need to be overridden to customize the Box2D fixture object.

createJoint()method 
protected function createJoint():void

This method will often need to be overridden to customize the Box2D joint object. A joint is not automatically created, because joints require two bodies. Therefore, if you need to create a joint, you will also need to create additional bodies, fixtures and shapes, and then also instantiate a new b2JointDef and b2Joint object.

createShape()method 
protected function createShape():void

This method will often need to be overridden to customize the Box2D shape object. The PhysicsObject creates a rectangle by default if the radius it not defined, but you can replace this method's definition and instead create a custom shape, such as a line or circle.

defineBody()method 
protected function defineBody():void

This method will often need to be overridden to provide additional definition to the Box2D body object.

defineFixture()method 
protected function defineFixture():void

This method will often need to be overridden to provide additional definition to the Box2D fixture object.

defineJoint()method 
protected function defineJoint():void

This method will often need to be overridden to provide additional definition to the Box2D joint object. A joint is not automatically created, because joints require two bodies. Therefore, if you need to create a joint, you will also need to create additional bodies, fixtures and shapes, and then also instantiate a new b2JointDef and b2Joint object.

destroy()method 
override public function destroy():void

getBody()method 
override public function getBody():*

Returns
*
handleBeginContact()method 
public function handleBeginContact(contact:b2Contact):void

Override this method to handle the begin contact collision.

Parameters

contact:b2Contact

handleEndContact()method 
public function handleEndContact(contact:b2Contact):void

Override this method to handle the end contact collision.

Parameters

contact:b2Contact

handlePostSolve()method 
public function handlePostSolve(contact:b2Contact, impulse:b2ContactImpulse):void

Override this method if you want to perform some actions after the collision.

Parameters

contact:b2Contact
 
impulse:b2ContactImpulse

handlePreSolve()method 
public function handlePreSolve(contact:b2Contact, oldManifold:b2Manifold):void

Override this method if you want to perform some actions before the collision (deactivate).

Parameters

contact:b2Contact
 
oldManifold:b2Manifold