Page 1 of 1

Running a transform on click? - Solved

Posted: Sun Dec 31, 2017 6:09 pm
by Springroll Games
I want to have a button rotate when it's clicked.

Is there any way to run a transform when a button is clicked, or is the best way to show and hide the buttons so they can have on show/hide transforms?

Thank you.

Re: Running a transform on click?

Posted: Sun Dec 31, 2017 7:22 pm
by trooper6

Code: Select all

default degs = 0

init python:
    def make_rotate():
        global degs
        degs += 40

transform rotary(degrees=0):
    subpixel True
    linear 1.0 rotate degrees

screen button_test():
    textbutton _("Push Me") action Function(make_rotate) at rotary(degs)

label start:
    show screen button_test()
    "This is a tester showing how to have a button that rotates when clicked."
    return

Re: Running a transform on click?

Posted: Sun Dec 31, 2017 7:55 pm
by Springroll Games
Wow, thank you so much! This is perfect. I would never have thought of that, but it makes so much sense!

Re: Running a transform on click? - Solved

Posted: Sun Dec 31, 2017 8:15 pm
by trooper6
Hm...you know what? Here is a shorter version of the code that cuts out the function and just updates the degrees directly:

Code: Select all

default degs = 0

transform rotary(degrees=0):
    subpixel True
    linear 1.0 rotate degrees

screen button_test():
    textbutton _("Push Me") action SetVariable("degs", degs + 40) at rotary(degs)

label start:
    show screen button_test()
    "This is a tester showing how to have a button that rotates when clicked."
    return

Re: Running a transform on click? - Solved

Posted: Mon Jan 01, 2018 9:16 am
by Springroll Games
Sweet. I never quite know how Renpy's actions really work ^^; Thanks again!