Package | org.flixel |
Class | public class FlxSprite |
Inheritance | FlxSprite ![]() ![]() ![]() |
Subclasses | FlxButton, FlxParticle, FlxText, FlxTileblock |
Property | Defined By | ||
---|---|---|---|
![]() | acceleration : FlxPoint
How fast the speed of this object is changing. | FlxObject | |
![]() | active : Boolean
Controls whether update() is automatically called by FlxState/FlxGroup. | FlxBasic | |
![]() | _ACTIVECOUNT : uint [static] | FlxBasic | |
![]() | alive : Boolean
Useful state for many game objects - "dead" (!alive) vs alive. | FlxBasic | |
![]() | allowCollisions : uint
Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions. | FlxObject | |
alpha : Number
Set alpha to a number between 0 and 1 to change the opacity of the sprite. | FlxSprite | ||
![]() | 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 | |
antialiasing : Boolean
Controls whether the object is smoothed when rotated, affects performance. | FlxSprite | ||
blend : String
Blending modes, just like Photoshop!
E.g. | FlxSprite | ||
cameras : Array | FlxSprite | ||
color : uint
Set color to a number in this format: 0xRRGGBB. | FlxSprite | ||
dirty : Boolean
Set this flag to true to force the sprite to update during the draw() call. | FlxSprite | ||
![]() | drag : FlxPoint
This isn't drag exactly, more like deceleration that is only applied
when acceleration is not affecting the sprite. | FlxObject | |
![]() | elasticity : Number | FlxObject | |
![]() | exists : Boolean
Controls whether update() and draw() are automatically called by FlxState/FlxGroup. | FlxBasic | |
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 | ||
finished : Boolean
Whether the current animation has finished its first (or only) loop. | FlxSprite | ||
![]() | flickering : Boolean [read-only]
Check to see if the object is still flickering. | 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 | ||
frames : uint
The total number of frames in this image (assumes each row is full). | FlxSprite | ||
frameWidth : uint
The width of the actual graphic or image being displayed (not necessarily the game object/bounding box). | FlxSprite | ||
![]() | health : Number
Handy for storing health percentage or armor points or whatever. | FlxObject | |
![]() | height : Number | FlxObject | |
![]() | ID : int
IDs seem like they could be pretty useful, huh?
| FlxBasic | |
![]() | immovable : Boolean
Whether an object will move/alter position after a collision. | FlxObject | |
![]() | last : FlxPoint | FlxObject | |
![]() | mass : Number | FlxObject | |
![]() | maxAngular : Number
Use in conjunction with angularAcceleration for fluid spin speed control. | 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 | |
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 | ||
origin : FlxPoint
WARNING: The origin of the sprite will default to its center. | FlxSprite | ||
pixels : BitmapData
Set pixels to any BitmapData object. | FlxSprite | ||
scale : FlxPoint
Change the size of your sprite's graphic. | FlxSprite | ||
![]() | 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 | FlxObject | |
![]() | touching : uint
Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts and collision qualities. | FlxObject | |
![]() | velocity : FlxPoint
The basic speed of this object. | FlxObject | |
![]() | visible : Boolean
Controls whether draw() is automatically called by FlxState/FlxGroup. | FlxBasic | |
![]() | _VISIBLECOUNT : uint [static] | FlxBasic | |
![]() | wasTouching : uint | FlxObject | |
![]() | width : Number | FlxObject | |
![]() | x : Number | FlxObject | |
![]() | y : Number | FlxObject |
Property | Defined By | ||
---|---|---|---|
_alpha : Number | FlxSprite | ||
_animations : Array | 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 | ||
_flashPoint : Point | FlxSprite | ||
_flashPointZero : Point | FlxSprite | ||
_flashRect : Rectangle | FlxSprite | ||
_flashRect2 : Rectangle | FlxSprite | ||
![]() | _flicker : Boolean
Internal helper used for retro-style flickering. | FlxObject | |
![]() | _flickerTimer : Number
Internal helper used for retro-style flickering. | FlxObject | |
_flipped : uint | FlxSprite | ||
_framePixels : BitmapData | FlxSprite | ||
_frameTimer : Number | FlxSprite | ||
_gfx : Graphics [static] | FlxSprite | ||
_gfxSprite : Sprite [static] | FlxSprite | ||
ImgDefault : Class | FlxSprite | ||
_mtx : Matrix | FlxSprite | ||
_pixels : BitmapData | FlxSprite | ||
![]() | _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 |
Method | Defined 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 | ||
corner():void | FlxSprite | ||
destroy():void [override] | FlxSprite | ||
draw():void [override]
Called by game loop, updates then blits or renders current frame of animation to the screen
| FlxSprite | ||
drawFrame(Force:Boolean = false):void
Request (or force) that the sprite update the frame before rendering. | FlxSprite | ||
drawLine(StartX:Number, StartY:Number, EndX:Number, EndY:Number, Color:uint, Thickness:uint = 1):void
This function draws a line on this sprite from position X1,Y1
to position X2,Y2 with the specified color. | FlxSprite | ||
fill(Color:uint):void
Fills this sprite's graphic with a specific color. | FlxSprite | ||
![]() | flicker(Duration:Number = 1):void
Tells this object to flicker, retro-style. | FlxObject | |
![]() | FlxObject | ||
[override]
Call this function to figure out the on-screen position of the object. | FlxSprite | ||
hurt(Damage:Number):void
Reduces the "health" variable of this sprite by the amount specified in Damage. | FlxSprite | ||
![]() | isTouching(Direction:uint):Boolean | FlxObject | |
![]() | justTouched(Direction:uint):Boolean | FlxObject | |
![]() | kill():void | FlxBasic | |
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 | ||
makeGraphic(Width:uint, Height:uint, Color:uint = 0xffffffff, Unique:Boolean = false, Key:String = null):FlxSprite
This function creates a flat colored square image dynamically. | FlxSprite | ||
onEmit():void
Triggered whenever this sprite is launched by a FlxEmitter. | FlxSprite | ||
[override]
Check and see if this object is currently on screen. | FlxSprite | ||
![]() |
Checks to see if some FlxObject overlaps this FlxObject object in world space. | FlxObject | |
overlapsPoint(X:Number, Y:Number, Camera:FlxCamera = null, PerPixel:Boolean = false):Boolean [override]
Checks to see if a point in 2D world space overlaps this FlxCore object. | FlxSprite | ||
play(AnimName:String, Force:Boolean = false):void
Plays an existing animation (e.g. | FlxSprite | ||
postUpdate():void [override] | FlxSprite | ||
![]() | preUpdate():void [override] | FlxObject | |
randomFrame():void
Tell the sprite to change to a random frame of animation
Useful for instantiating particles or other weird things. | FlxSprite | ||
![]() | reset(X:Number, Y:Number):void
Handy function for reviving game objects. | FlxObject | |
![]() | revive():void | FlxBasic | |
![]() | [static] | FlxObject | |
![]() | [static] | FlxObject | |
![]() | [static] | FlxObject | |
This function draws or stamps one FlxSprite onto another. | FlxSprite | ||
![]() | toString():String
Convert object to readable string name. | FlxBasic | |
![]() | update():void [override]
Called by the main game loop, handles motion/physics and game logic
| FlxObject |
Method | Defined By | ||
---|---|---|---|
calcFrame():void
Internal function to update the current animation frame. | FlxSprite | ||
resetHelpers():void
Resets some important variables for sprite optimization and rendering. | FlxSprite | ||
updateAnimation():void
Internal function for updating the sprite's animation. | FlxSprite | ||
![]() | updateMotion():void
Internal function for updating the position and speed of this object. | FlxObject |
_alpha | property |
protected var _alpha:Number
_animations | property |
protected var _animations:Array
_bakedRotation | property |
protected var _bakedRotation:Number
_caf | property |
protected var _caf:uint
_callback | property |
protected var _callback:Function
_color | property |
protected var _color:uint
_ct | property |
protected var _ct:ColorTransform
_curAnim | property |
protected var _curAnim:FlxAnim
_curFrame | property |
protected var _curFrame:uint
_facing | property |
protected var _facing:uint
_flashPoint | property |
protected var _flashPoint:Point
_flashPointZero | property |
protected var _flashPointZero:Point
_flashRect | property |
protected var _flashRect:Rectangle
_flashRect2 | property |
protected var _flashRect2:Rectangle
_flipped | property |
protected var _flipped:uint
_framePixels | property |
protected var _framePixels:BitmapData
_frameTimer | property |
protected var _frameTimer:Number
_gfx | property |
protected static var _gfx:Graphics
_gfxSprite | property |
protected static var _gfxSprite:Sprite
_mtx | property |
protected var _mtx:Matrix
_pixels | property |
protected var _pixels:BitmapData
alpha | property |
alpha:Number
Set alpha
to a number between 0 and 1 to change the opacity of the sprite.
public function get alpha():Number
public function set alpha(value:Number):void
antialiasing | property |
public var antialiasing:Boolean
Controls whether the object is smoothed when rotated, affects performance.
The default value is false
.
blend | property |
public var blend:String
Blending modes, just like Photoshop! E.g. "multiply", "screen", etc.
The default value is null
.
cameras | property |
public var cameras:Array
color | property |
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).
public function get color():uint
public function set color(value:uint):void
dirty | property |
public var dirty:Boolean
Set this flag to true to force the sprite to update during the draw() call. NOTE: Rarely if ever necessary, most sprite operations will flip this flag automatically.
facing | property |
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.
public function get facing():uint
public function set facing(value:uint):void
finished | property |
public var finished:Boolean
Whether the current animation has finished its first (or only) loop.
frame | property |
frame:uint
Tell the sprite to change to a specific frame of animation.
public function get frame():uint
public function set frame(value:uint):void
frameHeight | property |
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.
frames | property |
public var frames:uint
The total number of frames in this image (assumes each row is full).
frameWidth | property |
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.
ImgDefault | property |
protected var ImgDefault:Class
offset | property |
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.
origin | property |
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.
pixels | property |
pixels:BitmapData
Set pixels
to any BitmapData
object.
Automatically adjust graphic size and render helpers.
public function get pixels():BitmapData
public function set pixels(value:BitmapData):void
scale | property |
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!
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.
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!).
|
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.
|
calcFrame | () | method |
protected function calcFrame():void
Internal function to update the current animation frame.
corner | () | method |
public function corner():void
destroy | () | method |
override public function destroy():void
draw | () | method |
override public function draw():void
Called by game loop, updates then blits or renders current frame of animation to the screen
drawFrame | () | method |
public function drawFrame(Force:Boolean = false):void
Request (or force) that the sprite update the frame before rendering. Useful if you are doing procedural generation or other weirdness!
Parameters
Force:Boolean (default = false ) — Force the frame to redraw, even if its not flagged as necessary.
|
drawLine | () | method |
public function drawLine(StartX:Number, StartY:Number, EndX:Number, EndY:Number, Color:uint, Thickness:uint = 1):void
This function draws a line on this sprite from position X1,Y1 to position X2,Y2 with the specified color.
Parameters
StartX:Number — X coordinate of the line's start point.
| |
StartY:Number — Y coordinate of the line's start point.
| |
EndX:Number — X coordinate of the line's end point.
| |
EndY:Number — Y coordinate of the line's end point.
| |
Color:uint — The line's color.
| |
Thickness:uint (default = 1 ) — How thick the line is in pixels (default value is 1).
|
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, Camera:FlxCamera = null):FlxPoint
Call this function to figure out the on-screen position of the object.
Parameters
Point:FlxPoint (default = null ) — Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
| |
Camera:FlxCamera (default = null ) — Takes a Point object and assigns the post-scrolled X and Y values of this object to it.
|
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.
|
hurt | () | method |
public function hurt(Damage:Number):void
Reduces the "health" variable of this sprite by the amount specified in Damage. Calls kill() if health drops to or below zero.
Parameters
Damage:Number — How much health to take away (use a negative number to give a health bonus).
|
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.
|
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.
|
FlxSprite — This FlxSprite instance (nice for chaining stuff together, if you're into that).
|
makeGraphic | () | method |
public function makeGraphic(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.
|
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
.
onScreen | () | method |
override public function onScreen(Camera:FlxCamera = null):Boolean
Check and see if this object is currently on screen.
Parameters
Camera:FlxCamera (default = null ) — Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
Boolean — Whether the object is on screen or not.
|
overlapsPoint | () | method |
override public function overlapsPoint(X:Number, Y:Number, Camera:FlxCamera = null, PerPixel:Boolean = false):Boolean
Checks to see if a point in 2D world space overlaps this FlxCore object.
Parameters
X:Number — The X coordinate of the point.
| |
Y:Number — The Y coordinate of the point.
| |
Camera:FlxCamera (default = null ) — Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
| |
PerPixel:Boolean (default = false ) — Whether or not to use per pixel collision checking.
|
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.
|
postUpdate | () | method |
override public function postUpdate():void
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.
resetHelpers | () | method |
protected function resetHelpers():void
Resets some important variables for sprite optimization and rendering.
stamp | () | method |
public function stamp(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.
|
updateAnimation | () | method |
protected 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()
.