Making Viewport Snap to Certain Adjustment

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
Windchimes
Veteran
Posts: 288
Joined: Fri Nov 27, 2015 9:02 am
Projects: Reanimation Scheme, Emberfate: Tempest of Elements
Organization: Wind Chimes Games
Contact:

Making Viewport Snap to Certain Adjustment

#1 Post by Windchimes »

Hello!

So I have a kind of weird thing I'm trying to do with the viewports.

Basically I want it so if it's scrolled past a certain point, it'd snap to the max range of the viewport, otherwise it resets back to 0

Think like when you're swiping between home screens on a phone -- if you get past half when you release the swipe, it auto snaps to the next home screen. Otherwise, it resets back to the home screen you were on instead of changing to the next home screen.

So far I've managed to get it to snap to the next screen if you get past a certain point of scroll, but I'm unable to have it reset back to 0 if you don't get past that point. This is what I have so far:

Code: Select all

default xvalue = 1
default xadjtest = ui.adjustment(range=1920, page=1020, value=store.xvalue, changed=changevpscroll)

init python:
    def changevpscroll(x):
        global xvalue

        if xvalue < x:  
            if x > 900:
                renpy.run(Scroll("vptest", direction = "horizontal increase"))
        else:
            if x < 900:
                renpy.run(Scroll("vptest", direction = "horizontal decrease"))
        
        xvalue = x
In the screen

Code: Select all

viewport id "vptest":

        mousewheel False
        draggable True

        xinitial 0.0
        pos (0, 0)
        
        xysize (1920, 1080)
        child_size (3840, 1080)

        xadjustment xadjtest

        hbox:
            spacing 0
            add "test1"
            add "test2"
If I add an "else" to the function above to have it snap back to 0 xadjustment, it basically makes it so the viewport cannot be scrolled at all (I'm guessing because the adj would always be < 900 when you first start trying to scroll, and then it runs the Scroll function and makes it go back to 0 so there's no scrolling happening)
Failed version below of the function

Code: Select all

if xvalue < x:  
            if x > 900:
                renpy.run(Scroll("vptest", direction = "horizontal increase"))
            else:                
                renpy.run(Scroll("vptest", direction = "horizontal decrease"))
Theoretically I'd like to be able to run the function upon the end of dragging of viewport, but only thing I found that was relevant was

Code: Select all

viewport_drag_start = [ 'mousedown_1' ],
    viewport_drag_end = [ 'mouseup_1' ]
in Customizing Keymap and I have no clue how to make that work for my purposes...

So now I'm unsure what to do. I'm reluctant to give up on this since I feel like I'm already halfway there but I'm stuck LOL. Any help would be much appreciated!

Thank you!

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]