Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Question about loading a scene in touch listener
Started by dodi_games Dec 08 2018 11:28 AM

5 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 327 posts
  • Corona SDK

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

[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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

  • dodi_games likes this

[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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



[TOPIC: post.html]
#4

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 327 posts
  • Corona SDK

Thanks @roaminggamer, I will try to do this.

[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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.

 



[TOPIC: post.html]
#6

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 327 posts
  • Corona SDK

Awesome @roaminggamer


[topic_controls]
[/topic_controls]