【问题标题】:adding play/stop button corona labs?添加播放/停止按钮电晕实验室?
【发布时间】:2017-12-26 23:40:38
【问题描述】:

我是 Corona 游戏开发的新手,如果这有助于我在游戏中添加 播放/停止 按钮,这是我用来播放背景音乐的功能:

  local backgroundMusicChannel
  local backgroundMusicSounds = {}
  if (backgroundMusic == true) then
  for i=1, backgroundMusicNumber do
        backgroundMusicSounds["bg" .. i] = audio.loadStream("sounds/bg" .. i ..".mp3")
  end
  end
  function playBackgroundMusic()
  if (backgroundMusic == true) then
        backgroundMusicChannel = audio.play( backgroundMusicSounds["bg" .. math.random(1,backgroundMusicNumber)], { channel=5, loops=-1 } )
  end
  end

  function stopBackgroundMusic()
  if (backgroundMusic == true) then
        audio.stop( backgroundMusicChannel )
  end
  end

【问题讨论】:

  • 显示你到目前为止所做的事情。
  • 其实我根本没有找到解决办法
  • 所以也许最好从Chapter 1 — Creating an App 开始,然后再深入:) 祝你好运。

标签: coronasdk


【解决方案1】:
--Load audio stream
    local backgroundMusic = audio.loadStream( "backgroundMusic.m4a" )

--Play the background music on channel 1, loop infinitely
    local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1} )

--Pause Audio Stream
    local backgroundMusicChannel = audio.play( backgroundMusic, { loops=-1 }  ) 
    audio.pause( backgroundMusicChannel )

--Resume after 3 seconds
    timer.performWithDelay( 3000, function()
        audio.resume( backgroundMusicChannel )
    end, 1 )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多