[SOLVED] Play sound on hotspot click?

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
renpyhelp
Regular
Posts: 66
Joined: Tue Feb 27, 2018 2:01 am
Contact:

[SOLVED] Play sound on hotspot click?

#1 Post by renpyhelp » Wed Feb 28, 2018 1:27 pm

I currently have my hotspots jump to a label, plays a sound effect and then jump to a new screen.
Is it possible to simply play a sound effect within the hotspot code when clicked on?

My current hotspot code:
hotspot (1119, 634, 139, 68) action Jump("home_frontyard") hovered ShowTransient("label_frontyard") unhovered Hide("label_frontyard")

Hotspot -> label which plays SE and then calls screen for the frontyard.

Another question... is there some code I can use within a label that will jump back to the most recent screen?
Last edited by renpyhelp on Thu Mar 01, 2018 2:02 pm, edited 1 time in total.

ReDZiX
Regular
Posts: 32
Joined: Thu Jan 04, 2018 12:42 pm
Contact:

Re: Play sound on hotspot click?

#2 Post by ReDZiX » Thu Mar 01, 2018 9:43 am

I don't know if it will work with hotspot (as I never work with imagemap), but you can try the activate_sound property, giving a string with the sound file path and name.

Code: Select all

hotspot (1119, 634, 139, 68) activate_sound "clicked.ogg" action Jump("home_frontyard") hovered ShowTransient("label_frontyard") unhovered Hide("label_frontyard")
As for jumping back to the screen, if you call that screen from a label, you can return to that label if you use Call action instead of jump, and at the end of the called label, put a return statement. It's a little hard to explain, but consider this example.

Code: Select all


label start: 

    "Let's go to the beach."
    
    call beach #We call the beach label here
    
    "I have returned!" #We return here after the beach label finishes
    
    return #This ends the game since there's no previous label to return to
    
label beach:
    "The sea is beautiful."
    
    # We could call the beach imagemap screen here
    
    "Let's go back."
    
    return #This goes back to right after the beach label was called

renpyhelp
Regular
Posts: 66
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Play sound on hotspot click?

#3 Post by renpyhelp » Thu Mar 01, 2018 2:01 pm

ReDZiX wrote:
Thu Mar 01, 2018 9:43 am
I don't know if it will work with hotspot (as I never work with imagemap), but you can try the activate_sound property, giving a string with the sound file path and name.

Code: Select all

hotspot (1119, 634, 139, 68) activate_sound "clicked.ogg" action Jump("home_frontyard") hovered ShowTransient("label_frontyard") unhovered Hide("label_frontyard")
As for jumping back to the screen, if you call that screen from a label, you can return to that label if you use Call action instead of jump, and at the end of the called label, put a return statement. It's a little hard to explain, but consider this example.

Code: Select all


label start: 

    "Let's go to the beach."
    
    call beach #We call the beach label here
    
    "I have returned!" #We return here after the beach label finishes
    
    return #This ends the game since there's no previous label to return to
    
label beach:
    "The sea is beautiful."
    
    # We could call the beach imagemap screen here
    
    "Let's go back."
    
    return #This goes back to right after the beach label was called
Thank you so much. activate_sound on a hotspot does work. Originally I had multiple ways to enter a specific screen, some were through a door and others weren't, so my Jump to Label -> Jump to screen would play the door open sound no matter what, unless I had separate labels for each. This makes me completely not need to do that. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users