Hover sound for imagemap

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
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Hover sound for imagemap

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

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Hover sound for imagemap

#2 Post 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
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Re: Hover sound for imagemap

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

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

Re: Hover sound for imagemap

#4 Post 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'
< < insert Rick Cook quote here > >

User avatar
HeavenlyJoker
Regular
Posts: 97
Joined: Mon Feb 21, 2011 2:05 am
Projects: Enora: Monster Academy
Organization: Key Lime
Tumblr: keylimegames
Contact:

Re: Hover sound for imagemap

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

User avatar
Project_Astro
Newbie
Posts: 21
Joined: Wed Jun 13, 2018 1:02 pm
Projects: NeoLythe / Dark Investigations
Contact:

Re: Hover sound for imagemap

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

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Hover sound for imagemap

#7 Post 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
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
Project_Astro
Newbie
Posts: 21
Joined: Wed Jun 13, 2018 1:02 pm
Projects: NeoLythe / Dark Investigations
Contact:

Re: Hover sound for imagemap

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

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]