How canm you do health bars?
Offline
My initial thought is to have a Variable with the Health value in it. Then also have a Sprite for the health bar. If 20 is the max health, and the variable has the value of 20, then the Costume of the health bar would appear as the full health bar. You could then have multiple costumes for this health bar, and you could script that depending on the value of the Health variable, it would display a different Costume (to give the appearance of the health bar emptying or filling.
My second thought is that you could have the health bar with 11 Costumes (one for zero percent full, then one for each value from 10 to 100 percent full). You could have the system calculate the percentage of actual health versus max health, then show the appropriate costume as a percentage. This way, as you level up, and your max health increases, the health bar can show this value, relatively.
Last thought, look for games that use health bars, and see how they did it. You can learn a lot from looking at other peoples work.
Offline
One example is here:
http://scratch.mit.edu/projects/EdnaC/81880
This example "stamps" images of "health bars" onto the background. The demo is a sprite taken from: http://scratch.mit.edu/projects/EdnaC/81934 I used "stamping" because I'd rather play with programming than draw sprites. It's a good example of a (different) way to do health bars. Like most things you can program, there are many ways to do what you want.
TyCamden's idea of using costumes is easier to do (and would be more efficient/quicker). Using Costumes, you could check health, and just use the costume number to display whatever you'd like for that "health level".
-MrEd
Offline
A 3rd method would be to build the health bar out of multiple sprites and have those sprites set to show/hide depending on the value of variable "Health".
A 4th method - though better for a "heart" rather than a bar, would be to simple set the size of the health display to 10xvariable health (assuming health 1-10) so that the heart gradually shrinks.
Offline
I have used a different method in my game http://scratch.mit.edu/projects/B-Reyn428/79597
The health bar is made up of 3 sprites. One, in the back, is a red bar. Then there is a green bar on top of it that sets its x-position to the location of the red bar, minus the amount of your total health, plus your current health. (If you have a total of 100 health it would go to ["red bar" - 100 + (health)]. So as your health decreases, its x-position is lowered and it moves to the left, showing the red underneath. The final sprite is a copy of the background just to the left of your health, that goes to the front so that you can't see the rest of the green bar when it starts to move.
This is only one way to make the health bar, so if you know a better way, feel free to use your own
Last edited by B-Reyn428 (2008-02-08 22:35:08)
Offline
B-Reyn428 wrote:
I have used a different method in my game http://scratch.mit.edu/projects/B-Reyn428/79597
The health bar is made up of 3 sprites. One, in the back, is a red bar. Then there is a green bar on top of it that sets its x-position to the location of the red bar, minus the amount of your total health, plus your current health. (If you have a total of 100 health it would go to ["red bar" - 100 + (health)]. So as your health decreases, its x-position is lowered and it moves to the left, showing the red underneath. The final sprite is a copy of the background just to the left of your health, that goes to the front so that you can't see the rest of the green bar when it starts to move.
This is only one way to make the health bar, so if you know a better way, feel free to use your own![]()
That's just the method I use! A neat-looking one but takes quite a time to create.
Offline
You could do that with just two sprites, depending on the background colour of your screen. The Red Bar could be on top, but have a "hole" in the middle through which the green bar can be seen.
Offline
http://scratch.mit.edu/projects/Mayhem/96117
My sample health bars project
Offline
Perhaps someone should create a "Health Bars" gallery and show all the different approaches to Health bars, either from their own examples or by finding other people's good examples.
Offline
Heh - that's pretty much what I was trying to do, except I was collecting them in a single project (6 different methods so far)
Offline
I think that having a gallery with several small projects would make it easier for people to borrow ideas and code, and would make it easier for others to contribute ideas. But tutorial projects are good too.
I believe that there is already a gallery or two for tutorial projects like that. Could someone remind me where they are? (And add Mayhem's health-bar tutorial)
Offline
IceFire10 wrote:
HELP ME PLEASE!!!!!! I WANT TO MAKE A HEALTH BAR. AND WHEN THE FIRE OR GREEN ORB HITS ONE OF THEM, I WANT THE HEALTH BAR TO GO DOWN HELP!
http://scratch.mit.edu/projects/IceFire10/1057880
Hi,
Try not to spam in the future. People don't like it
In due time, people will notice your thread - and they did, just look at Paddle2See's post.
Offline