0 votes

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 random_scene=RandomNumberGenerator.new()
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.

in Engine by (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.

by (10,628 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.