audio - 在 Corona SDK Composer 中,当我重新加载场景时,音频会稍微淡出

标签 audio lua coronasdk

在我的 Corona SDK 项目中,我有一个名为“menu.lua”的 Composer 场景(使用 composer.newScene() 创建),它是第一个场景,由 main.lua 文件调用。我只有这个场景的背景音轨,在场景中加载:create() 和 audio.loadSound() 在本地变量中。当我加载另一个场景(假设它是一个“信用”场景,静态,没有音乐、声音、动画、计时器等)然后回到菜单场景时,音频仍在播放,但音量较低。

音频在 channel 2 上循环播放,我在场景中使用 audio.play():show "did"阶段。我在场景中使用 audio.fadeOut():隐藏“will”阶段,并在“did”阶段使用 audio.stop() 停止它,然后在场景中使用 audio.dispose() 处理它:destroy。

在“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

我已经尝试在场景:显示“did”阶段和场景:创建中播放音频,但问题仍然存在。问题发生在所有场景中,所有场景都是静态的(总共 3 个)。任何的想法?

最佳答案

你应该更换

audio.fadeOut(theme,{500})


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

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

audio.fadeOut()

关于audio - 在 Corona SDK Composer 中,当我重新加载场景时,音频会稍微淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54440349/

相关文章:

java - 使用 JLayer 时更改 Java 中的音量

javascript - 一个不涉及模拟经典继承的原型(prototype)继承的例子?

c++ - 创建 CCScale9Sprite 时使用 Lua 和 Cocos2d-x 的混淆

c++ - Lua:将外部函数定义重定向到指定表

lua - 将拍摄的照片缩放到屏幕尺寸

lua - Corona SDK - 从 eventListener 调用实例方法或类方法

android - Corona newScrollView hideScrollBar 仍然显示滚动条

ios - 随机化声音的最简单方法是什么

iphone - cocoa 接触-资源问题

python - 改善python视频演示的声音等待时间