Modal TitleScreens

I struggle with this a bit. My game has replay prompts using modal title screen groups. Not clear when I should remove them, and sometimes they don’t get removed. For Example:

  function

showPromptScreen(tStatus) 

 titleScreenGroup = display.newGroup(); 

  okGame = widget.newButton
  {
  onRelease = ReplayGame,
  }

 titleScreenGroup:insert(okGame); 

 

end

Can I remove this title screen group in the replayGame function? I’m not sure where my scope is?

Carey

titleScreenGroup has to be declared before your ReplayGame function then you can remove it there.

like so:

local titleScreenGroup local function ReplayGame(event) display.remove(titleScreenGroup) end showPromptScreen(tStatus) titleScreenGroup = display.newGroup(); okGame = widget.newButton { onRelease = ReplayGame, } titleScreenGroup:insert(okGame);

primoz,

Thanks. I have it declared correctly. Then I code:

   titleScreenGroup:removeSelf()
   storyboard.gotoScene(“level3”,options)

It works most of the time. But sometimes I’m stuck with the prompt on the screen.

 Is the gotoscene being called before  titleScreenGroup:removeSelf() finishes executing?

Thanks,

Carey

The only way I see it staying on screen is if you created it twice. Then you would loose the reference to the first instance and only remove the second one. Can not be sure without seeing everything you are doing.

You were right; not sure how I missed this. The reason it works once, is that when I reload, the triggering collision is happening twice, thus loading the screen twice. This is happening twice because an object is not being disposed of properly. This brings up a broader question regarding object cleanup as dynamically created objects I have issues with. let me pose my question better and I’ll get back you to.

Thanks,

Carey

When I run it the first time, my oncollision event fires once. When I reload the same scene again using storyboard, it’s firing twice, thus loading two prompt screens.

 onCollision(event)

  physics.pause()
  local st=showPromptScreen(gameStatus)
 end

I am removing the event listener in the destroy scene.

 Runtime:removeEventListener(“collision”,onCollision) 

Any thoughts come to mind on why my begin collision is firing twice. I think I’m cleaning up the objects 1 and 2 appropriately.

Destroy scene doesn’t get called when you change scenes, It only get’s called when you call removeScene or purgeScene or the system issues a memory warning and storyboard clears the scene. Move the removeEventListener to exitScene or didExitScene.

titleScreenGroup has to be declared before your ReplayGame function then you can remove it there.

like so:

local titleScreenGroup local function ReplayGame(event) display.remove(titleScreenGroup) end showPromptScreen(tStatus) titleScreenGroup = display.newGroup(); okGame = widget.newButton { onRelease = ReplayGame, } titleScreenGroup:insert(okGame);

primoz,

Thanks. I have it declared correctly. Then I code:

   titleScreenGroup:removeSelf()
   storyboard.gotoScene(“level3”,options)

It works most of the time. But sometimes I’m stuck with the prompt on the screen.

 Is the gotoscene being called before  titleScreenGroup:removeSelf() finishes executing?

Thanks,

Carey

The only way I see it staying on screen is if you created it twice. Then you would loose the reference to the first instance and only remove the second one. Can not be sure without seeing everything you are doing.

You were right; not sure how I missed this. The reason it works once, is that when I reload, the triggering collision is happening twice, thus loading the screen twice. This is happening twice because an object is not being disposed of properly. This brings up a broader question regarding object cleanup as dynamically created objects I have issues with. let me pose my question better and I’ll get back you to.

Thanks,

Carey

When I run it the first time, my oncollision event fires once. When I reload the same scene again using storyboard, it’s firing twice, thus loading two prompt screens.

 onCollision(event)

  physics.pause()
  local st=showPromptScreen(gameStatus)
 end

I am removing the event listener in the destroy scene.

 Runtime:removeEventListener(“collision”,onCollision) 

Any thoughts come to mind on why my begin collision is firing twice. I think I’m cleaning up the objects 1 and 2 appropriately.

Destroy scene doesn’t get called when you change scenes, It only get’s called when you call removeScene or purgeScene or the system issues a memory warning and storyboard clears the scene. Move the removeEventListener to exitScene or didExitScene.