Say I want to change maps (scenes in this case) and position my character at certain co-ordinates after the scene change...<br />How would I go about doing that?<br />Can you dynamically set objects as singletons via script or would you have to include an instance of the character in each scene?<br />Also, can you dynamically re-parent nodes via script? I can't seem to find a way and this is necessary to ensure everything works correctly (layers, collision etc.)

I don't know if this is the best way to do it, but in my game, I have a special area object that I position where the teleport should be. If the player touches it, then they get moved to a new set of coordinates into the new level. I only have teleports for the horizontal and vertical directions where the y coordinates in the horizontal direction depend on the position the teleport links to and the player's current offset from the current teleport. If you do it this way, then your layout has to make sense, and the teleports that connect those two levels should be the same height. The x coordinate will just be the one you want the player to teleport to. Same with the vertical one, but you swap the x and y coordinates.I have my game set up a bit like minilens where the player is in a separate container from the level and tilemaps so that they can be swapped without losing player state. But I find the physics server lags a bit, and if you use the move function, it will try to calculate the collisions in between. I used call_deferred to move the player to the correct location after the new level loads completely. If you're dynamically loading levels at run time, it might also be desirable to do some background loading. If you don't want any collisions to be calculated while the level is loading, you'll also have to pause your processes before the background loading and unpause it afterwards.

[quote author=Elf_Ears link=topic=15465.msg16064#msg16064 date=1462226384]Say I want to change maps (scenes in this case) and position my character at certain co-ordinates after the scene change...How would I go about doing that?Can you dynamically set objects as singletons via script or would you have to include an instance of the character in each scene?Also, can you dynamically re-parent nodes via script? I can't seem to find a way and this is necessary to ensure everything works correctly (layers, collision etc.)[/quote]To reparent nodes, simply use remove_child and add_child. Collisions would be automatically taken care of. About layers, they might be important, since they are nodes and your character must be reparented to a node. If you need multiple layers for one reason or another, I'd suggest to create in the editor one layer for all characters and add all new characters in this layer only.I don't think you need to make your characters as singletons. You can pass one node from a scene to another through a variable or a function parameter. Personnaly I prefer to have one singleton for all game data, with child nodes that contain data from characters. Then you add in scenes the nodes with mesh/sprite of your characters and initialize them with the singleton's children.That allows me to implement multiple controller-views (gameplays or appearances) for the same character.

7 years later