如何从一个lua场景移动到另一个场景,而无需用户输入,如幻灯片放映?

如何从一个lua场景移动到另一个场景,而无需用户输入,如幻灯片放映?,lua,android-transitions,corona-storyboard,Lua,Android Transitions,Corona Storyboard,在没有用户输入或按钮的情况下,如何将一个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 = dis

在没有用户输入或按钮的情况下,如何将一个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})

但是我还没有测试过它在音频上是否能像预期的那样工作。stopWithDelay

我问了两个问题,可能是重复的。由于第一次没有回复,我认为我实际上没有发布它。第二个更清楚地解释了我的问题。希望您能提供帮助。您可以查看您在个人资料页面上发布的问题。请看下一次,这次请删除您以前未回答的问题。我仍然无法将一个场景切换到另一个场景。你建议的代码是一个场景或一个更大身体的一部分所需的全部代码吗?我是否应该能够在场景2中重复此代码,并以相同的方式将其重定向回场景1?当我运行它时,我得到以下错误警告:尝试为全局“composer”索引一个空值堆栈回溯。梅因:卢阿:10;在函数“U侦听器”中-主Lua10是composer.gotoScene行。我假设您已经使用类似于中的模板的内容设置了场景代码?每个场景一个lua文件。那这个应该行了。谢谢,我来看看。