Packageorg.flixel
Classpublic class FlxObject
InheritanceFlxObject Inheritance FlxRect Inheritance FlxPoint Inheritance Object
Subclasses FlxGroup, FlxPanel, FlxSound, FlxSprite, TileLayer

This is the base class for most of the display objects It includes some basic attributes about game objects, including retro-style flickering, basic state information, sizes, scrolling, and basic physics and 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
[read-only] 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
If an object is 'fixed' in space, it will not budge when it collides with a not-fixed object.
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
[read-only] 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
[read-only] 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
If an object is dead, the functions that automate collisions will skip it (see FlxG.overlapArrays() and FlxG.collideArrays()).
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
[read-only] 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
  _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
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
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
  
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
  
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
  
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
  
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
_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.

_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

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 
public var fixed:Boolean

If an object is 'fixed' in space, it will not budge when it collides with a not-fixed object. Fixed objects also shortcut out of updateMotion by default.

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.

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 
public var solid:Boolean

If an object is dead, the functions that automate collisions will skip it (see FlxG.overlapArrays() and FlxG.collideArrays()).

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

Parameters

Object:FlxObject (default = null)

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.
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.

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.

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