Page 1 of 1

[SOLVED] Color-changing bar

Posted: Sun Apr 11, 2021 3:02 pm
by dellcartoons
I have a health bar

I want the bar to change color according to how healthy you are. For instance, if you are at full health the bar is green. If you are at half your health the bar is yellow. If you are severely injured, almost dead, the bar should be red

I've created several images for the bars, but I have no idea how to tell the program which one to use

Basically:

Code: Select all

style bar:
    ysize gui.bar_size
    left_bar Frame("gui/bar/left.png", gui.bar_borders, tile=gui.bar_tile)
    right_bar Frame("gui/bar/right.png", gui.bar_borders, tile=gui.bar_tile)
except left.png should be whichever bar is appropriate

Thank you

Re: Color-changing bar

Posted: Sun Apr 11, 2021 4:04 pm
by errowr
Maybe create an image using a condition switch which shows the appropriately colored image depending on your health variable.

Code: Select all

image lifebar_player = Composite((1200, 720),
    (0, 0), ConditionSwitch(
        "health > 5",  "greenbar.png",  
        "health == 5",  "yellowbar.png",  
        "health < 5",  "redbar.png",))
I think this code could be placed just about anywhere because images get loaded first.

Re: Color-changing bar

Posted: Sun Apr 11, 2021 4:55 pm
by dellcartoons
The image lifebar_player = Composite((1200, 720), keeps coming up w/ "not terminated with a newline. (Check strings and parenthesis.)"

Aside from that I can get the image to work

But where do I put the code so that the bar color changes?

Thank you

Re: Color-changing bar

Posted: Sun Apr 11, 2021 4:57 pm
by Remix
https://github.com/RenpyRemix/extra-animated-value

Also includes value that updates as the bar moves...

Re: Color-changing bar

Posted: Sun Apr 11, 2021 5:04 pm
by dellcartoons
Okay, that looks like what I want

Thank you