我正在处理声音开关,但是当我使用"audio.setVolume( 0.0 )“和"audio.setVolume( 0.7 )”时,它会工作,但是当我尝试使用"fade“& "fadeOut”函数时,它会像我想要的那样关闭声音,但不会再次打开。
function onOFF(event)
if event.phase == "began" then
if sound == 1 then
sound = sound + 1
audio.fadeOut({ channel=setVolume, time=500 } )
switchoff()
elseif sound == 2 then
sound = sound - 1
audio.fade({ channel=setVolume, time=500, volume=0.7 } )
switchon()
end
end
end
我能看出原因,有什么帮助吗?
function switchon()
screenGroup = self.view
SwitchOff = display.newImage("soundISon.png")
screenGroup:insert(SwitchOff)
SwitchOff.x = 50; SwitchOff.y = 600
transition.to( SwitchOff, { time=700, y=465, transition=easing.inOutExpo } )
transition.to( SwitchOn, { time=500, y=500, transition=easing.inOutExpo } )
SwitchOff:addEventListener("touch", onOFF)
end
发布于 2013-07-09 00:55:34
当您淡出音量时,您正在更改通道的音量。这个值是持久化的,,如果您想在以后的中再次使用该通道,那么您有责任重置通道上的卷。
您需要使用audio.setVolume()
再次设置通道的音量。
加法: audio.fadeOut()
--在指定的时间内停止播放声音,并在此过程中减弱到最小音量。音频将在时间结束时停止,频道将被释放。
因此,我认为您需要再次播放声音,并将音量设置为0.0,然后再使用audio.fade()
function onOFF(event)
if event.phase == "began" then
if sound == 1 then
sound = sound + 1
audio.fadeOut({ channel=setVolume, time=500 } )
switchoff()
elseif sound == 2 then
sound = sound - 1
audio.play( yourSound, {channel=setVolume, loops=-1}) -- Like this
audio.setVolume( 0.0, { channel=setVolume } )
audio.fade({ channel=setVolume, time=500, volume=0.7 } )
switchon()
end
end
end
参考文献
https://stackoverflow.com/questions/17535772
复制相似问题