How do I best manage sound channels?
My current setup involves loading the sound in my main.lua
bgMusic = audio.loadSound( "sounds/Torukia.mp3" )
musicIsPlaying = false
Creating and playing the sound channel on the first scene (I’m using Director to move between scenes)
[code]if musicIsPlaying == false then
if gameSettings.soundOn == true then
backgroundMusicChannel = audio.play( bgMusic, { loops=-1 } )
musicIsPlaying = true
elseif gameSettings.soundOff == true then
end
end[/code]
And stopping/playing the song on a different scene (also using a save/load function to make sure settings are remembered)
local function toggleSound( event )
if event.phase == "ended" then
if gameSettings.soundOn == true then
gameSettings.soundOn = false
gameSettings.soundOff = true
audio.stop( )
soundBtn:setFillColor( 255,0,0 )
elseif gameSettings.soundOff == true then
gameSettings.soundOn = true
gameSettings.soundOff = false
backgroundMusicChannel = audio.play( bgMusic, { loops=-1 } )
soundBtn:setFillColor( 0,255,0 )
end
saveSettings(gameSettings, "gameSettings.json")
end
end
This works fine, but it obviously wouldnt work if I want to create options for either music and sound effects, since currently it stops all sound channels from playing.
How would I optimize these bits of code? (is it possible to create sound channels without automatically playing the sound? I’ve tried a few things, but couldnt get that to work). [import]uid: 200198 topic_id: 36279 reply_id: 336279[/import]