Skip to main content

News

Topic: Play a sound multiple times without waiting for it to finish (Read 3381 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
Play a sound multiple times without waiting for it to finish
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?
  • Last Edit: April 30, 2017, 09:12:02 pm by Eggbert

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • Sphere Developer
Re: Play a sound multiple times without waiting for it to finish
Reply #1
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. :)
  • Last Edit: April 30, 2017, 11:30:00 pm by Fat Cerberus
neoSphere 5.9.2 - neoSphere engine - Cell compiler - SSj debugger
forum thread | on GitHub

Re: Play a sound multiple times without waiting for it to finish
Reply #2
I think that might have been the issue then. Though it seems to have issues if it restarts it repeatedly .