Imagebutton - transition on interaction

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
paych3ck
Newbie
Posts: 1
Joined: Thu Jan 25, 2024 9:00 pm
Contact:

Imagebutton - transition on interaction

#1 Post by paych3ck »

Hello! I have the following idea. I would like to make it so that when hovering (and unhovering) over my imagebutton (changing from idle to hover state), the idle image is replaced with the hover image, with the option to add a transition effect (such as dissolve). As far as I understand, this feature is not available by default in the engine. Perhaps someone can guide me on the path to solving my question? In my implementation, I would prefer not to use solutions such as duplicating screens.

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Imagebutton - transition on interaction

#2 Post by m_from_space »

paych3ck wrote: Thu Jan 25, 2024 9:11 pm In my implementation, I would prefer not to use solutions such as duplicating screens.
I suggest using a normal (invisible) button and then just show an image underneath that uses showif statements and therefore can transform itself on hiding and showing.

Code: Select all

transform mytrans:
    alpha 0.0
    on appear:
        linear 0.2 alpha 1.0
    on show:
        linear 0.2 alpha 1.0
    on hide:
        linear 0.2 alpha 0.0
        
screen myscreen():
    default button_hovered = False
    button:
        action NullAction()
        hovered SetScreenVariable("button_hovered", True)
        unhovered SetScreenVariable("button_hovered", False)
        xysize (200, 50) # has to be the same size as the images
        showif button_hovered:
            add "hover_button_image" at mytrans
        else:
            add "idle_button_image" at mytrans

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]