ATLTransform on imagebutton hover not working

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
Kinmoku
Miko-Class Veteran
Posts: 522
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

ATLTransform on imagebutton hover not working

#1 Post by Kinmoku » Tue Feb 11, 2020 5:25 am

Hi all,

I have an ATL Transform I'd like to use when hovering over an imagebutton. Here's the transform:

Code: Select all

transform choicehover:
    on show:
        crop_relative True
        alpha 0 crop (0,0, 0.0, 1.0) xoffset 0
        linear 0.15 crop (0,0, 0.5, 1.0) xoffset 0
        linear 0.25 alpha 1.0 crop(0,0, 1.0, 1.0 ) xoffset 0
        
    on hide:
        crop_relative True
        alpha 1.0 crop (0,0, 1.0, 1.0) xoffset 0
        linear 0.25 crop (0.5, 0, 1.0, 1.0) xoffset 288
        linear 0.15 alpha 0.0 crop(1.0,0, 1.0, 1.0 ) xoffset 575
I want the "hover" image to wipe on, then wipe off. It works for my menu choices, but I can't get it working on imagebuttons.

Code: Select all

            imagebutton idle "gui/auto_off.png" selected_idle "gui/auto_select.png" hover "gui/auto_on.png" hovered choicehover clicked Preference("auto-forward", "toggle") focus_mask None
This brings up the error report:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/explore.rpy", line 2136, in script call
    call screen table_search
  File "game/explore.rpy", line 2485, in script call
    call fortune_memory
  File "game/memories.rpy", line 4613, in script
    menu:
TypeError: list indices must be integers, not ATLTransform
I also tried "at choicehover" at the end of the imagebutton statement, and that didn't crash it, but it didn't play the animation, either.

Any ideas? :?:

User avatar
RicharDann
Veteran
Posts: 263
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: ATLTransform on imagebutton hover not working

#2 Post by RicharDann » Tue Feb 11, 2020 10:33 am

According to the documentation here: https://renpy.org/dev-doc/html/screens.html#button says that the hovered property expects an action, or a list of actions, not an ATL transform, that could be the cause of the error.

You could try adding a hover clause to your transform:

Code: Select all

transform choicehover():
    on hover:
        crop_relative True
        # etc.
And at choicehover in the button.
The most important step is always the next one.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 522
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: ATLTransform on imagebutton hover not working

#3 Post by Kinmoku » Tue Feb 11, 2020 11:05 am

Hey thanks for replying :)

So it *kind of* works. It doesn't crash, so that's better, but the animation only works 25% of the time (when more directly hovered over). The other times, it continues to show the idle image...so I guess it's struggling to decide what to do on hover.

It's a small button, 54x44, so maybe that's the reason? My code is below. I adjusted the transform to the correct pixel offsets so renamed it "imagehover".

Code: Select all

transform imagehover:
    on hover:
        crop_relative True
        alpha 0 crop (0,0, 0.0, 1.0) xoffset 0
        linear 0.15 crop (0,0, 0.5, 1.0) xoffset 0
        linear 0.25 alpha 1.0 crop(0,0, 1.0, 1.0 ) xoffset 0
        
    on hide:
        crop_relative True
        alpha 1.0 crop (0,0, 1.0, 1.0) xoffset 0
        linear 0.25 crop (0.5, 0, 1.0, 1.0) xoffset 27
        linear 0.15 alpha 0.0 crop(1.0,0, 1.0, 1.0 ) xoffset 54
In screens:

Code: Select all

            imagebutton idle "gui/auto_off.png" selected_idle "gui/auto_select.png" hover "gui/auto_on.png" clicked Preference("auto-forward", "toggle") focus_mask None at imagehover
Also, if button is selected, the animation doesn't work at all.

User avatar
RicharDann
Veteran
Posts: 263
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: ATLTransform on imagebutton hover not working

#4 Post by RicharDann » Tue Feb 11, 2020 3:23 pm

This is only a guess but I think that the cropping process is somehow interfering with the method Ren'Py uses to detect if the button is being hovered. Maybe because it changes the visibility or position of the image at the same time as the program is trying to see if the mouse is over it or not.
I tried using a different transform on a test project and it behaved as I expected. To make the animation work when selected I also had to add selected_hover and selected_idle to the atl:

Code: Select all

# made a simple transform to test
transform zooming:
    on hover, selected_hover:
        linear .25 zoom 1.5
    on idle, selected_idle:
        linear .25 zoom 1.
The most important step is always the next one.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 522
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: ATLTransform on imagebutton hover not working

#5 Post by Kinmoku » Wed Feb 12, 2020 4:41 am

Hmm...Good to know. I imagine that's what's going on. However, I got it working for Choice buttons: viewtopic.php?f=8&t=56835&p=520146#p520146

So, I tried to create a new (image) button this way (without text, using the image with "add") but it fails to play the animation :( I may do a frame by frame animation instead...Or change the transform altogether.

Post Reply

Who is online

Users browsing this forum: Google [Bot], SowaKisa