How to make main menu background image change?

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
exudin
Newbie
Posts: 2
Joined: Fri Oct 12, 2018 6:16 am
Contact:

How to make main menu background image change?

#1 Post by exudin »

I wanted to change the background image for the main menu after the player gets to a certain part of the game, but I would also like for the image to change during different runthroughs.

So, it would be something like: The main menu has a default background. During the game, you could choose which character you wanted to play as. After you choose, the background image of the main menu is now that character. You finish the game, and then the main menu goes back to the default background.

Any help is greatly appreciated! :D

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: How to make main menu background image change?

#2 Post by xavimat »

Use a persistent variable to tell the main menu what background to use.
main menu is technically "outside" the game, so you need to use a persistent variable, they serve to have info shared among plays.

Code: Select all

define persistent.main_menu_bg = "main_menu_bg_base"
label start:
    " Prologue. background image of menu not changed"
    menu:
        "Batman?":
            $ persistent.main_menu_bg = "main_menu_bg_batman"
            "Now main menu shows a man with a bat costume."
            jump batman_ending
        "Superman?":
            $ persistent.main_menu_bg = "main_menu_bg_superman"
            "Now main menu shows a man with a cape."
            jump superman_ending
    # ...
label batman_ending:
    $ persistent.main_menu_bg = "main_menu_bg_base"
    "THE END. main menu background is back to normal."
    return

label superman_ending:
    $ persistent.main_menu_bg = "main_menu_bg_base"
    "THE END. main menu background is back to normal."
    return
In screens.rpy, you need to change the main_menu screen to add your background.

Code: Select all

screen main_menu():

    ## This ensures that any other menu screen is replaced.
    tag menu

    style_prefix "main_menu"

    add persistent.main_menu_bg  # <-- CHANGE THIS LINE
    
    # ... the screen continues...
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

exudin
Newbie
Posts: 2
Joined: Fri Oct 12, 2018 6:16 am
Contact:

Re: How to make main menu background image change?

#3 Post by exudin »

Ahh, thank you so much! :D

Post Reply

Who is online

Users browsing this forum: Andredron, Bing [Bot]