Integrating sound with imagebuttons

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
Zeekee
Regular
Posts: 67
Joined: Wed Jul 23, 2014 10:17 pm
Projects: No One But You, The Anomaly
Organization: Annexe Interactive
Skype: ytmnd111
Soundcloud: zomgaarh
Location: USAF Academy, CO
Contact:

Integrating sound with imagebuttons

#1 Post by Zeekee »

I was wondering if anyone could help me integrate sound effects with my main menu imagebuttons. I have sound effects for when the mouse hovers over a menu option and another sound for when you click on the menu option, however I am not sure how to get it to work. Here's the code I have so far:

Code: Select all

        imagebutton auto "tstart_%s.png" xpos 10 ypos 410 action Start()
        imagebutton auto "tload_%s.png" xpos 145 ypos 410 action ShowMenu("load")
        imagebutton auto "toptions_%s.png" xpos 260 ypos 410 action ShowMenu("preferences")
        imagebutton auto "tquit_%s.png" xpos 430 ypos 410 action Quit(confirm=False)
        imagebutton auto "textras_%s.png" xpos 10 ypos 10 action Quit(confirm=False) 
Thanks in advance, I appreciate it!

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Integrating sound with imagebuttons

#2 Post by saguaro »

You will want to use audio screen actions.
http://www.renpy.org/doc/html/screen_ac ... io-actions

Imagebuttons take actions on hovered.
http://www.renpy.org/doc/html/screens.html#imagebutton

Code: Select all

    imagebutton auto "tstart_%s.png" xpos 10 ypos 410 hovered Play("sound", "click.ogg") action [Play("sound", "beep.ogg"), Start()]

User avatar
Zeekee
Regular
Posts: 67
Joined: Wed Jul 23, 2014 10:17 pm
Projects: No One But You, The Anomaly
Organization: Annexe Interactive
Skype: ytmnd111
Soundcloud: zomgaarh
Location: USAF Academy, CO
Contact:

Re: Integrating sound with imagebuttons

#3 Post by Zeekee »

I really appreciate the help! Quick question, though: In the documentation regarding audio screen actions, the first field of "Play" is the channel that the audio is played on. Is there documentation that elaborates on what the channel is? Would I just use "sound" like you did in your example or is there a more specific variable I need to enter?

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: Integrating sound with imagebuttons

#4 Post by yuucie »

I believe that sound is a predefined channel already (ex: play sound "soundeffect.mp3"), so you just enter sound like saguaro suggested.

SundownKid
Lemma-Class Veteran
Posts: 2299
Joined: Mon Feb 06, 2012 9:50 pm
Completed: Icebound, Selenon Rising Ep. 1-2
Projects: Selenon Rising Ep. 3-4
Organization: Fastermind Games
Deviantart: sundownkid
Location: NYC
Contact:

Re: Integrating sound with imagebuttons

#5 Post by SundownKid »

Sound is the default sound channel, which is already there. You can define and use new channels if you, say, don't want the sound of the button to interrupt the sound of a screen closing or opening. For example, if you put this in options:

Code: Select all

renpy.music.register_channel("sound2", "sfx", False)

User avatar
Zeekee
Regular
Posts: 67
Joined: Wed Jul 23, 2014 10:17 pm
Projects: No One But You, The Anomaly
Organization: Annexe Interactive
Skype: ytmnd111
Soundcloud: zomgaarh
Location: USAF Academy, CO
Contact:

Re: Integrating sound with imagebuttons

#6 Post by Zeekee »

Thanks so much! You guys are the best

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]