Playing sound upon hovering over imagebutton
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.
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.
- dizzcity
- Veteran
- Posts: 311
- Joined: Thu Aug 17, 2006 10:51 am
- Projects: Lakeside Sunset, Wedding Vows, Working Woman
- Location: Singapore
- Contact:
Playing sound upon hovering over imagebutton
Hi,
I could really use some help. Can anyone think of a way I can get a sound to play when I hover (not click) over an imagebutton? I'm trying to present the player with different choices in tone of voice they can use in a dialogue sequence, but to do that, they need to be able to "pre-hear" the choice of tone before actually selecting one.
(Alternatively, if anyone can think of another way to solve the same problem without using the hover function, that would also help. ^^)
Cheers,
-Dizzy-
I could really use some help. Can anyone think of a way I can get a sound to play when I hover (not click) over an imagebutton? I'm trying to present the player with different choices in tone of voice they can use in a dialogue sequence, but to do that, they need to be able to "pre-hear" the choice of tone before actually selecting one.
(Alternatively, if anyone can think of another way to solve the same problem without using the hover function, that would also help. ^^)
Cheers,
-Dizzy-
A smart man follows the rules, a dumb man breaks them. A great man bends the rules and thus creates them.
Fanfiction.net Profile.
Writer and director of Working Woman (NaNoRenO March 2010)
Writer and director of Wedding Vows (finished 2009).
Creator of Lakeside Sunset (finished 2006).
Fanfiction.net Profile.
Writer and director of Working Woman (NaNoRenO March 2010)
Writer and director of Wedding Vows (finished 2009).
Creator of Lakeside Sunset (finished 2006).
Re: Playing sound upon hovering over imagebutton
I believe it should be possible by setting the "hovered" parameter of imagebutton. The code should be something like this:
(untested and obviously you need to change the parameters to your needs)
Edit:
I noticed just now, that the function called by hovered has to be without parameters, so you have to wrap the renpy.music.play function to not need parameters or make new function with some extra voice parameter. I done something like that for showing hint text in Dream Chasers, copying the code in hope it helps:
If you still need help with it, let me know I can code it for you (don't have time right now).
Code: Select all
ui.imagebutton( your_parameters, hovered=renpy.music.play( audiofile, channel="voice"))
Edit:
I noticed just now, that the function called by hovered has to be without parameters, so you have to wrap the renpy.music.play function to not need parameters or make new function with some extra voice parameter. I done something like that for showing hint text in Dream Chasers, copying the code in hope it helps:
Code: Select all
def imagebutton(hover_text="None", idle_image=None, hover_image=None, clicked=None, hovered=None, selected=False, **properties):
if hover_text:
def lhovered(hover_text=hover_text):
if store.message != hover_text:
store.message = hover_text
renpy.restart_interaction()
if hovered:
hovered()- dizzcity
- Veteran
- Posts: 311
- Joined: Thu Aug 17, 2006 10:51 am
- Projects: Lakeside Sunset, Wedding Vows, Working Woman
- Location: Singapore
- Contact:
Re: Playing sound upon hovering over imagebutton
Thanks denzil... but I think I'm going to need further help after all. I understand what you're saying, and I'm pretty sure I'll need to make a new function with an extra voice parameter (since I'll be using it quite often with various different sound files), but I have no idea how to go about it. (Non-programmer here! Still trying to figure out what "argument" and "parameter" actually mean in non-technical terms...)
I've got a complicated work-around that throws in an extra menu and a ton of variables, so I can afford to wait, but would really appreciate someone coding it for me, please?
Or at least teaching me how to define a new function and adding stuff to it.
-Dizzy-
I've got a complicated work-around that throws in an extra menu and a ton of variables, so I can afford to wait, but would really appreciate someone coding it for me, please?
-Dizzy-
A smart man follows the rules, a dumb man breaks them. A great man bends the rules and thus creates them.
Fanfiction.net Profile.
Writer and director of Working Woman (NaNoRenO March 2010)
Writer and director of Wedding Vows (finished 2009).
Creator of Lakeside Sunset (finished 2006).
Fanfiction.net Profile.
Writer and director of Working Woman (NaNoRenO March 2010)
Writer and director of Wedding Vows (finished 2009).
Creator of Lakeside Sunset (finished 2006).
Re: Playing sound upon hovering over imagebutton
Meh, I missed part of the code when copying it...
Here is working code, the disadvantage is that you have to pass both the voice and some function to hovered (that's what's the skip function for). After label start is example how to use it.
Here is working code, the disadvantage is that you have to pass both the voice and some function to hovered (that's what's the skip function for). After label start is example how to use it.
Code: Select all
init:
python:
def v_imagebutton( idle_image=None, hover_image=None, clicked=None, hovered=None, selected=False, voicefile=None, **properties):
if hovered:
def lhovered(voicefile=voicefile):
if hovered:
renpy.music.play( voicefile, channel="voice")
hovered()
ui.imagebutton(idle_image, hover_image, clicked=clicked, hovered=lhovered, **properties)
def skip():
return
# The game starts here.
label start:
python:
ui.window()
ui.hbox()
v_imagebutton( idle_image="1.png", hover_image="1h.png", voicefile="1.ogg", clicked=ui.returns(" "), hovered=skip)
v_imagebutton( idle_image="2.png", hover_image="2h.png", voicefile="2.ogg", clicked=ui.returns(" "), hovered=skip)
ui.close()
ui.interact()
- dizzcity
- Veteran
- Posts: 311
- Joined: Thu Aug 17, 2006 10:51 am
- Projects: Lakeside Sunset, Wedding Vows, Working Woman
- Location: Singapore
- Contact:
Re: Playing sound upon hovering over imagebutton
THANK YOU! Thank you, thank you, thank you!
It works exactly the way I wanted it to now. You should really put this up in the cookbook... I can foresee how it can be useful in lots of ways (I think mugenjohncel is also asking for something similar, but for imagemaps).
Aha, with this I can finally complete my NaNo game! Should be posting it up within a couple of days or so.
EDIT: NanoReno game here: Working Woman
-Dizzy-
Aha, with this I can finally complete my NaNo game! Should be posting it up within a couple of days or so.
EDIT: NanoReno game here: Working Woman
-Dizzy-
A smart man follows the rules, a dumb man breaks them. A great man bends the rules and thus creates them.
Fanfiction.net Profile.
Writer and director of Working Woman (NaNoRenO March 2010)
Writer and director of Wedding Vows (finished 2009).
Creator of Lakeside Sunset (finished 2006).
Fanfiction.net Profile.
Writer and director of Working Woman (NaNoRenO March 2010)
Writer and director of Wedding Vows (finished 2009).
Creator of Lakeside Sunset (finished 2006).
Who is online
Users browsing this forum: _ticlock_
