Drawing GUI health bar

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
WizardofChaos
Posts: 17
Joined: Tue Jan 11, 2022 8:43 pm

Drawing GUI health bar

Post by WizardofChaos »

Hi there! I'm struggling with trying to find an appropriate method to create a scaling GUI health bar. I have the graphic I want to use and I want to change the size of said graphic as the player's health goes up or down (and having another one to act as a speedometer would also be nice).

I can't find a good way to get this done looking at the Irrlicht IGUIImage documentation. Would I use the setMaxSize functions from the base class to change the size of the element, or is there a better way? Is there some way to set up the bounds of the image? Any way to scale the element would be helpful - the only scaling I saw was done with the alignment and the scale-to-fit parent thing.
Local man gets so irritated with modern space sims that he starts writing his own
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Drawing GUI health bar

Post by CuteAlien »

If you use Irrlicht svn trunk you can use IGUIImage::setDrawBounds (which was pretty much coded for this use-case).

In Irrlicht 1.8 you probably have to figure out some workaround. Like setScaleImage(false) and then change the actual size with setRelativePosition for example. If you still want a border drawn then put another element behind it which draws the border.

Or another solution could be to give the element an invisible parent element (like an empty static-box or IGUIImage without borders) and then resize the parent to a fraction of the size of the child. Which will automatically clip it's child (pretty much same as above, but has the advantage that you don't need another non-gui variable to remember the original size, thought also disadvantage of being a tiny bit slower).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply