Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to properly restart a scene? — Gideros Forum

How to properly restart a scene?

KarrizKarriz Member
edited August 2013 in General questions
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

  • @Karriz in reality there should be no difference between going back to level select or straight to the same gamescene. It should behave the same.

    Do you call any specific code before going to the same gamescene?
  • KarrizKarriz Member
    edited August 2013
    I've tried to add some print() functions to figure out what happens and when, and it seems that when I restart the scene, it supposedly adds the body to the new scene, and then it runs the exitbegin, and after that it crashes. There's a function in the onEnterFrame that calls the body, and for some reason it cannot recognize it.

    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.
  • JesderJesder Member
    edited August 2013
    I agree with @ar2rsawseen. You should have no problems going from gamescene to a new instance of gamescene using the scene manager.

    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.



Sign In or Register to comment.