Widget - Black Screen before trans. effect finishes

I have a button widget to get me out of the menu to another scene (FYI: using Composer).

Here’s the function I use to go to the new scene:

local function GongBtn (event)

  if event.phase == “ended” then

  composer.loadScene( “gong”, false, options )

  composer.gotoScene ( “gong”, { effect=“crossFade”, time=800 } )

  end

end

If I touch the widget button twice before the “crossFade” effect has finished, the new scene quickly fades to a black screen with no way of getting out except reseting the simulator.

How do I prevent this black screen?  For example, if a user accidentally touches the widgetButton a second time before the crossfade effect has finished.

Sounds like you might need to code your button handler to ignore future requests while it’s processing the current one. 

Rob

Thanks for the tip, Rob.  But I’m not sure how to do this.  Can you point me to a sample? 

if event.effect = true then

don’t turn the screen black

; )

I should mention I tried “return true” but it’s the same object that’s getting touched which is causing this black screen phenomenon.  It didn’t work whether I put it before or after the 1st “end”.

Near the top of the scene file add:

local sceneChangeButtonAlreadyPressed

In your scene:show() do:

     if event.phase == “did” then

          sceneChangeButtonAlreadyPressed = false

          – the rest of your did phase processing

     end

then in your event function for your button:

local function GongBtn (event)

  if event.phase == “ended” then

      if sceneChangeButtonAlreadyPressed then

          return true

      end

      sceneChangeButtonAlreadyPressed = true

  composer.loadScene( “gong”, false, options )

  composer.gotoScene ( “gong”, { effect=“crossFade”, time=800 } )

  end

end

or something like that.

Thanks, Rob.  That helped a lot.  Just to show for others to see I put your middle code above here:

[lua]

function scene:show( event )

      local sceneGroup = self.view

      local phase = event.phase

      if ( phase == “will” ) then

      elseif ( phase == “did” ) then

        –      INSERT code here (e.g. start timers, load audio, start listeners, etc.)

      

      if event.phase == “did” then

          sceneChangeButtonAlreadyPressed = false

     end

    end

end

[/lua]

If I removed   if event.phase == “did” then and attached it to the elseif above, it wouldn’t work.

About your last part, if the part bolded below is written without a true or false then, is it another way to say “true.”  Is that statement really saying " if sceneChangeButtonAlreadyPressed  is true then return true?  Although I set it to false near the top of the scene…  

Confused.  I’m just trying to find a way to speak these lines of code (lines 3-6 below) in English, so i can understand why you’d write them this way- plus it will help me to remember it if I can make sense of it.

[lua]

local function GongBtn (event)

  if event.phase == “ended” then

      if sceneChangeButtonAlreadyPressed then

          return true

      end

      sceneChangeButtonAlreadyPressed = true

  composer.loadScene( “gong”, false, options )

  composer.gotoScene ( “gong”, { effect=“crossFade”, time=800 } )

  end

end

[/lua]

Sounds like you might need to code your button handler to ignore future requests while it’s processing the current one. 

Rob

Thanks for the tip, Rob.  But I’m not sure how to do this.  Can you point me to a sample? 

if event.effect = true then

don’t turn the screen black

; )

I should mention I tried “return true” but it’s the same object that’s getting touched which is causing this black screen phenomenon.  It didn’t work whether I put it before or after the 1st “end”.

Near the top of the scene file add:

local sceneChangeButtonAlreadyPressed

In your scene:show() do:

     if event.phase == “did” then

          sceneChangeButtonAlreadyPressed = false

          – the rest of your did phase processing

     end

then in your event function for your button:

local function GongBtn (event)

  if event.phase == “ended” then

      if sceneChangeButtonAlreadyPressed then

          return true

      end

      sceneChangeButtonAlreadyPressed = true

  composer.loadScene( “gong”, false, options )

  composer.gotoScene ( “gong”, { effect=“crossFade”, time=800 } )

  end

end

or something like that.

Thanks, Rob.  That helped a lot.  Just to show for others to see I put your middle code above here:

[lua]

function scene:show( event )

      local sceneGroup = self.view

      local phase = event.phase

      if ( phase == “will” ) then

      elseif ( phase == “did” ) then

        –      INSERT code here (e.g. start timers, load audio, start listeners, etc.)

      

      if event.phase == “did” then

          sceneChangeButtonAlreadyPressed = false

     end

    end

end

[/lua]

If I removed   if event.phase == “did” then and attached it to the elseif above, it wouldn’t work.

About your last part, if the part bolded below is written without a true or false then, is it another way to say “true.”  Is that statement really saying " if sceneChangeButtonAlreadyPressed  is true then return true?  Although I set it to false near the top of the scene…  

Confused.  I’m just trying to find a way to speak these lines of code (lines 3-6 below) in English, so i can understand why you’d write them this way- plus it will help me to remember it if I can make sense of it.

[lua]

local function GongBtn (event)

  if event.phase == “ended” then

      if sceneChangeButtonAlreadyPressed then

          return true

      end

      sceneChangeButtonAlreadyPressed = true

  composer.loadScene( “gong”, false, options )

  composer.gotoScene ( “gong”, { effect=“crossFade”, time=800 } )

  end

end

[/lua]