Health icons - removing and adding

0 favourites
  • 7 posts
From the Asset Store
Customize the animation of character when item changed
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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)

  • 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.

  • you can use visible/invisible

  • 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

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

    zeldalifebar_edited.capx (r109)

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)