Looping Sound

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
cracklings
Newbie
Posts: 14
Joined: Sat Nov 19, 2011 10:53 am

Looping Sound

#1 Post by cracklings » Sun Jul 22, 2012 12:14 am

Hi there,

Is there any way to loop sound while there is music playing in the background? My sound file is a three second audio and it is intended to loop as an annoying sound until the MC notices and remarks upon it. I know music loops but sound doesn't. I know I could use the persistent sound as music instead, but I don't want to as much as possible.

Code I use is the standard one

Code: Select all

play sound audiotrack.ogg
I have thought about splicing the sound file to create one big file, but 1. It might end up being too big or 2. Depending on how fast or slow the player will be, it can affect gameplay.

If there is a solution, please let me know.

RunicV
Veteran
Posts: 240
Joined: Tue May 29, 2012 12:06 am
IRC Nick: RunicV
Contact:

Re: Looping Sound

#2 Post by RunicV » Sun Jul 22, 2012 1:11 am

You could try this:

Code: Select all

    MC "This would work, wouldn't it?"
    play sound audiotrack.ogg
    queue sound audiotrack.ogg
    queue sound audiotrack.ogg
    queue sound audiotrack.ogg
    queue sound audiotrack.ogg
    queue sound audiotrack.ogg
    # Keep on queueing it to a large amount to make up for different reading speeds.
    MC "Hey, what's with that annoying sound?"
    stop sound
    MC "Oh, it stopped."
However, that would be troublesome. The best way is to use it as music. If you don't want to do that because you think you won't be able to play your background music while playing the sound, you could just place it on a different channel.

Hope I helped.
Hatred: the absence of love.
Please, treat me with kindness.

cracklings
Newbie
Posts: 14
Joined: Sat Nov 19, 2011 10:53 am

Re: Looping Sound

#3 Post by cracklings » Sun Jul 22, 2012 1:39 am

Hmm, I never thought of putting it in different channels. I'll check up on that. My original goal is to have it playing alongside the music.

I'll try the other solution a try too.

Thanks!

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Looping Sound

#4 Post by PyTom » Mon Jul 23, 2012 1:16 am

The right way to do this is to add another channel.

Code: Select all

init python:
    renpy.music.register_channel("annoying", "sfx", loop=True, tight=True)
then

Code: Select all

play annoying "annoyance.ogg"
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]