【发布时间】:2019-06-23 17:16:28
【问题描述】:
在我的 Corona SDK 项目中,我有一个名为“menu.lua”的作曲家场景(使用 composer.newScene() 创建),它是第一个场景,由 main.lua 文件调用。我只有这个场景的背景音轨,在场景中加载:create() 和 audio.loadSound() 在本地变量中。当我加载另一个场景(假设它是一个“信用”场景,静态,没有音乐、声音、动画、计时器等)然后回到菜单场景时,仍然播放音频,但音量较低。
音频在通道 2 上循环播放,我在场景中使用 audio.play():show "did" 阶段。我在 scene:hide "will" 阶段使用 audio.fadeOut(),并在 "did" 阶段使用 audio.stop() 停止它,然后在 scene:destroy 中使用 audio.dispose() 处理它。
在“menu.lua”文件中
local composer=require("composer")
local scene=composer.newScene()
local theme --this is the variable for audio
function scene:create(event)
local sceneGroup=self.view
theme=audio.loadSound("sfx/theme_short.mp3")
end
function scene:show(event)
local sceneGroup=self.view
if event.phase=="will"
audio.play(theme,{loops=-1,channel=2})
end
end
function scene:hide(event)
local sceneGroup=self.view
if event.phase=="will" then
audio.fadeOut(theme,{500})
end
elseif event.phase=="did" then
audio.stop(2)
end
end
function scene:destroy(event)
local sceneGroup=self.view
audio.dispose(theme)
end
另一个场景(假设它是“credits.lua”)由一个附加了“tap”事件的按钮调用。在“credits.lua”中,我使用此函数返回“menu.lua”场景(通过附加到按钮的“tap”事件调用函数)
local function goMenu()
composer.removeScene("menu")
composer.gotoScene("menu","slideUp",500)
return true
end
我已经尝试在 scene:show "did" 阶段和在 scene:create 中播放音频,但问题仍然存在。问题发生在所有场景中,所有场景都是静态的(总共 3 个)。有什么想法吗?
【问题讨论】: