添加播放/停止按钮电晕实验室?

问题描述 投票:0回答:1

我对Corona Game Development完全不熟悉,如果这有助于我使用播放背景音乐的功能,我会坚持为游戏添加一个播放/停止按钮:

  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
corona
1个回答
0
投票
--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 )
© www.soinside.com 2019 - 2024. All rights reserved.