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
1 2 3 4 5 6 7 8 9 |
// 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
- Flixel Power Tools v1.9 Released
- Flixel Power Tools v1.8 Released - Let's get clicky
- Flixel Power Tools v1.7 - Kaboom!
- Flixel Power Tools v1.6 released including FlxControl
- Flixel Power Tools v1.5 - A monster of an update!
- FlxScreenGrab and FlxScrollZone added to Flixel Power Tools
- Flixel Power Tools v1.3 - Now Flixel 2.5 compatible!
- FlxHealthBar added to Flixel Power Tools
3 Responses
Leave a commentMake yourself heard
FPT Classes
Hire Us
All about Photon Storm and our
HTML5 game development services
Recent Posts
OurGames
Filter our Content
- ActionScript3
- Art
- Cool Links
- Demoscene
- Flash Game Dev Tips
- Game Development
- Gaming
- Geek Shopping
- HTML5
- In the Media
- Phaser
- Phaser 3
- Projects
Brain Food
I know you’re focusing more on html5 nowadays, but a quick question on this.
Is there any easy way to recycle these in Flixel? I’m working with a game that requires a whole lot of enemies onscreen, and for a lot of them I’d like to be using FlxBar – I get the impression memory would be more manageable if I recycled these, but if there’s a straightforward way to do it, I’m not seeing it.
Thanks.
I would say it would be as simple as reinitializing it with a new parent/value. Haven’t taken a look at the class yet though, so I wouldn’t know if that could be done.
How do you set the color of those bars?