using crop on imagebutton hover

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
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

using crop on imagebutton hover

#1 Post by Kia »

I've tried to make an expandable button with crop but looks like this one going to be tricky. I've been changing values for half a day but can't achieve this effect. please help.
tyu7.jpg
this is what I've got so far:

Code: Select all

transform btnstat:
    on hover:
        linear 1.0 size (200, 50) crop (0, 0, 200, 50)
    on idle:
        linear 1.0 size (20, 50) crop (0, 0, 20, 50)

label keys:
    screen key1:
        imagebutton:
            xalign 0.4
            yalign 0.74
            idle "ui/2.png"
            hover "ui/2.png"
            focus_mask True
            action Jump("jmp1")
            at btnstat
    show screen key1
return
I know with adding pos (0.47,0.74) and pos (0.4,0.74) I can achieve the effect I want but I'm looking for a more efficient way to do this since I'm positioning this on different spots of screen and I might even need to move it around (or drag)

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: using crop on imagebutton hover

#2 Post by PyTom »

You'd have to use a CDD to make a drag-to-expand button like you want. A click-to-expand button would be easy:

Code: Select all

default expanded = False

hbox:
     textbutton "Expand" action SetScreenVariable("expanded", True)
     if expanded:
           textbutton "Clickable" action Return(True)
That might give you enough of a molly-guard for your purposes.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: using crop on imagebutton hover

#3 Post by Kia »

actually it's not drag to expand. it just a button that expands on hover. my only problem is I cant get it expand from one sides and it expands to the both side. is there anything like anchor that I can add to crop (0, 0, 20, 50) so it know from witch side it should crop? something similar for size can be useful when I want to keep the cropped image at center.

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: using crop on imagebutton hover

#4 Post by Milkymalk »

Your problem is that you use xalign. It sets the anchor, which you want to be at x=0. Use xpos instead and you should be fine.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: using crop on imagebutton hover

#5 Post by PyTom »

I'd suggest using xpos and ypos to position it, rather than xaligh and yalign. The later two set xanchor and yanchor as well, which is what is causing your problem.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: using crop on imagebutton hover

#6 Post by Kia »

like always I made the most simple mistake possible. thank you ^_^

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: using crop on imagebutton hover

#7 Post by Kia »

now for expanding in all for directions what do you suggest?
I've got something like this but the animations don't look as smooth.

Code: Select all

transform w4w:
    on hover:
        linear 0.5 size (100, 100) crop (0, 0, 100, 100) pos(-50,-50)

    on idle:
        linear 0.5 size (20, 20) crop (50, 50, 10, 10) pos(0,0)

label k4:
    screen k:
        hbox:
            xpos 0.3
            ypos 0.3
            imagebutton:
                idle "ui/3.png"
                hover "ui/3.png"
                focus_mask True
                action Jump("jmp1")
                at w4w
    show screen k
return
I'll start messing with values to see what I can get till then.

Post Reply

Who is online

Users browsing this forum: No registered users