首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >audio.fade()没有打开

audio.fade()没有打开
EN

Stack Overflow用户
提问于 2013-07-08 20:50:45
回答 1查看 228关注 0票数 0

我正在处理声音开关,但是当我使用"audio.setVolume( 0.0 )“和"audio.setVolume( 0.7 )”时,它会工作,但是当我尝试使用"fade“& "fadeOut”函数时,它会像我想要的那样关闭声音,但不会再次打开。

代码语言:javascript
运行
复制
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

我能看出原因,有什么帮助吗?

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-09 00:55:34

当您淡出音量时,您正在更改通道的音量。这个值是持久化的,,如果您想在以后的中再次使用该通道,那么您有责任重置通道上的卷。

您需要使用audio.setVolume()再次设置通道的音量。

加法: audio.fadeOut() --在指定的时间内停止播放声音,并在此过程中减弱到最小音量。音频将在时间结束时停止,频道将被释放。

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

代码语言:javascript
运行
复制
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

参考文献

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17535772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档