如何在没有用户输入或按钮的情况下将一个lua文件替换为另一个lua文件(如幻灯片放映)?声音结束?计时器?
例如,在scene1中编码:
<preference name="StatusBarOverlaysWebView" value="true" />
一旦音乐结束,成功了:
-- visuals
positionOne = display.newImage( note1, 170, pitch1 )
-- first of the two notes in the bar: 170 = x coordinate, pitch = y
coordinate
positionTwo = display.newImage( note2, 320, pitch2 )
-- second of the two notes in the bar
-- accomp 1
local accomp = audio.loadStream("sounds/chord1.mp3")
audio.play(accomp, {channel = 1})
audio.stopWithDelay(60000/72)
-- 72 = beats per minute
-- accomp 2
local function listener(event)
local accomp = audio.loadStream("sounds/chord2.mp3")
audio.play(accomp, {channel = 2})
audio.stopWithDelay(60000/72])
end
timer.performWithDelay(60000/72, listener)
end
作为初学者编码器,我无法理解Corona的现成多场景编码,无论如何都依赖于用户输入按钮。我注意到,在启动这样的项目时,主要直接移动到scene1而没有ui。其他场景可以这样吗?我错了什么?
答案 0 :(得分:0)
您可以使用timer.performWithDelay()
安排场景切换,因为您可以计算第二个音频播放何时停止。
类似的东西:
local function switchScene()
composer.gotoScene( "scene2", { effect = "slideLeft", time = 500} )
end
-- start the audio stuff here as before...
-- Register scene switch to happen once the audio is done
local timeBeforeSwitch = 2*(60000/72)
timer.performWithDelay(timeBeforeSwitch, switchScene)
作为替代方案,它应该能够将onComplete
回调注册到最后一个音频播放调用,如下所示:
audio.play(accomp, {channel = 2, onComplete=switchScene})
但我还没有通过audio.stopWithDelay()