Screen overlay

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
dasauto1
Newbie
Posts: 21
Joined: Sun Oct 31, 2021 2:26 pm
Contact:

Screen overlay

#1 Post by dasauto1 » Thu Dec 09, 2021 9:45 am

How to make a certain screen (it's a stats screen) always be over 3 screens whenever those 3 screens are active? Thanks!

User avatar
plastiekk
Regular
Posts: 40
Joined: Wed Sep 29, 2021 4:08 am
Discord: plastiekk#3072
Contact:

Re: Screen overlay

#2 Post by plastiekk » Tue Dec 14, 2021 10:36 am

In theory, this works with the function "renpy.get_screen". An example could look like the following.

Code: Select all

###############
#Status screen 
screen my_stats():
    zorder 1000     # on top of all other screens
    
    if (renpy.get_screen("my_screen1") and renpy.get_screen("my_screen2") and renpy.get_screen("my_screen3")):
        frame:
            xalign 0.5 yalign 0.5
            vbox:
                text "My Stats..."
    
    timer 0.5 repeat True action [Show("my_stats")] # this will redraw this screen every 0,5 seconds 

###############
# demo screens
screen my_screen1():
    vbox:
        xpos 0.1 ypos 0.1
        text "mytext1"
screen my_screen2():
    vbox:
        xpos 0.5 ypos 0.1
        text "mytext2"
screen my_screen3():
    vbox:
        xpos 0.8 ypos 0.1
        text "mytext3"

###############    
# The game starts here.

label start:
    show screen my_stats                # the screen which is redrawn every 0.5 seconds

    "showing screen1"
    show screen my_screen1              # demo screen 1

    "showing screen2"
    show screen my_screen2              # demo screen 2

    "showing screen3"
    show screen my_screen3              # demo screen 3

    "Showing STATS"                     # because all 3 screens are shown

    hide screen my_screen2
    "Not showing STATS"                 # because one screen is hidden
    
    return
Why on earth did I put the bread in the fridge?

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

Re: Screen overlay

#3 Post by zmook » Tue Dec 14, 2021 12:42 pm

This seems way more complicated that necessary. If you want a screen to appear on top of another screen, just make sure its `zorder` property is higher. You can show the screen any of the usual ways -- if it's something you want to stay permanently visible like a stats screen, just do:

Code: Select all

screen status_overlay():
    style_prefix "status"
    zorder 12
    
    vbox:
            text _("Week [gametime.week], [gametime.day_name], [gametime.hour]h00")
            text _("Credit: $[gk_credit]k")
            if g_population > 0:
                text _("Population: [g_population]")

Code: Select all

# The game starts here.
label start:
    show screen status_overlay()
Variables displayed in the status screen should just update automatically, any time you change their values.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

dasauto1
Newbie
Posts: 21
Joined: Sun Oct 31, 2021 2:26 pm
Contact:

Re: Screen overlay

#4 Post by dasauto1 » Tue Dec 14, 2021 4:59 pm

Thanks you so much!

Post Reply

Who is online

Users browsing this forum: Google [Bot]