I'm using Scenemanager for my game, which has multiple screens, such as levelselect and gamescene.
Now, I want to restart the game scene if I fail in the game. In this case, the player character body has been destroyed.
If I just directly try to reload the scene with:
sceneManager:changeScene("gamescene", 1, SceneManager.crossfade, easing.outBack)
I get the error "body has already been destroyed".
However, if I go back to level selection screen and then change to gamescene, it loads up just fine.
Is there a way to directly reload the gamescene from gamescene without running into issues? I'm using the "onexitbegin" to remove the enterframe.
Comments
Do you call any specific code before going to the same gamescene?
Oh, and if I restart the scene while the first body is still intact, everything works fine.
Here's the whole gamescene code: http://pastebin.com/gagsYgHE
I'm considering doing a workaround if this problem persists; some sort of a loading scene that handles the loading of gamescene should work.
Edit:using a loadingscene also seems to make the transition smoother, as previously there was some "jumpy" movement right after restarting the scene.
In the cutscene demo I released a few weeks back (source code here) the cutscene scene class loops at the end of each cutscene to a new instance of cutscene without issue.
@Karriz I've only had a quick loop through that file and one thing that stands out is a class member "lander" and a function called "lander()" - and that could be a source of some problems or strange behaviour.
"self.lander = self:lander(600, 50)"
I'm fairly certain this will replace your lander member function with the return content of the lander() function.
There are also a lot of global variables there that i imagine could be made local or class members too.