Playing music in the choice/menu screen

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
User avatar
HideAndSeekVN
Newbie
Posts: 2
Joined: Tue Apr 06, 2021 12:31 pm
Contact:

Playing music in the choice/menu screen

#1 Post by HideAndSeekVN »

I'm trying to implement a system like Life Is Strange where when the choice menu screen comes up, the currently playing music/sfx will fade to a lower volume and decision making background music will play on top.

I know how to do this in the script itself each time, but was hoping there's a better way to edit the screen itself so it happens automatically each time.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Playing music in the choice/menu screen

#2 Post by Ocelot »

First of all, I would register channel on which choice music would play:

Code: Select all

init python:
    renpy.music.register_channel("choice_music", mixer="music", loop=True)
Then, I would modify existing choice screen, so it silences main music channel and play choice music when it shown. Then reverts everything back when it is hidden:

Code: Select all

screen choice(items):
    style_prefix "choice"
    vbox:
        for i in items:
            textbutton i.caption action i.action
    on "show"     action [Play(channel="choice_music", file="audio/choice.mp3", fadein=1.0), Function(renpy.music.set_volume, 0.2, delay=1.0, channel="music")]
    on "replace"  action [Play(channel="choice_music", file="audio/choice.mp3", fadein=1.0), Function(renpy.music.set_volume, 0.2, delay=1.0, channel="music")]
    on "hide"     action [Stop(channel="choice_music", fadeout=1.0),                         Function(renpy.music.set_volume, 1.0, delay=1.0, channel="music")]
    on "replaced" action [Stop(channel="choice_music", fadeout=1.0),                         Function(renpy.music.set_volume, 1.0, delay=1.0, channel="music")]
You can read more on used function and action in documentation:
https://www.renpy.org/doc/html/screen_a ... io-actions
https://www.renpy.org/doc/html/audio.html#functions

I have attached example project, so you could test it and see, how it is done.
Attachments
TEST61908.zip
(6.45 MiB) Downloaded 14 times
< < insert Rick Cook quote here > >

User avatar
HideAndSeekVN
Newbie
Posts: 2
Joined: Tue Apr 06, 2021 12:31 pm
Contact:

Re: Playing music in the choice/menu screen

#3 Post by HideAndSeekVN »

Ahh, I think this is perfect! I added additional functions to silence the sound channel as well and it seems to work great. Thanks a bunch!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]