Packageorg.flixel
Classpublic class FlxObject
InheritanceFlxObject Inheritance FlxRect Inheritance FlxPoint
SubclassesFlxGroup, FlxPanel, FlxSound, FlxSprite, FlxTilemap

This is the base class for most of the display objects (FlxSprite, FlxText, etc). It includes some basic attributes about game objects, including retro-style flickering, basic state information, sizes, scrolling, and basic physics & motion.



Public Properties
 PropertyDefined by
  acceleration : FlxPoint
How fast the speed of this object is changing.
FlxObject
  active : Boolean
If an object is not alive, the game loop will not automatically call update() on it.
FlxObject
  angle : Number
Set the angle of a sprite to rotate it.
FlxObject
  angularAcceleration : Number
How fast the spin speed should change.
FlxObject
  angularDrag : Number
Like drag but for spinning.
FlxObject
  angularVelocity : Number
This is how fast you want this sprite to spin.
FlxObject
 Inheritedbottom : Number
The Y coordinate of the bottom of the rectangle.
FlxRect
  colHullX : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
  colHullY : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
  collideBottom : Boolean
Flag for direction collision resolution.
FlxObject
  collideLeft : Boolean
Flag for direction collision resolution.
FlxObject
  collideRight : Boolean
Flag for direction collision resolution.
FlxObject
  collideTop : Boolean
Flag for direction collision resolution.
FlxObject
  colOffsets : Array
An array of FlxPoint objects.
FlxObject
  colVector : FlxPoint
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
  dead : Boolean
Handy for tracking gameplay or animations.
FlxObject
  drag : FlxPoint
This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.
FlxObject
  exists : Boolean
Kind of a global on/off switch for any objects descended from FlxObject.
FlxObject
  fixed : Boolean
Set fixed to true if you want the object to stay in place during collisions.
FlxObject
  _group : Boolean
Dedicated internal flag for whether or not this class is a FlxGroup.
FlxObject
  health : Number
Handy for storing health percentage or armor points or whatever.
FlxObject
 Inheritedheight : Number
FlxRect
 Inheritedleft : Number
The X coordinate of the left side of the rectangle.
FlxRect
  maxAngular : Number
Use in conjunction with angularAcceleration for fluid spin speed control.
FlxObject
  maxThrust : Number
Used to cap thrust, helpful and easy!
FlxObject
  maxVelocity : FlxPoint
If you are using acceleration, you can use maxVelocity with it to cap the speed automatically (very useful!).
FlxObject
  moves : Boolean
Set this to false if you want to skip the automatic motion/movement stuff (see updateMotion()).
FlxObject
  onFloor : Boolean
Flag that indicates whether or not you just hit the floor.
FlxObject
  origin : FlxPoint
WARNING: The origin of the sprite will default to its center.
FlxObject
 Inheritedright : Number
The X coordinate of the right side of the rectangle.
FlxRect
  scrollFactor : FlxPoint
A point that can store numbers from 0 to 1 (for X and Y independently) that governs how much this object is affected by the camera subsystem.
FlxObject
  solid : Boolean
Set solid to true if you want to collide this object.
FlxObject
  thrust : Number
If you want to do Asteroids style stuff, check out thrust, instead of directly accessing the object's velocity or acceleration.
FlxObject
 Inheritedtop : Number
The Y coordinate of the top of the rectangle.
FlxRect
  velocity : FlxPoint
The basic speed of this object.
FlxObject
  visible : Boolean
If an object is not visible, the game loop will not automatically call render() on it.
FlxObject
 Inheritedwidth : Number
FlxRect
 Inheritedx : Number
FlxPoint
 Inheritedy : Number
FlxPoint
Protected Properties
 PropertyDefined by
  _fixed : Boolean
Internal tracker for whether an object will move/alter position after a collision (see fixed).
FlxObject
  _flashPoint : Point
This is a pre-allocated Flash Point object, which is useful for certain Flash graphics API calls
FlxObject
  _flicker : Boolean
Internal helper used for retro-style flickering.
FlxObject
  _flickerTimer : Number
Internal helper used for retro-style flickering.
FlxObject
  _point : FlxPoint
This is just a pre-allocated x-y point container to be used however you like
FlxObject
  _rect : FlxRect
This is just a pre-allocated rectangle container to be used however you like
FlxObject
  _solid : Boolean
Internal tracker for whether or not the object collides (see solid).
FlxObject
Public Methods
 MethodDefined by
  
FlxObject(X:Number = 0, Y:Number = 0, Width:Number = 0, Height:Number = 0)
Creates a new FlxObject.
FlxObject
  
collide(Object:FlxObject = null):Boolean
If you don't want to call FlxU.collide() you can use this instead.
FlxObject
  
destroy():void
Called by FlxGroup, commonly when game states are changed.
FlxObject
  
flicker(Duration:Number = 1):void
Tells this object to flicker, retro-style.
FlxObject
  
flickering():Boolean
Check to see if the object is still flickering.
FlxObject
  
Returns the appropriate color for the bounding box depending on object state.
FlxObject
  
getScreenXY(Point:FlxPoint = null):FlxPoint
Call this function to figure out the on-screen position of the object.
FlxObject
  
hitBottom(Contact:FlxObject, Velocity:Number):void
Called when this object's bottom edge collides with the top of another FlxObject.
FlxObject
  
hitLeft(Contact:FlxObject, Velocity:Number):void
Called when this object's left side collides with another FlxObject's right.
FlxObject
  
hitRight(Contact:FlxObject, Velocity:Number):void
Called when this object's right side collides with another FlxObject's left.
FlxObject
  
hitSide(Contact:FlxObject, Velocity:Number):void
Since most games have identical behavior for running into walls, you can just override this function instead of overriding both hitLeft and hitRight.
FlxObject
  
hitTop(Contact:FlxObject, Velocity:Number):void
Called when this object's top collides with the bottom of another FlxObject.
FlxObject
  
hurt(Damage:Number):void
Call this function to "damage" (or give health bonus) to this sprite.
FlxObject
  
kill():void
Call this function to "kill" a sprite so that it no longer 'exists'.
FlxObject
  
onScreen():Boolean
Check and see if this object is currently on screen.
FlxObject
  
overlaps(Object:FlxObject):Boolean
Checks to see if some FlxObject object overlaps this FlxObject object.
FlxObject
  
overlapsPoint(X:Number, Y:Number, PerPixel:Boolean = false):Boolean
Checks to see if a point in 2D space overlaps this FlxObject object.
FlxObject
  
preCollide(Object:FlxObject):void
FlxU.collide() (and thus FlxObject.collide()) call this function each time two objects are compared to see if they collide.
FlxObject
  
refreshHulls():void
Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.
FlxObject
  
render():void
Override this function to draw graphics (see FlxSprite).
FlxObject
  
reset(X:Number, Y:Number):void
Handy function for reviving game objects.
FlxObject
 Inherited
toString():String
Convert object to readable string name.
FlxPoint
  
update():void
Called by the main game loop, handles motion/physics and game logic
FlxObject
Protected Methods
 MethodDefined by
  
Just updates the retro-style flickering.
FlxObject
  
updateMotion():void
Internal function for updating the position and speed of this object.
FlxObject
Protected Constants
 ConstantDefined by
  _pZero : FlxPoint
[static] A handy "empty point" object
FlxObject
Property detail
accelerationproperty
public var acceleration:FlxPoint

How fast the speed of this object is changing. Useful for smooth movement and gravity.

activeproperty 
public var active:Boolean

If an object is not alive, the game loop will not automatically call update() on it.

angleproperty 
public var angle:Number

Set the angle of a sprite to rotate it. WARNING: rotating sprites decreases rendering performance for this sprite by a factor of 10x!

angularAccelerationproperty 
public var angularAcceleration:Number

How fast the spin speed should change.

angularDragproperty 
public var angularDrag:Number

Like drag but for spinning.

angularVelocityproperty 
public var angularVelocity:Number

This is how fast you want this sprite to spin.

colHullXproperty 
public var colHullX:FlxRect

These store a couple of useful numbers for speeding up collision resolution.

colHullYproperty 
public var colHullY:FlxRect

These store a couple of useful numbers for speeding up collision resolution.

collideBottomproperty 
public var collideBottom:Boolean

Flag for direction collision resolution.

collideLeftproperty 
public var collideLeft:Boolean

Flag for direction collision resolution.

collideRightproperty 
public var collideRight:Boolean

Flag for direction collision resolution.

collideTopproperty 
public var collideTop:Boolean

Flag for direction collision resolution.

colOffsetsproperty 
public var colOffsets:Array

An array of FlxPoint objects. By default contains a single offset (0,0).

colVectorproperty 
public var colVector:FlxPoint

These store a couple of useful numbers for speeding up collision resolution.

deadproperty 
public var dead:Boolean

Handy for tracking gameplay or animations.

dragproperty 
public var drag:FlxPoint

This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.

existsproperty 
public var exists:Boolean

Kind of a global on/off switch for any objects descended from FlxObject.

_fixedproperty 
protected var _fixed:Boolean

Internal tracker for whether an object will move/alter position after a collision (see fixed).

fixedproperty 
fixed:Boolean  [read-write]

Set fixed to true if you want the object to stay in place during collisions. Useful for levels and other environmental objects.

Implementation
    public function get fixed():Boolean
    public function set fixed(value:Boolean):void
_flashPointproperty 
protected var _flashPoint:Point

This is a pre-allocated Flash Point object, which is useful for certain Flash graphics API calls

_flickerproperty 
protected var _flicker:Boolean

Internal helper used for retro-style flickering.

_flickerTimerproperty 
protected var _flickerTimer:Number

Internal helper used for retro-style flickering.

_groupproperty 
public var _group:Boolean

Dedicated internal flag for whether or not this class is a FlxGroup.

healthproperty 
public var health:Number

Handy for storing health percentage or armor points or whatever.

maxAngularproperty 
public var maxAngular:Number

Use in conjunction with angularAcceleration for fluid spin speed control.

maxThrustproperty 
public var maxThrust:Number

Used to cap thrust, helpful and easy!

maxVelocityproperty 
public var maxVelocity:FlxPoint

If you are using acceleration, you can use maxVelocity with it to cap the speed automatically (very useful!).

movesproperty 
public var moves:Boolean

Set this to false if you want to skip the automatic motion/movement stuff (see updateMotion()). FlxObject and FlxSprite default to true. FlxText, FlxTileblock, FlxTilemap and FlxSound default to false.

onFloorproperty 
public var onFloor:Boolean

Flag that indicates whether or not you just hit the floor. Primarily useful for platformers, this flag is reset during the updateMotion().

originproperty 
public var origin:FlxPoint

WARNING: The origin of the sprite will default to its center. If you change this, the visuals and the collisions will likely be pretty out-of-sync if you do any rotation.

_pointproperty 
protected var _point:FlxPoint

This is just a pre-allocated x-y point container to be used however you like

_rectproperty 
protected var _rect:FlxRect

This is just a pre-allocated rectangle container to be used however you like

scrollFactorproperty 
public var scrollFactor:FlxPoint

A point that can store numbers from 0 to 1 (for X and Y independently) that governs how much this object is affected by the camera subsystem. 0 means it never moves, like a HUD element or far background graphic. 1 means it scrolls along a the same speed as the foreground layer. scrollFactor is initialized as (1,1) by default.

_solidproperty 
protected var _solid:Boolean

Internal tracker for whether or not the object collides (see solid).

solidproperty 
solid:Boolean  [read-write]

Set solid to true if you want to collide this object.

Implementation
    public function get solid():Boolean
    public function set solid(value:Boolean):void
thrustproperty 
public var thrust:Number

If you want to do Asteroids style stuff, check out thrust, instead of directly accessing the object's velocity or acceleration.

velocityproperty 
public var velocity:FlxPoint

The basic speed of this object.

visibleproperty 
public var visible:Boolean

If an object is not visible, the game loop will not automatically call render() on it.

Constructor detail
FlxObject()constructor
public function FlxObject(X:Number = 0, Y:Number = 0, Width:Number = 0, Height:Number = 0)

Creates a new FlxObject.

Parameters
X:Number (default = 0) — The X-coordinate of the point in space.
 
Y:Number (default = 0) — The Y-coordinate of the point in space.
 
Width:Number (default = 0) — Desired width of the rectangle.
 
Height:Number (default = 0) — Desired height of the rectangle.
Method detail
collide()method
public function collide(Object:FlxObject = null):Boolean

If you don't want to call FlxU.collide() you can use this instead. Just calls FlxU.collide(this,Object);. Will collide against itself if Object==null.

Parameters
Object:FlxObject (default = null) — The you want to collide with.

Returns
Boolean
destroy()method 
public function destroy():void

Called by FlxGroup, commonly when game states are changed.

flicker()method 
public function flicker(Duration:Number = 1):void

Tells this object to flicker, retro-style.

Parameters
Duration:Number (default = 1) — How many seconds to flicker for.
flickering()method 
public function flickering():Boolean

Check to see if the object is still flickering.

Returns
Boolean — Whether the object is flickering or not.
getBoundingColor()method 
public function getBoundingColor():uint

Returns the appropriate color for the bounding box depending on object state.

Returns
uint
getScreenXY()method 
public function getScreenXY(Point:FlxPoint = null):FlxPoint

Call this function to figure out the on-screen position of the object.

Parameters
Point:FlxPoint (default = null) — Takes a Point object and assigns the post-scrolled X and Y values of this object to it.

Returns
FlxPoint — The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.
hitBottom()method 
public function hitBottom(Contact:FlxObject, Velocity:Number):void

Called when this object's bottom edge collides with the top of another FlxObject.

Parameters
Contact:FlxObject — The FlxObject you just ran into.
 
Velocity:Number — The suggested new velocity for this object.
hitLeft()method 
public function hitLeft(Contact:FlxObject, Velocity:Number):void

Called when this object's left side collides with another FlxObject's right. NOTE: by default this function just calls hitSide().

Parameters
Contact:FlxObject — The FlxObject you just ran into.
 
Velocity:Number — The suggested new velocity for this object.
hitRight()method 
public function hitRight(Contact:FlxObject, Velocity:Number):void

Called when this object's right side collides with another FlxObject's left. NOTE: by default this function just calls hitSide().

Parameters
Contact:FlxObject — The FlxObject you just ran into.
 
Velocity:Number — The suggested new velocity for this object.
hitSide()method 
public function hitSide(Contact:FlxObject, Velocity:Number):void

Since most games have identical behavior for running into walls, you can just override this function instead of overriding both hitLeft and hitRight.

Parameters
Contact:FlxObject — The FlxObject you just ran into.
 
Velocity:Number — The suggested new velocity for this object.
hitTop()method 
public function hitTop(Contact:FlxObject, Velocity:Number):void

Called when this object's top collides with the bottom of another FlxObject.

Parameters
Contact:FlxObject — The FlxObject you just ran into.
 
Velocity:Number — The suggested new velocity for this object.
hurt()method 
public function hurt(Damage:Number):void

Call this function to "damage" (or give health bonus) to this sprite.

Parameters
Damage:Number — How much health to take away (use a negative number to give a health bonus).
kill()method 
public function kill():void

Call this function to "kill" a sprite so that it no longer 'exists'.

onScreen()method 
public function onScreen():Boolean

Check and see if this object is currently on screen.

Returns
Boolean — Whether the object is on screen or not.
overlaps()method 
public function overlaps(Object:FlxObject):Boolean

Checks to see if some FlxObject object overlaps this FlxObject object.

Parameters
Object:FlxObject — The object being tested.

Returns
Boolean — Whether or not the two objects overlap.
overlapsPoint()method 
public function overlapsPoint(X:Number, Y:Number, PerPixel:Boolean = false):Boolean

Checks to see if a point in 2D space overlaps this FlxObject object.

Parameters
X:Number — The X coordinate of the point.
 
Y:Number — The Y coordinate of the point.
 
PerPixel:Boolean (default = false) — Whether or not to use per pixel collision checking (only available in FlxSprite subclass).

Returns
Boolean — Whether or not the point overlaps this object.
preCollide()method 
public function preCollide(Object:FlxObject):void

FlxU.collide() (and thus FlxObject.collide()) call this function each time two objects are compared to see if they collide. It doesn't necessarily mean these objects WILL collide, however.

Parameters
Object:FlxObject — The FlxObject you're about to run into.
refreshHulls()method 
public function refreshHulls():void

Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.

render()method 
public function render():void

Override this function to draw graphics (see FlxSprite).

reset()method 
public function reset(X:Number, Y:Number):void

Handy function for reviving game objects. Resets their existence flags and position, including LAST position.

Parameters
X:Number — The new X position of this object.
 
Y:Number — The new Y position of this object.
update()method 
public function update():void

Called by the main game loop, handles motion/physics and game logic

updateFlickering()method 
protected function updateFlickering():void

Just updates the retro-style flickering. Considered update logic rather than rendering because it toggles visibility.

updateMotion()method 
protected function updateMotion():void

Internal function for updating the position and speed of this object. Useful for cases when you need to update this but are buried down in too many supers.

Constant detail
_pZeroconstant
protected static const _pZero:FlxPoint

A handy "empty point" object