I need help with my little project here...
I have a game with two scenes (menu and game) and I can't change scenes correctly. My main problem is that I cannot remove all my scene.view DisplayObjects correctly since storyboard.purgeScene("game") generates this error:
"didRemoveListeners" (a nil value)
Here's my code explained:
- In "Menu Scene" I call storyboard.goToScene("game")
- Inside CreateScene in "game" I create my DisplayObject and insert them to the GroupView (scene.view)
Further in my code, I create various DisplayObjects (balls) with physics and add them to scene.view through
stageGroupView:insert(ball)
*stageGroupView is a local variable declared on top of the module assigned with display.getCurrentStage( ) in CreateScene of "game"
When a condition is met inside my collision detectors, I call goToScene("menu") wich, if I understood well, execute the exitScene listener of my "game" scene.
Inside "exitScene" I remove all my listeners and timers
Inside "didRemoveScene" I've tried to purge/remove the scene but everytime I get the aforementioned runtime error.
At this point, if I leave didRemoveScene empty, the storyboard does it's work but the game scene.view doesn't get erased. I just want to know an effective way of adding dinamically created DisplayObject to my scene.view and be able to purge/remove my scene without runtime error.
Here's some parts of my code for better understanding:
local function addBall(ball)
stageGroupView:insert(ball)
end
function scene:exitScene( event )
local group = self.view
timer.cancel( spawnTimer )
timer.cancel( gameTimer )
background:removeEventListener( "touch", onTouch )
player:removeEventListener( "touch", onTouch )
player:removeEventListener( "collision", onPlayerCollision )
bottomBorder:removeEventListener( "collision", onBottomBorderCollision )
rightBorder:removeEventListener( "collision", onRightBorderCollision )
end
function scene:didExitScene(event)
--local group = self.view
--group:removeSelf()
storyboard.purgeScene( "game" )
end
As you can see I even tried group:removeSelf() to erase my scene.view, but with scarse results... Another runtime error pops up triggered by "menu" goToScene("game") once I exit and re-enter "game" scene: bad argument #-2 to 'insert" (Procy expected, got nil) in function 'insert' ?:in function 'goToScene' in menu.lua.
Plz help! Much appreciated!
0 comments:
Post a Comment