Some help with storyboard

Hi,

  I am having a big trouble using storyboard.I managed to go to a “GameOver” scene,but when I tap the restart button,all that apears is a black screen.

   I want “levelOne” scene to be removed (all the objects,event listeners,physics,etc) when the player transition to “GameOver” scene.How I do that?

  Here’s the whole code,tell me where I am mistakeing

Thanks & happy hollidays!

display.setStatusBar(display.HiddenStatusBar)GameOver local storyboard = require "storyboard" local scene = storyboard.newScene() local physics = require "physics" physics.start() --physics.setDrawMode("hybrid") physics.setGravity (0,0) function scene:createScene (event) local group = self.view local enviroment = display.newImageRect ("sea.png",600,350) enviroment.x = 225 enviroment.y = 160 group:insert (enviroment) end function scene:enterScene (event) local group = self.view -- ASSETS local sand = display.newImageRect ("thesand.png",600,400) sand.x = 225 sand.y = 160 group:insert (sand) local sand2 = display.newImageRect ("thesand.png",600,400) sand2.x = 820 sand2.y = 160 group:insert (sand2) local sheetData = {width = 100,height = 100,numFrames = 8,sheetContentWidth = 200,sheetContentHeight = 400} local mySheet = graphics.newImageSheet ("squid.png",sheetData) local sequenceData = { {name = "swim",start = 1,count = 8,time = 900,loopCount = 0}} local squid= display.newSprite (mySheet,sequenceData) squid.x = 160 squid.y = 150 squid:play() physics.addBody (squid,"dynamic",{radius = 15}) group:insert (squid) local sheetData = {width = 100,height = 100,numFrames = 6,sheetContentWidth = 200,sheetContentHeight = 300} local mySheet = graphics.newImageSheet ("toothfish.png",sheetData) local sequenceData = { {name = "swim1",start = 1,count = 6,time = 450,loopCount = 0}} local toothFish = display.newSprite (mySheet,sequenceData) toothFish:play() physics.addBody (toothFish,"static",{radius = 20}) group:insert (toothFish) local sheetData = {width = 100,height = 100,numFrames = 6,sheetContentWidth = 200,sheetContentHeight = 300} local mySheet = graphics.newImageSheet ("purpleFish.png",sheetData) local sequenceData = { {name = "swim2",start = 1,count = 6,time = 600,loopCount = 0}} local purpleFish = display.newSprite (mySheet,sequenceData) purpleFish:play() physics.addBody (purpleFish,"static",{radius = 20}) group:insert (purpleFish) local sheetData = {width = 200,height = 100,numFrames = 6,sheetContentWidth = 400,sheetContentHeight = 300} local mySheet = graphics.newImageSheet ("greenFish.png",sheetData) local sequenceData = { {name = "swim3",start = 1,count = 6,time = 1000,loopCount = 0}} local greenFish = display.newSprite (mySheet,sequenceData) greenFish:play() physics.addBody (greenFish,"static",{radius = 20}) group:insert (greenFish) local sheetData = {width = 200,height = 100,numFrames = 6,sheetContentWidth = 400,sheetContentHeight = 300} local mySheet = graphics.newImageSheet ("blueFish.png",sheetData) local sequenceData = { {name = "swim4",start = 1,count = 6,time = 800,loopCount = 0}} local blueFish = display.newSprite (mySheet,sequenceData) blueFish:play() physics.addBody (blueFish,"static",{radius = 20}) group:insert (blueFish) local sheetData = {width = 200,height = 200,numFrames = 10,sheetContentWidth = 400,sheetContentHeight = 1000} local mySheet = graphics.newImageSheet ("blowFish.png",sheetData) local sequenceData = { {name = "swim5",start = 1,count = 10,time = 1100,loopCount = 0}} local blowFish = display.newSprite (mySheet,sequenceData) blowFish:play() physics.addBody (blowFish,"static",{radius = 25}) blowFish.isVisible = false group:insert (blowFish) local banner = display.newImageRect ("banner.png",500,92) banner.rotation = -5 banner.isVisible = false group:insert (banner) local buttonUp = display.newImageRect ("up2.png",70,70) buttonUp.x = 5 buttonUp.y = 290 group:insert (buttonUp) local buttonUp2 = display.newImageRect ("up1.png",70,70) buttonUp2.x = 5 buttonUp2.y = 280 buttonUp2.isVisible = false group:insert (buttonUp2) local buttonDown = display.newImageRect ("down1.png",70,70) buttonDown.x = 490 buttonDown.y = 280 group:insert (buttonDown) local buttonDown2 = display.newImageRect ("down2.png",70,70) buttonDown2.x = 490 buttonDown2.y = 280 buttonDown2.isVisible = false group:insert (buttonDown2) local displayScore = display.newText ("Score:",-10,10,native.systemFontBold,17) local score = 0 local currentScore = display.newText (score,30,10,native.systemFontBold,17) local banner = display.newImageRect ("banner.png",500,92) banner.x = 240 banner.y = 100 banner.isVisible = false group:insert(banner) -- FUNCTIONS local function gameOver (event) if event.phase == "began" then storyboard.gotoScene ("GameOver") storyboard.removeScene("levelOne") end end local function groundMovement (self,event) if self.x \<-365 then self.x = 823 else self.x = self.x - 3.7 end end local function enemyMovement (self,event) if self.x \<-410 then self.x = math.random (650,1200) self.y = math.random (35,300) else self.x = self.x - 2 end end local function enemyMovement2 (self,event) if self.x \<-440 then self.x = math.random (650,1600) self.y = math.random (35,230) else self.x = self.x - 4 end end local function buttonUpPressed (event) if event.phase == "began" then buttonUp.isVisible = false buttonUp2.isVisible = true squid.y = squid.y - 7 end end local function buttonUpReleased (event) if event.phase == "ended" then buttonUp.isVisible = true buttonUp2.isVisible = false end end local function buttonDownPressed (event) if event.phase == "began" then buttonDown.isVisible = false buttonDown2.isVisible = true squid.y = squid.y + 7 end end local function buttonDownReleased (event) if event.phase == "ended" then buttonDown.isVisible = true buttonDown2.isVisible = false end end local function scoreKeeper (event) if event.phase == "began" then score = score + 1 currentScore.text = score end end local function oneOrangeShell () local sheetData = {width = 100,height = 100,numFrames = 8,sheetContentWidth = 200,sheetContentHeight = 400} local mySheet = graphics.newImageSheet ("orangeShell.png",sheetData) local sequenceData = { {name = "shell1",start = 1,count = 8,time = 1100,loopCount = 0}} local orangeShell = display.newSprite (mySheet,sequenceData) orangeShell:play() physics.addBody (orangeShell,"static",{radius = 7}) return orangeShell end local function oneRedShell () local sheetData = {width = 100,height = 100,numFrames = 8,sheetContentWidth = 200,sheetContentHeight = 400} local mySheet = graphics.newImageSheet ("redShell.png",sheetData) local sequenceData = { {name = "shell2",start = 1,count = 8,time = 1100,loopCount = 0}} local redShell = display.newSprite (mySheet,sequenceData) redShell:play() physics.addBody (redShell,"static",{radius = 7}) return redShell end local function oneGreenShell () local sheetData = {width = 100,height = 100,numFrames = 8,sheetContentWidth = 200,sheetContentHeight = 400} local mySheet = graphics.newImageSheet ("greenShell.png",sheetData) local sequenceData = { {name = "shell3",start = 1,count = 8,time = 1100,loopCount = 0}} local greenShell = display.newSprite (mySheet,sequenceData) greenShell:play() physics.addBody (greenShell,"static",{radius = 7}) return greenShell end local function spawningShells (event) for i = 0,0 do local orangeShell1 = oneOrangeShell() orangeShell1.x = math.random (650,900) orangeShell1.y = math.random (40,250) local redShell2 = oneRedShell() redShell2.x = math.random (700,1000) redShell2.y = math.random (50,200) local greenShell3 = oneGreenShell() greenShell3.x = math.random (900,1200) greenShell3.y = math.random (100,200) local removeShell3 = function () display.remove (greenShell3) greenShell3 = nil end local removeShell2 = function () display.remove(redShell2) redShell2 = nil end local removeShell1 = function () display.remove(orangeShell1) orangeShell1 = nil end orangeShellTransition = transition.to (orangeShell1,{time = 5000,x = -10,onComplete = removeShell1}) redShellTransition = transition.to (redShell2,{time = 6000,x = -10,onComplete = removeShell2}) greenShellTransition = transition.to (greenShell3,{time = 10000,x = -10,onComplete = removeShell3}) orangeShell1:addEventListener ("collision",scoreKeeper) redShell2:addEventListener ("collision",scoreKeeper) greenShell3:addEventListener ("collision",scoreKeeper) end end local function blowFishTime () blowFish.isVisible = true banner.isVisible = true blowFish.x = math.random (650,1000) blowFish.y = math.random (100,200) blowFish.enterFrame = enemyMovement Runtime:addEventListener ("enterFrame",blowFish) local removeBanner = function () display.remove (banner) banner = nil end bannerTransition = transition.to (banner,{time = 3000,y = 0,onComplete = removeBanner}) end -- EVENT LISTENERS sand.enterFrame = groundMovement Runtime:addEventListener ("enterFrame",sand) sand2.enterFrame = groundMovement Runtime:addEventListener ("enterFrame",sand2) purpleFish.enterFrame = enemyMovement Runtime:addEventListener ("enterFrame",purpleFish) greenFish.enterFrame = enemyMovement Runtime:addEventListener ("enterFrame",greenFish) toothFish.enterFrame = enemyMovement2 Runtime:addEventListener ("enterFrame",toothFish) blueFish.enterFrame = enemyMovement2 Runtime:addEventListener ("enterFrame",blueFish) timer.performWithDelay (7000,spawningShells,0) timer.performWithDelay (150000,blowFishTime,1) buttonUp:addEventListener ("touch",buttonUpPressed) Runtime:addEventListener ("touch",buttonUpReleased) buttonDown:addEventListener ("touch",buttonDownPressed) Runtime:addEventListener ("touch",buttonDownReleased) toothFish:addEventListener("collision",gameOver) purpleFish:addEventListener("collision",gameOver) blowFish:addEventListener("collision",gameOver) blueFish:addEventListener("collision",gameOver) greenFish:addEventListener("collision",gameOver) end function scene:exitScene (event) local group = self.view Runtime:removeEventListener ("enterFrame",groundMovement) Runtime:removeEventListener ("enterFrame",enemyMovement) Runtime:removeEventListener ("enterFrame",enemyMovement2) Runtime:removeEventListener ("enterFrame",spawningShells) 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

@bog,

Hi.  This is not a full answers, but I want to suggest before you spend time learning any more about storyboard, you consider switching to composer (scene library).  Storyboard is no longer the official scene management library.

As far as managing objects (having them auto removed), do the following:

  1. Don’t use globals to hold references to objects.

  2. If you can’t avoid #1, be sure to clear those references when the scene is removed.

  3. IMPORTANT - Add all objects that you want ‘auto-managed’ by a scene to that scene’s group OR to a group which in turn you’ve added to the scene’s group. The key here is, if the object is not a child or grand-child of a scene’s group, the scene won’t manage it.

@

roaminggamer

Hi,

Thanks for the answer I’ll try using composer to see how that works.

@bog,

Hi.  This is not a full answers, but I want to suggest before you spend time learning any more about storyboard, you consider switching to composer (scene library).  Storyboard is no longer the official scene management library.

As far as managing objects (having them auto removed), do the following:

  1. Don’t use globals to hold references to objects.

  2. If you can’t avoid #1, be sure to clear those references when the scene is removed.

  3. IMPORTANT - Add all objects that you want ‘auto-managed’ by a scene to that scene’s group OR to a group which in turn you’ve added to the scene’s group. The key here is, if the object is not a child or grand-child of a scene’s group, the scene won’t manage it.

@

roaminggamer

Hi,

Thanks for the answer I’ll try using composer to see how that works.