如何在没有用户输入(如幻灯片放映)的情况下从一个 lua 场景移动到另一个场景?
How to move from one lua scene to another without user input like a slide show?
如何在没有用户输入或按钮的情况下将一个 lua 文件替换为另一个 lua 文件(如幻灯片)?声音结束?定时器?
例如,场景 1 中的编码:
-- 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现成的多场景编码,无论如何都依赖于用户输入按钮。我注意到在启动这样一个项目时,main 直接移动到 scene1,没有 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()
一起工作
如何在没有用户输入或按钮的情况下将一个 lua 文件替换为另一个 lua 文件(如幻灯片)?声音结束?定时器?
例如,场景 1 中的编码:
-- 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现成的多场景编码,无论如何都依赖于用户输入按钮。我注意到在启动这样一个项目时,main 直接移动到 scene1,没有 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()