预期
如何在没有用户输入或按钮的情况下将一个lua文件替换为另一个lua文件(如幻灯片)?声音结束了?计时器吗?
例如,scene1:
中的代码-- 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
当音乐结束后,被这个接替:
-- visuals
positionOne = display.newImage( note1, 170, pitch3 )
-- first of the two notes in the bar: 170 = x coordinate, pitch = y
coordinate
positionTwo = display.newImage( note2, 320, pitch4 )
-- second of the two notes in the bar
-- accomp 1
local accomp = audio.loadStream("sounds/chord3.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/chord4.mp3")
audio.play(accomp, {channel = 2})
audio.stopWithDelay(60000/72])
end
timer.performWithDelay(60000/72, listener)
end
作为一名初学者,我无法理解Corona现成的多场景编码,因为它依赖于用户输入按钮。我注意到,在启动这样一个项目时,主要内容直接移动到场景1,没有ui。其他场景也是这样吗?我说错了什么?
您可以使用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()