class flixel.FlxSprite extends FlxObject

Available on all platforms

The main "game object" class, the sprite is a FlxObject * with a bunch of graphics options and abilities, like animation and stamping.

Instance Fields

var alpha:Float

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

var animation:FlxAnimationController

Class that handles adding and playing animations on this sprite.

var antialiasing:Bool

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

var bakedRotationAngle:Float

The minimum angle (out of 360°) for which a new baked rotation exists. Example: 90 means there * are 4 baked rotations in the spritesheet. 0 if this sprite does not have any baked rotations.

var blend:BlendMode

Blending modes, just like Photoshop or whatever, e.g. "multiply", "screen", etc.

var color:Int

Tints the whole sprite to a color (0xRRGGBB format) - similar to OpenGL vertex colors. You can use * 0xAARRGGBB colors, but the alpha value will simply be ignored. To change the opacity use alpha.

var dirty:Bool

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.

var facing:Int

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

var flipX:Bool

Whether this sprite is flipped on the X axis

var flipY:Bool

Whether this sprite is flipped on the Y axis

var frame:FlxFrame

Link to current FlxFrame from loaded atlas

var frameHeight:Int

The height of the actual graphic or image being displayed (not necessarily the game object/bounding box).

var framePixels:BitmapData

The actual Flash BitmapData object representing the current display state of the sprite.

var frameWidth:Int

The width of the actual graphic or image being displayed (not necessarily the game object/bounding box).

var frames:Int

The total number of frames in this image. WARNING: assumes each row in the sprite sheet is full!

var offset:FlxPoint

Controls the position of the sprite's hitbox. Likely needs to be adjusted after * changing a sprite's width, height or scale.

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.

var pixels:BitmapData

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

var region:Region

Rendering variables.

var scale:FlxPoint

Change the size of your sprite's graphic. NOTE: The hitbox is not automatically adjusted, use updateHitbox for that * (or setGraphicSize(). WARNING: When using blitting (flash), scaling sprites decreases rendering performance by a factor of about x10!

var useColorTransform:Bool

Whether or not to use a colorTransform set via setColorTransform.

function new(?X:Float = 0, ?Y:Float = 0, ?SimpleGraphic:Dynamic = null):Void

Creates a FlxSprite at a specified position with a specified one-frame graphic. * If none is provided, a 16x16 image of the HaxeFlixel logo is used. * *

X

The initial X position of the sprite. *

Y

The initial Y position of the sprite. *

SimpleGraphic

The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!).

function centerOffsets(?AdjustPosition:Bool = false):Void

Helper function that adjusts the offset automatically to center the bounding box within the graphic. *

AdjustPosition

Adjusts the actual X and Y position just once to match the offset change. Default is false.

function centerOrigin():Void

Sets the sprite's origin to its center - useful after adjusting * scale to make sure rotations work as expected.

function clone(?NewSprite:FlxSprite = null):FlxSprite

function destroy():Void

WARNING: This will remove this object entirely. Use kill() if you want to disable it temporarily only and reset() it later to revive it. * Override this function to null out variables manually or call destroy() on class members if necessary. Don't forget to call super.destroy()!

function draw():Void

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

function drawFrame(?Force:Bool = false):Void

Request (or force) that the sprite update the frame before rendering. * Useful if you are doing procedural generation or other weirdness! *

Force

Force the frame to redraw, even if its not flagged as necessary.

function getFlxFrameBitmapData():BitmapData

Retrieves BitmapData of current FlxFrame

function getGraphicMidpoint(?point:FlxPoint = null):FlxPoint

Retrieve the midpoint of this sprite's graphic in world coordinates. * *

point

Allows you to pass in an existing FlxPoint object if you're so inclined. Otherwise a new one is created. *

returns

A FlxPoint object containing the midpoint of this sprite's graphic in world coordinates.

function isOnScreen(?Camera:FlxCamera = null):Bool

Check and see if this object is currently on screen. Differs from FlxObject's implementation * in that it takes the actual graphic into account, not just the hitbox or bounding box or whatever. * *

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

returns

Whether the object is on screen or not.

function isSimpleRender():Bool

Checks if the Sprite is being rendered in "simple mode" (via copyPixels). True for flash when no angle, bakedRotations, * scaling or blend modes are used. This enables the sprite to be rendered much faster if true.

function loadGraphic(Graphic:Dynamic, ?Animated:Bool = false, ?Width:Int = 0, ?Height:Int = 0, ?Unique:Bool = false, ?Key:String = null):FlxSprite

Load an image from an embedded graphic file. * *

Graphic

The image you want to use. *

Animated

Whether the Graphic parameter is a single sprite or a row of sprites. *

Width

Optional, specify the width of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets). *

Height

Optional, specify the height of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets). *

Unique

Optional, whether the graphic should be a unique instance in the graphics cache. Default is false. *

Key

Optional, set this parameter if you're loading BitmapData. *

returns

This FlxSprite instance (nice for chaining stuff together, if you're into that).

function loadGraphicFromSprite(Sprite:FlxSprite):FlxSprite

Load graphic from another FlxSprite and copy its tileSheet data. * This method can useful for non-flash targets (and is used by the FlxTrail effect). * *

Sprite

The FlxSprite from which you want to load graphic data *

returns

This FlxSprite instance (nice for chaining stuff together, if you're into that).

function loadGraphicFromTexture(Data:Dynamic, ?Unique:Bool = false, ?FrameName:String = null):FlxSprite

Loads TexturePacker atlas. * *

Data

Atlas data holding links to json-data and atlas image *

Unique

Optional, whether the graphic should be a unique instance in the graphics cache. Default is false. *

FrameName

Default frame to show. If null then will be used first available frame. *

returns

This FlxSprite instance (nice for chaining stuff together, if you're into that).

function loadRotatedGraphic(Graphic:Dynamic, ?Rotations:Int = 16, ?Frame:Int = -1, ?AntiAliasing:Bool = false, ?AutoBuffer:Bool = false, ?Key:String = null):FlxSprite

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

Graphic

The image you want to rotate and stamp. *

Rotations

The number of rotation frames the final sprite should have. For small sprites this can be quite a large number (360 even) without any problems. *

Frame

If the Graphic has a single row of square animation frames on it, you can specify which of the frames you want to use here. Default is -1, or "use whole graphic." *

AntiAliasing

Whether to use high quality rotations when creating the graphic. Default is false. *

AutoBuffer

Whether to automatically increase the image size to accomodate rotated corners. Default is false. Will create frames that are 150% larger on each axis than the original frame or graphic. *

Key

Optional, set this parameter if you're loading BitmapData. *

returns

This FlxSprite instance (nice for chaining stuff together, if you're into that).

function loadRotatedGraphicFromTexture(Data:Dynamic, Image:String, ?Rotations:Int = 16, ?AntiAliasing:Bool = false, ?AutoBuffer:Bool = false):FlxSprite

Creates a pre-rotated sprite sheet from provided image in atlas. * This can make a huge difference in graphical performance on flash target! * *

Data

Atlas data holding links to json-data and atlas image *

Image

The image from atlas you want to rotate and stamp. *

Rotations

The number of rotation frames the final sprite should have. For small sprites this can be quite a large number (360 even) without any problems. *

AntiAliasing

Whether to use high quality rotations when creating the graphic. Default is false. *

AutoBuffer

Whether to automatically increase the image size to accomodate rotated corners. *

returns

This FlxSprite instance (nice for chaining stuff together, if you're into that).

function makeGraphic(Width:Int, Height:Int, ?Color:Int = -1, ?Unique:Bool = false, ?Key:String = null):FlxSprite

This function creates a flat colored square image dynamically. *

Width

The width of the sprite you want to generate. *

Height

The height of the sprite you want to generate. *

Color

Specifies the color of the generated block (ARGB format). *

Unique

Whether the graphic should be a unique instance in the graphics cache. Default is false. *

Key

Optional parameter - specify a string key to identify this graphic in the cache. Trumps Unique flag. *

returns

This FlxSprite instance (nice for chaining stuff together, if you're into that).

function pixelsOverlapPoint(point:FlxPoint, ?Mask:Int = 255, ?Camera:FlxCamera = null):Bool

Checks to see if a point in 2D world space overlaps this FlxSprite object's current displayed pixels. * This check is ALWAYS made in screen space, and always takes scroll factors into account. * *

Point

The point in world space you want to check. *

Mask

Used in the pixel hit test to determine what counts as solid. *

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

returns

Whether or not the point overlaps this object.

function replaceColor(Color:Int, NewColor:Int, ?FetchPositions:Bool = false):Array<FlxPoint>

Replaces all pixels with specified Color with NewColor pixels *

Color

Color to replace *

NewColor

New color *

FetchPositions

Whether we need to store positions of pixels which colors were replaced *

returns

Array replaced pixels positions

function resetFrameBitmapDatas():Void

Helper function for reseting precalculated FlxFrame bitmapdatas. * Useful when _pixels bitmapdata changes (e.g. after stamp(), FlxSpriteUtil.drawLine() and other similar method calls).

function resetFrameSize():Void

Resets frame size to frame dimensions

function resetSize():Void

Resets _flashRect variable used for frame bitmapData calculation

function resetSizeFromFrame():Void

Resets sprite's size back to frame size

function setColorTransform(?redMultiplier:Float = 1.0f, ?greenMultiplier:Float = 1.0f, ?blueMultiplier:Float = 1.0f, ?alphaMultiplier:Float = 1.0f, ?redOffset:Float = 0, ?greenOffset:Float = 0, ?blueOffset:Float = 0, ?alphaOffset:Float = 0):Void

Set sprite's color transformation with control over color offsets. * *

redMultiplier

The value for the red multiplier, in the range from 0 to 1. *

greenMultiplier

The value for the green multiplier, in the range from 0 to 1. *

blueMultiplier

The value for the blue multiplier, in the range from 0 to 1. *

alphaMultiplier

The value for the alpha transparency multiplier, in the range from 0 to 1. *

redOffset

The offset value for the red color channel, in the range from -255 to 255. *

greenOffset

The offset value for the green color channel, in the range from -255 to 255. *

blueOffset

The offset for the blue color channel value, in the range from -255 to 255. *

alphaOffset

The offset for alpha transparency channel value, in the range from -255 to 255.

function setFacingFlip(Direction:Int, FlipX:Bool, FlipY:Bool):Void

Set how a sprite flips when facing in a particular direction. * *

Direction

Use constants from FlxObject: LEFT, RIGHT, UP, and DOWN. These may be combined with the bitwise OR operator. E.g. To make a sprite flip horizontally when it is facing both UP and LEFT, use setFacingFlip(FlxObject.LEFT | FlxObject.UP, true, false);

FlipX

Whether to flip the sprite on the X axis *

FlipY

Whether to flip the sprite on the Y axis

function setGraphicSize(?Width:Int = 0, ?Height:Int = 0):Void

Helper function to set the graphic's dimensions by using scale, allowing you to keep the current aspect ratio * should one of the Integers be <= 0. It might make sense to call updateHitbox() afterwards! * *

Width

How wide the graphic should be. If <= 0, and a Height is set, the aspect ratio will be kept. *

Height

How high the graphic should be. If <= 0, and a Width is set, the aspect ratio will be kept.

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 draw()! *

Brush

The image you want to use as a brush or stamp or pen or whatever. *

X

The X coordinate of the brush's top left corner on this sprite. *

Y

They Y coordinate of the brush's top left corner on this sprite.

function update():Void

function updateFrameData():Void

Use this method for creating tileSheet for FlxSprite. Must be called after makeGraphic(), loadGraphic or loadRotatedGraphic(). * If you forget to call it then you will not see this FlxSprite on c++ target

function updateHitbox():Void

Updates the sprite's hitbox (width, height, offset) according to the current scale. * Also calls setOriginToCenter(). Called by setGraphicSize().