Page 1 of 1
[Solved] How to add button sounds?
Posted: Fri Sep 30, 2016 6:36 pm
by shwippie
How do I add button sounds to the main menu and preference screens in the new version of Ren'Py (6.99.11)? I'd like to do both a hover sound and a select sound. Is it possible to do both?
Re: How to add button sounds?
Posted: Fri Sep 30, 2016 6:51 pm
by papiersam
You can try something like:
Code: Select all
screen main_menu():
button:
text "Button w/ Sound" size 48 outlines [(3, "#000000", 0, 0)]
align 0.5,0.75
action NullAction()
background "#0009"
xysize 300, 75
activate_sound "click.ogg" #sound when pressed
hovered Play ("some_track_name", "hover.ogg") #sound when hovered
at slowdis(0.5)
Or some variation therein (maybe using textbutton or imagebutton; they mostly take the same
style argument).
Re: How to add button sounds?
Posted: Fri Sep 30, 2016 6:56 pm
by Ocelot
There is also hover_sound style property.
By default main menu buttons are hidden in 'navigation' screen.
You can add 'hover_sound' and 'activate_sound' style properties to style 'navigation_button' defined below that screen.
Re: How to add button sounds?
Posted: Fri Sep 30, 2016 7:01 pm
by papiersam
There is also hover_sound style property.
That's the one; I couldn't remember the name. The new button should look something like this:
Code: Select all
screen main_menu():
button:
text "Button w/ Sound" size 48 outlines [(3, "#000000", 0, 0)]
align 0.5,0.75
action NullAction()
background "#0009"
xysize 300, 75
activate_sound "click.ogg" #sound when pressed
hover_sound "hover.ogg" #sound when hovered
Also, I overlooked the part where you mention the new Renpy. I haven't really used the new GUI yet, but as Ocelot said, check out the navigation screen in options.rpy:
Code: Select all
screen navigation():
vbox:
style_prefix "navigation"
xpos gui.navigation_xpos
yalign 0.5
spacing gui.navigation_spacing
if main_menu:
textbutton _("Start") action Start()
else:
textbutton _("History") action ShowMenu("history")
textbutton _("Save") action ShowMenu("save")
textbutton _("Load") action ShowMenu("load")
textbutton _("Preferences") action ShowMenu("preferences")
if _in_replay:
textbutton _("End Replay") action EndReplay(confirm=True)
elif not main_menu:
textbutton _("Main Menu") action MainMenu()
textbutton _("About") action ShowMenu("about")
if renpy.variant("pc"):
## Help isn't necessary or relevant to mobile devices.
textbutton _("Help") action ShowMenu("help")
## The quit button is banned on iOS and unnecessary on Android.
textbutton _("Quit") action Quit(confirm=not main_menu)
style navigation_button is gui_button
style navigation_button_text is gui_button_text
style navigation_button:
size_group "navigation"
properties gui.button_properties("navigation_button")
style navigation_button_text:
properties gui.button_text_properties("navigation_button")
Re: How to add button sounds?
Posted: Fri Sep 30, 2016 7:20 pm
by shwippie
Ocelot wrote:
You can add 'hover_sound' and 'activate_sound' style properties to style 'navigation_button' defined below that screen.
r_sami wrote: The new button should look something like this:
Thank you. This worked- there is a point on the screen that makes a sound. It's invisible, though. Should I be able to see it, since a color was defined for it?
Re: How to add button sounds?
Posted: Fri Sep 30, 2016 7:34 pm
by papiersam
there is a point on the screen that makes a sound. It's invisible, though. Should I be able to see it, since a color was defined for it?
Yes, it should show (I gave it a semi-transparent black colour). It's most likely underneath the other menu images and such. You could either put it at the end of the navigation (code is read sequentially), or put it in the screen main_menu().
Re: How to add button sounds?
Posted: Fri Sep 30, 2016 8:57 pm
by shwippie
r_sami wrote: You could either put it at the end of the navigation (code is read sequentially), or put it in the screen main_menu().
I see it now. Thanks again!
Re: [Solved] How to add button sounds?
Posted: Sun Jan 01, 2017 5:31 pm
by Treladon
I know this has been solved already, but, as an added note, to add a sound to one of the pre-made main menu buttons (like the start button) on the new gui version, go to screens:
screen navigation():
vbox:
style_prefix "navigation"
xpos gui.navigation_xpos
yalign 0.5
spacing gui.navigation_spacing
if main_menu:
textbutton _("Start") action Start():
activate_sound "button fx.wav"
Put a colon on the end of a line with 'action' and add " activate_sound "button fx.wav" ".