How to bring hovered imagebutton on top?

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
User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

How to bring hovered imagebutton on top?

#1 Post by Ocelot » Wed Sep 28, 2016 8:21 am

I have two buttons on screen defined like that:

Code: Select all

imagebutton auto 'images/menu/door_left_%s.png'  focus_mask "images/menu/door_left_mask.png"  action Quit(False)
imagebutton auto 'images/menu/door_right_%s.png' focus_mask "images/menu/door_right_mask.png" action Quit(False)
The problem is in "hovered" images: they are large and should partially cover other button. However it works properly only with right button. if I hovet on the left one, right door is drawn on top of left door hovered image.

I understand that this is happening because of drawing order of images. So I want to know how can I bring currently selected button to the top when it is in hovered state (and preferably to send it back when it is unhovered)

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to bring hovered imagebutton on top?

#2 Post by PyTom » Wed Sep 28, 2016 8:30 pm

There isn't a straightforward way of doing this. A non-straightforward way would be some sort of screen that changes the order of images.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to bring hovered imagebutton on top?

#3 Post by Ocelot » Thu Sep 29, 2016 4:06 am

Solved it. Here is what I have done:
  1. Added another two static images, same as idle state of my buttons, positioned the same way as my buttons, but drawn before them. Essentiallly hidden behind them. On second though I just added them to the background, but this might not be suited for all.
  2. Creates completely transparent image to be used as insensitive state.
  3. Made buttons to be sensitive only when no other button is focused by using hovered/unhovered actions to set screen variable.
Screen code example:

Code: Select all

default ch = None
background "bg room"
imagebutton auto 'images/menu/door_left_%s.png'  focus_mask 'images/menu/door_left_mask.png'  action Quit(False) insensitive "images/menu/none.png" hovered SetScreenVariable("ch", 'ld') unhovered SetScreenVariable('ch', None) sensitive ch == None or ch == 'ld'
imagebutton auto 'images/menu/door_right_%s.png' focus_mask 'images/menu/door_right_mask.png' action Quit(False) insensitive "images/menu/none.png" hovered SetScreenVariable("ch", 'rd') unhovered SetScreenVariable('ch', None) sensitive ch == None or ch == 'rd'
Alternative approaches are still welcome.
< < insert Rick Cook quote here > >

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to bring hovered imagebutton on top?

#4 Post by Alex » Thu Sep 29, 2016 12:52 pm

Try something like this

Code: Select all

screen button_one():
    textbutton "Test 1" action [[]] hovered Show("button_one") unhovered Hide("button_one") align (0.45, 0.52)
    
screen button_two():
    textbutton "Test 2" action [[]] hovered Show("button_two") unhovered Hide("button_two") align (0.5, 0.5)
    
screen button_three():
    textbutton "Test 3" action [[]] hovered Show("button_three") unhovered Hide("button_three") align (0.55, 0.48)
    
screen my_scr():
    use button_one
    use button_two
    use button_three
    
label start:
    "..."
    show screen my_scr
    "?"

Post Reply

Who is online

Users browsing this forum: No registered users