Ren'Py Auto Refresh Screen or infinite loop

Anonymous50000

Newbie
Modder
Jan 4, 2018
97
355
I was wondering if it's possible to actualise the screen content like renpy text or make a loop that do not make crash renpy

Code:
init 999 python:
    import pygame

screen Dev_screen():
    python:
        mouseX = pygame.mouse.get_pos()[0]
        mouseY = pygame.mouse.get_pos()[1]
            
    viewport id "Dev_screen":
        vbox:
            text "X : [mouseX]" #Need to refresh this
            text "Y : [mouseY]"
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,199
I was wondering if it's possible to actualise the screen content like renpy text or make a loop that do not make crash renpy
The screen update itself automatically, but the mouse thing is tricky and hard to make works correctly even when refreshing the screen.

Therefore, you need to rely on something else to achieve what you want :
Python:
init python:
    # Not needed if you don't use the line referencing /pygame/.
    import pygame_sdl2 as pygame

    class AONMousePos(renpy.Displayable):
        x = 0
        y = 0

        def __init__(self, **kwargs):
            super(AONMousePos, self).__init__(**kwargs)

        # Will be called each time an event happen, and moving the mouse is an event.
        # The /x/ and /y/ arguments are the position of the mouse.
        def event(self, ev, x, y, st):
            if (x < 0 or y < 0): return None
            #  Those line isn't mandatory. It just ensure that you'll not ask
            # for a screen refresh when the events is something else than
            # the mouse moving.
            if ev.type != pygame.MOUSEMOTION: return None
            #  Keep the new position of the mouse. If you want to use the
            # position in your code, store it outside of the object itself.
            self.x = x
            self.y = y
            # And ask Ren'py to redraw the displayable, which will update the
            # position shown on the screen. If you don't want to show the 
            # position, just don't add this line
            renpy.redraw(self, 0)

        # If you don't want to show the position, return a blank render.
        def render(self, width, height, st, at):
            rv = renpy.Render(width, height)
            # What will be added to the screen by the displayable.
            rv.blit( renpy.render(Text( "X: {}\nY: {}".format( int( self.x ), int( self.y ) ), size=20, color="#fff", outlines=[ (1, "#000", 0, 0 ) ]), width, height, st, at), (0, 0))
            return rv


#  An example screen that display the mouse position on the top left corner
# of the screen.
screen AONMousePos():
    zorder 1000
    vbox:
        xalign 0.0 yalign 0.0
        # Adding the displayable mean :
        # It will display something and be called every time an event happen.
        add AONMousePos()
 

Anonymous50000

Newbie
Modder
Jan 4, 2018
97
355
The screen update itself automatically, but the mouse thing is tricky and hard to make works correctly even when refreshing the screen.

Therefore, you need to rely on something else to achieve what you want :
Python:
init python:
    # Not needed if you don't use the line referencing /pygame/.
    import pygame_sdl2 as pygame

    class AONMousePos(renpy.Displayable):
        x = 0
        y = 0

        def __init__(self, **kwargs):
            super(AONMousePos, self).__init__(**kwargs)

        # Will be called each time an event happen, and moving the mouse is an event.
        # The /x/ and /y/ arguments are the position of the mouse.
        def event(self, ev, x, y, st):
            if (x < 0 or y < 0): return None
            #  Those line isn't mandatory. It just ensure that you'll not ask
            # for a screen refresh when the events is something else than
            # the mouse moving.
            if ev.type != pygame.MOUSEMOTION: return None
            #  Keep the new position of the mouse. If you want to use the
            # position in your code, store it outside of the object itself.
            self.x = x
            self.y = y
            # And ask Ren'py to redraw the displayable, which will update the
            # position shown on the screen. If you don't want to show the
            # position, just don't add this line
            renpy.redraw(self, 0)

        # If you don't want to show the position, return a blank render.
        def render(self, width, height, st, at):
            rv = renpy.Render(width, height)
            # What will be added to the screen by the displayable.
            rv.blit( renpy.render(Text( "X: {}\nY: {}".format( int( self.x ), int( self.y ) ), size=20, color="#fff", outlines=[ (1, "#000", 0, 0 ) ]), width, height, st, at), (0, 0))
            return rv


#  An example screen that display the mouse position on the top left corner
# of the screen.
screen AONMousePos():
    zorder 1000
    vbox:
        xalign 0.0 yalign 0.0
        # Adding the displayable mean :
        # It will display something and be called every time an event happen.
        add AONMousePos()
Thank you guys I will try to understand that
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,808
24,388
or:
Python:
screen mousepos():
    zorder 200

    $ x, y = renpy.get_mouse_pos()

    drag:
        draggable True

        frame:
            background "#0008"
            padding (20, 15)

            has vbox

            text "x: [x]" color "#fff8"
            text "y: [y]" color "#fff8"

init:
    $ config.per_frame_screens.append("mousepos")
    $ config.overlay_screens.append("mousepos")
 

Anonymous50000

Newbie
Modder
Jan 4, 2018
97
355
or:
Python:
screen mousepos():
    zorder 200

    $ x, y = renpy.get_mouse_pos()

    drag:
        draggable True

        frame:
            background "#0008"
            padding (20, 15)

            has vbox

            text "x: [x]" color "#fff8"
            text "y: [y]" color "#fff8"

init:
    $ config.per_frame_screens.append("mousepos")
    $ config.overlay_screens.append("mousepos")
Thank you really usefull I don't know there's a per_frame_screens