renpy/doc/cookbook/Music Room
From Ren'Py Visual Novel Engine
Music Room
This page is obsolete; see http://www.renpy.org/doc/html/rooms.html instead.
This is the code for a sample music room. It displays a list of buttons corresponding to music tracks. If a given track has been heard by the user before, a button is displayed with the tracks name. When the button is clicked, the track is played. Otherwise, a disabled button with "???" as the label is shown.
The important things to customize here are the scene statement (which controls the background used) and the various music_button calls.
init python: def set_playing_(track): store.playing = track return True set_playing = renpy.curry(set_playing_) # Call this with a button name and a track to define a music # button. def music_button(name, track): if store.playing == track: role = "selected_" else: role = "" if not renpy.seen_audio(track): name = "???" clicked = None else: clicked = set_playing(track) ui.textbutton( name, clicked=clicked, role=role, size_group="music") # Add to the main menu. config.main_menu.insert(3, ("Music Room", "music_room", "True")) label music_room: scene black python: _game_menu_screen = None # The default track of music. playing = "11-Yesterday.ogg" label music_room_loop: # Play the playing music, if it changed. python: renpy.music.play(playing, if_changed=True, fadeout=1) # Display the various music buttons. ui.vbox(xalign=0.5, ypos=100) music_button("Yesterday", "11-Yesterday.ogg") music_button("Yellow Submarine", "15-Yellow_Submarine.ogg") music_button("Hey Jude", "21-Hey_Jude.ogg") ui.close() # This is how we return to the main menu. ui.textbutton( "Return", clicked=ui.returns(False), xalign=0.5, ypos=450, size_group="music") if ui.interact(): jump music_room_loop else: return