I’m adding more sound aspects to my game, and I’m wondering if there’s a way to do sound.stop() for all current sounds, instead of just having to go one by one stopping all the sounds that could be playing.
1 Like
For this, e.g. I have a module that is managing all the sounds I want to play or stop (and I also have all the sound components collected in one game object that is receiving messages to play given sound as “event”)
You can then write a script in the same game object that have all sound components and add more functionalities (fading in, out, delays, gains, etc), for example:
function on_message(self, message_id, message, sender)
if message_id == m.MUSIC then -- for example differentiate background music
sound_manager.manage_music(message.name, message.attack, message.decay, message.gain, message.speed)
elseif message_id == m.PLAY then -- and SFX
sound_manager.manage_play(message.name, message.gate, message.attack, message.gain,
message.speed, message.gain_variation, message.custom_cb)
elseif message_id == m.STOP then
sound_manager.manage_stop(message.name, message.decay, message.open_now)
end
end
I have such module in WIP state, it might be released soon
4 Likes