Spherical forums

Sphere Development => Sphere Support => Script Support => Topic started by: Eggbertx on April 30, 2017, 09:06:13 pm

Title: Play a sound multiple times without waiting for it to finish
Post by: Eggbertx on April 30, 2017, 09:06:13 pm
I'm trying to get it so that I can play a loaded Sound file multiple times (for example, playing a bullet firing sound quickly), but calling sound_obj.play(Mixer.Default) seems to block it script execution until it finishes. Is there a way to play sound objects asynchronously?
Title: Re: Play a sound multiple times without waiting for it to finish
Post by: Fat Cerberus on April 30, 2017, 11:27:24 pm
Sound#play() shouldn't block.  The music module in particular specifically relies on it not blocking, so it's kind of weird if it is for you.

That said, a single Sound can only have one instance playing at a time - calling play() on it again will just restart it:

Code: [Select]

Sound#play([mixer]);

    Begins or resumes sound playback.  When called with no `mixer` argument,
    Sound#play() will resume playback for a paused sound.  Otherwise, the sound
    is started from the beginning on the specified mixer.


I should probably implement a SoundEffect API like Sphere 1.6.  Something to think about for the next miniSphere version, I guess. :)
Title: Re: Play a sound multiple times without waiting for it to finish
Post by: Eggbertx on May 01, 2017, 02:56:01 am
I think that might have been the issue then. Though it seems to have issues if it restarts it repeatedly .