hi i have asked this question in developer support subforum but apparently nobody know how to do it properly, here’s the link:
http://developer.anscamobile.com/forum/2012/03/11/how-restart-game-mainlua-again
*my problem is not the first post, read my 2nd post. That’s what Im trying to do, here the question again:
Here in game.lua i have a restart button with code:
local function restart(event)
if event.phase == "ended" then
onSystemEvent ()
Runtime:removeEventListener("touch", stop )
Runtime:removeEventListener("enterFrame", wrapit)
Runtime:removeEventListener("enterFrame", bucketfollow)
Runtime:removeEventListener("enterFrame", bananacheck)
Runtime:removeEventListener("enterFrame", testCollisions)
Runtime:removeEventListener("system", onSystemEvent )
audio.stop (gameMusicChannel)
director:changeScene ("restart")
end
end
restartBtn:addEventListener('touch', restart)
and in restart.lua, i have
[code]display.setStatusBar (display.HiddenStatusBar)
local function main()
director:changeScene(“game”)
–> Change the scene, no effects
end
timer.performWithDelay(100, main, 1)
–> Starts our app
[/code]
but it returned with blank screen after i click the restart button - which has director:changeScene (“restart”) inside the code
strangely, it works if I redirect to “restart” from main.lua but it doesnt work if i redirect to “restart” from game.lua.
so if lets say the whole redirection is like this, it does work:
main -> restart -> game
but if the redirection is like this, it doesnt work:
main -> game -> restart -> game
what’s the best way to fix this? Basically i just want to restart game.lua when i touch the restart button in the game.
*PS: I have already included local director = require (“director”) in my main.lua [import]uid: 114765 topic_id: 23404 reply_id: 323404[/import]