transform inside a button ?

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
jack_norton
Lemma-Class Veteran
Posts: 4085
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

transform inside a button ?

#1 Post by jack_norton »

I am having trouble doing something that I think can be done, but I'm not entirely sure how :)
In short: I have buttons that pops up (zooming in/out) as you hover on them. And that works fine.
But I also have a text inside those buttons that I'd like to hide (alpha 0.0) when they're not hovered, and show (alpha=1.0) when they're hovered.
I tried using an at transform clause in the button but it doesn't work (it ignores it and always displays the text with full alpha).
The code is below, ignore my custom coding stuff, the line in question is the last one (at ttext).
Am I missing something or perhaps it's not possible at all to have such behavior ? thanks!

Code: Select all

transform tsign:
    on hover:
        yoffset 50 zoom .3
        linear 0.3 yoffset 0 zoom 1.0
    on idle:
        linear 0.1 yoffset 50 zoom .3

transform ttext:
    on hover:
        alpha 0.0
        linear 0.5 alpha 1.0
    on idle:
        linear .3 alpha 0.0

screen map():
    add "map/basemap.jpg"
    for loc in map_system.list_locations(DayNight[CurTime]):
        button xcenter loc.x ypos loc.y at tsign:
            xsize 235 ysize 210 xpadding 0 ypadding 0 left_padding 8 top_padding 8
            action Return(loc.image)
            background "map/sign.png"
            add "map/%s.png" % loc.image
            text loc.name xcenter .5 ypos 45 size 36 outlines [(2,"#000")] at ttext
follow me on Image Image Image
computer games

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

Re: transform inside a button ?

#2 Post by m_from_space »

It's possible, you can use logic inside screen elements. Here is an example, make sure that you change the events inside your "ttext" transform accordingly:

Code: Select all

transform ttext:
    alpha 0.0
    on show:
        linear 0.5 alpha 1.0
    on hide:
        linear 0.3 alpha 0.0

screen map():
    default button_hovered = False
    button at tsign:
        # ...
        hovered SetScreenVariable("button_hovered", True)
        unhovered SetScreenVariable("button_hovered", False)
        showif button_hovered:
            text "Click me!" at ttext

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4085
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: transform inside a button ?

#3 Post by jack_norton »

Ah right, I didn't think about that! Just tried it and works, thanks a lot :)
follow me on Image Image Image
computer games

Post Reply

Who is online

Users browsing this forum: Milkymalk