Packagenet.flashpunk
Classpublic class Entity
InheritanceEntity Inheritance Tweener Inheritance Object

Main game Entity class updated by World.



Public Properties
 PropertyDefined By
 Inheritedactive : Boolean = true
If this object should update.
Tweener
 InheritedautoClear : Boolean = false
If the Tweener should clear on removal.
Tweener
  bottom : Number
[read-only] The bottommost position of the Entity's hitbox.
Entity
  centerX : Number
[read-only] The center x position of the Entity's hitbox.
Entity
  centerY : Number
[read-only] The center y position of the Entity's hitbox.
Entity
  collidable : Boolean = true
If the Entity should respond to collision checks.
Entity
  graphic : Graphic
Graphical component to render to the screen.
Entity
  halfHeight : Number
[read-only] Half the Entity's height.
Entity
  halfWidth : Number
[read-only] Half the Entity's width.
Entity
  height : int
Height of the Entity's hitbox.
Entity
  layer : int
The rendering layer of this Entity.
Entity
  left : Number
[read-only] The leftmost position of the Entity's hitbox.
Entity
  mask : Mask
An optional Mask component, used for specialized collision.
Entity
  name : String
The Entity's instance name.
Entity
  onCamera : Boolean
[read-only] If the Entity collides with the camera rectangle.
Entity
  originX : int
X origin of the Entity's hitbox.
Entity
  originY : int
Y origin of the Entity's hitbox.
Entity
  renderTarget : BitmapData
The BitmapData target to draw the Entity to.
Entity
  right : Number
[read-only] The rightmost position of the Entity's hitbox.
Entity
  top : Number
[read-only] The topmost position of the Entity's hitbox.
Entity
  type : String
The collision type, used for collision checking.
Entity
  visible : Boolean = true
If the Entity should render.
Entity
  width : int
Width of the Entity's hitbox.
Entity
  world : World
[read-only] The World object this Entity has been added to.
Entity
  x : Number = 0
X position of the Entity in the World.
Entity
  y : Number = 0
Y position of the Entity in the World.
Entity
Public Methods
 MethodDefined By
  
Entity(x:Number = 0, y:Number = 0, graphic:Graphic = null, mask:Mask = null)
Constructor.
Entity
  
added():void
Override this, called when the Entity is added to a World.
Entity
  
Adds the graphic to the Entity via a Graphiclist.
Entity
 Inherited
addTween(t:Tween, start:Boolean = false):Tween
Adds a new Tween.
Tweener
  
Center's the Entity's origin (half width & height).
Entity
  
clampHorizontal(left:Number, right:Number, padding:Number = 0):void
Clamps the Entity's hitbox on the x-axis.
Entity
  
clampVertical(top:Number, bottom:Number, padding:Number = 0):void
Clamps the Entity's hitbox on the y axis.
Entity
 Inherited
Removes all Tweens.
Tweener
  
collide(type:String, x:Number, y:Number):Entity
Checks for a collision against an Entity type.
Entity
  
collideInto(type:String, x:Number, y:Number, array:Object):void
Populates an array with all collided Entities of a type.
Entity
  
collidePoint(x:Number, y:Number, pX:Number, pY:Number):Boolean
Checks if this Entity overlaps the specified position.
Entity
  
collideRect(x:Number, y:Number, rX:Number, rY:Number, rWidth:Number, rHeight:Number):Boolean
Checks if this Entity overlaps the specified rectangle.
Entity
  
collideTypes(types:Object, x:Number, y:Number):Entity
Checks for collision against multiple Entity types.
Entity
  
collideTypesInto(types:Object, x:Number, y:Number, array:Object):void
Populates an array with all collided Entities of multiple types.
Entity
  
collideWith(e:Entity, x:Number, y:Number):Entity
Checks if this Entity collides with a specific Entity.
Entity
  
distanceFrom(e:Entity, useHitboxes:Boolean = false):Number
Calculates the distance from another Entity.
Entity
  
distanceToPoint(px:Number, py:Number, useHitbox:Boolean = false):Number
Calculates the distance from this Entity to the point.
Entity
  
distanceToRect(rx:Number, ry:Number, rwidth:Number, rheight:Number):Number
Calculates the distance from this Entity to the rectangle.
Entity
  
getClass():Class
Entity
  
moveBy(x:Number, y:Number, solidType:Object = null, sweep:Boolean = false):void
Moves the Entity by the amount, retaining integer values for its x and y.
Entity
  
moveCollideX(e:Entity):Boolean
When you collide with an Entity on the x-axis with moveTo() or moveBy().
Entity
  
moveCollideY(e:Entity):Boolean
When you collide with an Entity on the y-axis with moveTo() or moveBy().
Entity
  
moveTo(x:Number, y:Number, solidType:Object = null, sweep:Boolean = false):void
Moves the Entity to the position, retaining integer values for its x and y.
Entity
  
moveTowards(x:Number, y:Number, amount:Number, solidType:Object = null, sweep:Boolean = false):void
Moves towards the target position, retaining integer values for its x and y.
Entity
  
removed():void
Override this, called when the Entity is removed from a World.
Entity
 Inherited
Removes a Tween.
Tweener
  
render():void
Renders the Entity.
Entity
  
setHitbox(width:int = 0, height:int = 0, originX:int = 0, originY:int = 0):void
Sets the Entity's hitbox properties.
Entity
  
setHitboxTo(o:Object):void
Sets the Entity's hitbox to match that of the provided object.
Entity
  
setOrigin(x:int = 0, y:int = 0):void
Sets the origin of the Entity.
Entity
  
toString():String
Gets the class name as a string.
Entity
  
update():void
[override] Updates the Entity.
Entity
 Inherited
Updates all contained tweens.
Tweener
Public Constants
 ConstantDefined By
 InheritedLOOPING : uint = 1
Looping Tween type, will restart immediately when it finishes.
Tweener
 InheritedONESHOT : uint = 2
Oneshot Tween type, will stop and remove itself from its core container when it finishes.
Tweener
 InheritedPERSIST : uint = 0
Persistent Tween type, will stop when it finishes.
Tweener
Property Detail
bottomproperty
bottom:Number  [read-only]

The bottommost position of the Entity's hitbox.


Implementation
    public function get bottom():Number
centerXproperty 
centerX:Number  [read-only]

The center x position of the Entity's hitbox.


Implementation
    public function get centerX():Number
centerYproperty 
centerY:Number  [read-only]

The center y position of the Entity's hitbox.


Implementation
    public function get centerY():Number
collidableproperty 
public var collidable:Boolean = true

If the Entity should respond to collision checks.

graphicproperty 
graphic:Graphic

Graphical component to render to the screen.


Implementation
    public function get graphic():Graphic
    public function set graphic(value:Graphic):void
halfHeightproperty 
halfHeight:Number  [read-only]

Half the Entity's height.


Implementation
    public function get halfHeight():Number
halfWidthproperty 
halfWidth:Number  [read-only]

Half the Entity's width.


Implementation
    public function get halfWidth():Number
heightproperty 
public var height:int

Height of the Entity's hitbox.

layerproperty 
layer:int

The rendering layer of this Entity. Higher layers are rendered first.


Implementation
    public function get layer():int
    public function set layer(value:int):void
leftproperty 
left:Number  [read-only]

The leftmost position of the Entity's hitbox.


Implementation
    public function get left():Number
maskproperty 
mask:Mask

An optional Mask component, used for specialized collision. If this is not assigned, collision checks will use the Entity's hitbox by default.


Implementation
    public function get mask():Mask
    public function set mask(value:Mask):void
nameproperty 
name:String

The Entity's instance name. Use this to uniquely identify single game Entities, which can then be looked-up with World.getInstance().


Implementation
    public function get name():String
    public function set name(value:String):void
onCameraproperty 
onCamera:Boolean  [read-only]

If the Entity collides with the camera rectangle.


Implementation
    public function get onCamera():Boolean
originXproperty 
public var originX:int

X origin of the Entity's hitbox.

originYproperty 
public var originY:int

Y origin of the Entity's hitbox.

renderTargetproperty 
public var renderTarget:BitmapData

The BitmapData target to draw the Entity to. Leave as null to render to the current screen buffer (default).

rightproperty 
right:Number  [read-only]

The rightmost position of the Entity's hitbox.


Implementation
    public function get right():Number
topproperty 
top:Number  [read-only]

The topmost position of the Entity's hitbox.


Implementation
    public function get top():Number
typeproperty 
type:String

The collision type, used for collision checking.


Implementation
    public function get type():String
    public function set type(value:String):void
visibleproperty 
public var visible:Boolean = true

If the Entity should render.

widthproperty 
public var width:int

Width of the Entity's hitbox.

worldproperty 
world:World  [read-only]

The World object this Entity has been added to.


Implementation
    public function get world():World
xproperty 
public var x:Number = 0

X position of the Entity in the World.

yproperty 
public var y:Number = 0

Y position of the Entity in the World.

Constructor Detail
Entity()Constructor
public function Entity(x:Number = 0, y:Number = 0, graphic:Graphic = null, mask:Mask = null)

Constructor. Can be usd to place the Entity and assign a graphic and mask.

Parameters
x:Number (default = 0) — X position to place the Entity.
 
y:Number (default = 0) — Y position to place the Entity.
 
graphic:Graphic (default = null) — Graphic to assign to the Entity.
 
mask:Mask (default = null) — Mask to assign to the Entity.
Method Detail
added()method
public function added():void

Override this, called when the Entity is added to a World.

addGraphic()method 
public function addGraphic(g:Graphic):Graphic

Adds the graphic to the Entity via a Graphiclist.

Parameters

g:Graphic — Graphic to add.

Returns
Graphic
centerOrigin()method 
public function centerOrigin():void

Center's the Entity's origin (half width & height).

clampHorizontal()method 
public function clampHorizontal(left:Number, right:Number, padding:Number = 0):void

Clamps the Entity's hitbox on the x-axis.

Parameters

left:Number — Left bounds.
 
right:Number — Right bounds.
 
padding:Number (default = 0) — Optional padding on the clamp.

clampVertical()method 
public function clampVertical(top:Number, bottom:Number, padding:Number = 0):void

Clamps the Entity's hitbox on the y axis.

Parameters

top:Number — Min bounds.
 
bottom:Number — Max bounds.
 
padding:Number (default = 0) — Optional padding on the clamp.

collide()method 
public function collide(type:String, x:Number, y:Number):Entity

Checks for a collision against an Entity type.

Parameters

type:String — The Entity type to check for.
 
x:Number — Virtual x position to place this Entity.
 
y:Number — Virtual y position to place this Entity.

Returns
Entity — The first Entity collided with, or null if none were collided.
collideInto()method 
public function collideInto(type:String, x:Number, y:Number, array:Object):void

Populates an array with all collided Entities of a type.

Parameters

type:String — The Entity type to check for.
 
x:Number — Virtual x position to place this Entity.
 
y:Number — Virtual y position to place this Entity.
 
array:Object — The Array or Vector object to populate.

collidePoint()method 
public function collidePoint(x:Number, y:Number, pX:Number, pY:Number):Boolean

Checks if this Entity overlaps the specified position.

Parameters

x:Number — Virtual x position to place this Entity.
 
y:Number — Virtual y position to place this Entity.
 
pX:Number — X position.
 
pY:Number — Y position.

Returns
Boolean — If the Entity intersects with the position.
collideRect()method 
public function collideRect(x:Number, y:Number, rX:Number, rY:Number, rWidth:Number, rHeight:Number):Boolean

Checks if this Entity overlaps the specified rectangle.

Parameters

x:Number — Virtual x position to place this Entity.
 
y:Number — Virtual y position to place this Entity.
 
rX:Number — X position of the rectangle.
 
rY:Number — Y position of the rectangle.
 
rWidth:Number — Width of the rectangle.
 
rHeight:Number — Height of the rectangle.

Returns
Boolean — If they overlap.
collideTypes()method 
public function collideTypes(types:Object, x:Number, y:Number):Entity

Checks for collision against multiple Entity types.

Parameters

types:Object — An Array or Vector of Entity types to check for.
 
x:Number — Virtual x position to place this Entity.
 
y:Number — Virtual y position to place this Entity.

Returns
Entity — The first Entity collided with, or null if none were collided.
collideTypesInto()method 
public function collideTypesInto(types:Object, x:Number, y:Number, array:Object):void

Populates an array with all collided Entities of multiple types.

Parameters

types:Object — An array of Entity types to check for.
 
x:Number — Virtual x position to place this Entity.
 
y:Number — Virtual y position to place this Entity.
 
array:Object — The Array or Vector object to populate.

collideWith()method 
public function collideWith(e:Entity, x:Number, y:Number):Entity

Checks if this Entity collides with a specific Entity.

Parameters

e:Entity — The Entity to collide against.
 
x:Number — Virtual x position to place this Entity.
 
y:Number — Virtual y position to place this Entity.

Returns
Entity — The Entity if they overlap, or null if they don't.
distanceFrom()method 
public function distanceFrom(e:Entity, useHitboxes:Boolean = false):Number

Calculates the distance from another Entity.

Parameters

e:Entity — The other Entity.
 
useHitboxes:Boolean (default = false) — If hitboxes should be used to determine the distance. If not, the Entities' x/y positions are used.

Returns
Number — The distance.
distanceToPoint()method 
public function distanceToPoint(px:Number, py:Number, useHitbox:Boolean = false):Number

Calculates the distance from this Entity to the point.

Parameters

px:Number — X position.
 
py:Number — Y position.
 
useHitbox:Boolean (default = false) — If hitboxes should be used to determine the distance. If not, the Entities' x/y positions are used.

Returns
Number — The distance.
distanceToRect()method 
public function distanceToRect(rx:Number, ry:Number, rwidth:Number, rheight:Number):Number

Calculates the distance from this Entity to the rectangle.

Parameters

rx:Number — X position of the rectangle.
 
ry:Number — Y position of the rectangle.
 
rwidth:Number — Width of the rectangle.
 
rheight:Number — Height of the rectangle.

Returns
Number — The distance.
getClass()method 
public function getClass():Class

Returns
Class
moveBy()method 
public function moveBy(x:Number, y:Number, solidType:Object = null, sweep:Boolean = false):void

Moves the Entity by the amount, retaining integer values for its x and y.

Parameters

x:Number — Horizontal offset.
 
y:Number — Vertical offset.
 
solidType:Object (default = null) — An optional collision type (or array of types) to stop flush against upon collision.
 
sweep:Boolean (default = false) — If sweeping should be used (prevents fast-moving objects from going through solidType).

moveCollideX()method 
public function moveCollideX(e:Entity):Boolean

When you collide with an Entity on the x-axis with moveTo() or moveBy().

Parameters

e:Entity — The Entity you collided with.

Returns
Boolean
moveCollideY()method 
public function moveCollideY(e:Entity):Boolean

When you collide with an Entity on the y-axis with moveTo() or moveBy().

Parameters

e:Entity — The Entity you collided with.

Returns
Boolean
moveTo()method 
public function moveTo(x:Number, y:Number, solidType:Object = null, sweep:Boolean = false):void

Moves the Entity to the position, retaining integer values for its x and y.

Parameters

x:Number — X position.
 
y:Number — Y position.
 
solidType:Object (default = null) — An optional collision type (or array of types) to stop flush against upon collision.
 
sweep:Boolean (default = false) — If sweeping should be used (prevents fast-moving objects from going through solidType).

moveTowards()method 
public function moveTowards(x:Number, y:Number, amount:Number, solidType:Object = null, sweep:Boolean = false):void

Moves towards the target position, retaining integer values for its x and y.

Parameters

x:Number — X target.
 
y:Number — Y target.
 
amount:Number — Amount to move.
 
solidType:Object (default = null) — An optional collision type (or array of types) to stop flush against upon collision.
 
sweep:Boolean (default = false) — If sweeping should be used (prevents fast-moving objects from going through solidType).

removed()method 
public function removed():void

Override this, called when the Entity is removed from a World.

render()method 
public function render():void

Renders the Entity. If you override this for special behaviour, remember to call super.render() to render the Entity's graphic.

setHitbox()method 
public function setHitbox(width:int = 0, height:int = 0, originX:int = 0, originY:int = 0):void

Sets the Entity's hitbox properties.

Parameters

width:int (default = 0) — Width of the hitbox.
 
height:int (default = 0) — Height of the hitbox.
 
originX:int (default = 0) — X origin of the hitbox.
 
originY:int (default = 0) — Y origin of the hitbox.

setHitboxTo()method 
public function setHitboxTo(o:Object):void

Sets the Entity's hitbox to match that of the provided object.

Parameters

o:Object — The object defining the hitbox (eg. an Image or Rectangle).

setOrigin()method 
public function setOrigin(x:int = 0, y:int = 0):void

Sets the origin of the Entity.

Parameters

x:int (default = 0) — X origin.
 
y:int (default = 0) — Y origin.

toString()method 
public function toString():String

Gets the class name as a string.

Returns
String — A string representing the class name.
update()method 
override public function update():void

Updates the Entity.