Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 2D Health Bar

Author
Message
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 16th Feb 2010 08:02 Edited at: 15th Jun 2010 00:15
How do I make a health bar from a image based on the percentageh of my health witch is left?vhhnfyk

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Feb 2010 09:20
Here's a quick example just using a box to draw the health bar. change the maxlength variable to change the bar length to whatever you want. This doesn't change the health value, just the size of the bar. Use the left right arrow keys to increase or decrease the health.



If you want to use an image, create a sliver (maybe 1 pixel wide and however many high) of the image that you'd use as the "fill up". After getting the percentage, find the x2 of the maximum length based on the percentage of health. Create a loop from the start of the bar to the x2 value, and paste the sliver at each new x value building up the bar with your fill image. If the fill image changes or you want to use an image that isn't exactly the same for it's entire length, then store a copy of the complete fill bar on an offscreen bitmap and use copy bitmap to only copy the portion you need to screen 1 at the proper location:


The position is found the same way as in the example.

Enjoy your day.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 16th Feb 2010 22:31
Thanks Latch, the second one is what I need. But the third way is very helpful, I always knew you can copy from a off-screen bitmap but I could never figure it out.

For future perpose:



That should work right?

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Feb 2010 22:56
Yup.

Make sure to create the bitmap to the size you need. The copy bitmap function is sized from 0 to width-1 and 0 to height-1 so keep that in mind when retrieving values or you'll get an error. It's probably safe just to add an extra pixel or 2 to the dimensions so you have a little breathing room:

Sideways:


Up and Down:


Remember to read back the bitmap information in the correct direction for vertical bars or horizontal bars.

Enjoy your day.
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 17th Feb 2010 02:50
OK, thanks. Got it working, now I've got AI and special attacks to work on then I'll have the battle part of my game finished.

Login to post a reply

Server time is: 2024-04-24 04:16:32
Your offset time is: 2024-04-24 04:16:32