Imagebutton action that rotates an 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
frankfrankstud
Newbie
Posts: 12
Joined: Tue Feb 09, 2021 3:42 am
Contact:

Imagebutton action that rotates an image

#1 Post by frankfrankstud »

Hi all,

What's the best way to create an action on an imagebutton within a screen that rotates an image showing on the screen?

I basically want to create a puzzle where you have to turn buttons into the correct places to unlock something. The mechanics work perfectly, but I want to add an image that spins on top of the buttons just as a visual cue.

Thanks.

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

Re: Imagebutton action that rotates an image

#2 Post by m_from_space »

Something like this is possible:

Code: Select all

screen rotscreen():
    default ang = 0
    textbutton "Rotate" action SetScreenVariable("ang", ang+1)
    add "eileen":
        rotate ang

frankfrankstud
Newbie
Posts: 12
Joined: Tue Feb 09, 2021 3:42 am
Contact:

Re: Imagebutton action that rotates an image

#3 Post by frankfrankstud »

m_from_space wrote: Tue Mar 02, 2021 6:59 am Something like this is possible:

Code: Select all

screen rotscreen():
    default ang = 0
    textbutton "Rotate" action SetScreenVariable("ang", ang+1)
    add "eileen":
        rotate ang
Unfortunately it keeps doing the same rotation over and over again (and even though the action is only added to one imagebutton on the screen, they all cause it to happen) but thank you for somewhere to start!

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Imagebutton action that rotates an image

#4 Post by _ticlock_ »

frankfrankstud wrote: Wed Mar 03, 2021 7:52 am and even though the action is only added to one imagebutton on the screen, they all cause it to happen
You need to use a single variable for each image to ratate them individually. For example for better organizing you can use list or dict:

Code: Select all

default angles = [0,0]
screen rotscreen():
    vbox:
        imagebutton idle Text("Rotate") action SetDict(angles, 0,  angles[0]+90)
        add "eileen":
            at rot(angles[0])
        imagebutton idle Text("Rotate") action SetDict(angles, 1,  angles[1]+90)
        add "eileen":
            at rot(angles[1])

transform rot(angle):
    linear 0.5 rotate angle
frankfrankstud wrote: Wed Mar 03, 2021 7:52 am Unfortunately it keeps doing the same rotation over and over again
You probably causing the screen to replace itself. As a result, your screen variables are resetting to default values. You can use a global variable, instead of a screen variable.

frankfrankstud
Newbie
Posts: 12
Joined: Tue Feb 09, 2021 3:42 am
Contact:

Re: Imagebutton action that rotates an image

#5 Post by frankfrankstud »

_ticlock_ wrote: Wed Mar 03, 2021 10:57 am
frankfrankstud wrote: Wed Mar 03, 2021 7:52 am and even though the action is only added to one imagebutton on the screen, they all cause it to happen
You need to use a single variable for each image to ratate them individually. For example for better organizing you can use list or dict:

Code: Select all

default angles = [0,0]
screen rotscreen():
    vbox:
        imagebutton idle Text("Rotate") action SetDict(angles, 0,  angles[0]+90)
        add "eileen":
            at rot(angles[0])
        imagebutton idle Text("Rotate") action SetDict(angles, 1,  angles[1]+90)
        add "eileen":
            at rot(angles[1])

transform rot(angle):
    linear 0.5 rotate angle
frankfrankstud wrote: Wed Mar 03, 2021 7:52 am Unfortunately it keeps doing the same rotation over and over again
You probably causing the screen to replace itself. As a result, your screen variables are resetting to default values. You can use a global variable, instead of a screen variable.
Thank you. Yes, I created one variable for each image and used a global variable already. I think the main issue is that the screen jumps somewhere else, which then calls the screen again if a code is inputted wrong - which means that it just keeps repeating the same rotate. I'm still working out how to get through that, but thank you.

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

Re: Imagebutton action that rotates an image

#6 Post by m_from_space »

@_ticclock_'s example works fine here, I can do other stuff in the meantime and the objects don't just randomly rotate. They shouldn't either because I don't click their buttons. What are you doing inside your code that leads to the objects to rotate (to their defaults?)

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Imagebutton action that rotates an image

#7 Post by _ticlock_ »

m_from_space,
m_from_space wrote: Sat Mar 06, 2021 3:38 am I can do other stuff in the meantime and the objects don't just randomly rotate. They shouldn't either because I don't click their buttons.
I put the variable angles to globals to avoid rotation due to screen resetting. That is probably why "the objects don't just randomly rotate".
m_from_space wrote: Sat Mar 06, 2021 3:38 am What are you doing inside your code that leads to the objects to rotate (to their defaults?)
I am not sure what you mean. The objects rotate from the previous state to the new state by transform rot.

The new state is defined by variables in the list angles. The previous state is defined either by 0 degrees (if the screen was hidden and shown again) or by the previous angle of the displayable(object) (if the screen is still shown).

Let me know if you meant something else.

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

Re: Imagebutton action that rotates an image

#8 Post by m_from_space »

_ticlock_ wrote: Sat Mar 06, 2021 10:02 amLet me know if you meant something else.
Sorry, I forgot the quotes in my post and meant to reply to OP. I just meant that your example works fine for me while frankfrankstud states that the objects rotate sometimes. Also my "@" wasn't properly used. :D So again, your example is great. ^^

Post Reply

Who is online

Users browsing this forum: No registered users