Packageorg.flixel
Classpublic class FlxSprite
InheritanceFlxSprite Inheritance FlxObject Inheritance FlxRect Inheritance FlxPoint Inheritance Object
Subclasses Actor, FlxFade, FlxFlash, FlxText, Label

The main "game object" class, handles basic physics and animation.



Public Properties
 PropertyDefined By
 Inheritedacceleration : FlxPoint
How fast the speed of this object is changing.
FlxObject
 Inheritedactive : Boolean
If an object is not alive, the game loop will not automatically call update() on it.
FlxObject
  alpha : Number
Set alpha to a number between 0 and 1 to change the opacity of the sprite.
FlxSprite
 Inheritedangle : Number
Set the angle of a sprite to rotate it.
FlxObject
 InheritedangularAcceleration : Number
How fast the spin speed should change.
FlxObject
 InheritedangularDrag : Number
Like drag but for spinning.
FlxObject
 InheritedangularVelocity : Number
This is how fast you want this sprite to spin.
FlxObject
  _animations : Array
FlxSprite
  antialiasing : Boolean
Controls whether the object is smoothed when rotated, affects performance.
FlxSprite
  blend : String
Blending modes, just like Photoshop! E.g.
FlxSprite
 Inheritedbottom : Number
[read-only] The Y coordinate of the bottom of the rectangle.
FlxRect
 InheritedcolHullX : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 InheritedcolHullY : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 InheritedcollideBottom : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideLeft : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideRight : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideTop : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcolOffsets : Array
An array of FlxPoint objects.
FlxObject
  color : uint
Set color to a number in this format: 0xRRGGBB.
FlxSprite
 InheritedcolVector : FlxPoint
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 Inheriteddead : Boolean
Handy for tracking gameplay or animations.
FlxObject
 Inheriteddrag : FlxPoint
This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.
FlxObject
 Inheritedexists : Boolean
Kind of a global on/off switch for any objects descended from FlxObject.
FlxObject
  facing : uint
Set facing using FlxSprite.LEFT,RIGHT, UP, and DOWN to take advantage of flipped sprites and/or just track player orientation more easily.
FlxSprite
  filter : *
FlxSprite
  finished : Boolean
Whether the current animation has finished its first (or only) loop.
FlxSprite
 Inheritedfixed : Boolean
If an object is 'fixed' in space, it will not budge when it collides with a not-fixed object.
FlxObject
  frame : uint
Tell the sprite to change to a specific frame of animation.
FlxSprite
  frameHeight : uint
The height of the actual graphic or image being displayed (not necessarily the game object/bounding box).
FlxSprite
  _framePixels : BitmapData
FlxSprite
  frameWidth : uint
The width of the actual graphic or image being displayed (not necessarily the game object/bounding box).
FlxSprite
 Inherited_group : Boolean
Dedicated internal flag for whether or not this class is a FlxGroup.
FlxObject
 Inheritedhealth : 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
 InheritedmaxAngular : Number
Use in conjunction with angularAcceleration for fluid spin speed control.
FlxObject
 InheritedmaxThrust : Number
Used to cap thrust, helpful and easy!
FlxObject
 InheritedmaxVelocity : FlxPoint
If you are using acceleration, you can use maxVelocity with it to cap the speed automatically (very useful!).
FlxObject
 Inheritedmoves : Boolean
Set this to false if you want to skip the automatic motion/movement stuff (see updateMotion()).
FlxObject
  offset : FlxPoint
If you changed the size of your sprite object to shrink the bounding box, you might need to offset the new bounding box from the top-left corner of the sprite.
FlxSprite
 InheritedonFloor : Boolean
Flag that indicates whether or not you just hit the floor.
FlxObject
 Inheritedorigin : FlxPoint
WARNING: The origin of the sprite will default to its center.
FlxObject
  pixels : BitmapData
Set pixels to any BitmapData object.
FlxSprite
  realFrameCount : int
FlxSprite
 Inheritedright : Number
[read-only] The X coordinate of the right side of the rectangle.
FlxRect
  scale : FlxPoint
Change the size of your sprite's graphic.
FlxSprite
 InheritedscrollFactor : 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
 Inheritedsolid : Boolean
If an object is dead, the functions that automate collisions will skip it (see FlxG.overlapArrays() and FlxG.collideArrays()).
FlxObject
 Inheritedthrust : 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
 Inheritedvelocity : FlxPoint
The basic speed of this object.
FlxObject
 Inheritedvisible : 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
  _alpha : Number
FlxSprite
  _bakedRotation : Number
FlxSprite
  _caf : uint
FlxSprite
  _callback : Function
FlxSprite
  _color : uint
FlxSprite
  _ct : ColorTransform
FlxSprite
  _curAnim : FlxAnim
FlxSprite
  _curFrame : uint
FlxSprite
  _facing : uint
FlxSprite
 Inherited_flashPoint : Point
This is a pre-allocated Flash Point object, which is useful for certain Flash graphics API calls
FlxObject
  _flashPointZero : Point
FlxSprite
  _flashRect : Rectangle
FlxSprite
  _flashRect2 : Rectangle
FlxSprite
 Inherited_flicker : Boolean
Internal helper used for retro-style flickering.
FlxObject
 Inherited_flickerTimer : Number
Internal helper used for retro-style flickering.
FlxObject
  _flipped : uint
FlxSprite
  _frameTimer : Number
FlxSprite
  _mtx : Matrix
FlxSprite
  _pixels : BitmapData
FlxSprite
 Inherited_point : FlxPoint
This is just a pre-allocated x-y point container to be used however you like
FlxObject
 Inherited_rect : FlxRect
This is just a pre-allocated rectangle container to be used however you like
FlxObject
Public Methods
 MethodDefined By
  
FlxSprite(X:Number = 0, Y:Number = 0, SimpleGraphic:Class = null)
Creates a white 8x8 square FlxSprite at the specified position.
FlxSprite
  
addAnimation(Name:String, Frames:Array, FrameRate:Number = 0, Looped:Boolean = true):void
Adds a new animation to the sprite.
FlxSprite
  
addAnimationCallback(AnimationCallback:Function):void
Pass in a function to be called whenever this sprite's animation changes.
FlxSprite
  
applyFilter(filter:*):void
FlxSprite
 Inherited
collide(Object:FlxObject = null):Boolean
FlxObject
  
createGraphic(Width:uint, Height:uint, Color:uint = 0xffffffff, Unique:Boolean = false, Key:String = null):FlxSprite
This function creates a flat colored square image dynamically.
FlxSprite
 Inherited
destroy():void
Called by FlxGroup, commonly when game states are changed.
FlxObject
  
draw(Brush:FlxSprite, X:int = 0, Y:int = 0):void
This function draws or stamps one FlxSprite onto another.
FlxSprite
  
fill(Color:uint):void
Fills this sprite's graphic with a specific color.
FlxSprite
 Inherited
flicker(Duration:Number = 1):void
Tells this object to flicker, retro-style.
FlxObject
 Inherited
flickering():Boolean
Check to see if the object is still flickering.
FlxObject
  
[override] Call this function to figure out the on-screen position of the object.
FlxSprite
 Inherited
hitBottom(Contact:FlxObject, Velocity:Number):void
Called when this object's bottom edge collides with the top of another FlxObject.
FlxObject
 Inherited
hitLeft(Contact:FlxObject, Velocity:Number):void
Called when this object's left side collides with another FlxObject's right.
FlxObject
 Inherited
hitRight(Contact:FlxObject, Velocity:Number):void
Called when this object's right side collides with another FlxObject's left.
FlxObject
 Inherited
hitTop(Contact:FlxObject, Velocity:Number):void
Called when this object's top collides with the bottom of another FlxObject.
FlxObject
 Inherited
hurt(Damage:Number):void
Call this function to "damage" (or give health bonus) to this sprite.
FlxObject
 Inherited
kill():void
Call this function to "kill" a sprite so that it no longer 'exists'.
FlxObject
  
loadExtGraphic(Graphic:Bitmap, Animated:Boolean = false, Reverse:Boolean = false, Width:uint = 0, Height:uint = 0, Unique:Boolean = false, Key:String = null):FlxSprite
FlxSprite
  
loadGraphic(Graphic:Class, Animated:Boolean = false, Reverse:Boolean = false, Width:uint = 0, Height:uint = 0, Unique:Boolean = false):FlxSprite
Load an image from an embedded graphic file.
FlxSprite
  
loadRotatedGraphic(Graphic:Class, Rotations:uint = 16, Frame:int = -1, AntiAliasing:Boolean = false, AutoBuffer:Boolean = false):FlxSprite
Create a pre-rotated sprite sheet from a simple sprite.
FlxSprite
  
onEmit():void
Triggered whenever this sprite is launched by a FlxEmitter.
FlxSprite
 Inherited
onScreen():Boolean
Check and see if this object is currently on screen.
FlxObject
 Inherited
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
[override] Checks to see if a point in 2D space overlaps this FlxCore object.
FlxSprite
  
play(AnimName:String, Force:Boolean = false):void
Plays an existing animation (e.g.
FlxSprite
  
playFromFrame(StartFrame:int = 0):void
Plays the current Animation from a specific frame
FlxSprite
 Inherited
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
  
Tell the sprite to change to a random frame of animation Useful for instantiating particles or other weird things.
FlxSprite
 Inherited
Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.
FlxObject
  
removeFilter(filter:*):void
Call this function to remove one (or more) filters from the sprite
FlxSprite
  
Call this function to remove the last filter that was applied
FlxSprite
  
Call this function to remove the last filter that was applied
FlxSprite
  
render():void
[override] Called by game loop, updates then blits or renders current frame of animation to the screen
FlxSprite
 Inherited
reset(X:Number, Y:Number):void
Handy function for reviving game objects.
FlxObject
  
setFilter(filter:*):void
Call this function to add a filter to the sprite
FlxSprite
 Inherited
toString():String
Convert object to readable string name.
FlxPoint
  
unsafeBind(Pixels:BitmapData):void
Internal function, currently only used to quickly update FlxState.screen for post-processing.
FlxSprite
  
update():void
[override] Main game loop update function.
FlxSprite
  
Internal function for updating the sprite's animation.
FlxSprite
Protected Methods
 MethodDefined By
  
calcFrame():void
Internal function to update the current animation frame.
FlxSprite
  
Internal function that performs the actual sprite rendering, called by render().
FlxSprite
  
Resets some important variables for sprite optimization and rendering.
FlxSprite
 Inherited
Just updates the retro-style flickering.
FlxObject
 Inherited
Internal function for updating the position and speed of this object.
FlxObject
Public Constants
 ConstantDefined By
  DOWN : uint = 3
[static] Useful for checking player orientation.
FlxSprite
  LEFT : uint = 0
[static] Useful for controlling flipped animations and checking player orientation.
FlxSprite
  RIGHT : uint = 1
[static] Useful for controlling flipped animations and checking player orientation.
FlxSprite
  UP : uint = 2
[static] Useful for checking player orientation.
FlxSprite
Protected Constants
 ConstantDefined By
 Inherited_pZero : FlxPoint
[static] A handy "empty point" object
FlxObject
Property Detail
_alphaproperty
protected var _alpha:Number

_animationsproperty 
public var _animations:Array

_bakedRotationproperty 
protected var _bakedRotation:Number

_cafproperty 
protected var _caf:uint

_callbackproperty 
protected var _callback:Function

_colorproperty 
protected var _color:uint

_ctproperty 
protected var _ct:ColorTransform

_curAnimproperty 
protected var _curAnim:FlxAnim

_curFrameproperty 
protected var _curFrame:uint

_facingproperty 
protected var _facing:uint

_flashPointZeroproperty 
protected var _flashPointZero:Point

_flashRectproperty 
protected var _flashRect:Rectangle

_flashRect2property 
protected var _flashRect2:Rectangle

_flippedproperty 
protected var _flipped:uint

_framePixelsproperty 
public var _framePixels:BitmapData

_frameTimerproperty 
protected var _frameTimer:Number

_mtxproperty 
protected var _mtx:Matrix

_pixelsproperty 
protected var _pixels:BitmapData

alphaproperty 
alpha:Number

Set alpha to a number between 0 and 1 to change the opacity of the sprite.


Implementation
    public function get alpha():Number
    public function set alpha(value:Number):void
antialiasingproperty 
public var antialiasing:Boolean

Controls whether the object is smoothed when rotated, affects performance.

The default value is false.

blendproperty 
public var blend:String

Blending modes, just like Photoshop! E.g. "multiply", "screen", etc.

The default value is null.

colorproperty 
color:uint

Set color to a number in this format: 0xRRGGBB. color IGNORES ALPHA. To change the opacity use alpha. Tints the whole sprite to be this color (similar to OpenGL vertex colors).


Implementation
    public function get color():uint
    public function set color(value:uint):void
facingproperty 
facing:uint

Set facing using FlxSprite.LEFT,RIGHT, UP, and DOWN to take advantage of flipped sprites and/or just track player orientation more easily.


Implementation
    public function get facing():uint
    public function set facing(value:uint):void
filterproperty 
public var filter:*

finishedproperty 
public var finished:Boolean

Whether the current animation has finished its first (or only) loop.

frameproperty 
frame:uint

Tell the sprite to change to a specific frame of animation.


Implementation
    public function get frame():uint
    public function set frame(value:uint):void
frameHeightproperty 
public var frameHeight:uint

The height of the actual graphic or image being displayed (not necessarily the game object/bounding box). NOTE: Edit at your own risk!! This is intended to be read-only.

frameWidthproperty 
public var frameWidth:uint

The width of the actual graphic or image being displayed (not necessarily the game object/bounding box). NOTE: Edit at your own risk!! This is intended to be read-only.

offsetproperty 
public var offset:FlxPoint

If you changed the size of your sprite object to shrink the bounding box, you might need to offset the new bounding box from the top-left corner of the sprite.

pixelsproperty 
pixels:BitmapData

Set pixels to any BitmapData object. Automatically adjust graphic size and render helpers.


Implementation
    public function get pixels():BitmapData
    public function set pixels(value:BitmapData):void
realFrameCountproperty 
public var realFrameCount:int

scaleproperty 
public var scale:FlxPoint

Change the size of your sprite's graphic. NOTE: Scale doesn't currently affect collisions automatically, you will need to adjust the width, height and offset manually. WARNING: scaling sprites decreases rendering performance for this sprite by a factor of 10x!

Constructor Detail
FlxSprite()Constructor
public function FlxSprite(X:Number = 0, Y:Number = 0, SimpleGraphic:Class = null)

Creates a white 8x8 square FlxSprite at the specified position. Optionally can load a simple, one-frame graphic instead.

Parameters
X:Number (default = 0) — The initial X position of the sprite.
 
Y:Number (default = 0) — The initial Y position of the sprite.
 
SimpleGraphic:Class (default = null) — The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!).
Method Detail
addAnimation()method
public function addAnimation(Name:String, Frames:Array, FrameRate:Number = 0, Looped:Boolean = true):void

Adds a new animation to the sprite.

Parameters

Name:String — What this animation should be called (e.g. "run").
 
Frames:Array — An array of numbers indicating what frames to play in what order (e.g. 1, 2, 3).
 
FrameRate:Number (default = 0) — The speed in frames per second that the animation should play at (e.g. 40 fps).
 
Looped:Boolean (default = true) — Whether or not the animation is looped or just plays once.

addAnimationCallback()method 
public function addAnimationCallback(AnimationCallback:Function):void

Pass in a function to be called whenever this sprite's animation changes.

Parameters

AnimationCallback:Function — A function that has 3 parameters: a string name, a uint frame number, and a uint frame index.

applyFilter()method 
public function applyFilter(filter:*):void

Parameters

filter:*

calcFrame()method 
protected function calcFrame():void

Internal function to update the current animation frame.

createGraphic()method 
public function createGraphic(Width:uint, Height:uint, Color:uint = 0xffffffff, Unique:Boolean = false, Key:String = null):FlxSprite

This function creates a flat colored square image dynamically.

Parameters

Width:uint — The width of the sprite you want to generate.
 
Height:uint — The height of the sprite you want to generate.
 
Color:uint (default = 0xffffffff) — Specifies the color of the generated block.
 
Unique:Boolean (default = false) — Whether the graphic should be a unique instance in the graphics cache.
 
Key:String (default = null) — Optional parameter - specify a string key to identify this graphic in the cache. Trumps Unique flag.

Returns
FlxSprite — This FlxSprite instance (nice for chaining stuff together, if you're into that).
draw()method 
public function draw(Brush:FlxSprite, X:int = 0, Y:int = 0):void

This function draws or stamps one FlxSprite onto another. This function is NOT intended to replace render()!

Parameters

Brush:FlxSprite — The image you want to use as a brush or stamp or pen or whatever.
 
X:int (default = 0) — The X coordinate of the brush's top left corner on this sprite.
 
Y:int (default = 0) — They Y coordinate of the brush's top left corner on this sprite.

fill()method 
public function fill(Color:uint):void

Fills this sprite's graphic with a specific color.

Parameters

Color:uint — The color with which to fill the graphic, format 0xAARRGGBB.

getScreenXY()method 
override 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.
loadExtGraphic()method 
public function loadExtGraphic(Graphic:Bitmap, Animated:Boolean = false, Reverse:Boolean = false, Width:uint = 0, Height:uint = 0, Unique:Boolean = false, Key:String = null):FlxSprite

Parameters

Graphic:Bitmap
 
Animated:Boolean (default = false)
 
Reverse:Boolean (default = false)
 
Width:uint (default = 0)
 
Height:uint (default = 0)
 
Unique:Boolean (default = false)
 
Key:String (default = null)

Returns
FlxSprite
loadGraphic()method 
public function loadGraphic(Graphic:Class, Animated:Boolean = false, Reverse:Boolean = false, Width:uint = 0, Height:uint = 0, Unique:Boolean = false):FlxSprite

Load an image from an embedded graphic file.

Parameters

Graphic:Class — The image you want to use.
 
Animated:Boolean (default = false) — Whether the Graphic parameter is a single sprite or a row of sprites.
 
Reverse:Boolean (default = false) — Whether you need this class to generate horizontally flipped versions of the animation frames.
 
Width:uint (default = 0) — OPTIONAL - Specify the width of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).
 
Height:uint (default = 0) — OPTIONAL - Specify the height of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).
 
Unique:Boolean (default = false) — Whether the graphic should be a unique instance in the graphics cache.

Returns
FlxSprite — This FlxSprite instance (nice for chaining stuff together, if you're into that).
loadRotatedGraphic()method 
public function loadRotatedGraphic(Graphic:Class, Rotations:uint = 16, Frame:int = -1, AntiAliasing:Boolean = false, AutoBuffer:Boolean = false):FlxSprite

Create a pre-rotated sprite sheet from a simple sprite. This can make a huge difference in graphical performance!

Parameters

Graphic:Class — The image you want to rotate and stamp.
 
Rotations:uint (default = 16) — The number of frames you want to use (more == smoother rotations).
 
Frame:int (default = -1) — Use this to select a specific frame to draw from the graphic.
 
AntiAliasing:Boolean (default = false) — Whether to use high quality rotations when creating the graphic.
 
AutoBuffer:Boolean (default = false) — Whether to automatically increase the image size to accomodate rotated corners.

Returns
FlxSprite — This FlxSprite instance (nice for chaining stuff together, if you're into that).
onEmit()method 
public function onEmit():void

Triggered whenever this sprite is launched by a FlxEmitter.

overlapsPoint()method 
override public function overlapsPoint(X:Number, Y:Number, PerPixel:Boolean = false):Boolean

Checks to see if a point in 2D space overlaps this FlxCore 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.

Returns
Boolean — Whether or not the point overlaps this object.
play()method 
public function play(AnimName:String, Force:Boolean = false):void

Plays an existing animation (e.g. "run"). If you call an animation that is already playing it will be ignored.

Parameters

AnimName:String — The string name of the animation you want to play.
 
Force:Boolean (default = false) — Whether to force the animation to restart.

playFromFrame()method 
public function playFromFrame(StartFrame:int = 0):void

Plays the current Animation from a specific frame

Parameters

StartFrame:int (default = 0) — Which frame of the animation to start from if possible.

randomFrame()method 
public function randomFrame():void

Tell the sprite to change to a random frame of animation Useful for instantiating particles or other weird things.

removeFilter()method 
public function removeFilter(filter:*):void

Call this function to remove one (or more) filters from the sprite

Parameters

filter:* — Takes an object (or array) and removes any of those filters that are applied.

removeFirstFilter()method 
public function removeFirstFilter():void

Call this function to remove the last filter that was applied

removeLastFilter()method 
public function removeLastFilter():void

Call this function to remove the last filter that was applied

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

Called by game loop, updates then blits or renders current frame of animation to the screen

renderSprite()method 
protected function renderSprite():void

Internal function that performs the actual sprite rendering, called by render().

resetHelpers()method 
protected function resetHelpers():void

Resets some important variables for sprite optimization and rendering.

setFilter()method 
public function setFilter(filter:*):void

Call this function to add a filter to the sprite

Parameters

filter:* — Takes an object (or array) and applies any filters not already applied. Send in null to remove all.

unsafeBind()method 
public function unsafeBind(Pixels:BitmapData):void

Internal function, currently only used to quickly update FlxState.screen for post-processing. Potentially super-unsafe, since it doesn't call resetHelpers()!

Parameters

Pixels:BitmapData — The BitmapData object you want to point at.

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

Main game loop update function. Override this to create your own sprite logic! Just don't forget to call super.update() or any of the helper functions.

updateAnimation()method 
public function updateAnimation():void

Internal function for updating the sprite's animation. Useful for cases when you need to update this but are buried down in too many supers. This function is called automatically by FlxSprite.update().

Constant Detail
DOWNConstant
public static const DOWN:uint = 3

Useful for checking player orientation.

LEFTConstant 
public static const LEFT:uint = 0

Useful for controlling flipped animations and checking player orientation.

RIGHTConstant 
public static const RIGHT:uint = 1

Useful for controlling flipped animations and checking player orientation.

UPConstant 
public static const UP:uint = 2

Useful for checking player orientation.