HELP! What happens between createScene and enterScene?

Hey all

I am coding a game and on one particular level I place an object in position using the translate function within the createScene method.  If I add a print statement inside the method it reports the correct x and y locations.

Once the enterScene method is called, however, the x and y locations have changed (as shown with a different print statement)!

Even more obscurely, if I restart the level (using a button on screen) the behaviour is not observed.

Does anyone have any ideas why this is happening?

A

Well one thing that happens between scenes is time.  Depending on what transitions you have going on (or translations), the objects could move if you start the movement in createScene() and then have to wait for the scene to transition on the screen.  Things like that are best to start up in enterScene() when the scene is fully on the screen.

Hi Rob

Thanks for the reply.  The object in question should be stationary.  Also the amount that the object moves between the method calls is deterministic which suggests the issue isn’t temporal.  In any case I’ve added a check in the enterScene method to correct the location which seems to have solved my issue.

I general, though, are you saying that it is best practice to position objects on the screen within the enterScene method rather than createScene?  At the moment I am structuring my code to put objects on screen and position them within createScene and add the event listeners within enterScene.

Appreciate the help.

A

Well one thing that happens between scenes is time.  Depending on what transitions you have going on (or translations), the objects could move if you start the movement in createScene() and then have to wait for the scene to transition on the screen.  Things like that are best to start up in enterScene() when the scene is fully on the screen.

Hi Rob

Thanks for the reply.  The object in question should be stationary.  Also the amount that the object moves between the method calls is deterministic which suggests the issue isn’t temporal.  In any case I’ve added a check in the enterScene method to correct the location which seems to have solved my issue.

I general, though, are you saying that it is best practice to position objects on the screen within the enterScene method rather than createScene?  At the moment I am structuring my code to put objects on screen and position them within createScene and add the event listeners within enterScene.

Appreciate the help.

A