Problem with composer.gotoScene

I’m building an app using CoronaCards that has 3 scenes and I have no problem transitioning between the scenes when I test it in the Corona Simulator, but when I build the app and run it on a mobile device, the scene:create function of the second scene executes, but the background and button from the previous scene are still displayed.

My code (simplified) is basically:

main.lua

local composer = require( "composer" ) math.randomseed(os.time()) composer.gotoScene("splash")

splash.lua

local composer = require( "composer" ) local widget = require("widget") local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- function handlePlayButton(event) local phase = event.phase if phase == "ended" then print("Play button pressed") composer.gotoScene("play") end end -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared -- on screen print("In splash scene") local background = display.newImageRect("img/splash\_background.jpg", display.contentWidth, display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY sceneGroup:insert(background) local playButton = widget.newButton { parent = self.view, left = 749, top = 369, width = 528, height = 297, defaultFile = "img/play\_button.png", onEvent = handlePlayButton, } sceneGroup:insert(playButton) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) print("splash phase hide - will") composer.removeScene("splash") elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen print("splash phase hide - did") end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

play.lua

local composer = require( "composer" ) local widget = require("widget") local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- function handleRevealButton(event) local phase = event.phase if phase == "ended" then print("Reveal button pressed") composer.gotoScene("win", {time=800, effect="crossFade"}) end end -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) print("In play scene") local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local background = display.newImageRect("img/play\_background.jpg", display.contentWidth, display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY sceneGroup:insert(background) print("width/height" .. display.contentWidth .. "/" .. display.contentHeight) local revealButton = widget.newButton { parent = self.view, left = 749, top = 369, width = 475, height = 152, defaultFile = "img/reveal\_button.png", onEvent = handleRevealButton, } sceneGroup:insert(revealButton) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

and the output in logcat is:

09-20 19:00:19.709 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: Play button pressed

09-20 19:00:19.709 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: splash phase hide - will

09-20 19:00:19.713 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: In play scene

09-20 19:00:19.717 17322-17372/com.lindelsee.tapcentive_tapdemo_android I/Corona: width/height1920/1008

but the splash screen and button are still displayed instead of them disappearing and the play and reveal buttons being displayed.

I’m not sure (and can’t test right now) but I think that this part from the splash scene looks a little strange. You’re destroying the splash scene with composer.removeScene() while the scene is still visible. Maybe that has something do do with it? Try to remove that line of code and see if anything changes.

function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("splash phase hide - will") composer.removeScene("splash") elseif ( phase == "did" ) then print("splash phase hide - did") end end

You can can call composer.removeScene(“splash”) in the “did” phase, but not the “will” phase.

But Composer should be managing the scene and successfully hiding the scene. You don’t have to remove the scene to have it’s objects hidden when you change scenes.

I don’t see any reason why this shouldn’t be working.  Have you tried running your Corona project in the simulator?

Rob

Yes, the project runs perfectly in the simulator.  The only reason that the composer.removeScene() is in the “will” section instead of the “did” section is that I found an example somewhere that had the cleanup in that section and I was grasping at straws to find something that might solve the problem.  Originally, I started with the cleanup in the “did” section.

The other reason I was testing doing the cleanup in the “will” section is that based on the print statements I’ve put in each of the sections, it seems like the “did” even’t isn’t firing (this seems to be true in both the CoronaCards version running on my device and in the simulator).

Just out of curiosity, what version of CoronaCards are you running? It’s a different install from the Simulator.

Rob

I’m using 2017.3135.

Can you zip up your project and share it with us?  Maybe put it on DropBox or Google Drive and post the link to it?

Thanks

Rob

Rob,

Happy to share the source with the team – though I’d rather not share it publicly.  Please let me know the best way to get you the link to the file on Google Drive.  You can reach me at mike (at) tapcentive (dot) com.  

I’ve also tested on multiple devices running different versions of Android (5.0, 5.1, and 7.0) and saw the same behavior.

Mike

Please email support@coronalabs.com with the information.

Rob

Done.  I’ve also provided some info about running the app.  Please let me know if any other information would be helpful.

Mike

I’m not sure (and can’t test right now) but I think that this part from the splash scene looks a little strange. You’re destroying the splash scene with composer.removeScene() while the scene is still visible. Maybe that has something do do with it? Try to remove that line of code and see if anything changes.

function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("splash phase hide - will") composer.removeScene("splash") elseif ( phase == "did" ) then print("splash phase hide - did") end end

You can can call composer.removeScene(“splash”) in the “did” phase, but not the “will” phase.

But Composer should be managing the scene and successfully hiding the scene. You don’t have to remove the scene to have it’s objects hidden when you change scenes.

I don’t see any reason why this shouldn’t be working.  Have you tried running your Corona project in the simulator?

Rob

Yes, the project runs perfectly in the simulator.  The only reason that the composer.removeScene() is in the “will” section instead of the “did” section is that I found an example somewhere that had the cleanup in that section and I was grasping at straws to find something that might solve the problem.  Originally, I started with the cleanup in the “did” section.

The other reason I was testing doing the cleanup in the “will” section is that based on the print statements I’ve put in each of the sections, it seems like the “did” even’t isn’t firing (this seems to be true in both the CoronaCards version running on my device and in the simulator).

Just out of curiosity, what version of CoronaCards are you running? It’s a different install from the Simulator.

Rob

I’m using 2017.3135.

Can you zip up your project and share it with us?  Maybe put it on DropBox or Google Drive and post the link to it?

Thanks

Rob

Rob,

Happy to share the source with the team – though I’d rather not share it publicly.  Please let me know the best way to get you the link to the file on Google Drive.  You can reach me at mike (at) tapcentive (dot) com.  

I’ve also tested on multiple devices running different versions of Android (5.0, 5.1, and 7.0) and saw the same behavior.

Mike

Please email support@coronalabs.com with the information.

Rob

Done.  I’ve also provided some info about running the app.  Please let me know if any other information would be helpful.

Mike