[SOLVED] Color-changing bar

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
dellcartoons
Regular
Posts: 29
Joined: Sat Jul 13, 2019 3:35 pm
Contact:

[SOLVED] Color-changing bar

#1 Post 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
Last edited by dellcartoons on Sun Apr 11, 2021 5:05 pm, edited 1 time in total.

errowr
Newbie
Posts: 6
Joined: Sat Apr 10, 2021 9:24 am
Contact:

Re: Color-changing bar

#2 Post 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.
Last edited by errowr on Mon Apr 12, 2021 5:18 am, edited 1 time in total.

dellcartoons
Regular
Posts: 29
Joined: Sat Jul 13, 2019 3:35 pm
Contact:

Re: Color-changing bar

#3 Post 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

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Color-changing bar

#4 Post by Remix »

https://github.com/RenpyRemix/extra-animated-value

Also includes value that updates as the bar moves...
Frameworks & Scriptlets:

dellcartoons
Regular
Posts: 29
Joined: Sat Jul 13, 2019 3:35 pm
Contact:

Re: Color-changing bar

#5 Post by dellcartoons »

Okay, that looks like what I want

Thank you

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot], Ocelot, Semrush [Bot]