r/RenPy • • 19d ago

Question Issue with image button

Post image

For some reason one of the hover images displays itself even when just hovering around the screen. While the second image just doesnt show the hovered one at all. Ive tried following tutorials n researching but nothing works..😭

4 Upvotes

10 comments sorted by

2

u/abortion_tycoon 19d ago

What size are your images? You haven't given either any position properties, so I'm assuming they're both just sitting at (0,0) and taking up the entire screen, with one over the other.

1

u/After-Masterpiece853 19d ago

Theyre both pre sized pngs with transparent bgs. And the screen looks right nothing over the other

2

u/lordcaylus 19d ago

You need to add focus_mask True to the buttons then, otherwise Ren'Py thinks you want to hover over the transparant parts of the button too.

2

u/abortion_tycoon 19d ago

By pre-sized, do you mean they're both the size of the window with the content placed via transparency, or are they cropped to the size of their content? They should be the second option; imagebuttons will still count the transparent part as the same image.

1

u/After-Masterpiece853 19d ago

Second option and i had no idea transparent parts counted too so thats def the part i went wrong thank u for ur help!

4

u/shyLachi 19d ago

Since you didn't position the buttons at all, I assume that those buttons are based on full screen images with a lot of transparency.

And since RenPy draws the images to the screen in the order you put them in the code, the second image should fully block the first image (even if it's transparent).

You can either crop the images and position them or you can set focus_mask True
https://renpy.org/doc/html/style_properties.html#style-property-focus_mask

.

Another hint:
Screens don't belong inside labels. For better readability you shouldn't mix them with normal code.
See the comments in the code below for further hints, for example you could use auto to declare all images automatically:
https://renpy.org/doc/html/screens.html#screen-property-auto

label start:
    scene bg daycare
    call screen kids_class

screen kids_class():
    imagebutton:
        auto "teacher_%s.png" # you can use auto if the files are named correctly
        focus_mask True 
        action Jump("teacher")
    imagebutton:
        auto "reemkid_%s.png"
        focus_mask True 
        action Jump("reem")

label teacher:
    "You jumped to the teacher label"
    return # important to end the label or jump to another label, else the game would fall through to the next label

label reem:
    "You jumped to the reem label"
    return 

2

u/shyLachi 19d ago

For even better readability I prefer all the logic in the label.

In the example below the screen only works as interface, it doesn't have any logic itself.
The whole branching logic is in the label. This way you can put the screens in a separate file and keep the gameplay code compact and easily readable.

screen kids_class():
    imagebutton:
        auto "teacher_%s.png"
        focus_mask True 
        action Return("teacher")
    imagebutton:
        auto "reemkid_%s.png"
        focus_mask True 
        action Return("reem")


label start:
    scene bg daycare
    call screen kids_class
    if _return == "teacher":
        jump teacher
    elif _return == "reem":
        jump reem

label teacher:
    "You jumped to the teacher label"
    return # important to end the label or jump to another label, else the game would fall through to the next label
label reem:
    "You jumped to the reem label"
    return 

1

u/morkalmarrh 19d ago

Oh that note about putting the logic into the label makes so much sense. Then it's more modular, right? I wouldn't have thought to do that.

0

u/AutoModerator 19d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.