Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua audio.fade()未打开_Lua_Coronasdk - Fatal编程技术网

Lua audio.fade()未打开

Lua audio.fade()未打开,lua,coronasdk,Lua,Coronasdk,我正在使用声音打开和关闭开关,但当我使用“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.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
我知道原因了,有什么帮助吗



淡入音量时,您正在更改频道的音量。此值是永久性的,如果您以后想再次使用该频道,您有责任重置该频道上的音量

您需要使用
audio.setVolume()

添加:
audio.fadeOut()
-这会在指定的时间内停止播放声音,并在播放时衰减到最小音量。音频将在时间结束时停止,频道将被释放

因此,我认为在使用
audio.fade()之前,您需要再次播放声音并将音量设置为0.0


你能在你的问题上添加switch on()函数吗?你知道,你可以编辑你自己的问题。我编辑了我的答案,请复习。当我使用“audio.setVolume(0.0)”和“audio.setVolume(0.7)”时,还有一件奇怪的事它关闭和打开所有声音,包括其他屏幕,但我使用“淡入”只关闭当前屏幕中的声音。您可以在
audio.setVolume(0.7,{channel=setVolume})上添加要更改的频道
是,但“audio.setVolume”或“setVolume”应该是主音量控制,因此理论上,如果将音量调低到“0.0”,则所有声道都应处于“0.0”位置,对吗?是的,这是正确的,如果要淡出或淡出所有声道,则必须删除类似以下的频道选项
audio.fade({time=500,volume=0.7})
音频淡出({time=500})
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
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