Question about loading a scene in touch listener

Hi! just want to know if this practice is bad for app performance, if not, 200ms is enough to load a heavy scene?

local function onSceneChange( event ) local options = { effect = "fade", time = 800 } if ( event.phase == "began" ) then audio.play(click) local load = composer.loadScene( "scenes.scene2", false) print( "Touch event began on: " .. event.target.id ) elseif ( event.phase == "ended" ) then local tmr = timer.performWithDelay( 200, function() composer.gotoScene( "scenes.scene2", options ) end ) print( "Touch event ended on: " .. event.target.id ) end return true end

Thanks in advance
DoDi

That code really doesn’t accomplish anything useful.  It will in fact feel and look bad. 

As soon as you start loading your (heavy) scene, it will block all activity and interaction with the current scene.

i.e. You’ll get a big hiccup while it loads.

You’re better off having some kind of covering transition effect to hide the loading time.

You’d be much better off doing something like this:

local function touch( event ) if ( event.phase == "began" ) then audio.play(click) elseif ( event.phase == "ended" ) then -- 1 Render something to cover the screen. -- Do not put the object in the scene. -- Make this as elaborate as you want or need, but this is as -- simple as it can be. local cover = display.newImageRect( ??? ) -- fill in ??? yourself cover.x = display.contentCenterX cover.y = display.contentCenterY function cover.enterFrame(self) self:toFront() end Runtime:addEventListener("enterFrame",cover) -- 2 Now load the scene composer.gotoScene( "scenes.scene2", { effect = "fade", time = 800 } ) -- 3 Remove the cover after fade is complete. timer.performWithDelay( 1000, function() Runtime:removeEventListener("enterFrame",cover) display.remove(cover) end ) end return true end

You can make this even safer and better, by passing ‘cover’ to scene2 and run the step #3 code in the show ‘did’ phase.

Thanks @roaminggamer, I will try to do this.

This super simple example shows what I mean: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/12/hideLoading.zip

It makes ‘curtains’ to cover the scene on each scene load.  The next scene then opens the curtains and they self-destruct.

This way, no matter how long the scene load takes it will work fine.

https://www.youtube.com/watch?v=zx9oIYSqI2M&feature=youtu.be

Awesome @roaminggamer

That code really doesn’t accomplish anything useful.  It will in fact feel and look bad. 

As soon as you start loading your (heavy) scene, it will block all activity and interaction with the current scene.

i.e. You’ll get a big hiccup while it loads.

You’re better off having some kind of covering transition effect to hide the loading time.

You’d be much better off doing something like this:

local function touch( event ) if ( event.phase == "began" ) then audio.play(click) elseif ( event.phase == "ended" ) then -- 1 Render something to cover the screen. -- Do not put the object in the scene. -- Make this as elaborate as you want or need, but this is as -- simple as it can be. local cover = display.newImageRect( ??? ) -- fill in ??? yourself cover.x = display.contentCenterX cover.y = display.contentCenterY function cover.enterFrame(self) self:toFront() end Runtime:addEventListener("enterFrame",cover) -- 2 Now load the scene composer.gotoScene( "scenes.scene2", { effect = "fade", time = 800 } ) -- 3 Remove the cover after fade is complete. timer.performWithDelay( 1000, function() Runtime:removeEventListener("enterFrame",cover) display.remove(cover) end ) end return true end

You can make this even safer and better, by passing ‘cover’ to scene2 and run the step #3 code in the show ‘did’ phase.

Thanks @roaminggamer, I will try to do this.

This super simple example shows what I mean: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/12/hideLoading.zip

It makes ‘curtains’ to cover the scene on each scene load.  The next scene then opens the curtains and they self-destruct.

This way, no matter how long the scene load takes it will work fine.

https://www.youtube.com/watch?v=zx9oIYSqI2M&feature=youtu.be

Awesome @roaminggamer