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.
-
goldo
- Regular
- Posts: 63
- Joined: Mon Jan 23, 2017 8:23 am
-
Contact:
#1
Post
by goldo » Thu Oct 29, 2020 8:55 am
Hi guys,
I'm trying to set a simple button layout where the alpha on each button changes when it's selected, idle or hovered over.
I want alpha to be:
* 1.0 if the button is selected or hovered
* 0.3 if the button is idle.
I thought this simple screen would do it:
Code: Select all
screen buttons:
default cl = "warrior.webp"
vbox xalign 0.5 yalign 0.5:
hbox:
for but in ["warrior.webp", "wizard.webp", "trader.webp"]:
button action (SelectedIf(but == cl), SetScreenVariable("cl", but)):
add but yalign 0.5:
idle_alpha 0.3
hover_alpha 1.0
selected_idle_alpha 1.0
selected_hover_alpha 1.0
textbutton "OK" action Return(True)
Unfortunately, this only works until a button is clicked. After that,
all buttons raise their alpha up to 1.0 until you hover over them, then unhover again
slowly. It's quite a mess.
What am I doing wrong?
Last edited by
goldo on Tue Dec 01, 2020 1:24 pm, edited 1 time in total.
-
_ticlock_
- Veteran
- Posts: 391
- Joined: Mon Oct 26, 2020 5:41 pm
-
Contact:
#2
Post
by _ticlock_ » Thu Oct 29, 2020 11:10 am
Hi
goldo,
I would change to imagebuttons and use transform to make a smooth alpha transition. Try this code:
Code: Select all
screen buttons:
default cl = "warrior.webp"
vbox xalign 0.5 yalign 0.5:
hbox:
for but in ["warrior.webp", "wizard.webp", "trader.webp"]:
imagebutton:
yalign 0.5
action (SetScreenVariable("cl", but))
idle but
selected cl == but
at alpha_transform
textbutton "OK" action Return(True)
transform alpha_transform:
alpha 0.3
on hover:
linear 0.25 alpha 1.0
on idle:
linear 0.25 alpha 0.3
on selected_hover:
linear 0.25 alpha 1.0
on selected_idle:
linear 0.25 alpha 0.8
-
goldo
- Regular
- Posts: 63
- Joined: Mon Jan 23, 2017 8:23 am
-
Contact:
#3
Post
by goldo » Thu Oct 29, 2020 2:04 pm
It works! Thank you very much!

Users browsing this forum: Google [Bot]