Page 1 of 1

Hover sound for imagemap

Posted: Tue May 16, 2017 9:51 pm
by HeavenlyJoker
So it's been a while since I've coded, and I just updated to the newest version of Ren'Py. I ran into what I feel shouldn't be a problem, but I've exhausted all my knowledge on how to fix it. My goal is for a short sound effect to play once each time someone hovers over a designated hotspot on an imagemap. I went through numerous attempts to code this, and every attempt would end in either crashing the game as soon as I hovered over the hotspot, crashing the game as soon as the main menu loaded, or just not play the sound at all.

Not sure if it's helpful information or not, but I would often see "'play' not defined" or "KeyError: 'sfx'" mentioned in the traceback depending on my method--all these attempts were made past midnight last night and I'm afraid I didn't have the sense to catalogue all the errors (though if need be, I'd be all too happy to get some fresh crashes going).

The imagemap works flawlessly, I'm just not sure how to incorporate a sound using the hovered function without crashing the game. Any advice would be appreciated! Thank you!

Re: Hover sound for imagemap

Posted: Tue May 16, 2017 10:45 pm
by Imperf3kt
How important is having an imagemap to you? Could you perhaps settle for imagebuttons instead? I'm not sure how to use different hoversounds per button, but if you add to your config somewhere such as options.rpy

Code: Select all

imagebutton hover sound = "file"#might be hover_sound or image_button, cannot remember
It should work

Re: Hover sound for imagemap

Posted: Wed May 17, 2017 12:15 am
by HeavenlyJoker
I'm attached to the imagemap only in that it works well and I trust it xD I've never messed much with imagebuttons before, but I suspect I should try to remedy that.

I will certainly try out the code you gave me when I experiment with the imagebutton route you suggested, but I'm going to leave the thread open just in case anyone has a solution that will work for imagemaps. Thank you so much for the information!

Re: Hover sound for imagemap

Posted: Wed May 17, 2017 12:37 am
by Ocelot
It would be really helpful to actually see what you tried to figure out what was wrong. For example, was the thing passed to hovered property a proper Action?

Anyway, hotspots take button style properties, so you could use them. For example, hover_sound.

Code: Select all

imagemap:
    # . . .
    hotspot /* . . . */ hover_sound 'mysound.wav'

Re: Hover sound for imagemap

Posted: Wed May 17, 2017 12:51 am
by HeavenlyJoker
Ocelot wrote:It would be really helpful to actually see what you tried to figure out what was wrong. For example, was the thing passed to hovered property a proper Action?

Anyway, hotspots take button style properties, so you could use them. For example, hover_sound.

Code: Select all

imagemap:
    # . . .
    hotspot /* . . . */ hover_sound 'mysound.wav'
I popped in the code you mentioned and grabbed the traceback when it crashed:

Code: Select all

While running game code:
  File "game/weekend.rpy", line 45, in script
    call screen visiting
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
KeyError: 'sfx'
This is what the code looked like:

Code: Select all

screen visiting:
    imagemap:
        ground "graphics/Screens and Menus/Visit.png"
        hover "graphics/Screens and Menus/Visit2.png"
        
        hotspot (213, 105, 107, 232) clicked Return("fritz") hover_sound 'music/pop.wav'

Re: Hover sound for imagemap

Posted: Thu Jul 05, 2018 3:19 am
by Project_Astro
Well, it's been a whiiiiiiiiiile since you posted this topic but who knows ? I assume that someone will need it one day, hehe x)

So I have a code that works perfeclty. I tried it just now :) :

Code: Select all

screen Bdoors():
    imagemap:
        idle "portes/DoorBlack.png"
        hover "portes/DoorBlack2.png"
        ground "portes/DoorBlack.png"
        
        hotspot (83,87,164,319) action Jump("your_label") hovered [ Play ("sound", "your_sound.wav")] focus_mask True 
        hotspot (435,87,164,319) action Jump("another_label") hovered [ Play ("sound", "your_sound.wav")] focus_mask True 
        hotspot (807,88,163,319) action Jump("too_much_label") hovered [ Play ("sound", "your_sound.wav")] focus_mask True
        ##Ainsi de suite until you've done all your hotspots! 
https://www.renpy.org/doc/html/style_pr ... properties
So you've got to change the idle, hover and ground, the hotspots and the sound/sounds' name :)

Hope I helped someone,


Project_Astro

Re: Hover sound for imagemap

Posted: Thu Jul 05, 2018 4:39 am
by xavimat
You could use also the property hover_sound, instead of the hovered action Play()
https://www.renpy.org/doc/html/style_pr ... over_sound

Re: Hover sound for imagemap

Posted: Thu Jul 05, 2018 6:46 am
by Project_Astro
xavimat wrote:
Thu Jul 05, 2018 4:39 am
You could use also the property hover_sound, instead of the hovered action Play()
like this ?

Code: Select all

 hotspot (83,87,164,319) action Jump("your_label") hover_sound "your_sound.wav" 
I guess that's ten times simpler haha!

Thanks for the tip by the way!