【发布时间】: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 程序员经常犯的错误。 -
谢谢,就像我说的。代码运行正常,是重新加载场景不起作用