[SOLVED] How do I have scrolling screens keep their positions after being interacted with?

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
Cat_Bardy
Newbie
Posts: 5
Joined: Wed Mar 22, 2023 1:19 pm
IRC Nick: Bardy
Contact:

[SOLVED] How do I have scrolling screens keep their positions after being interacted with?

#1 Post by Cat_Bardy »

So I've been trying to learn how to use scrollable screens, and whenever I interact with something on the screen, the screen jumps to the center of the image before displaying text, regardless of where the user was when the image was interacted with.

So far I've got:

Code: Select all

screen scrolling_screen():
        viewport:
            child_size(2600,1080) 
            arrowkeys True 
            edgescroll (300,2000) 
            xinitial .5 
            add "test_bg.png" 
            imagebutton:
                auto "test_door_%s.png" focus_mask True
                action Jump ("scroll_test")


label scroll_test:
    show test_bg
    "sample text"
    call screen scrolling_screen
I include the "Show test_bg" line just so that there is something displayed after clicking the imagebutton, otherwise it displays no backgrounds. Is there something I could do to keep the screen from returning to the center after clicking the imagebutton?
This is my first post here and I'm a total noob at this stuff, so apologies if this is written poorly lol.
Last edited by Cat_Bardy on Sat Apr 08, 2023 10:45 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2438
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How do I have scrolling screens keep their positions after being interacted with?

#2 Post by Ocelot »

Provide a *adjustment object which will be stored somewhere between screen invocations:

Code: Select all

default screen_scroll = ui.adjustment()

screen scrolling_screen():
    viewport:
        xadjustment screen_scroll 
https://www.renpy.org/doc/html/screens.html#viewport
https://www.renpy.org/doc/html/screen_p ... adjustment
< < insert Rick Cook quote here > >

User avatar
Cat_Bardy
Newbie
Posts: 5
Joined: Wed Mar 22, 2023 1:19 pm
IRC Nick: Bardy
Contact:

Re: How do I have scrolling screens keep their positions after being interacted with?

#3 Post by Cat_Bardy »

Thank you, that helps with keeping the screen remembering where it was, but is there a way to apply this to the image after interacting with the imagebutton? The "Show test_bg" is still displays the image at the center. Is there a way to apply the " xadjustment screen_scroll " to the image somehow? Or maybe a way to keep the screen from hiding itself after interacting with the imagebutton?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2438
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How do I have scrolling screens keep their positions after being interacted with?

#4 Post by Ocelot »

Did you remove xinitial property from viewport?
< < insert Rick Cook quote here > >

User avatar
Cat_Bardy
Newbie
Posts: 5
Joined: Wed Mar 22, 2023 1:19 pm
IRC Nick: Bardy
Contact:

Re: How do I have scrolling screens keep their positions after being interacted with?

#5 Post by Cat_Bardy »

Yes, heres what I have now:

Code: Select all

default screen_scroll = ui.adjustment(1,300)

screen scrolling_screen():
        viewport:
            xadjustment screen_scroll
            child_size(2600,1080)
            arrowkeys True 
            edgescroll (300,2000) 

            add "test_bg.png" 
            imagebutton:
                auto "test_door_%s.png" focus_mask True
                action Jump ("scroll_test")


label scroll_test:
    scene test_bg
    "sample text"
    call screen scrolling_screen

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

Re: How do I have scrolling screens keep their positions after being interacted with?

#6 Post by _ticlock_ »

Cat_Bardy wrote: Fri Apr 07, 2023 2:12 pm Thank you, that helps with keeping the screen remembering where it was, but is there a way to apply this to the image after interacting with the imagebutton? The "Show test_bg" is still displays the image at the center. Is there a way to apply the " xadjustment screen_scroll " to the image somehow? Or maybe a way to keep the screen from hiding itself after interacting with the imagebutton?
You can reshow screen with show screen statement. It might make sense to add argument to control if the screen is interactive or just background

Code: Select all

screen scrolling_screen(interact = True):
        viewport:
            xadjustment screen_scroll
            child_size(2600,1080)
            arrowkeys interact
            if interact: 
                edgescroll (300,2000) 

            add "test_bg.png"
            if interact: 
                imagebutton:
                    auto "test_door_%s.png" focus_mask True
                    action Jump ("scroll_test")
In this case you can use call screen scrolling_screen() for interaction and show screen scrolling_screen(interact = False) to show screen as a backgound

Code: Select all

label scroll_test:
    show screen scrolling_screen(False)
    "sample text"
    call screen scrolling_screen

User avatar
Cat_Bardy
Newbie
Posts: 5
Joined: Wed Mar 22, 2023 1:19 pm
IRC Nick: Bardy
Contact:

Re: How do I have scrolling screens keep their positions after being interacted with?

#7 Post by Cat_Bardy »

_ticlock_ wrote: Fri Apr 07, 2023 11:42 pm
Cat_Bardy wrote: Fri Apr 07, 2023 2:12 pm Thank you, that helps with keeping the screen remembering where it was, but is there a way to apply this to the image after interacting with the imagebutton? The "Show test_bg" is still displays the image at the center. Is there a way to apply the " xadjustment screen_scroll " to the image somehow? Or maybe a way to keep the screen from hiding itself after interacting with the imagebutton?
You can reshow screen with show screen statement. It might make sense to add argument to control if the screen is interactive or just background

Code: Select all

screen scrolling_screen(interact = True):
        viewport:
            xadjustment screen_scroll
            child_size(2600,1080)
            arrowkeys interact
            if interact: 
                edgescroll (300,2000) 

            add "test_bg.png"
            if interact: 
                imagebutton:
                    auto "test_door_%s.png" focus_mask True
                    action Jump ("scroll_test")
In this case you can use call screen scrolling_screen() for interaction and show screen scrolling_screen(interact = False) to show screen as a backgound

Code: Select all

label scroll_test:
    show screen scrolling_screen(False)
    "sample text"
    call screen scrolling_screen
This works, thank you so much!

Post Reply

Who is online

Users browsing this forum: No registered users