How to create a 2d endless map generator?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By soul_gugu

I create 3 maps which will be appended at the end of current map randomly. Element structure of my level is:-

|-TileMap //initial map
|-Spawner(a 2d Node) // responsible to append levels in future

Following script is attched to spawners:-

extends Node2D
export(Array,PackedScene) var scenes

var selected_scene_index=0
func _on_Timer_timeout():
    var tmp=scenes[selected_scene_index].instance()

The code is working as expected,i.e., generating maps but how can i set the position of maps so that they appear after one another and do not overlap.

:bust_in_silhouette: Reply From: njamster

Like you set the position of everything else as well: change the global_position of your map scenes. Given your initial map is a TileMap, I’ll assume the map scenes are TileMap-nodes as well. You can use get_used_rect to get a TileMaps dimensions in tiles, multiply it with the tile-size (check the cell_size-property!) and offset it by the TIleMaps position (if it’s not Vector2.ZERO) and you’’ end up with global coordinates.