I have a class(game.lua) and from there I can to gameover.lua or gamesuccess.lua
From last 2 I can restart the game.
I have the clean class:
local function cleanGroups ( currentGroup, level )
if currentGroup.numChildren then
while currentGroup.numChildren and currentGroup.numChildren > 0 do
Runtime:removeEventListener( “enterFrame”, currentGroup[currentGroup.numChildren] )
cleanGroups ( currentGroup[currentGroup.numChildren], level+1 )
end
if level > 0 then
display.remove( currentGroup )
currentGroup = nil
collectgarbage(“collect”);
end
else
display.remove( currentGroup )
currentGroup = nil
collectgarbage(“collect”);
return
end
end
cleanScreen = function()
– Stop listeners
Runtime:removeEventListener( “touch”, touchListener )
Runtime:removeEventListener( “enterFrame”, objectSpawner )
Runtime:removeEventListener( “system”, onSystem )
gameIsActive = false
physics.stop()
cleanGroups( backgroundGroup, 0 )
cleanGroups( flyingNotCompletedGroup, 0 )
cleanGroups( flyingCompleteGroup, 0 )
cleanGroups( menuGroup, 0 )
cleanGroups( hudGroup, 0 )
cleanGroups( flyingNotCompletedGroup, 0 )
for i = 2, display.getCurrentStage( ).numChildren do
display.getCurrentStage( ):remove( 2 )
end
print(“last chance children on the screen:”…display.getCurrentStage( ).numChildren )
collectgarbage(“collect”);
end
here is restart game function:
restartGame = function()
timer.performWithDelay( 0, cleanScreen, 1 )
timer.performWithDelay( 200, gotoRestartScreen, 1 )
end
The problem is when I reload the game.lua, I see, the old instance is not deleted and when I call a function, is called from old instance and not from the new one.
It’s important to know, I don’t use storyboard in my project.
The transitions between the screen is with director:changeScene. [import]uid: 84731 topic_id: 32917 reply_id: 332917[/import]