So I’m trying to reload a really simple scene but it always results in a black screen when I do it the second time.
This how my main.lua looks like
display.setStatusBar( display.HiddenStatusBar ) local composer = require( "composer" ) composer.gotoScene( "test" )
This how test.lua looks like
local composer = require( "composer" ) local scene = composer.newScene() -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- background local bg = display.newRect(0, 0, display.contentWidth, display.contentHeight) bg.anchorX = 0 bg.anchorY = 0 bg:setFillColor(1) bg:addEventListener( "tap", restart ) sceneGroup:insert( bg) local text = display.newText( "PLAY", display.contentWidth\*0.5, display.contentHeight-200, native.systemFont, 70) text:setFillColor(0) sceneGroup:insert(text) end -- end of scene function restart( event ) composer.gotoScene( "tryagain" ) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
and this is how my tryagain.lua looks like
local composer = require( "composer" ) local scene = composer.newScene() -- "scene:create()" function scene:create( event ) local sceneGroup = self.view composer.removeScene( "test" ) composer.loadScene( "test" ) composer.gotoScene( "test" ) end -- end of scene -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
This is a really basic example that I used to test this issue. So all I’m doing is displaying a white background and every time you tap it it should reload the scene again( display the white background and some text again). When I tap it the first time it seems to work fine. but when I tap it the second time, I get a black screen and there is no error in the console either. Anyone know why is this happening? Is this a bug? or am i doing something wrong here?