Ren'Py Create a hud in renpy

ayerkgzhkx

New Member
Jun 22, 2020
6
0
HI,
i am creating an hud however I am unable to create a screen seperate for hud.
however I am unable to make a standalone function fot hud.I have to write hud code on eachnscreen with below approach.





Python:
screen hud_map(n_map):
    zorder 99
    modal True
    if n_map=="CityMap":
        add "CityMap"   
    elif n_map=="mc_house":
        add "mc_house"
    
    imagebutton auto "./menu/hud_inventory_mask_%s.png":
        focus_mask "hud_inventory_mask_idle"
        action Notify ("hud_inventory_mask")
    imagebutton auto "./menu/hud_memo_mask_%s.png":
        focus_mask "hud_memo_mask_idle"
        action Notify ("hud_memo_mask")
    imagebutton auto "./menu/hud_phone_mask_%s.png":
        focus_mask "hud_phone_mask_idle"
#        action Notify ("hud_phone_mask")   
        action Jump("hud_phone_mask")#phone_call_test)
    if n_map!="CityMap":
        imagebutton auto "./menu/hud_map_mask_%s.png":
            focus_mask "hud_map_mask_idle"
            action Jump ("cityMap")
    else:
        imagebutton auto "./menu/hud_mcroom_%s.png":
            focus_mask "hud_mcroom_idle"
            action Notify ("hud_mcroom")



    if n_map=="CityMap":
        imagebutton auto "./menu/citymap_mc_house_%s.png":
            focus_mask "citymap_mc_house_idle"
#            action Notify ("mcHouse")
            action Jump("mcHouse")
        imagebutton auto "./menu/citymap_b1_%s.png":
            focus_mask "citymap_b1_idle"
            action Notify ("mcHouse")
        imagebutton auto "./menu/citymap_b2_%s.png":
            focus_mask "citymap_b2_idle"
            action Notify ("mcHouse")
        imagebutton auto "./menu/citymap_b3_%s.png":
            focus_mask "citymap_b3_idle"
            action Notify ("mcHouse")
        imagebutton auto "./menu/underconstruction_%s.png":
            focus_mask "underconstruction_idle"
            action Notify ("Under Construction to greedy perv. Wait !!")

    if n_map=="mc_house":
        imagebutton auto "./house/mc_house_%s.png":
            focus_mask "mc_house_idle"
            action Notify ("Under Construction to greedy perv. Wait !!")



label cityMap:
    call screen hud_map("CityMap")
Also how to call two screen one after the other
Code:
label mcHouse:
    call screen hud()
    call screen mc_hose()
 

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,504
8,040
Call screen will interrupt the code execution until it's returned, Show screen will show the screen without interrupting the code execution.
 
  • Like
Reactions: ayerkgzhkx

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
In addition to Winterfire answer:

Modal screen will catch the events even when shown, and the screen statement is what you are looking for.

So, to design a HUD, you need to follow this process:
Python:
screen hud():

   imagebutton auto "./menu/hud_inventory_mask_%s.png":
        focus_mask "hud_inventory_mask_idle"
        action Show( "hud_inventory" )
    imagebutton auto "./menu/hud_memo_mask_%s.png":
        focus_mask "hud_memo_mask_idle"
        action Show ( "hud_memo" )
    imagebutton auto "./menu/hud_phone_mask_%s.png":
        focus_mask "hud_phone_mask_idle"
        action Show( "hud_phone")
    if n_map!="CityMap":
        imagebutton auto "./menu/hud_map_mask_%s.png":
            focus_mask "hud_map_mask_idle"
            action Jump ("cityMap")
    else:
        imagebutton auto "./menu/hud_mcroom_%s.png":
            focus_mask "hud_mcroom_idle"
            action [...]

screen map( n_map ):

    [content of the screen, without the HUD part]

    #  At the end of the screen for it to be display on top.
    use hud

screen hud_inventory():

   # For the screen to catch the events and, therefore, momentarily stop the advance of the game.
   modal True

   [Whatever is the content of the screen]

screen hud_memo():

   modal True
   [...]

[...]

label start:

    [...]
    show screen whatever_screen_you_have_to_show
Alternatively, you can also define the hud as overlay with .
Python:
screen hud():

   # Display the image buttons only when the HUD must be visible
   if hud_visible:
       imagebutton auto "./menu/hud_inventory_mask_%s.png":
            focus_mask "hud_inventory_mask_idle"
            action Show( "hud_inventory" )
       [...]

screen map( n_map ):

    [content of the screen without the HUD part]

    #This is now useless
    #use hud

screen hud_inventory():

   [same than above]
   [...]

init python:

    config.overlay_screens.append( "HUD" )

default hud_visible = True

label whatever:
    # Temporarily hide the HUD
    $ hud_visible = False
    [...]
    # Show the HUD again
    $ hud_visible = True

Edit: Fixed a format error.
 
Last edited:
  • Like
Reactions: ayerkgzhkx