Imagebutton Question!

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
VimislikArt
Regular
Posts: 90
Joined: Sun Mar 06, 2016 6:50 pm
Projects: King of the Cul-De-Sac
Deviantart: vimislikart
itch: vimislikart
Location: Rochester, NY
Contact:

Imagebutton Question!

#1 Post by VimislikArt »

I have a hidden-picture-esque minipuzzle in my visual novel, using image buttons for the various clickable elements, and then using the "_hover" and "_idle" extensions on the image names to have the images change shape while the player hovers over them (so it makes a bowl of candy glow for instance, or a candle light up).

Is there a simple way for me to have the hover state remain on? Preferably, I'd like to keep the hover state up for a dialogue screen or two, and then reset it, but I can work around keeping it on for the duration of the puzzle. I know about a "_selected_idle" extension in the Ren'py documentation that appears to be what I'm looking for, but I'm unsure how to implement it?

Otherwise, I could probably set variables and if statements for each clickable, like I treat the candle in the code example below, but I'm sure there must be a quicker, easier way to do it. I have a few areas like this in my game where I'll be using code like this, so I'll be applying this lesson a few times.

Code for the screen:

Code: Select all

screen p2_puzzle_basement:

    imagebutton auto "p2_basement/bride_%s.png" xpos 840 ypos 140 focus_mask True action If(propsEnabled, Return ("bride"))
    imagebutton auto "p2_basement/candy_%s.png" xpos 0 ypos 300 focus_mask True action If(propsEnabled, Return ("candy"))
    imagebutton auto "p2_basement/door_%s.png" xpos 1320 ypos 45 xanchor 1.0 focus_mask True action If(propsEnabled, Return ("door"))
    imagebutton auto "p2_basement/rip_%s.png" xpos 980 ypos 290 focus_mask True action If(propsEnabled, Return ("rip"))
    imagebutton auto "p2_basement/skull_%s.png" xpos 620 ypos 60 focus_mask True action If(propsEnabled, Return ("skull"))
    imagebutton auto "p2_basement/snake_%s.png" xpos 390 ypos 145 focus_mask True action If(propsEnabled, Return ("snake"))
    imagebutton auto "p2_basement/soup_%s.png" xpos 600 ypos -2 xanchor 1.0 focus_mask True action If(propsEnabled, Return ("soup"))
    imagebutton auto "p2_basement/lights_%s.png" xpos 0 ypos 0 focus_mask True action If(propsEnabled, Return ("lights"))

    # We only want to display the key if the player has not collected it yet.
    if keyCollected == False:
        image "karah anger.png" ypos 165 xpos 140 zoom 0.75
        imagebutton auto "p2_basement/candle_%s.png" xpos 1000 ypos 10 focus_mask True action If(propsEnabled, Return ("key"))
    else:
        add "p2_basement/candlepressed.png" xpos 1000 ypos 10
        imagebutton auto "p2_basement/hole_%s.png" xpos 300 ypos 485 focus_mask True action If(propsEnabled, Return ("hole"))
        image "karah smile.png" ypos 165 xpos 50 zoom 0.75
Where the screen is called in the game:

Code: Select all

while True:
        $ propsEnabled = True
        call screen p2_puzzle_basement
        $ propsEnabled = False
        show screen p2_puzzle_basement
        show screen textbox_overlay

        if _return == "key":
            $ keyCollected = True
            show screen p2_puzzle_basement
            show screen textbox_overlay
            k "Okay, gateway to a dark dimension.  That's progress."

        elif _return == "candy":
            show screen p2_puzzle_basement
            show screen textbox_overlay
            k "Bram always gives out the best candy on Halloween."
            
            ETC., ETC., 
            
        elif _return == "hole":
            jump p2_basement_splitpath
            
Check out my VN, King of the Cul-De-Sac, currently in Open Beta production! Try it out HERE!

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Imagebutton Question!

#2 Post by philat »

See selected. https://www.renpy.org/doc/html/screens.html#imagebutton

Code: Select all

imagebutton auto "p2_basement/candle_%s.png" xpos 1000 ypos 10 focus_mask True action If(propsEnabled, Return ("key")) selected keyCollected

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]