Flixel Power Tools FlxBar

Back to the Flixel Power Tools

Released in version 1.7

Note: This class replaces the old FlxHealthBar class.

FlxBar started life as a way to display the health of a sprite. In version 1.7 it grew up and became a lot more versatile! It can now be used as a general purpose bar. Be that a progress bar, loading indicator, time delay or health bar.

You can have it track any value on a parent sprite and update automatically. For example if you link the bar to the health value of a sprite, and the sprite gets hurt, it will update to reflect this. It can automatically follow the parent sprite around like a little floating bar over players / enemies heads. Or it can be placed into a HUD.

This class provides a really fast way to create them, and they are highly customisable. You can have a plain-colour filled bar (supporting alpha levels), a gradient-filled bar or an image filled bar. The bar can fill in one of 8 different directions.

Screen Shot

Code Example


//	Creates a new FlxBar positioned at 16x64 that fills from left to right
//	The 64x4 is the width and height of the bar.
//	ufo is the FlxSprite it is bound to, and "health" is the FlxSprite variable it will monitor
ufoHealthBar = new FlxBar(16, 64, FlxBar.FILL_LEFT_TO_RIGHT, 64, 4, ufo, "health");
			
//	This tells it to track the x/y position of the red FlxSprite, but offset by the values given
ufoHealthBar.trackParent(0, -5);

Recent Flixel Power Tool Posts

  1. Flixel Power Tools v1.9 Released
  2. Flixel Power Tools v1.8 Released - Let's get clicky
  3. Flixel Power Tools v1.7 - Kaboom!
  4. Flixel Power Tools v1.6 released including FlxControl
  5. Flixel Power Tools v1.5 - A monster of an update!
  6. FlxScreenGrab and FlxScrollZone added to Flixel Power Tools
  7. Flixel Power Tools v1.3 - Now Flixel 2.5 compatible!
  8. FlxHealthBar added to Flixel Power Tools

3 Responses

Leave a comment

Make yourself heard