【问题标题】:Corona: Restart scene when game completedCorona:游戏完成后重启场景
【发布时间】:2013-04-05 07:24:33
【问题描述】:

当玩家完成游戏后,我想重新启动场景,即我想重新加载当前场景。我试过 storyboard:reloadScene() 没有成功。 我也尝试清除场景然后重新加载它,也没有任何结果。

local function onEveryFramePoop()
if(foodBalls) then
    for i = foodBalls.numChildren, 1, -1 do
        local ball = foodBalls[i]

        if(ball.y > 200 and not(ball.isBeingPooped)) then
            ball.isBeingPooped = true

            local function tempRemove()
                if(foodBalls.numChildren)then
                    ball:removeSelf()
                    ball = nil
                    print("removed")
                end
            end
            physics.removeBody(ball)

            transition.to(ball, {time = 2000, y = 400, onComplete = tempRemove})
            audio.play(fartSound)
        end
    end

    if(foodBalls.numChildren == 0 and food.numChildren == 2) then

        reward.playRewardAnimation()
        Runtime:removeEventListener("enterFrame", onEveryFramePoop)     
        timer.performWithDelay(2500, reloadSceneWithDelay)  
    end
  end
end

function reloadSceneWithDelay()
     storyboard.gotoScene("levels.levelDigestion") -- **HERE I WANT TO RESTART SCENE**
end

似乎什么都没有发生。我在这里错过了什么?

【问题讨论】:

  • 您的意思是if(foodBalls.numChildren > 0)then 而不是if(foodBalls.numChildren)then
  • 这不是问题!我只需要在调用 reloadSceneWithDelay 时重新加载场景。
  • 是的,这不是主要问题。但是在 Lua 中写 if(a)then 而不是 if a~=0 then 是 C 程序员经常犯的错误。
  • 谢谢,就像我说的。代码运行正常,是重新加载场景不起作用

标签: lua coronasdk


【解决方案1】:

我没有使用故事板,但是你可以试试这个:

在情节提要中创建黑色场景 然后,当你想重新开始的时候,只要去黑色场景,然后再去你想去的场景。

问题可能与您尝试从自身调用模块有关。

【讨论】:

    猜你喜欢
    • 2016-04-12
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多