How do i make a graphic health bar

Get help using Construct 2

Post » Wed Jan 16, 2013 6:55 pm

Hello all,

I was discussing with my partner as to the direction we wanted to go with our game and we came to a consensus to avoid using numbers wherever possible. With that in mind, I was hoping you lovely people here on the forums could help with my dilemma.

To cut a long story short, I was wanting to have a graphic show how much health the player has remaining, but I cant figure out how to attach a graphic to a variable. Basically we are shooting for a life bar similar to the ones used in the old Megaman X games. For instance, if the player has 20 health remaining out of 30 maximum the bar would show 20 horizontal bars out of a possible 30 bars. Any help on how to create a connection between the sprite and the health would be greatly appreciated.

As a side note, we also want to have pick ups that increase the value of the maximum health too. So if someone knows of a way to simplify the graphic so that we don't have to keep replacing it that would be awesome as well.

Thanks for the help,
Joe
B
12
S
1
G
1
Posts: 11
Reputation: 1,000

Post » Wed Jan 16, 2013 7:08 pm

When you update the score, do:

HealthBar set animation "20"

Have single animation frames in HealthBar for all the states you want to display.
mattharrington2013-01-16 19:08:42
B
6
S
2
G
3
Posts: 10
Reputation: 2,402


Post » Wed Jan 16, 2013 8:47 pm

Without having to use 30 different frames of an animation you could create 1 with all 30 heath slots then simply move the sprite backwards 10 pixels each time they loose a live. Hiding the front half behind another icon, or mask it off visually.

Or make one health tick. Then add as many as needed each time you pick up health or loose heath

eg:
On health added.
-> loop for current health -> create health tick sprite at previous health tick + 10


So if the player currently had 20 health points, it would loop 20 times adding another tick visually each time.justifun2013-01-16 20:50:14
B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Thu Jan 17, 2013 1:12 pm

While unfortunately I didn't have time to check back for replies last night, but I will check out the capx file in the evening when I get home tonight. Thank you all for the help and ideas, I greatly appreciate them!
B
12
S
1
G
1
Posts: 11
Reputation: 1,000

Post » Thu Jan 17, 2013 4:04 pm

Use a tiled background for the health bar. Have your little tick for one health bar as a single image and set it as the tiled bg. Then, have an event like

- Every Tick
-> HealthBar set Width to width of a single bar * Health

If you want to have some empty space between each bar just put a bit of transparent padding on the sides and dont crop it in the editor.
B
40
S
12
G
7
Posts: 603
Reputation: 7,646

Post » Thu Jan 17, 2013 6:55 pm

Will using a tiled background work if I want to have a shield as well that regenerates over time? For example:

If I want the shields to have a max amount that can regenerate, and I want to have health that does not regenerate.

Shield 0 < X < max (Increasing by 1 every x seconds until max value.)

Health 0 < x < max (Only increasing when a specific item is picked up)

I get that if I set the width to x*(health variable) but what would I do if I have a shield graphic? Would it be as simple at the health bar with another line that makes the (shield variable) an increasing over time array?

Again any discussion is appreciated, I still have a lot to learn on using Construct 2 as well as programming in general.
B
12
S
1
G
1
Posts: 11
Reputation: 1,000

Post » Thu Jan 17, 2013 7:32 pm

You could just use a solid green sprite and set the height to the value of health.
B
5
Posts: 8
Reputation: 766

Post » Thu Jan 17, 2013 9:18 pm

Is this what you're trying to do?

https://www.dropbox.com/s/qdqnsb691rowvey/shieldbar.capx

You may also be able to use local variables for the shield sprite itself, i'm not sure which is more correct but hopefully this helps.
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Thu Jan 17, 2013 11:19 pm

I will check out all the tips and capx files either tonight or tomorrow. Thanks again for all the support!
B
12
S
1
G
1
Posts: 11
Reputation: 1,000

Next

Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt and 31 guests