Adding sound to each main menu button[SOLVED]

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
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Adding sound to each main menu button[SOLVED]

#1 Post by AsHLeX » Sat Mar 28, 2015 5:40 am

So I wanted to add like a sound that plays when you click on "save" and another when you click on "load" and etc. I don't really know where to start. I'm sorry D: Can someone help me here?
Last edited by AsHLeX on Sun Mar 29, 2015 10:48 am, edited 1 time in total.
Image

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Adding sound to each main menu button

#2 Post by yuucie » Sat Mar 28, 2015 2:17 pm

A way I handled it is by assigning sounds to the hover state when defining the button.

First, I defined sound channels (so when your mouse runs over one button and then moves quickly to the second button, the resulting sound is overlapped and not stilted)

Code: Select all

init python:
    renpy.music.register_channel("first", "sfx", False)
    renpy.music.register_channel("second", "sfx", False)

Then for text buttons:

Code: Select all

        textbutton _("History") action [SetVariable("yvalue", 1.0), ShowMenu('text_history')] hovered Play ("first", "sound/hover3.mp3")
        textbutton _("Skip") action Skip() hovered Play ("second", "sound/boop.mp3")
The important part is the hovered bit, which you can see both buttons use a different channel (to make the sound effect overlap and not jilt awkwardly) and a different sound effect.

same goes for image buttons:

Code: Select all

imagebutton auto "UI/Extras Char1_%s.png" action Start(label='Char1_Extra') hovered Play ("second", "sound/hover1.mp3") xalign 0.025 yalign 0.3 focus_mask True
since you are talking about main menus, you may be using hotspots on an imagemap instead:

Code: Select all

hotspot (20, 217, 217, 59) action ShowMenu("Char1_Gallery") hovered Play ("first", "sound/hover3.mp3")
change the channels among the buttons and you can alter their individual sound effects.

User avatar
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Adding sound to each main menu button

#3 Post by AsHLeX » Sun Mar 29, 2015 10:47 am

Got it, thank you so much! :)
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Adding sound to each main menu button[SOLVED]

#4 Post by trooper6 » Sun Mar 29, 2015 12:42 pm

I'm at a cafe so I can't give you specifics, but the easiest would be to go to your project's options.rpy file. In there is code in there that has been commented out that adds a sound to buttons by default. Uncomment that code and make sure the file it plays is the name of your audio file. I believe the default that is listed there is 'click.wave'

No need to do it individually, when you can make it default and the code is already written.

Also, if you haven't looked through the options.rpy file, I recommend looking to see what options are already there.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Adding sound to each main menu button[SOLVED]

#5 Post by AsHLeX » Sun Mar 29, 2015 12:52 pm

@trooper6:
Thank you so much!! ^^"
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]