A small question about composer?

Greetings!

This is my first post so bear with any  mistakes.

I am using composer for the first time and have a problem.

In a scene called level1.lua I have 20 circles (display objects) on the screen.

In scene:create -> I create them and insert them in scene:group

In scene:show ->I set their positions and start physics

In scene: hide -> I do nothing!

In scene:destroy -> I remove all display objects, stop physics and remove event listeners

And I have a menu.lua scene too.

Okay so the problem. Why are the display objects removed when, upon button tap, I move from  level1.lua to menu.lua?

As far as I have read, when we move from one scene to another, scene:hide is called, and in hide I have done nothing, so how and why are the circles removed?

Thanks in advance!

Hi @mostwanted_1996,

Do you want the menu scene to appear “over” the level scene, so that the level scene is not truly hidden from view? If so, you should create the menu scene as an overlay… that is outlined in the Composer documentation and guides.

https://docs.coronalabs.com/guide/system/composer/index.html#overlay-scenes

Hope this helps,

Brent

Have you added your circles in sceneGroup?

–SonicX278

In scene:create -\> I create them and insert them in scene:group In scene:show -\>I set their positions and start physics In scene: hide -\> I do nothing! In scene:destroy -\> I remove all display objects, stop physics and remove event listeners

scene:hide() is where you should remove any Runtime event listeners. Touch and Tap handlers will be removed when the objects are hidden or finally deleted.  You should stop physics in scene:hide().

The only thing you need to do in scene:destroy() is remove anything that you did in create() that isn’t a display object, for instance audio.

scene:destroy() is called as a result of composer.removeScene() or if the system calls composer.removeScene() for you. scene:hide() is called everytime the scene leaves the screen. Display objects like your circles will likely be hidden behind the replacement scene or be off screen. In that case the display objects cannot be touched. When composer.removeScene() is called, then the display objects that you inserted into the group will be destroyed for you.

Rob

Thank you all!

My problem has been solved!

Hi @mostwanted_1996,

Do you want the menu scene to appear “over” the level scene, so that the level scene is not truly hidden from view? If so, you should create the menu scene as an overlay… that is outlined in the Composer documentation and guides.

https://docs.coronalabs.com/guide/system/composer/index.html#overlay-scenes

Hope this helps,

Brent

Have you added your circles in sceneGroup?

–SonicX278

In scene:create -\> I create them and insert them in scene:group In scene:show -\>I set their positions and start physics In scene: hide -\> I do nothing! In scene:destroy -\> I remove all display objects, stop physics and remove event listeners

scene:hide() is where you should remove any Runtime event listeners. Touch and Tap handlers will be removed when the objects are hidden or finally deleted.  You should stop physics in scene:hide().

The only thing you need to do in scene:destroy() is remove anything that you did in create() that isn’t a display object, for instance audio.

scene:destroy() is called as a result of composer.removeScene() or if the system calls composer.removeScene() for you. scene:hide() is called everytime the scene leaves the screen. Display objects like your circles will likely be hidden behind the replacement scene or be off screen. In that case the display objects cannot be touched. When composer.removeScene() is called, then the display objects that you inserted into the group will be destroyed for you.

Rob

Thank you all!

My problem has been solved!