How do I set a health bar width to variable based on % only?

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • One of my projects has multiple variables I'd like to display as bars that shrink/grow based on the variable changes.

    The issue I keep running in to is when I set the bar width = to the variable number I end up with different sized bars. The different variables are ranged from 100 to 13000 and the larger number produces a bar that goes off the screen.

    I wanted to know if anyone has a simple way to shrink the bar width based on % instead of a number value, What i mean is; instead of showing 80/100 I would rather like to show 80%/100% so the bar that happens to be 30 pixels long will shrink percentage wise rather than grow to 100 pixels and then start to shrink.

    Please let me know if you need clarification, It's a bit late and I know I start to get goofy after midnight haha.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you need two variabled: current health + Max health

    width = (Current Health / Max Health) * Max Size of Bar

    For example, if you have 30 HP left out of 50 and the bar has a max width of 150 pixels, the bar will be 90 pixels wide.

    hope this helps you

    EDIT: Sorry, was a mistake in my previous formula.

  • you need two variabled: current health + Max health

    width = (Current Health / Max Health) * Max Size of Bar

    For example, if you have 30 HP left out of 50 and the bar has a max width of 150 pixels, the bar will be 90 pixels wide.

    hope this helps you

    EDIT: Sorry, was a mistake in my previous formula.

    I tried this method and it doesn't seem to work. I end up with the current health variable dividing itself by the max width or "max health" veritable and only a sliver of the bar appears.

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