Going to previous scene results in black screen

Hi, my game is all good so far however I’m not sure whether its because I updated to the latest public build or i changed a little bit of my code, but when I first start the game up it works perfectly goes to the first level etc. but when i go back to the menu from any level then go back to that level using previous scene it goes to a blank screen, it never used to do this! here is some code:

scene1

function menubutton:touch( event ) if event.phase == "began" then storyboard.gotoScene( "menu", "slideRight", 750 ) audio.play(click) display.getCurrentStage():setFocus( event.target ) event.target.isFocus = true elseif event.target.isFocus then if event.phase == "moved" then print( "user has moved their finger off the button." ) elseif event.phase == "ended" then print( "user has switched to the main menu" ) display.getCurrentStage():setFocus( nil ) event.target.isFocus = false end end return true end

menu

local function onSceneTouch( event ) if event.phase == "ended" then audio.play(click) local previousScene = storyboard.getPrevious() if previousScene == nil then storyboard.gotoScene( "scene1", "slideLeft", 750 ) else storyboard.gotoScene(previousScene) return true end end end

Are you getting any errors in your console output?

No I’m not getting any errors, sorry i should i have said that in the first post.

can you post your scene code?

Heres the scene code, its a basic word find game.

local storyboard = require ( "storyboard" ) local scene = storyboard.newScene() local screenGroup = display.newGroup() local tfs = display.newGroup() local lines = display.newGroup() local line local bell = audio.loadStream('corect.wav') local click = audio.loadStream('click.wav') local ding = audio.loadStream('ding.wav') local L1 = {"DOG"} local L1Map = {{}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, "D", "O", "G"}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} local alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} local correct = 0 local wordsList; local clueText; local gameBg; local lvlnumber; local lvlText; local menubutton; local menuText; local token; local answerText; local function hitTestObjects(obj1, obj2) local left = obj1.contentBounds.xMin \<= obj2.contentBounds.xMin and obj1.contentBounds.xMax \>= obj2.contentBounds.xMin local right = obj1.contentBounds.xMin \>= obj2.contentBounds.xMin and obj1.contentBounds.xMin \<= obj2.contentBounds.xMax local up = obj1.contentBounds.yMin \<= obj2.contentBounds.yMin and obj1.contentBounds.yMax \>= obj2.contentBounds.yMin local down = obj1.contentBounds.yMin \>= obj2.contentBounds.yMin and obj1.contentBounds.yMin \<= obj2.contentBounds.yMax return (left or right) and (up or down) end local startDraw = function (e) if(e.phase == "began") then initX = e.x initY = e.y elseif(e.phase == "moved") then if line then display.remove(line); line = nil; end line = display.newLine(initX, initY, e.x, e.y) line.width = 16 line:setColor(60, 60, 255, 100) lines:insert(line) elseif(e.phase == "ended") then local selectedWord = "" for i = 1, tfs.numChildren do if(hitTestObjects(lines[lines.numChildren], tfs[i])) then selectedWord = selectedWord .. tfs[i].text end end -- Check if word is on list for j = 0, 5 do if(selectedWord == L1[j]) then audio.play(bell) currentWords.text = currentWords.text .. " " .. selectedWord currentWords:setReferencePoint(display.TopLeftReferencePoint) currentWords.x = 5 correct = correct + 1 end end print (CORRECT) if(correct == #L1) then --alert() print ("CORRECT "..#L1) line.isVisible = false storyboard.gotoScene( "scene2", "slideLeft", 750) storyboard.removeScene( "scene1" ) end end end local function gameListeners(action) if(action == "add") then gameBg:addEventListener("touch", startDraw) --gameBg:addEventListener("touch", detectLetters) else gameBg:removeEventListener("touch", startDraw) --gameBg:removeEventListener("touch", detectLetters) end end local function alert() gameListeners("rm") -- -- alert = display.newImage("alert.png") -- --alert:addEventListener("tap", restart) or next level! end function scene:createScene(event) screenGroup = self.view local createHud = function () gameBg = display.newImage("titleBg3.png") gameBg.x = display.contentWidth / 2 gameBg.y = display.contentHeight / 2 lvlnumber = display.newImage("lvlnumber1.png", 0, -6) menubutton = display.newImage("menubutton5.png", -10, -4) token = display.newImage("token1.png", 205, 0) screenGroup:insert(gameBg) screenGroup:insert(lvlnumber) screenGroup:insert(menubutton) screenGroup:insert(token) clueText = display.newText( " Dog ", 0, 450, "Arial", 16) clueText:setTextColor(255, 255, 255) clueText.x = 160 screenGroup:insert(clueText) lvlText = display.newText ( "1", 0, 20, "Arial", 16) lvlText:setTextColor(255, 255, 255) lvlText.x = 157 screenGroup:insert(lvlText) menuText = display.newText ( "Menu", 0, 16, "Arial", 16) menuText:setTextColor(255, 255, 255) menuText.x = 53 screenGroup:insert(menuText) answerText = display.newText( " Dog ", 0, 450, "Arial", 16) answerText:setTextColor(255, 255, 255) answerText.x = 160 answerText.isVisible = false screenGroup:insert(answerText) end local buildSoup = function () for i = 1, 10 do for j = 1, 12 do local tf = display.newText("", 0, 0, "Arial", 19) tf:setTextColor(102, 102, 102) --tf.width = 320 --tf.height = 480 tf.x = math.floor(-10 + (31.3 \* i)) tf.y = math.floor(-10 + (35 \* j)) -- Change 0"s to Random Letters if(L1Map[j][i] == 0) then L1Map[j][i] = alphabet[math.floor(math.random() \* table.maxn(alphabet))+1] end tf.text = L1Map[j][i] tfs:insert(tf) end end end local wordsList = function () local wordsString = "" for i = 1, #L1 do wordsString = wordsString .. " " .. L1[i] end wordsList = display.newText(wordsString, 7500, 7500, "Arial", 14) wordsList:setTextColor(238, 238, 238) screenGroup:insert(wordsList) currentWords = display.newText("", 7500, 7500, "Arial", 14) currentWords:setTextColor(238, 146, 63) screenGroup:insert(currentWords) end createHud() buildSoup() wordsList() screenGroup:insert(tfs) end function scene:enterScene(event) local group = self.view function menubutton:touch( event ) if event.phase == "began" then storyboard.gotoScene( "menu", "slideRight", 750 ) audio.play(click) display.getCurrentStage():setFocus( event.target ) event.target.isFocus = true elseif event.target.isFocus then if event.phase == "moved" then print( "user has moved their finger off the button." ) elseif event.phase == "ended" then print( "user has switched to the main menu" ) display.getCurrentStage():setFocus( nil ) event.target.isFocus = false end end return true end function tokenTouch( event ) if event.phase == "began" then if storyboard.state.score \>0 then storyboard.state.score = storyboard.state.score - 1 score.text = tostring(storyboard.state.score) clueText.isVisible = false answerText.isVisible = true audio.play(ding) display.getCurrentStage():setFocus( event.target ) event.target.isFocus = true end elseif event.target.isFocus then if event.phase == "moved" then print( "user has moved their finger off the token." ) elseif event.phase == "ended" then print( "user has used a token" ) display.getCurrentStage():setFocus( nil ) event.target.isFocus = false end end return true end token:addEventListener( "touch", tokenTouch ) menubutton:addEventListener( "touch", menubutton) --function alert() gameListeners("add") --end -- end function scene:exitScene(event) local group = self.view storyboard.destroyScene( "scene1" ) end function scene:destroyScene(event) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

Anyone have any ideas? This is really pushing my game right backwards.

Bump

Are you getting any errors in your console output?

No I’m not getting any errors, sorry i should i have said that in the first post.

Please see my answers here
http://stackoverflow.com/questions/16372428/corona-going-to-previous-scene-results-in-black-screen/16388993#16388993

can you post your scene code?

Heres the scene code, its a basic word find game.

local storyboard = require ( "storyboard" ) local scene = storyboard.newScene() local screenGroup = display.newGroup() local tfs = display.newGroup() local lines = display.newGroup() local line local bell = audio.loadStream('corect.wav') local click = audio.loadStream('click.wav') local ding = audio.loadStream('ding.wav') local L1 = {"DOG"} local L1Map = {{}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, "D", "O", "G"}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} local alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} local correct = 0 local wordsList; local clueText; local gameBg; local lvlnumber; local lvlText; local menubutton; local menuText; local token; local answerText; local function hitTestObjects(obj1, obj2) local left = obj1.contentBounds.xMin \<= obj2.contentBounds.xMin and obj1.contentBounds.xMax \>= obj2.contentBounds.xMin local right = obj1.contentBounds.xMin \>= obj2.contentBounds.xMin and obj1.contentBounds.xMin \<= obj2.contentBounds.xMax local up = obj1.contentBounds.yMin \<= obj2.contentBounds.yMin and obj1.contentBounds.yMax \>= obj2.contentBounds.yMin local down = obj1.contentBounds.yMin \>= obj2.contentBounds.yMin and obj1.contentBounds.yMin \<= obj2.contentBounds.yMax return (left or right) and (up or down) end local startDraw = function (e) if(e.phase == "began") then initX = e.x initY = e.y elseif(e.phase == "moved") then if line then display.remove(line); line = nil; end line = display.newLine(initX, initY, e.x, e.y) line.width = 16 line:setColor(60, 60, 255, 100) lines:insert(line) elseif(e.phase == "ended") then local selectedWord = "" for i = 1, tfs.numChildren do if(hitTestObjects(lines[lines.numChildren], tfs[i])) then selectedWord = selectedWord .. tfs[i].text end end -- Check if word is on list for j = 0, 5 do if(selectedWord == L1[j]) then audio.play(bell) currentWords.text = currentWords.text .. " " .. selectedWord currentWords:setReferencePoint(display.TopLeftReferencePoint) currentWords.x = 5 correct = correct + 1 end end print (CORRECT) if(correct == #L1) then --alert() print ("CORRECT "..#L1) line.isVisible = false storyboard.gotoScene( "scene2", "slideLeft", 750) storyboard.removeScene( "scene1" ) end end end local function gameListeners(action) if(action == "add") then gameBg:addEventListener("touch", startDraw) --gameBg:addEventListener("touch", detectLetters) else gameBg:removeEventListener("touch", startDraw) --gameBg:removeEventListener("touch", detectLetters) end end local function alert() gameListeners("rm") -- -- alert = display.newImage("alert.png") -- --alert:addEventListener("tap", restart) or next level! end function scene:createScene(event) screenGroup = self.view local createHud = function () gameBg = display.newImage("titleBg3.png") gameBg.x = display.contentWidth / 2 gameBg.y = display.contentHeight / 2 lvlnumber = display.newImage("lvlnumber1.png", 0, -6) menubutton = display.newImage("menubutton5.png", -10, -4) token = display.newImage("token1.png", 205, 0) screenGroup:insert(gameBg) screenGroup:insert(lvlnumber) screenGroup:insert(menubutton) screenGroup:insert(token) clueText = display.newText( " Dog ", 0, 450, "Arial", 16) clueText:setTextColor(255, 255, 255) clueText.x = 160 screenGroup:insert(clueText) lvlText = display.newText ( "1", 0, 20, "Arial", 16) lvlText:setTextColor(255, 255, 255) lvlText.x = 157 screenGroup:insert(lvlText) menuText = display.newText ( "Menu", 0, 16, "Arial", 16) menuText:setTextColor(255, 255, 255) menuText.x = 53 screenGroup:insert(menuText) answerText = display.newText( " Dog ", 0, 450, "Arial", 16) answerText:setTextColor(255, 255, 255) answerText.x = 160 answerText.isVisible = false screenGroup:insert(answerText) end local buildSoup = function () for i = 1, 10 do for j = 1, 12 do local tf = display.newText("", 0, 0, "Arial", 19) tf:setTextColor(102, 102, 102) --tf.width = 320 --tf.height = 480 tf.x = math.floor(-10 + (31.3 \* i)) tf.y = math.floor(-10 + (35 \* j)) -- Change 0"s to Random Letters if(L1Map[j][i] == 0) then L1Map[j][i] = alphabet[math.floor(math.random() \* table.maxn(alphabet))+1] end tf.text = L1Map[j][i] tfs:insert(tf) end end end local wordsList = function () local wordsString = "" for i = 1, #L1 do wordsString = wordsString .. " " .. L1[i] end wordsList = display.newText(wordsString, 7500, 7500, "Arial", 14) wordsList:setTextColor(238, 238, 238) screenGroup:insert(wordsList) currentWords = display.newText("", 7500, 7500, "Arial", 14) currentWords:setTextColor(238, 146, 63) screenGroup:insert(currentWords) end createHud() buildSoup() wordsList() screenGroup:insert(tfs) end function scene:enterScene(event) local group = self.view function menubutton:touch( event ) if event.phase == "began" then storyboard.gotoScene( "menu", "slideRight", 750 ) audio.play(click) display.getCurrentStage():setFocus( event.target ) event.target.isFocus = true elseif event.target.isFocus then if event.phase == "moved" then print( "user has moved their finger off the button." ) elseif event.phase == "ended" then print( "user has switched to the main menu" ) display.getCurrentStage():setFocus( nil ) event.target.isFocus = false end end return true end function tokenTouch( event ) if event.phase == "began" then if storyboard.state.score \>0 then storyboard.state.score = storyboard.state.score - 1 score.text = tostring(storyboard.state.score) clueText.isVisible = false answerText.isVisible = true audio.play(ding) display.getCurrentStage():setFocus( event.target ) event.target.isFocus = true end elseif event.target.isFocus then if event.phase == "moved" then print( "user has moved their finger off the token." ) elseif event.phase == "ended" then print( "user has used a token" ) display.getCurrentStage():setFocus( nil ) event.target.isFocus = false end end return true end token:addEventListener( "touch", tokenTouch ) menubutton:addEventListener( "touch", menubutton) --function alert() gameListeners("add") --end -- end function scene:exitScene(event) local group = self.view storyboard.destroyScene( "scene1" ) end function scene:destroyScene(event) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

First of all, calling destroyScene() isn’t something you should call.  It’s an event handler that gets called when the scene is destroyed.  You are not doing anything in your scene’s destroyScene any way.

Next you declare sceneGroup to be a display.newGroup() at the top, then in side of createScene() you are overwriting it, creating a small memory leak.  You just need to declare sceneGroup at the top:

local sceneGroup

I would also still like for you to do a print on the value of the previous scene to make sure you’re going to the right place.  Is the code above the scene you are leaving or the scene you are going to?

Anyone have any ideas? This is really pushing my game right backwards.

I will do a print when i get onto my main computer, to answer you question the code above is the scene i am leaving to go to the main menu, if the user decides to play the game and gets the answer correct it goes to scene 2 which works. You may want the main menu code too as that is where the problem occurs going to the previous scene = black screen:

--requires local storyboard = require ( "storyboard" ) local scene = storyboard.newScene() --load sound local click = audio.loadStream('click.wav') --create scene function scene:createScene(event) local screenGroup = self.view titleBg = display.newImage('titleBg2.png') titleBg.x = display.contentWidth / 2 titleBg.y = display.contentHeight / 2 startBtn = display.newImage('play.png') startBtn.x = display.contentCenterX startBtn.y = display.contentCenterY + 20 playtext = display.newText("PLAY", 142, 252, "ARIAL", 16) titletext = display.newText("1 CLUE 1 WORD", 85, 150, "ARIAL", 20) screenGroup:insert(titleBg) screenGroup:insert(startBtn) screenGroup:insert(playtext) screenGroup:insert(titletext) end function scene:enterScene(event) local group = self.view local function onSceneTouch( event ) if event.phase == "ended" then audio.play(click) local previousScene = storyboard.getPrevious() if previousScene == nil then storyboard.gotoScene( "scene1", "slideLeft", 750 ) else storyboard.gotoScene(previousScene) return true end end end function startButtonListeners(action) if(action == 'add') then startBtn:addEventListener('touch', onSceneTouch) end end startButtonListeners('add') end function scene:exitScene( event ) local group = self.view end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

I did a print on the value of the previous scene and it matches the place it is supposed to go to. destroyScene() is removed and i did the local sceneGroup you said to do and I still get a blank screen.

After all this time i have found a “temporary” fix it was to create another main menu that the player returns to from there they can goto the previous scene they were on, however it is a temporary fix and not permanent. From the info i have gathered i suspect it must be something to do with this line of code:

local previousScene = storyboard.getPrevious() if previousScene == nil then storyboard.gotoScene( "scene1", "slideLeft", 750 ) else storyboard.gotoScene(previousScene)

I will need a permanent fix as this will not be efficient in the long run.

Is this a bug since when the user goes back to the second main menu i made and clicks play again it will also goto a black screen :frowning:

Bump

I noticed today when i started my app up that i got a warning in the console saying:

WARNING: failed to create audio sound<click.wav>

any thoughts?