class flixel.ui.FlxBar extends FlxSprite

Available on all platforms

FlxBar is a quick and easy way to create a graphical bar which can * be used as part of your UI/HUD, or positioned next to a sprite. It could represent * a loader, progress or health bar. * * @version 1.6 - October 10th 2011 * @link http://www.photonstorm.com * @author Richard Davey / Photon Storm

Class Fields

Instance Fields

var fixedPosition:Bool

fixedPosition controls if the FlxBar sprite is at a fixed location on screen, or tracking its parent

var positionOffset:FlxPoint

The positionOffset controls how far offset the FlxBar is from the parent sprite (if at all)

var pxPerPercent:Float

How many pixels = 1% of the bar (barWidth (or height) / 100)

function new(?x:Float = 0, ?y:Float = 0, ?direction:Int = 1, ?width:Int = 100, ?height:Int = 10, ?parentRef:Dynamic = null, ?variable:String = '', ?min:Float = 0, ?max:Float = 100, ?border:Bool = false):Void

Create a new FlxBar Object * *

x

The x coordinate location of the resulting bar (in world pixels) *

y

The y coordinate location of the resulting bar (in world pixels) *

direction

One of the FlxBar.FILL constants (such as FILLLEFTTORIGHT, FILLTOPTO_BOTTOM etc) *

width

The width of the bar in pixels *

height

The height of the bar in pixels *

parentRef

A reference to an object in your game that you wish the bar to track *

variable

The variable of the object that is used to determine the bar position. For example if the parent was an FlxSprite this could be "health" to track the health value *

min

The minimum value. I.e. for a progress bar this would be zero (nothing loaded yet) *

max

The maximum value the bar can reach. I.e. for a progress bar this would typically be 100. *

border

Include a 1px border around the bar? (if true it adds +2 to width and height to accommodate it)

function createFilledBar(empty:Int, fill:Int, ?showBorder:Bool = false, ?border:Int = -1):Void

Creates a solid-colour filled health bar in the given colours, with optional 1px thick border.
* All colour values are in 0xAARRGGBB format, so if you want a slightly transparent health bar give it lower AA values. * *

empty

The color of the bar when empty in 0xAARRGGBB format (the background colour) *

fill

The color of the bar when full in 0xAARRGGBB format (the foreground colour) *

showBorder

Should the bar be outlined with a 1px solid border? *

border

The border colour in 0xAARRGGBB format

function createGradientBar(empty:Array<Int>, fill:Array<Int>, ?chunkSize:Int = 1, ?rotation:Int = 180, ?showBorder:Bool = false, ?border:Int = -1):Void

Creates a gradient filled health bar using the given colour ranges, with optional 1px thick border.
* All colour values are in 0xAARRGGBB format, so if you want a slightly transparent health bar give it lower AA values. * *

empty

Array of colour values used to create the gradient of the health bar when empty, each colour must be in 0xAARRGGBB format (the background colour) *

fill

Array of colour values used to create the gradient of the health bar when full, each colour must be in 0xAARRGGBB format (the foreground colour) *

chunkSize

If you want a more old-skool looking chunky gradient, increase this value! *

rotation

Angle of the gradient in degrees. 90 = top to bottom, 180 = left to right. Any angle is valid *

showBorder

Should the bar be outlined with a 1px solid border? *

border

The border colour in 0xAARRGGBB format

function createImageBar(?empty:Dynamic = null, ?fill:Dynamic = null, ?emptyBackground:Int = -16777216, ?fillBackground:Int = -16711936):Void

Creates a health bar filled using the given bitmap images.
* You can provide "empty" (background) and "fill" (foreground) images. either one or both images (empty / fill), and use the optional empty/fill colour values * All colour values are in 0xAARRGGBB format, so if you want a slightly transparent health bar give it lower AA values. * *

empty

Bitmap image used as the background (empty part) of the health bar, if null the emptyBackground colour is used *

fill

Bitmap image used as the foreground (filled part) of the health bar, if null the fillBackground colour is used *

emptyBackground

If no background (empty) image is given, use this colour value instead. 0xAARRGGBB format *

fillBackground

If no foreground (fill) image is given, use this colour value instead. 0xAARRGGBB format

function destroy():Void

function setCallbacks(onEmpty:Void ->Void, onFilled:Void ->Void, ?killOnEmpty:Bool = false):Void

Sets callbacks which will be triggered when the value of this FlxBar reaches min or max. * Functions will only be called once and not again until the value changes. * Optionally the FlxBar can be killed if it reaches min, but if will fire the empty callback first (if set) * *

onEmpty

The function that is called if the value of this FlxBar reaches min *

onFilled

The function that is called if the value of this FlxBar reaches max *

killOnEmpty

If set it will call FlxBar.kill() if the value reaches min

function setFillDirection(direction:Int):Void

Set the direction from which the health bar will fill-up. Default is from left to right. Change takes effect immediately. * *

direction

One of the FlxBar.FILL constants (such as FILLLEFTTORIGHT, FILLTOPTO_BOTTOM etc)

function setParent(parentRef:Dynamic, variable:String, ?track:Bool = false, ?offsetX:Int = 0, ?offsetY:Int = 0):Void

Sets a parent for this FlxBar. Instantly replaces any previously set parent and refreshes the bar. * *

parentRef

A reference to an object in your game that you wish the bar to track *

variable

The variable of the object that is used to determine the bar position. For example if the parent was an FlxSprite this could be "health" to track the health value *

track

If you wish the FlxBar to track the x/y coordinates of parent set to true (default false) *

offsetX

The offset on X in relation to the origin x/y of the parent *

offsetY

The offset on Y in relation to the origin x/y of the parent

function setRange(min:Float, max:Float):Void

Set the minimum and maximum allowed values for the FlxBar * *

min

The minimum value. I.e. for a progress bar this would be zero (nothing loaded yet) *

max

The maximum value the bar can reach. I.e. for a progress bar this would typically be 100.

function stopTrackingParent(posX:Int, posY:Int):Void

Tells the health bar to stop following the parent sprite. The given posX and posY values are where it will remain on-screen. * *

posX

X coordinate of the health bar now it's no longer tracking the parent sprite *

posY

Y coordinate of the health bar now it's no longer tracking the parent sprite

function toString():String

function trackParent(offsetX:Int, offsetY:Int):Void

Track the parent FlxSprites x/y coordinates. For example if you wanted your sprite to have a floating health-bar above their head.
* If your health bar is 10px tall and you wanted it to appear above your sprite, then set offsetY to be -10
* If you wanted it to appear below your sprite, and your sprite was 32px tall, then set offsetY to be 32. Same applies to offsetX. * * @see stopTrackingParent

offsetX

The offset on X in relation to the origin x/y of the parent *

offsetY

The offset on Y in relation to the origin x/y of the parent *

function update():Void