How do I make an imagelike health bar [solved]

Get help using Construct 2

Post » Sat Jul 25, 2015 11:30 pm

Hello.

So I am trying to make a health bar Zelda like, with hearts or whatever image you like.

Lets say you have 3 hearths and whenever you get hit you lose 1, and when you lose all 3 you die. Alright so I found this tutorial but I can't seem to put it to use to such a thing:I don't really care for the buttons, I guess that's the way to explain how it works but can't seem to apply it to an actual game and I do believe it has to be easier to do so.

I've set the hearths, but I don't know how to exactly make the hearts become the global variable for health points. I suppose I have to do something like whenever you lose 1 hp withdraw 1 heart, but can't seem to get it right.

Anyone has some experience with this matter would be appreciated.

Thanks!
Last edited by Smileh on Sun Jul 26, 2015 12:41 am, edited 1 time in total.
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Sun Jul 26, 2015 12:14 am

I made a game with this kind of health bar, it is very simple (don't be scared by the length, it is very detailed) :
- create a "heart" sprite
- create a specific layer to put the "health bar" (can be skipped)
- create an event at the start of layout (or at the start of your game) :
repeat 3 times :
create heart on layer "health bar" in (50+50*loopindex() , 50)

this create the hearts in (50,50) ; (100,50) ; (150,50)
the values "50" can be replaced if you want to place your hearts at a different position.
- add a condition to the event where the player lose a life, you must already have created :
heart : pick nearest to (720, 0)
this pick the heart at left (even if there is more or less hearts)
You can also change the value "720"
- add a sub-condition to this event :
compare 2 values : heart.count > 0
- and the action corresponding :
heart : destroy
- you can add a "Else" condition : that means the player lose, there is no heart left.


in few words:
repeat 3 times : create heart on layer "health bar" in (50+50*loopindex() , 50)
heart : pick nearest to (720, 0)
- if heart.count > 0 : destroy heart
- else : player lose
B
8
S
1
Posts: 76
Reputation: 628

Post » Sun Jul 26, 2015 12:28 am

[edit] is it me or you just have removed your message?

yes, it should work
I think the detection polygons aren't well defined, or the collisions are maybe deactivated.
you can try the condition: "Player is overlapping X"
B
8
S
1
Posts: 76
Reputation: 628

Post » Sun Jul 26, 2015 12:30 am

Yeah I deleted it because I made it to work. probably what you're saying was the problem I tried with every X seconds and it worked just fine.

I think this way is easier for me but thank you very much for your help, might come handy in the future!

Cheers
B
14
S
5
Posts: 248
Reputation: 1,705

Post » Sun Jul 26, 2015 12:40 am

you're welcome! :)
There is often many ways to do something, I just suggested one way, certainly not the best. In that case, your way is effectively better, I think.

don't forget to edit your first post and add [solved]
B
8
S
1
Posts: 76
Reputation: 628

Post » Sun Jul 26, 2015 12:41 am

Cheers buddy, you're awesome!
B
14
S
5
Posts: 248
Reputation: 1,705


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests