I'm currently working on a project involving a main "hub" screen with nine sub-pages accessible from the main page. On the simulator, I can open the first five scenes, in any order, without a problem, and go back to the main scene. However, after the sixth one, the background goes black, with only the "back button" image asset appearing. When I tried building it and using it on my LG smartphone, it managed to open seven scenes, with the eight scene causing the entire scene to go black. (presumably no displayobjects were loading in)
I followed the template when creating the scenes, and I exit scene by calling the removeScene() function prior to calling the gotoScene() function, to no avail. (I figured it might have been a memory issue stemming from not removing scenes.) Maybe there is a limit on creating scenes I am unaware of.
Anyone experience this issue before? If so, did you manage to find a work-around?
Any input would be appreciated.
Black screen after certain amount of scene changes
Aug 13 2018 03:08 PM
Best Answer Rob Miracle , 15 August 2018 - 01:36 PM
It might be helpful if you shared any messages you're getting in your console log. In particular, you need to learn how to read the device's console log and watch for error messages there.
Finally, you can't remove the scene you're currently in. I personally prefer to remove a scene **before** I go to it. So if I'm going to "sceneA", I'll do:
This is of course kind of a brute force way to manage this. Your old scenes hang around for a while, but code-wise it's the simplest approach.
There is a way to make a scene self-removing. This is perhaps the best practice if you feel the urgency to always remove scenes. You can change the scene:hide() function to be:
-- 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 composer.removeScene( composer.getSceneName( "current" ) ) end end
This is the one and only time you can remove the scene you're in because at this point the scene is done and off screen so you can at this point safely remove it.