Page 1 of 1

Drawing GUI health bar

Posted: Sat Feb 19, 2022 6:22 am
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.

Re: Drawing GUI health bar

Posted: Sat Feb 19, 2022 1:05 pm
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).