How do I make a simple health bar? capx attatched

  • Hello,thank you for the help. I am struggling a bit with events.

    How do I make the player lose a heart every time he is hit?

    I have this health bar animation.

    I have one even > at start of layout, set health animation to frame 4.

    Thanks all

  • Have a global variable for health set to 3 by default.

    When hit subtract one from global variable.

    Set health bar animation frame to global variable.

  • Thanks, how do I set the heathbar animation to the global variable though?

  • Every tick : set health.animationframe to global variable. You pick it from the object, set frame.

  • Thanks buddy, I will try that.

  • Every tick : set health.animationframe to global variable. You pick it from the object, set frame.

    Use "Every tick" is not a wise option.. just IMHO. it is unnecessary use

    It is like force the CPU doing something every tick change the animation frame which is useless if nothing change. So I think that is not a good programming design

    Try this example :)

    https://www.dropbox.com/s/zu38dqshelmku6r/Health_Bar.c3p?dl=0

    I prefer this example which only change the animation frame when needed (on collision.. or something that cause life decrease) not every tick.

    ================

    more tips from founder:

    construct.net/en/make-games/manuals/construct-3/tips-and-guides/performance-tips

  • Try this example :)

    https://www.dropbox.com/s/zu38dqshelmku6r/Health_Bar.c3p?dl=0

    Thank you very much for this Javanie, I really like how this is done. Thanks as well pilpgam, I do try and avoid every tick.

    Its all been useful because id wasn't even thinking global variables until plinkie mentioned them.

    Slowly learning which is positive, but it seems I have some basic knowledge gaps. :-(.

    Thanks all

  • Try this example :)

    https://www.dropbox.com/s/zu38dqshelmku6r/Health_Bar.c3p?dl=0

    This works really well. Thank you.

    I have used this new knowledge and done the events so when the player picks up a potion he picks up the health, it works but wondering if it looks ok? Its my first time using functions. I didnt use another global variable.

    Thanks buddy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > Every tick : set health.animationframe to global variable. You pick it from the object, set frame.

    Use "Every tick" is not a wise option.. just IMHO. it is unnecessary use

    It is like force the CPU doing something every tick change the animation frame which is useless if nothing change. So I think that is not a good programming design

    pilpgam

    That was just used in response to how to set a global variable as the knowledge of op seems like beginner. If you look in my original post to the question you will see how I put 'on hit' adjust health which would be a trigger. Also I think my example is better as it accomplishes everything in one event, where the animation frame number matches the global variable. Aside from that, setting an animation frame every tick has minimal effect, you must be thinking of text.

  • pilpgam

    That was just used in response to how to set a global variable as the knowledge of op seems like beginner. If you look in my original post to the question you will see how I put 'on hit' adjust health which would be a trigger. Also I think my example is better as it accomplishes everything in one event, where the animation frame number matches the global variable. Aside from that, setting an animation frame every tick has minimal effect, you must be thinking of text.

    plinkie

    okay.. thankyou very much for the input and insight about this method.

    I am just beginner... really appreciate your for the example, help me understand another things. Thanks.

  • I will try both methods. It's good to learn different ways of working. I appreciate the help from all of you :-).

    I'm probably more of a begginer than any of you!

  • add the health before you change the health bar, otherwise the health bar will set to the previous amount of health.

    destroy the potion in the collision event otherwise you destroy every single potion because the function doesn't specify which potion to delete

  • Thanks dude,

    like this? > it works well.

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