[SOLVED] Sound on 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
4listair
Newbie
Posts: 11
Joined: Tue Jul 31, 2018 10:54 pm
Contact:

[SOLVED] Sound on Click?

#1 Post by 4listair »

Is there any way to set it so that each click makes a sound? I tried a few things, but all I can seem to manage is making it so buttons make sounds, but that isn't exactly what I'm going for. Thanks!

Edit: OR, is there a way to make it so when you click to continue in the dialogue, it makes a sound?
Last edited by 4listair on Wed Sep 05, 2018 4:23 pm, edited 1 time in total.

User avatar
dGameBoy101b
Regular
Posts: 31
Joined: Sun Aug 12, 2018 8:32 am
itch: dgameboy101b
Contact:

Re: Sound on Click?

#2 Post by dGameBoy101b »

You can create a screen that has an invisible image button over the whole display and uses a Play() action to play an audio file whenever the player clicks or presses a button to advance the dialogue.

Code: Select all

init:
    transform FullScreen():
        python:
            x = renpy.get_physical_size()[0]
            y = renpy.get_physical_size()[1]
        align(0.0,0.0)
        size(x,y)
    screen ClickSound():
        modal False
        python:
            keys = config.keymap["dismiss"]
        imagebutton:
            idle "null.png" at FullScreen #null.png is a transparent image
            action Play("sound","click.ogg") #click.ogg is the sound you want played
            keysym keys
start:
    show screen ClickSound
    "I like to make sounds when you click!"

User avatar
MaydohMaydoh
Regular
Posts: 165
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Sound on Click?

#3 Post by MaydohMaydoh »

dGameBoy101b wrote: Sat Aug 18, 2018 7:23 am You can create a screen that has an invisible image button over the whole display and uses a Play() action to play an audio file whenever the player clicks or presses a button to advance the dialogue.

Code: Select all

init:
    transform FullScreen():
        python:
            x = renpy.get_physical_size()[0]
            y = renpy.get_physical_size()[1]
        align(0.0,0.0)
        size(x,y)
    screen ClickSound():
        modal False
        python:
            keys = config.keymap["dismiss"]
        imagebutton:
            idle "null.png" at FullScreen #null.png is a transparent image
            action Play("sound","click.ogg") #click.ogg is the sound you want played
            keysym keys
start:
    show screen ClickSound
    "I like to make sounds when you click!"
To simplify that button code, all you need is:

Code: Select all

screen ClickSound():
    button:
        background None ## Makes button invisible
        xfill True yfill True ## Automatically makes button same size as window
        action Play('sound', 'click.ogg')
        keysym 'dismiss' ## Give the dismiss keys directly to keysym
This will also override the say screens ctc so you can't advance the text, but there are workarounds to make it work.

A different method would be to just play a sound each time the say screen is hidden, which it does every time you click to continue and advance the text.

Code: Select all

screen say(who, what):
    
    if not config.skipping and what: ## Stop sound playing when skipping
    	on 'hide' action Play('sound', 'click.ogg') ## Play sound when say screen is hidden
Edit: There's also a click to conitnue screen that you can use instead.

Code: Select all

screen ctc(arg=None):
    if not config.skipping:
        on 'hide' action Play('sound', 'click.ogg')

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Sound on Click?

#4 Post by Remix »

Alternatively (though this is not fully tested)

Code: Select all

init python:

    config.underlay.append(
        renpy.Keymap( 
            mousedown_1 = lambda: renpy.run( renpy.play("audio/auto/default/completion_7_meghan.ogg")  ) # rename the file as needed
        )
    )
Frameworks & Scriptlets:

4listair
Newbie
Posts: 11
Joined: Tue Jul 31, 2018 10:54 pm
Contact:

Re: Sound on Click?

#5 Post by 4listair »

All of your guys' solutions were wayy less complicated than what I'd come up with... Damn. Many thanks!

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], peach_light