Packagecitrus.objects.platformer.box2d
Classpublic class Enemy
InheritanceEnemy Inheritance Box2DPhysicsObject Inheritance APhysicsObject Inheritance CitrusObject Inheritance Object

This is a common example of a side-scrolling bad guy. He has limited logic, basically only turning around when he hits a wall. When controlling collision interactions between two objects, such as a Hero and Enemy, I like to let each object perform its own actions, not control one object's action from the other object. For example, the Hero doesn't contain the logic for killing the Enemy, and the Enemy doesn't contain the logic for making the hero "Spring" when he kills him.



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
 InheritedbeginContactCallEnabled : Boolean
This flag determines if the handleBeginContact method is called or not.
Box2DPhysicsObject
 Inheritedbody : b2Body
[read-only] A direct reference to the Box2D body associated with this object.
Box2DPhysicsObject
 Inheriteddepth : Number
[read-only] No depth in a 2D Physics world.
Box2DPhysicsObject
 InheritedendContactCallEnabled : Boolean
This flag determines if the handleEndContact method is called or not.
Box2DPhysicsObject
  enemyClass : *
Enemy
  enemyKillVelocity : Number = 3
Enemy
 Inheritedgroup : uint
The group is similar to a z-index sorting.
APhysicsObject
 Inheritedheight : Number
This can only be set in the constructor parameters.
Box2DPhysicsObject
 InheritedhideParamWarnings : Boolean = false
[static]
CitrusObject
  hurtDuration : Number = 400
Enemy
 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
  leftBound : Number = -100000
Enemy
 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
 Inheritedpoints : Array
Used to define vertices' x and y points.
Box2DPhysicsObject
 InheritedpostContactCallEnabled : Boolean
This flag determines if the handlePostSolve method is called or not.
Box2DPhysicsObject
 InheritedpreContactCallEnabled : Boolean
This flag determines if the handlePreSolve method is called or not.
Box2DPhysicsObject
 Inheritedradius : 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
  rightBound : Number = 100000
Enemy
 Inheritedrotation : Number
Box2DPhysicsObject
  speed : Number = 1.3
Enemy
  startingDirection : String = left
Enemy
 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
 Inheritedvelocity : 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
  wallSensorHeight : Number = 2
Enemy
  wallSensorOffset : Number = 10
Enemy
  wallSensorWidth : Number = 2
Enemy
 Inheritedwidth : Number
This can only be set in the constructor parameters.
Box2DPhysicsObject
 Inheritedx : Number
Box2DPhysicsObject
 Inheritedy : Number
Box2DPhysicsObject
 Inheritedz : Number
[read-only]
Box2DPhysicsObject
Protected Properties
 PropertyDefined By
 Inherited_animation : String
APhysicsObject
 Inherited_art : ICitrusArt
APhysicsObject
 Inherited_beginContactCallEnabled : Boolean = false
Box2DPhysicsObject
 Inherited_body : b2Body
Box2DPhysicsObject
 Inherited_bodyDef : b2BodyDef
Box2DPhysicsObject
 Inherited_box2D : Box2D
Box2DPhysicsObject
 Inherited_ce : CitrusEngine
CitrusObject
 Inherited_endContactCallEnabled : Boolean = false
Box2DPhysicsObject
  _enemyClass : *
Enemy
 Inherited_fixture : b2Fixture
Box2DPhysicsObject
 Inherited_fixtureDef : b2FixtureDef
Box2DPhysicsObject
 Inherited_height : Number = 1
Box2DPhysicsObject
  _hurt : Boolean = false
Enemy
  _hurtTimeoutID : uint = 0
Enemy
 Inherited_initialized : Boolean = false
CitrusObject
 Inherited_inverted : Boolean = false
APhysicsObject
  _leftSensorFixture : b2Fixture
Enemy
  _leftSensorShape : b2PolygonShape
Enemy
 Inherited_parallaxX : Number = 1
APhysicsObject
 Inherited_parallaxY : Number = 1
APhysicsObject
 Inherited_params : Object
CitrusObject
 Inherited_postContactCallEnabled : Boolean = false
Box2DPhysicsObject
 Inherited_preContactCallEnabled : Boolean = false
Box2DPhysicsObject
 Inherited_radius : Number = 0
APhysicsObject
  _rightSensorFixture : b2Fixture
Enemy
  _rightSensorShape : b2PolygonShape
Enemy
 Inherited_rotation : Number = 0
APhysicsObject
  _sensorFixtureDef : b2FixtureDef
Enemy
 Inherited_shape : b2Shape
Box2DPhysicsObject
 Inherited_timeDelta : Number
The time elasped between two update call.
CitrusObject
 Inherited_touchable : Boolean = false
APhysicsObject
 Inherited_vertices : Array
Box2DPhysicsObject
 Inherited_view : *
APhysicsObject
 Inherited_visible : Boolean = true
APhysicsObject
 Inherited_width : Number = 1
Box2DPhysicsObject
 Inherited_x : Number = 0
APhysicsObject
 Inherited_y : Number = 0
APhysicsObject
 Inherited_z : Number = 0
APhysicsObject
Public Methods
 MethodDefined By
  
Enemy(name:String, params:Object = null)
Enemy
 Inherited
addPhysics():void
[override] All your init physics code must be added in this method, no physics code into the constructor.
Box2DPhysicsObject
  
destroy():void
[override]
Enemy
 Inherited
This method doesn't depend of your application enter frame.
APhysicsObject
 Inherited
[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]
Enemy
 Inherited
handleEndContact(contact:b2Contact):void
Override this method to handle the end contact collision.
Box2DPhysicsObject
 Inherited
handlePostSolve(contact:b2Contact, impulse:b2ContactImpulse):void
Override this method if you want to perform some actions after the collision.
Box2DPhysicsObject
 Inherited
handlePreSolve(contact:b2Contact, oldManifold:b2Manifold):void
Override this method if you want to perform some actions before the collision (deactivate).
Box2DPhysicsObject
  
hurt():void
The enemy is hurt, start the time out with hurtDuration value.
Enemy
 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
  
turnAround():void
Change enemy's direction
Enemy
  
update(timeDelta:Number):void
[override]
Enemy
Protected Methods
 MethodDefined By
 Inherited
Box2DPhysicsObject
  
createBody():void
[override]
Enemy
  
[override]
Enemy
 Inherited
This method will often need to be overridden to customize the Box2D joint object.
Box2DPhysicsObject
  
[override]
Enemy
 Inherited
defineBody():void
This method will often need to be overridden to provide additional definition to the Box2D body object.
Box2DPhysicsObject
  
[override]
Enemy
 Inherited
This method will often need to be overridden to provide additional definition to the Box2D joint object.
Box2DPhysicsObject
  
The enemy is no more hurt, but it is killed.
Enemy
  
Enemy
Property Detail
_enemyClassproperty
protected var _enemyClass:*

_hurtproperty 
protected var _hurt:Boolean = false

_hurtTimeoutIDproperty 
protected var _hurtTimeoutID:uint = 0

_leftSensorFixtureproperty 
protected var _leftSensorFixture:b2Fixture

_leftSensorShapeproperty 
protected var _leftSensorShape:b2PolygonShape

_rightSensorFixtureproperty 
protected var _rightSensorFixture:b2Fixture

_rightSensorShapeproperty 
protected var _rightSensorShape:b2PolygonShape

_sensorFixtureDefproperty 
protected var _sensorFixtureDef:b2FixtureDef

enemyClassproperty 
enemyClass:*


Implementation
    public function get enemyClass():*
    public function set enemyClass(value:any):void
enemyKillVelocityproperty 
public var enemyKillVelocity:Number = 3

hurtDurationproperty 
public var hurtDuration:Number = 400

leftBoundproperty 
public var leftBound:Number = -100000

rightBoundproperty 
public var rightBound:Number = 100000

speedproperty 
public var speed:Number = 1.3

startingDirectionproperty 
public var startingDirection:String = left

wallSensorHeightproperty 
public var wallSensorHeight:Number = 2

wallSensorOffsetproperty 
public var wallSensorOffset:Number = 10

wallSensorWidthproperty 
public var wallSensorWidth:Number = 2

Constructor Detail
Enemy()Constructor
public function Enemy(name:String, params:Object = null)



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

createFixture()method 
override protected function createFixture():void

createShape()method 
override protected function createShape():void

defineFixture()method 
override protected function defineFixture():void

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

endHurtState()method 
protected function endHurtState():void

The enemy is no more hurt, but it is killed. Override this function to prevent enemy's death.

handleBeginContact()method 
override public function handleBeginContact(contact:b2Contact):void

Parameters

contact:b2Contact

hurt()method 
public function hurt():void

The enemy is hurt, start the time out with hurtDuration value. Then it called endHurtState's function.

turnAround()method 
public function turnAround():void

Change enemy's direction

update()method 
override public function update(timeDelta:Number):void

Parameters

timeDelta:Number

updateAnimation()method 
protected function updateAnimation():void