This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-12-01 13:08:45

Slacker101
Scratcher
Registered: 2007-07-23
Posts: 60

Health bar?

How canm you do health bars?

Offline

 

#2 2008-02-06 19:44:32

TyCamden
Scratcher
Registered: 2007-10-27
Posts: 5

Re: Health bar?

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

 

#3 2008-02-06 23:06:54

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: Health bar?

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

 

#4 2008-02-07 01:15:24

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Health bar?

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.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#5 2008-02-08 22:34:35

B-Reyn428
Scratcher
Registered: 2007-09-08
Posts: 55

Re: Health bar?

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  smile

Last edited by B-Reyn428 (2008-02-08 22:35:08)


http://img233.imageshack.us/img233/7682/mybannerblinkyd0675d390.gif
http://scratch.mit.edu/projects/B-Reyn428/673836

Offline

 

#6 2008-02-09 05:19:35

MyRedNeptune
Community Moderator
Registered: 2007-05-07
Posts: 1000+

Re: Health bar?

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  smile

That's just the method I use! A neat-looking one but takes quite a time to create.  smile


http://i52.tinypic.com/5es7t0.png I know what you're thinking! "Neptune! Get rid of those filthy advertisements and give us back the Zarathustra siggy, you horrible person!" Well, don't worry about it, the Zara siggy will be back soon, new and improved! ^^ Meanwhile, just do what the sig tells you to. >.>

Offline

 

#7 2008-02-09 06:31:54

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Health bar?

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.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#8 2008-02-09 12:31:07

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Health bar?

http://scratch.mit.edu/projects/Mayhem/96117

My sample health bars project


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#9 2008-02-09 17:48:56

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Health bar?

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

 

#10 2008-02-09 17:52:04

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Health bar?

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)


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#11 2008-02-09 18:04:40

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Health bar?

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

 

#12 2010-05-17 23:23:25

IceFire10
Scratcher
Registered: 2010-05-17
Posts: 3

Re: Health bar?

[blocks]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![/blocks]

Offline

 

#13 2010-05-17 23:25:31

IceFire10
Scratcher
Registered: 2010-05-17
Posts: 3

Re: Health bar?

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

Offline

 

#14 2010-05-18 07:30:33

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Health bar?

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  smile
In due time, people will notice your thread - and they did, just look at Paddle2See's post.

Offline

 

Board footer