Different 'on hide' transform depending on button clicked

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
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Different 'on hide' transform depending on button clicked

#1 Post by _ticlock_ »

Hello everyone,

I have a screen that is supposed to have different transform animation 'on hide' depending on what the user selects:

Code: Select all

transform hide_left:
    on hide:
    	xalign 0.5 yalian 0.5
    	linear xoffset -1000 alpha 0.0
transform hide_right:
    on hide:
    	xalign 0.5 yalian 0.5
    	linear xoffset +1000 alpha 0.0

screen some_screen:
    def on_hide_var = 0
    frame:
        if on_hide_var == -1:
		at hide_left
		timer 0.01 action Return()
        elif on_hide_var == 1:
	    at hide_right
	    timer 0.01 action Return()
        #...
    textbutton _('Left'):
        xalign 0.0 yalign 1.0
        action SetScreenVariable('on_hide_var', -1)
    textbutton _('Right'):
        xalign 1.0 yalign 1.0
        action SetScreenVariable('on_hide_var', 1)
I wonder if there is a way to perform it without a timer? Or just a better way to perform different transforms depending on the variable value.

Gouvernathor
Newbie
Posts: 23
Joined: Thu Aug 06, 2020 9:27 am
Github: Gouvernathor
Discord: Armise#6515
Contact:

Re: Different 'on hide' transform depending on button clicked

#2 Post by Gouvernathor »

Have you tried using [SetScreenVariable(...), Return()] as an action (list) ?

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

Re: Different 'on hide' transform depending on button clicked

#3 Post by _ticlock_ »

Gouvernathor wrote: Thu Jun 16, 2022 6:52 pm Have you tried using [SetScreenVariable(...), Return()] as an action (list) ?
No, it does not work like this. I believe renpy updates the screen after all actions and only if the control is not passed somewhere else.

Gouvernathor
Newbie
Posts: 23
Joined: Thu Aug 06, 2020 9:27 am
Github: Gouvernathor
Discord: Armise#6515
Contact:

Re: Different 'on hide' transform depending on button clicked

#4 Post by Gouvernathor »

This doesn't replace any and all ATL transform with an "on hide" clause (although you can easily convert your ATL transforms to ATL transitions), but you can use [With(moveoutright), Return()].
moveoutright isn't exactly the same as the transform you're using, but as I said you can convert yours to a valid transform using this https://www.renpy.org/dev-doc/html/atl. ... ransitions

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Different 'on hide' transform depending on button clicked

#5 Post by zmook »

_ticlock_ wrote: Thu Jun 16, 2022 4:22 pm I wonder if there is a way to perform it without a timer? Or just a better way to perform different transforms depending on the variable value.
I'm not sure I understand what you're looking for. Does this help?

https://www.renpy.org/doc/html/screens. ... all-screen
Since calling a screen is an interaction, and interactions trigger an implicit with None, using a with statement after the call screen instruction won't make the screen disappear using the transition, as the screen will already will be gone. To disable the implicit with None transition, pass the _with_none=False special keyword argument to the screen, as in the example below.

Other ways of triggering transitions also work, such as the [ With(dissolve), Return() ] action list.

Code: Select all

# Shows the screen with dissolve and hides it with pixellate.
call screen my_other_screen(_with_none=False) with dissolve
with pixellate
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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

Re: Different 'on hide' transform depending on button clicked

#6 Post by _ticlock_ »

Gouvernathor wrote: Thu Jun 16, 2022 10:31 pm you can use [With(moveoutright), Return()].
Transition is applied to the whole screen, I believe. I like it, but the intention was to apply animation "on hide" only for one child of the screen.
zmook wrote: Thu Jun 16, 2022 10:40 pm Does this help?
I don't think it will help in the way I'm trying to do it, but maybe it will help if I try to do it in a different way. Thanks for pointing that out.



The timer actually works pretty good for me, it just looks weird. Also, I am trying to figure out if it may cause some unexpected errors, that would be hard to track. What do you think?

I liked that I have everything in one screen, I guess that is the reason of this problem.

Thank you for your help and ideas!

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Different 'on hide' transform depending on button clicked

#7 Post by zmook »

_ticlock_ wrote: Thu Jun 16, 2022 11:25 pm Transition is applied to the whole screen, I believe. I like it, but the intention was to apply animation "on hide" only for one child of the screen.
Aha. Well, remember that transforms are just functions, and you can assign functions to variables and return them from methods. When screens get complicated, it can be useful to offload logic into a python controller class -- that is, to start implementing the Model-View-Controller pattern.

I've never messed with "on hide" triggers, so I don't know offhand if there's a better way than your timer to make sure that they do get shown, but you can certainly do all the logic you want on *what* transform to show:

Code: Select all

screen some_screen:
    default screen_controller = SomeScreenController()
    frame:
        if screen_controller.is_time_to_hide():
		at screen_controller.frame_hide_transform()
		timer 0.01 action Return()
        #...
    textbutton _('Left'):
        xalign 0.0 yalign 1.0
        action Function(screen_controller.click_left)
    textbutton _('Right'):
        xalign 1.0 yalign 1.0
        action Function(screen_controller.click_right)
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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

Re: Different 'on hide' transform depending on button clicked

#8 Post by _ticlock_ »

zmook wrote: Fri Jun 17, 2022 7:03 am Aha. Well, remember that transforms are just functions, and you can assign functions to variables and return them from methods. When screens get complicated, it can be useful to offload logic into a python controller class -- that is, to start implementing the Model-View-Controller pattern.
Great. It can be very useful! Even for some other things I wanted to do.

Thank you!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], dragondatingsim