Making An Imagebutton's idle image fade to it's hover image?

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
Velvetique
Newbie
Posts: 15
Joined: Tue Mar 14, 2017 10:37 pm
Contact:

Making An Imagebutton's idle image fade to it's hover image?

#1 Post by Velvetique »

Hey there! So, I'm working on my game and I sort of am hitting a snag in how I want it to look.

So, I have an image button, and as a standard for them they have the idle image and the image for when the mouse hovers on them. It does this switch instantly.

What I'm struggling with is that instead of having it just instantly switch, I'd like if they could fade in and out of eachother, kind of like so (apologies for the ugly gif):

Image

For reference, here's the two images I'm using:
idle
Image
hover
Image

If anyone could help me with this I'd be greatly appreciative!
Image Image

User avatar
dGameBoy101b
Regular
Posts: 31
Joined: Sun Aug 12, 2018 8:32 am
itch: dgameboy101b
Contact:

Re: Making An Imagebutton's idle image fade to it's hover image?

#2 Post by dGameBoy101b »

You can use the show button action with the hovered and unhovered attributes of a screen button to switch between two different screens of the idle button and the hovered button to use transitions between the two states. Here is an example.

Code: Select all

screen fadeButtonHover():
    modal false
    tag fadeButton1
    imagebutton:
        idle "button_hover.png"
        unhovered Show("fadeButtonIdle",transition=dissolve)
        action Jump("start")
screen fadeButtonIdle():
    modal false
    tag fadeButton1
    imagebutton:
        idle "button_idle.png"
        hovered Show("fadeButtonHover",transition=dissolve)
        action NullAction()
You can use any transition you want (including custom defined transitions) to switch between the two states or even have different states depending on which direction the button state is switching. This does mean you will have to layer screens for multiple buttons at the same time and ensure that each of those screens have modal set to false with unique tags for each button.

User avatar
Velvetique
Newbie
Posts: 15
Joined: Tue Mar 14, 2017 10:37 pm
Contact:

Re: Making An Imagebutton's idle image fade to it's hover image?

#3 Post by Velvetique »

Exactly what I was needing, thank you so much! This helps a ton.
Image Image

User avatar
dGameBoy101b
Regular
Posts: 31
Joined: Sun Aug 12, 2018 8:32 am
itch: dgameboy101b
Contact:

Re: Making An Imagebutton's idle image fade to it's hover image?

#4 Post by dGameBoy101b »

It might be possible to get this to work using an atl tranform with "on" event handlers, since the transform can be passed "hover" and "idle" events from the button, but I haven't been able to get it to work yet.

Post Reply

Who is online

Users browsing this forum: henne