class flixel.util.FlxSpriteUtil
Available on all platforms
Some handy functions for FlxSprite manipulation, mostly drawing-related. * Some of these work with FlxObject too.
Class Fields
static var flashGfxSprite:Sprite
Useful helper objects for doing Flash-specific rendering. * Primarily used for "debug visuals" like drawing bounding boxes directly to the screen buffer.
static function alphaMask(output:FlxSprite, source:Dynamic, mask:Dynamic):FlxSprite
Takes two source images (typically from Embedded bitmaps) and puts the resulting image into the output FlxSprite. * Note: It assumes the source and mask are the same size. Different sizes may result in undesired results. * It works by copying the source image (your picture) into the output sprite. Then it removes all areas of it that do not * have an alpha color value in the mask image. So if you draw a big black circle in your mask with a transparent edge, you'll * get a circular image appear. Look at the mask PNG files in the assets/pics folder for examples. * *
output | The FlxSprite you wish the resulting image to be placed in (will adjust width/height of image) * |
source | The source image. Typically the one with the image / picture / texture in it. * |
mask | The mask to apply. Remember the non-alpha zero areas are the parts that will display. * |
returns | The FlxSprite for chaining |
static function alphaMaskFlxSprite(sprite:FlxSprite, mask:FlxSprite, output:FlxSprite):FlxSprite
Takes the image data from two FlxSprites and puts the resulting image into the output FlxSprite. * Note: It assumes the source and mask are the same size. Different sizes may result in undesired results. * It works by copying the source image (your picture) into the output sprite. Then it removes all areas of it that do not * have an alpha color value in the mask image. So if you draw a big black circle in your mask with a transparent edge, you'll * get a circular image appear. * *
sprite | The source FlxSprite. Typically the one with the image / picture / texture in it. * |
mask | The FlxSprite containing the mask to apply. Remember the non-alpha zero areas are the parts that will display. * |
output | The FlxSprite you wish the resulting image to be placed in (will adjust width/height of image) * |
returns | The output FlxSprite for chaining |
static function beginDraw(Color:Int, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null):Void
Helper function that the drawing functions use at the start to set the color and lineStyle. * *
Color | The color to use for drawing * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle() |
static function bound(sprite:FlxSprite, ?MinX:Float = 0, ?MaxX:Float = 0, ?MinY:Float = 0, ?MaxY:Float = 0):FlxSprite
Makes sure a FlxSprite doesn't leave the specified area - most common use case is to call this every frame in update(). * If you call this without specifying an area, the game area (FlxG.width / height as max) will be used. Takes the graphic size into account. * *
sprite | The FlxSprite to bound to an area * |
MinX | The minimum x position allowed * |
MaxX | The maximum x position allowed * |
MinY | The minimum y position allowed * |
MaxY | The minimum y position allowed * |
returns | The FlxSprite for chaining |
static function drawCircle(sprite:FlxSprite, ?X:Float = -1, ?Y:Float = -1, ?Radius:Float = -1, ?Color:Int = -1, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws a circle on a FlxSprite at position X,Y with the specified color. * *
sprite | The FlxSprite to manipulate * |
X | X coordinate of the circle's center (automatically centered on the sprite if -1) * |
Y | Y coordinate of the circle's center (automatically centered on the sprite if -1) * |
Radius | Radius of the circle (makes sure the circle fully fits on the sprite's graphic if < 1, assuming and and y are centered) * |
Color | Color of the circle * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle() * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function drawEllipse(sprite:FlxSprite, X:Float, Y:Float, Width:Float, Height:Float, Color:Int, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws an ellipse on a FlxSprite. * *
sprite | The FlxSprite to manipulate * |
X | X coordinate of the ellipse's start point. * |
Y | Y coordinate of the ellipse's start point. * |
Width | Width of the ellipse * |
Height | Height of the ellipse * |
Color | The ellipse's color. * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle() * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function drawLine(sprite:FlxSprite, StartX:Float, StartY:Float, EndX:Float, EndY:Float, ?lineStyle:LineStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws a line on a FlxSprite from position X1,Y1 * to position X2,Y2 with the specified color. * *
sprite | The FlxSprite to manipulate * |
StartX | X coordinate of the line's start point. * |
StartY | Y coordinate of the line's start point. * |
EndX | X coordinate of the line's end point. * |
EndY | Y coordinate of the line's end point. * |
Color | The line's color. * |
Thickness | How thick the line is in pixels (default value is 1). * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function drawPolygon(sprite:FlxSprite, Vertices:Array<FlxPoint>, Color:Int, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws a polygon on a FlxSprite. * *
sprite | The FlxSprite to manipulate * |
Vertices | Array of Vertices to use for drawing the polygon * |
Color | Color of the polygon * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle(); * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function drawRect(sprite:FlxSprite, X:Float, Y:Float, Width:Float, Height:Float, Color:Int, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws a rectangle on a FlxSprite. * *
sprite | The FlxSprite to manipulate * |
X | X coordinate of the rectangle's start point. * |
Y | Y coordinate of the rectangle's start point. * |
Width | Width of the rectangle * |
Height | Height of the rectangle * |
Color | The rectangle's color. * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle() * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function drawRoundRect(sprite:FlxSprite, X:Float, Y:Float, Width:Float, Height:Float, EllipseWidth:Float, EllipseHeight:Float, Color:Int, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws a rounded rectangle on a FlxSprite. * *
sprite | The FlxSprite to manipulate * |
X | X coordinate of the rectangle's start point. * |
Y | Y coordinate of the rectangle's start point. * |
Width | Width of the rectangle * |
Height | Height of the rectangle * |
EllipseWidth | The width of the ellipse used to draw the rounded corners * |
EllipseHeight | The height of the ellipse used to draw the rounded corners * |
Color | The rectangle's color. * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle() * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function drawRoundRectComplex(sprite:FlxSprite, X:Float, Y:Float, Width:Float, Height:Float, TopLeftRadius:Float, TopRightRadius:Float, BottomLeftRadius:Float, BottomRightRadius:Float, Color:Int, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws a rounded rectangle on a FlxSprite. Same as drawRoundRect, * except it allows you to determine the radius of each corner individually. * *
sprite | The FlxSprite to manipulate * |
X | X coordinate of the rectangle's start point. * |
Y | Y coordinate of the rectangle's start point. * |
Width | Width of the rectangle * |
Height | Height of the rectangle * |
TopLeftRadius | The radius of the top left corner of the rectangle * |
TopRightRadius | The radius of the top right corner of the rectangle * |
BottomLeftRadius | The radius of the bottom left corner of the rectangle * |
BottomRightRadius | The radius of the bottom right corner of the rectangle * |
Color | The rectangle's color. * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle() * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function drawTriangle(sprite:FlxSprite, X:Float, Y:Float, Height:Float, Color:Int, ?lineStyle:LineStyle = null, ?fillStyle:FillStyle = null, ?drawStyle:DrawStyle = null):FlxSprite
This function draws a simple, equilateral triangle on a FlxSprite. * *
sprite | The FlxSprite to manipulate * |
X | X position of the triangle * |
Y | Y position of the triangle * |
Height | Height of the triangle * |
Color | Color of the triangle * |
lineStyle | A LineStyle typedef containing the params of Graphics.lineStyle() * |
fillStyle | A FillStyle typedef containing the params of Graphics.fillStyle() * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function endDraw(sprite:FlxSprite, ?drawStyle:DrawStyle = null):FlxSprite
Helper function that the drawing functions use at the end. * *
sprite | The FlxSprite to draw to * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |
static function fadeIn(sprite:FlxSprite, ?Duration:Float = 1, ?ResetAlpha:Bool = null, ?OnComplete:CompleteCallback = null):FlxSprite
Fade in a sprite. * *
sprite | The object to fade. * |
Duration | How long the fade will take (in seconds). * |
returns | The FlxSprite for chaining |
static function fadeOut(sprite:FlxSprite, ?Duration:Float = 1, ?FadeToBlack:Bool = null, ?OnComplete:CompleteCallback = null):FlxSprite
Fade out a sprite. * *
sprite | The object to fade. * |
Duration | How long the fade will take (in seconds). * |
returns | The FlxSprite for chaining |
static function fill(sprite:FlxSprite, Color:Int):FlxSprite
Fills this sprite's graphic with a specific color. * *
Sprite | The FlxSprite to manipulate * |
Color | The color with which to fill the graphic, format 0xAARRGGBB. * |
returns | The FlxSprite for chaining |
static function flicker(Object:FlxObject, ?Duration:Float = 1, ?Interval:Float = 0.04f, ?EndVisibility:Bool = true, ?ForceRestart:Bool = true, ?CompletionCallback:FlxFlicker ->Void = null, ?ProgressCallback:FlxFlicker ->Void = null):FlxObject
A simple flicker effect for sprites achieved by toggling visibility. * *
Object | The sprite. * |
Duration | How long to flicker for. 0 means "forever". * |
Interval | In what interval to toggle visibility. Set to FlxG.elapsed if <= 0! * |
EndVisibility | Force the visible value when the flicker completes, useful with fast repetitive use. * |
ForceRestart | Force the flicker to restart from beginnig, discarding the flickering effect already in progress if there is one. * |
CompletionCallback | An optional callback that will be triggered when a flickering has finished. * |
ProgressCallback | An optional callback that will be triggered when visibility is toggled. * |
returns | The FlxObject for chaining |
static function isFlickering(Object:FlxObject):Bool
Returns whether an object is flickering or not. * *
Object | The object to check against. |
static function screenCenter(object:FlxObject, ?xAxis:Bool = true, ?yAxis:Bool = true):FlxObject
Centers the given FlxObject on the screen, either by the x axis, y axis, or both * *
object | The FlxSprite to center * |
Horizontally | Boolean true if you want it centered horizontally * |
Vertically | Boolean true if you want it centered vertically * |
returns | The FlxObject for chaining |
static function screenWrap(sprite:FlxSprite, ?Left:Bool = true, ?Right:Bool = true, ?Top:Bool = true, ?Bottom:Bool = true):FlxSprite
Checks the x/y coordinates of the FlxSprite and keeps them within the * area of 0, 0, FlxG.width, FlxG.height (i.e. wraps it around the screen) * *
sprite | The FlxSprite to keep within the screen * |
Left | Whether to activate screen wrapping on the left side of the screen * |
Right | Whether to activate screen wrapping on the right side of the screen * |
Top | Whether to activate screen wrapping on the top of the screen * |
Bottom | Whether to activate screen wrapping on the bottom of the screen * |
returns | The FlxSprite for chaining |
static function setLineStyle(lineStyle:LineStyle):Void
Just a helper function that is called in the draw functions * to set the lineStyle via Graphics.lineStyle() * *
lineStyle | The lineStyle typedef |
static function space(objects:Array<FlxObject>, startX:Int, startY:Int, ?horizontalSpacing:Int = 0, ?verticalSpacing:Int = 0, ?spaceFromBounds:Bool = false):Void
Aligns a set of FlxObjects so there is equal spacing between them * *
objects | An Array of FlxObjects * |
startX | The base X coordinate to start the spacing from * |
startY | The base Y coordinate to start the spacing from * |
horizontalSpacing | The amount of pixels between each sprite horizontally (default 0) * |
verticalSpacing | The amount of pixels between each sprite vertically (default 0) * |
spaceFromBounds | If set to true the h/v spacing values will be added to the width/height of the sprite, if false it will ignore this |
static function stopFlickering(Object:FlxObject):FlxObject
Stops flickering of the object. Also it will make the object visible. * *
Object | The object to stop flickering. * |
returns | The FlxObject for chaining |
static function updateSpriteGraphic(sprite:FlxSprite, ?drawStyle:DrawStyle = null):FlxSprite
Just a helper function that is called at the end of the draw functions * to handle a few things related to updating a sprite's graphic. * *
Sprite | The FlxSprite to manipulate * |
drawStyle | A DrawStyle typdef containing the params of BitmapData.draw() * |
returns | The FlxSprite for chaining |