Play sound effects with delay

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
Yuuji
Regular
Posts: 96
Joined: Tue Jan 20, 2015 3:08 am
Location: Russia, Perm
Contact:

Play sound effects with delay

#1 Post by Yuuji »

Hello! I want to play some of sound effects in my game with delay. So I want next phrase to begin appear on say screen and after couple of seconds from that moment sound effect should play. Is there any way to do that? I'd appreciate any help with that.
There's no point in standing around with your mouth open waiting for talent to fall from the sky. You make your own. No matter what you're doing, the most essential thing is not to give up.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Play sound effects with delay

#2 Post by PyTom »

Short of just queuing up silence, no.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Donmai
Eileen-Class Veteran
Posts: 1960
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Play sound effects with delay

#3 Post by Donmai »

You can also choose where in the sentence the sound will play, by using the no wait tag and the extend character. Of course this will only have some effect if cps is not zero.

Code: Select all

    "Eileen tried to say something more, but {nw}"
    play sound "punch.ogg"
    extend "Lucy knocked her down before she could do it."
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
Yuuji
Regular
Posts: 96
Joined: Tue Jan 20, 2015 3:08 am
Location: Russia, Perm
Contact:

Re: Play sound effects with delay

#4 Post by Yuuji »

PyTom, Donmai, thank you for your answers!
There's no point in standing around with your mouth open waiting for talent to fall from the sky. You make your own. No matter what you're doing, the most essential thing is not to give up.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Play sound effects with delay

#5 Post by nyaatrap »

Akakyouryuu made a code to run functions with delay

Code: Select all

# http://akakyouryuu.com/配布物/renpy/
# 遅延実行のスクリプトです。
# show expression delay_run(3, [renpy.curry(camera_move)(0, 0, 1000, 0, 3), renpy.restart_interaction])
# show expression delay_run(3, hogehoge_function)
#
# delay_run(delay, functions)
# delay: 遅延する秒数です。
# functions: 遅延実行する関数または関数のリストです。引数を使用したい場合は
# renpy.curry関数を使用してください。

    class DelayRunBehavior(renpy.display.layout.Null):

        def __init__(self, delay, functions, *args, **properties):
            super(DelayRunBehavior, self).__init__(**properties)

            self.delay = delay
            if not isinstance(functions, list):
                functions = [functions]
            self.functions = functions
            self.args = args

        def event(self, ev, x, y, st):

            if st >= self.delay:

                if renpy.game.interface.drawn_since(st - self.delay):
                    for function in self.functions:
                        function()
                    self.functions = []
    delay_run = renpy.ui.Wrapper(DelayRunBehavior)
You can play sound like
$delay_run(1.0, [renpy.curry(renpy.music.play)("filename","sound"), renpy.restart_interaction])

Post Reply

Who is online

Users browsing this forum: Donmai