Reputation: 714
Am using Corona's SDK storyboard API, in my app I want to let users "try again" the level. I though simply calling
storyboard.gotoScene("level20","flip")
where level20 is the current scene, after an event (taping the "try again" button) would work but the scene keeps all it's display objects in the same place instead of resetting like when I come from a different scene.
Is it possible to restart a scene from the same scene?
Thanks.
Edit:
Am using Corona's Version: 2.0.0, Build: 2011.704
Edit (possible fix):
I might have found the fix. From the docs in the "Scene Purging and Removal": when you go to a new scene the previous scene sticks around in memory for fast reloading, scene:createScene() removes this memory.
So the fix I found was to call scene:createScene()
, it seems to work but if this is the wrong approach please let us know. Thanks.
Upvotes: 3
Views: 10241
Reputation: 2322
Above seemed not work well, I got my solution with simple transition effect.
function scene:refresh(event)
local v = self.view
transition.to(v, {time=500, alpha=0.5, transition=easing.inExpo, onComplete=function(e)
self:destroyScene()
self:createScene()
storyboard.reloadScene()
transition.to(v, {time=500, alpha=1, transition=easing.outExpo})
end})
end
Upvotes: 1
Reputation: 19
create a 'dummy scene' where u can storyboard.purgeScene("level20") under createScene() then create a function in enterScene() that u can storyboard.gotoScene("level20","flip"). make sure u storyboard.purgeScene ('dummy scene') in ''level'' 20. Your next question will be 'Do I need to create 20 dummy scenes?' No store a variable under storyboard.level = '20' than call it from the 'dummy scene'
Upvotes: 1
Reputation: 3039
I haven't actually done this myself, but based on the discussion here:
http://blog.anscamobile.com/2011/11/introducing-the-storyboard-api/
It looks like you'll need to call storyboard.purgeScene("level20")
before calling storyboard.gotoScene("level20","flip")
Upvotes: 0