Proper way to refresh a scene

I got the advice from Rob some months back that it was OK to do a full delete and recreate when one needs to update the scene. “Deleting and creating happens so quickly that it doesn’t matter how you do it”, I think was the message.

This is what I do (for non-performance critical menu system scenes):

[Lua]

function reloadScene(event)

    local name = storyboard.getCurrentSceneName()

    local scene = storyboard.getScene(name)

    local group = scene.view

    

    for i=group.numChildren, 1, -1 do

        display.remove(group[i]) group[i] = nil

    end

    

    scene:createScene(event)

end

[/Lua]

However, after Widget 2.0 appeared, I have noticed that the GUI actually “blinks” briefly sometimes while deleting and re-creating. The deleting/re-creating presumably now takes so long that the GUI thread renders the deleted scene before it is re-created. This makes the GUI look buggy.

  • Is Widget 2.0 slower than Widget 1.0?

  • Is it no more advisable to do a full delete and re-create?

  • Do I now have to write custom code for every object I want to disable or enable after the scene is created? (I pray that this is not the case)

Please let me know how I can solve this in a simple way that does not involve lots of new code.

Thanks!

Anyone at Corona Staff? I never heard back on this one, and I’d really like to know if it’s totally fine to delete the entire scene and re-create it whenever needed (I’m not talking regular many-times-per-second updates like in-game stuff, like when a user clicks something in a menu that requires a change in the scene).

A lot depends on how complex your scene is.  The scene is typically created off screen or under the current screen then transitioned on after it’s done being created.  Complex scenes could have a lag while it creates the scene before it puts it on the screen.  Also removing the scene can be costly on very complex scenes.

But on more simple scenes it shouldn’t matter.  Now you’re talking about reloading which is an area that I’m a bit personally uncomfortable with.  The scene is already on the screen.  Destroying it and re-creating it has to happen in less than 1/60th of a second for a 60fps app or 1/30th of a second for a 30fps app, which for most apps is an eternity but…

As far as widgets go, they should be faster and more efficient, but how things like tableView’s rows are rendered has changed.  If you don’t need to re-create things don’t.  Just keep in mind that many people working with Storyboard, put things in places where they don’t get re-executed and you have to do certain things to make sure createScene gets called every time so this reloading scene’s can be tricky depending on where you’ve put things and what all you need to reset.

Anyone at Corona Staff? I never heard back on this one, and I’d really like to know if it’s totally fine to delete the entire scene and re-create it whenever needed (I’m not talking regular many-times-per-second updates like in-game stuff, like when a user clicks something in a menu that requires a change in the scene).

A lot depends on how complex your scene is.  The scene is typically created off screen or under the current screen then transitioned on after it’s done being created.  Complex scenes could have a lag while it creates the scene before it puts it on the screen.  Also removing the scene can be costly on very complex scenes.

But on more simple scenes it shouldn’t matter.  Now you’re talking about reloading which is an area that I’m a bit personally uncomfortable with.  The scene is already on the screen.  Destroying it and re-creating it has to happen in less than 1/60th of a second for a 60fps app or 1/30th of a second for a 30fps app, which for most apps is an eternity but…

As far as widgets go, they should be faster and more efficient, but how things like tableView’s rows are rendered has changed.  If you don’t need to re-create things don’t.  Just keep in mind that many people working with Storyboard, put things in places where they don’t get re-executed and you have to do certain things to make sure createScene gets called every time so this reloading scene’s can be tricky depending on where you’ve put things and what all you need to reset.