Modified viewport scrolling

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
Sublingual
Newbie
Posts: 3
Joined: Thu Sep 26, 2019 4:23 pm
Contact:

Modified viewport scrolling

#1 Post by Sublingual » Thu Sep 26, 2019 4:53 pm

Hello all! I am working on a point and click adventure game that I am trying to move over to RenPy. Think something like Myst, except with characters you can talk to. I am just getting my bearings and I think I have a good place to start, but I am stumped on one specific thing.

The action of the game takes place inside a viewport, which is slightly larger than the screen. Your mouse position within the viewport determines what part of the screen you see. So, for example, having your mouse in the lower left quadrant of the screen will display more of the lower left backdrop.

I know that this sounds like edgescroll, but that's not quite what I want. If the cursor is sitting still, I don't want the backdrop to be continuously moving. Rather, I want the location of the mouse cursor to have a 1:1.25 relation to the offset of the viewport.

My first stab at this involved using edgescroll anyway and defining a function in python, something like this (abridged):

Code: Select all

init python:
    def scroll_speed(i):
        //How do I adjust the viewport from here?
        return i
        
screen containerscreen():   
    viewport id "room_view":
        #code that defines the size of the viewport goes here...
        
        edgescroll (280, 50, scroll_speed)
Something about this seems a little bit hacky, and I couldn't really get anything useful to happen in that python block. Plus, the documentation says that screen language should be used over python language. So I'm not really sure where to go from here. If someone could point me in the right direction that would be really helpful.

User avatar
Remix
Eileen-Class Veteran
Posts: 1312
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Modified viewport scrolling

#2 Post by Remix » Thu Sep 26, 2019 7:34 pm

You *could* use a periodic callback or step ATL through to a python function to adjust the x/yadjustments based on mouse position.

Basic example (note you will want to tweak the math to suit (the viewport adjustment versus actual screen pos bit))

Code: Select all

init python:

    def py_move_vp(trans, st, at):
        # The trans(form) doesn't actually have the xadjustment we want, so we look for the actual widget
        if renpy.get_screen('containerscreen'):
            vp = renpy.get_widget('containerscreen', 'room_view')
            if vp:
                mouse_pos = renpy.get_mouse_pos()
                vp.xadjustment.change(mouse_pos[0] - 100) # I used minus 100 to match viewport area
                vp.yadjustment.change(mouse_pos[1] - 100) # You might just want int(mouse_pos[n] // 4.0) if pic is 25% larger
        return 0

transform move_vp():
    function py_move_vp

screen containerscreen():
    viewport id "room_view" at move_vp:
        area (100, 100, 400, 400)

        add "images/925270_1441060379485284_1418650314_n.jpg":
            zoom 2.0
Mad Scientist Todo List:
  • Finish Improved Event Handler
  • Implement DragonBones animation as a Creator Defined Container
  • Develop Cartoon Speech Bubble dialogue
  • Finish Bitmask collision and rebound vector system
  • Develop time based building mechanic
  • Others
  • *Find a superb artist and actually write a game*

Sublingual
Newbie
Posts: 3
Joined: Thu Sep 26, 2019 4:23 pm
Contact:

Re: Modified viewport scrolling

#3 Post by Sublingual » Sun Sep 29, 2019 9:30 pm

I just got this working, thank you so much for your help!

Post Reply

Who is online

Users browsing this forum: Google [Bot]