电晕:游戏完成时重新启动场景
问题描述:
当玩家完成游戏时,我希望重新开始场景,即我想重新加载当前场景。我曾尝试故事板: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'? – 2013-04-05 08:34:05
这不是问题!我只需要在reloadSceneWithDelay被调用时重新加载场景。 – Eyeball 2013-04-05 08:36:15
是的,这不是主要问题。但是,如果(a)then代替'then a〜= 0 then',那么在Lua中编写C程序员的错误非常频繁。 – 2013-04-05 08:39:35