Page 1 of 1

How to turn off audio inside game loop

Posted: Mon Jul 09, 2018 10:20 am
by janglee
hi everyone , i am working on 2d endless running game for android . I only want to mute all sounds with button just like other games . I can do it by putting every sound play statements inside if statement but it is not a proper way . can anyone suggest me how can i do that ?

Re: How to turn off audio inside game loop

Posted: Mon Jul 09, 2018 11:14 am
by Nixola
You can use love.audio.setVolume to keep playing them while muted, or love.audio.stop to stop everything that's playing and then, as you said, not play anything unless it's unmuted. What you choose is up to you - I guess the former will be a bit heavier on the processor and/or battery and/or might mess with volume controls since it might technically still be playing sounds, and the music progresses while not heard so when someone unmutes it will be as if it never stopped; the latter will require "if guards" or similar, but it'll truly stop any audio from being played and processed; the music will resume from the beginning when unmuting.
This might all bee moot if LÖVE, or OpenAL, handles no volume as a special case; in that case, I guess it's just the same.