[Solved] How to add button sounds?

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
shwippie
Regular
Posts: 129
Joined: Wed Dec 22, 2010 4:12 pm
Completed: Double Romance
Projects: Rolland's Candy Shop. Mitzi's Fable
Tumblr: shwippie
Deviantart: shwippie
Contact:

[Solved] How to add button sounds?

#1 Post 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?
Last edited by shwippie on Fri Sep 30, 2016 9:02 pm, edited 2 times in total.
Image Image Image

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: How to add button sounds?

#2 Post 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).

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

Re: How to add button sounds?

#3 Post 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.
< < insert Rick Cook quote here > >

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: How to add button sounds?

#4 Post 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")

shwippie
Regular
Posts: 129
Joined: Wed Dec 22, 2010 4:12 pm
Completed: Double Romance
Projects: Rolland's Candy Shop. Mitzi's Fable
Tumblr: shwippie
Deviantart: shwippie
Contact:

Re: How to add button sounds?

#5 Post 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?

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: How to add button sounds?

#6 Post 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().

shwippie
Regular
Posts: 129
Joined: Wed Dec 22, 2010 4:12 pm
Completed: Double Romance
Projects: Rolland's Candy Shop. Mitzi's Fable
Tumblr: shwippie
Deviantart: shwippie
Contact:

Re: How to add button sounds?

#7 Post 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!

User avatar
Treladon
Regular
Posts: 40
Joined: Sat Dec 31, 2016 3:20 pm
Projects: ToMaG, Feinted Game
Organization: Kuehler-Corrada Productions
Deviantart: Journie
Contact:

Re: [Solved] How to add button sounds?

#8 Post 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" ".

Post Reply

Who is online

Users browsing this forum: Bing [Bot]