composer.removeScene() not working?

So I am trying to make a game over menu. I am using a scene to act as a transitional scene to remove my gameplay scene. I have tried calling the removeScene function everywhere I can in my gameOver.lua file. No matter where I place the code it will not remove the scene. When I press “Retry” in my game over screen it takes me back to the gamePlay.lua file like it should but none of the code outside of the listener functions reset and the previous physics boxes that I had in my first run still exist when I try recalling it. Is this a bug going on or am I just calling this wrong?

I’ve used the composer.removeScene(“playGame”) outside the scene, inside create, inside show, inside the remove in my playGame file. It just wont work no matter where I place it.

Thanks for reading.

I was having a similar problem with my game. You are correct to perform the composer.removeScene(“scene”), I put mine in the scene:create function of your tryAgain.lua. 

What require statements are your calling in your game? Also, are you adding your onscreen image items to the sceneGroup with sceneGroup:insert(object)?

Well for me every time I’ve tried inserting my objects into the sceneGroup nothing actually displays. I don’t know if Ive been calling that wrong or not. Eventually I said screw it and I’ve been running everything outside of the group. All my code still exists within the create, show, hide, and destroy. The only difference is I keep my local variables outside the code so I can pass my variables and settings throughout the code. Is it not working because the objects are not in the sceneGroup?

EDIT: Just figured out how to display objects in the group. Going to convert my gamePlay.lua file into all objects in the groups and try again.

EDIT 2: sceneGroup doesn’t display the scene:create. Objects only display in scene:show.

I was also having a problem with my composer.removeScene(), turns out it needs to be in the scene:show function and not the scene:create. 

Just to be as clear as possible here.   In scene:create() you create display.* objects that you want to have transition on the screen when the scene shows.  Things that get created later, like new enemies that are spawning can be deferred until after scene:show() happens.  You must insert these object’s into the the scene’s “view”:  i.e.:

sceneGroup:insert(object)

self.view:insert(object)  – if in one of the scene event handlers

scene.view:insert(object) – in a function that’s not part of the scene object/handlers.

If you do not do this, then Composer won’t do squat for you.  If it is not working as expected then either you have not inserted things into the the sceneGroup properly.

By design things that are not inserted in a scene sit on top of the scenes.  Lets say you create a background/splash screen in your main.lua (which is not a scene and the background cannot be inserted into the scene) and you try to go to a scene where things are inserted properly,  that background/splash screen will stay on top and it will appear as if the scene management isn’t working.    You can’t use composer.removeScene() to remove it because it’s not part of the scene.  By not inserting things in groups, they get stacked on top and again, removeScene has nothing to do.

Based on your description, it sounds like you have something you’re not inserting into a scene that’s staying on top.

Rob

Thanks Rob. I got it working well.

I was having a similar problem with my game. You are correct to perform the composer.removeScene(“scene”), I put mine in the scene:create function of your tryAgain.lua. 

What require statements are your calling in your game? Also, are you adding your onscreen image items to the sceneGroup with sceneGroup:insert(object)?

Well for me every time I’ve tried inserting my objects into the sceneGroup nothing actually displays. I don’t know if Ive been calling that wrong or not. Eventually I said screw it and I’ve been running everything outside of the group. All my code still exists within the create, show, hide, and destroy. The only difference is I keep my local variables outside the code so I can pass my variables and settings throughout the code. Is it not working because the objects are not in the sceneGroup?

EDIT: Just figured out how to display objects in the group. Going to convert my gamePlay.lua file into all objects in the groups and try again.

EDIT 2: sceneGroup doesn’t display the scene:create. Objects only display in scene:show.

I was also having a problem with my composer.removeScene(), turns out it needs to be in the scene:show function and not the scene:create. 

Just to be as clear as possible here.   In scene:create() you create display.* objects that you want to have transition on the screen when the scene shows.  Things that get created later, like new enemies that are spawning can be deferred until after scene:show() happens.  You must insert these object’s into the the scene’s “view”:  i.e.:

sceneGroup:insert(object)

self.view:insert(object)  – if in one of the scene event handlers

scene.view:insert(object) – in a function that’s not part of the scene object/handlers.

If you do not do this, then Composer won’t do squat for you.  If it is not working as expected then either you have not inserted things into the the sceneGroup properly.

By design things that are not inserted in a scene sit on top of the scenes.  Lets say you create a background/splash screen in your main.lua (which is not a scene and the background cannot be inserted into the scene) and you try to go to a scene where things are inserted properly,  that background/splash screen will stay on top and it will appear as if the scene management isn’t working.    You can’t use composer.removeScene() to remove it because it’s not part of the scene.  By not inserting things in groups, they get stacked on top and again, removeScene has nothing to do.

Based on your description, it sounds like you have something you’re not inserting into a scene that’s staying on top.

Rob

Thanks Rob. I got it working well.