gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > How would you go about creating a Health Bar?

#49778 - lewisrevill - Tue Aug 02, 2005 12:56 pm

Hey I'm working in Mode 4 creating an original game. Im just wondering what would be the best way of creating a health bar. A sprite is not option due to space. Would I be right thinking, using a certain background and just drawing to that? Please help. Thank you

#49784 - strager - Tue Aug 02, 2005 1:56 pm

Well, if you could loose a few scan lines, why not switch to mode 0 (per say) durring VBlank time then set up an HBlank interrupt to switch back to mode 4? This would be the easiest way (other than sprites) to render a health bar (that I could think of...). Give it a try and see what happends.

#49793 - poslundc - Tue Aug 02, 2005 4:01 pm

Mode 4 consumes all of your BG VRAM so it would be very difficult to combine it with another mode unless you're prepared to also swap a lot of data (both your map and char data) in and out of the undisplayed buffer-half during VBlank.

If you can't afford a sprite, then pretty much all you can do is manually draw your health bar in, using your own sprite-drawing routines.

More reasons to use the map modes instead...

Dan.

#50036 - justinGBA - Thu Aug 04, 2005 6:44 pm

Well my idea for such screen GUI things, was to use up a spare background. make a map that is 256x256 but only use the portion that is the size of the screen. make tiles for letters of the alphabet, as well as any gui drawing stuff you may need. Then draw the letters tile by tile, along with your health bar in the locations of the map you need. Once you have a good set of functions for arranging tile in the map properly, you could in theory change each tile at runtime... makeing a health bar. thats what i would do, but i can't even get my sprite class to work, so maybe i'm wrong..

#50038 - poslundc - Thu Aug 04, 2005 6:49 pm

justinGBA wrote:
Well my idea for such screen GUI things, was to use up a spare background.


There are no spare backgrounds in Mode 4.

Dan.

#50041 - justinGBA - Thu Aug 04, 2005 7:16 pm

Ahh yes. My bad i saw a mode 0 in there and thought everyone was talking about mode 0.

#52837 - cooky - Sat Sep 03, 2005 8:09 pm

Simply stretch a 8x8 sprite the alotted distance. Then when you health reduces reduce the x axis stretch. (watch out though as stretching on the gba as with most transforms is not uniform (it streches in powers of twos i think) so you will need to flattern out the streching with some counter balancing mathmatics)

If you wanted you could even change its colour two from green to red maybe.
_________________
Rolling a six is unlikely but how do you know if you have never picked up the dice.
www.ceorron.co.uk

#52838 - tepples - Sat Sep 03, 2005 8:21 pm

Sprite scaling on the GBA isn't limited to factors of powers of 2, but it is limited to stretch factors of 256/x where x >= 128, meaning your 8x8 sprite can't be stretched more than by a factor of 2.

The right way to do a health bar in a bitmap mode, whether on the PC or on the GBA, is to draw a colored rectangle for the part that is there and a dark rectangle for the part that isn't there. Do you know how to draw a rectangle in mode 4?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.