【问题标题】:In Corona SDK composer, when I reload a scene, audio slightly fades out在 Corona SDK 作曲家中,当我重新加载场景时,音频会稍微淡出
【发布时间】: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 个)。有什么想法吗?

【问题讨论】:

    标签: audio lua coronasdk


    【解决方案1】:

    你应该替换

    audio.fadeOut(theme,{500})
    

    audio.fadeOut( { channel=2, time=500 } )
    

    因为你使用了错误的语法。

    audio.fadeOut()

    【讨论】:

    • 我已经更正了语法,但问题仍然存在。我尝试在场景中停止音频:隐藏“将”阶段并将其放置在场景中:隐藏“做”,问题消失但音频不会淡出(这是一个小问题,我不太在意它)。可能是电晕虫?无论如何,非常感谢您的回答
    • 编辑我的错!没有很好地阅读 audio.fadeOut() 页面,抱歉。在场景中播放音频后:show() "will" 阶段我使用 audio.setVolume(1,{channel=2}) 并且一切似乎都运行良好,即使淡出
    【解决方案2】:

    确保您阅读了文档的“Gotcha”部分:

    当您淡出音量时,您正在改变频道的音量。此值是持久的,如果您想稍后再次使用该通道,您有责任重置该通道的音量(请参阅 audio.setVolume())。

    您负责设置通道音量,因为淡出会改变通道的音量。

    【讨论】:

      猜你喜欢
      • 2015-06-05
      • 2015-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多