class FlxBar
package flixel.ui
extends FlxSprite › FlxObject › FlxBasic
extended by FlxUIBar
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.
@link http://www.photonstorm.com
Constructor
new(x:Float = 0, y:Float = 0, ?direction:FlxBarFillDirection, width:Int = 100, height:Int = 10, ?parentRef:Dynamic, variable:String = "", min:Float = 0, max:Float = 100, showBorder:Bool = false)
Create a new FlxBar Object
Parameters:
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 | The fill direction, LEFT_TO_RIGHT by default |
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. |
showBorder | Include a 1px border around the bar? (if true it adds +2 to width and height to accommodate it) |
Variables
fillDirection:FlxBarFillDirection
The direction from which the health bar will fill-up. Default is from left to right. Change takes effect immediately.
fixedPosition:Bool = true
If false, the bar is tracking its parent (the position is synchronized with the parent's position).
frontFrames:FlxImageFrame
BarFrames which will be used for filled bar rendering. It is recommended to use this property in tile render mode (although it will work in blit render mode also).
numDivisions:Int = 100
Number of frames FlxBar will have. Default value is 100. The bigger value you set then visual will change smoother.
4.1.0
.read onlypositionOffset:FlxPoint
The positionOffset controls how far offset the FlxBar is from the parent sprite (if at all)
Methods
createColoredEmptyBar(empty:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar
Creates a solid-colour filled background for health bar in the given colour, with optional 1px thick border.
Parameters:
empty | The color of the bar when empty in 0xAARRGGBB format (the background colour) |
---|---|
showBorder | Should the bar be outlined with a 1px solid border? |
border | The border colour in 0xAARRGGBB format |
Returns:
This FlxBar object with generated image for rendering health bar background.
createColoredFilledBar(fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar
Creates a solid-colour filled foreground for health bar in the given colour, with optional 1px thick border.
Parameters:
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 |
Returns:
This FlxBar object with generated image for rendering actual values.
createFilledBar(empty:FlxColor, fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar
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.
Parameters:
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 |
Returns:
This FlxBar object with generated images for front and background.
createGradientBar(empty:Array<FlxColor>, fill:Array<FlxColor>, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar
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.
Parameters:
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 |
Returns:
This FlxBar object with generated images for front and background.
createGradientEmptyBar(empty:Array<FlxColor>, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar
Creates a gradient filled background for health bar using the given colour range, with optional 1px thick border.
Parameters:
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) |
---|---|
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 |
Returns:
This FlxBar object with generated image for background rendering.
createGradientFilledBar(fill:Array<FlxColor>, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar
Creates a gradient filled foreground for health bar using the given colour range, with optional 1px thick border.
Parameters:
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 |
Returns:
This FlxBar object with generated image for rendering actual values.
createImageBar(?empty:Null<FlxGraphicAsset>, ?fill:Null<FlxGraphicAsset>, emptyBackground:FlxColor = FlxColor.BLACK, fillBackground:FlxColor = FlxColor.LIME):FlxBar
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. NOTE: This method doesn't check if the empty image doesn't have the same size as fill image.
Parameters:
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 |
Returns:
This FlxBar object with generated images for front and background.
createImageEmptyBar(?empty:Null<FlxGraphicAsset>, emptyBackground:FlxColor = FlxColor.BLACK):FlxBar
Loads given bitmap image for health bar background.
Parameters:
empty | Bitmap image used as the background (empty part) of the health bar, if null the emptyBackground colour is used |
---|---|
emptyBackground | If no background (empty) image is given, use this colour value instead. 0xAARRGGBB format |
Returns:
This FlxBar object with generated image for background rendering.
createImageFilledBar(?fill:Null<FlxGraphicAsset>, fillBackground:FlxColor = FlxColor.LIME):FlxBar
Loads given bitmap image for health bar foreground.
Parameters:
fill | Bitmap image used as the foreground (filled part) of the health bar, if null the fillBackground colour is used |
---|---|
fillBackground | If no foreground (fill) image is given, use this colour value instead. 0xAARRGGBB format |
Returns:
This FlxBar object with generated image for rendering actual values.
setCallbacks(onEmpty:() ‑> Void, onFilled:() ‑> 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)
Parameters:
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 |
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.
Parameters:
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 |
setRange(min:Float, max:Float):Void
Set the minimum and maximum allowed values for the FlxBar
Parameters:
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. |
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.
Parameters:
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 |
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.
Parameters:
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 |
See also:
stopTrackingParent