Health icons - removing and adding

Get help using Construct 2

Post » Sun Nov 18, 2012 1:57 pm

Hi

I am trying to make a system that shows 3 health icons (hearts in this instance). When the player is hit it'll remove the furthest right icon until they are all gone.

Then, if you pick up a new health heart in the level I want to add a new heart up to the maximum of three.

I can get the health removing itself in a brute force method by manually assigning each heart a specific number (0,1,2) to coincide with the players health. But can't reverse the process when you pick up more health. So far I do this:
- when health = 2
- play the animation for heart 2 disappearing

But what do I do when I pick up more health, how do I say, health was 1, and now it's 2 so play the animation for heart 2 appearing.

I wanted to use a for each loop, and number them based on the sprite.x position but I couldn't get that working. I'm keen to learn to do things programmatically rather than brute force every time :)

Any ideas on the logic I should be using?

Thanks
Simon
B
8
S
2
G
1
Posts: 21
Reputation: 1,492

Post » Sun Nov 18, 2012 3:59 pm

You mean like the hearts in Zelda? There's a great example for that by 7Soul:

http://www.scirra.com/arcade/example/320/zelda-style-lifebar

(capx can be downloaded from the link in the description)
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Sun Nov 18, 2012 4:12 pm

You could simply have one animation from empty to full hearts and make the animation frame equal to the value of the health variable points.
So for example when health variable is 2, it will display frame two, wich has two hearts in the animation.
B
43
S
9
G
5
Posts: 231
Reputation: 7,291

Post » Sun Nov 18, 2012 4:42 pm

you can use visible/invisible
B
20
S
8
G
2
Posts: 122
Reputation: 3,202

Post » Mon Nov 19, 2012 11:54 am

Thanks Nimtrix, that tutorial has helped me - I can't quite get it to work automatically but it's closer than before :) (that tutorial has half health which I think has confused me a little with the extra code)

I'll work on it a bit more and see where I get to :)

Thanks again
Simon


B
8
S
2
G
1
Posts: 21
Reputation: 1,492

Post » Mon Nov 19, 2012 4:08 pm

Happy to help. With full hearts instead of half ones, you could do something like this:

zeldalifebar_edited.capx (r109)Nimtrix2012-11-19 16:08:33
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Tue Nov 20, 2012 10:34 am

Wow, thats really helpful Nimtrix.

I eventually got everything working, although it wasn't as easy as expected. I found that when that code was in a group it did not work at all, moving it outside of the group fixed it... I'm not sure why to be honest, everything else within my 'HUD' group works ok.

Simon
B
8
S
2
G
1
Posts: 21
Reputation: 1,492


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests