Hello,
I added some audio into my game, Hammy’s Harvest but I can’t get it to resume. I’m not sure if there is something going on with the channels but everything else seems to be working…
local sound = {
on = display.newImageRect("sound\_on.png", 75, 68),
off = display.newImageRect("sound\_off.png", 75, 68),
}
sound.on.x, sound.on.y = 40, 440
sound.off.x, sound.off.y = 40, 440
button\_sound = audio.loadSound("pop.wav")
--I added the code below because I thought that it would help performance. Any advice?
music\_channel = audio.loadStream("Soundtrack.mp3")
--I got rid of the extra button because I wanted to just make one button for the SFX and Soundtrack
--[[local music = {
on = display.newImageRect("music\_on.png", 75, 68),
off = display.newImageRect("music\_off.png", 75, 68),
}
music.on.x, music.on.y = 100, 440
music.off.x, music.off.y = 100, 440
--]]
--music\_channel = audio.loadSound("Soundtrack.mp3")
music\_channel = audio.play( music\_channel, { channel=1, loops=-1, fadein=5000 } )
--play\_sound(music\_channel)
local function set\_btn\_states()
if settings.game.options.sound then
sound.on.isVisible = true sound.off.isVisible = false
else
sound.on.isVisible = false sound.off.isVisible = true
end
end
set\_btn\_states()
--I tore down this code from what it was before only because it wasn't working but if you see anything that would fix it let me know. How this code looked before I tore it down is below in the next section.
local function switch\_state(event)
if event.phase == "ended" then
if event.target==sound.on then
audio.pause( music\_channel )
print("First State Working")
end
if event.target==sound.off then
audio.resume( music\_channel )
print("Second State Working")
end
-- this is for the pop sound
set\_btn\_states()
settings:save()
--audio.resume( { channel = 1 } )
play\_sound(button\_sound)
end
end
sound.on:addEventListener("touch", switch\_state)
sound.off:addEventListener("touch", switch\_state)
Pre torn down…
local sound = {
on = display.newImage("sound\_on.png"),
off = display.newImage("sound\_off.png"),
}
sound.on.x, sound.on.y = 250, 30
sound.off.x, sound.off.y = 250, 30
local music = {
on = display.newImage("music\_on.png"),
off = display.newImage("music\_off.png"),
}
music.on.x, music.on.y = 300, 30
music.off.x, music.off.y = 300, 30
localGroup:insert(sound.on)
localGroup:insert(sound.off)
localGroup:insert(music.on)
localGroup:insert(music.off)
button\_sound = audio.loadSound("button.wav")
local function set\_btn\_states()
if settings.game.options.sound then
sound.on.isVisible = true sound.off.isVisible = false
else
sound.on.isVisible = false sound.off.isVisible = true
end
if settings.game.options.music then
music.on.isVisible = true music.off.isVisible = false
else
music.on.isVisible = false music.off.isVisible = true
end
end
set\_btn\_states()
--[[
DISCOMMENT FOLLOWING LINES IF YOU PLAN TO USE MUSIC
local music\_channel = audio.play("music.mp3", {loops=-1})
if not settings.game.options.music then
audio.pause(music\_channel)
end
]]
local function switch\_state(event)
if event.phase == "ended" then
if event.target==sound.on or event.target==sound.off then
settings.game.options.sound = not settings.game.options.sound
else
settings.game.options.music = not settings.game.options.music
if not settings.game.options.music then
audio.pause(music\_channel)
else
audio.resume(music\_channel)
end
end
set\_btn\_states()
settings:save()
play\_sound(button\_sound)
end
end
sound.on:addEventListener("touch", switch\_state)
sound.off:addEventListener("touch", switch\_state)
music.on:addEventListener("touch", switch\_state)
music.off:addEventListener("touch", switch\_state)
return localGroup
end
Thanks for checking it out, I hope this doesn’t look daunting I just wanted to show everything.
Danny [import]uid: 59140 topic_id: 27019 reply_id: 327019[/import]

