0 votes

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

Node2d
|-Player
|-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 random_scene=RandomNumberGenerator.new()
var selected_scene_index=0
func _on_Timer_timeout():
    random_scene.randomize()
    selected_scene_index=random_scene.randi_range(0,scenes.size()-1)
    var tmp=scenes[selected_scene_index].instance()
    add_child_below_node(self,tmp)

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.

asked Jun 16 in Engine by soul_gugu (14 points)

1 Answer

0 votes

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.

answered Jun 18 by njamster (8,986 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.