Restart scene: menu.lua --> level1.lua --> tryagain.lua --> level1.lua not completely working.

Hi guys, I’m almost finishing my game and just noticed something annoying.

It’s a one scene game and it follows the flow:

       

            “menu.lua --> level1.lua --> tryagain.lua --> level1.lua”

I read that from here (http://forums.coronalabs.com/topic/38414-how-to-reload-a-scene-and-proceed-like-normal/) and is suppossed to be the best way to reload a scene. Really my “tryagain.lua” is a scene with some buttons that let you go to the menu, and restart the game.

My game uses physics, and I noticed that the main character doesn’t starts as it should, it has a slightly rotation and that rotation is related with the collision of the previous level1.lua executed. Maybe something related with the physics??

The button to “tryagain.lua” does the following:

local handleAgain = function (event) composer.removeScene("level1") composer.gotoScene( "level1", { params = { mode = mode } }) return true end

Maybe there is not enough time to complete remove the scene?

Thanks a lot!!!

I just moved the composer.removeScene(“scene”) to the phase = did of the function scene:show( event ) and it worked fine, but the problem is that I need to keep the previous scene until the last moment because I need to take a screenshot of the previous scene if the user wants to share that, so I can remove it until I know the user is going to the menu or trying again.

Take the screenshot every time and destroy it if the user doesn’t share it.

Physics objects will suffer from slight changes in their state/position/etc if you re-use them. You should destroy them all and re-create at the end of a scene.

With (older) storyboard and composer issues be VERY sure that you are not leaving objects or references in memory when a scene exits. Make sure that you clean everything up in the destroy event.

This is like my exact issue / pain the last few days.

I’ve got two scenes: Menu and level1

Both have buttons that when released, it will execute following: 

composer.removeScene(“level1”)
composer.gotoScene( “Menu”, fade, 250)

OR Vice versa whatever scene I’m on.

Currently , it works great if I choose to go from Menu —> level1

The issues arise when I go from level1 ----> Menu

Some reason, the touch eventlistner function for level1 is occuring when I touch screen on Menu - even tho I had removed it (well all event listeners) on the ‘Scene:Destory’ function (a composer function) of level1 scene.

It’s almost acting as if I’m only partially destroying Level1 … but I have the sceneGroup setup correctly for all objects to be inserted into, hence getting destroyed at switch of level, and I’ve gone through my code hundreds of time to make sure all objects are being Removed then being set to Nil.  I been going through my code non-stop past 3-4 days and tried almost every combination of when to remove the scene at various composer functions or remove eventListeners as that seems to be the issue… but alas, nothing seems to work.

Also when I go from Menu --> level1 --> and back to Menu , my memory tracker stays relatively even / the same.

But when I go from Menu – > level1 --> Menu and then on return to Level1 -> there’s a big spike in memory

Please any help!

Take the screenshot every time and destroy it if the user doesn’t share it.

Physics objects will suffer from slight changes in their state/position/etc if you re-use them. You should destroy them all and re-create at the end of a scene.

With (older) storyboard and composer issues be VERY sure that you are not leaving objects or references in memory when a scene exits. Make sure that you clean everything up in the destroy event.

This is like my exact issue / pain the last few days.

I’ve got two scenes: Menu and level1

Both have buttons that when released, it will execute following: 

composer.removeScene(“level1”)
composer.gotoScene( “Menu”, fade, 250)

OR Vice versa whatever scene I’m on.

Currently , it works great if I choose to go from Menu —> level1

The issues arise when I go from level1 ----> Menu

Some reason, the touch eventlistner function for level1 is occuring when I touch screen on Menu - even tho I had removed it (well all event listeners) on the ‘Scene:Destory’ function (a composer function) of level1 scene.

It’s almost acting as if I’m only partially destroying Level1 … but I have the sceneGroup setup correctly for all objects to be inserted into, hence getting destroyed at switch of level, and I’ve gone through my code hundreds of time to make sure all objects are being Removed then being set to Nil.  I been going through my code non-stop past 3-4 days and tried almost every combination of when to remove the scene at various composer functions or remove eventListeners as that seems to be the issue… but alas, nothing seems to work.

Also when I go from Menu --> level1 --> and back to Menu , my memory tracker stays relatively even / the same.

But when I go from Menu – > level1 --> Menu and then on return to Level1 -> there’s a big spike in memory

Please any help!