Trying to make a infinity generated top-down 2D map

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

Hi there! im new to gogot and so far im loving it, but i have a problem. im currently trying to figure out how to make my map go on for infinity and have no clue how to do it, please help. thanks!

:bust_in_silhouette: Reply From: CassanovaWong

Parallax Background, maybe?

:bust_in_silhouette: Reply From: estebanmolca

This is a basic example to generate random tile squares according to their probability:

extends Node2D
onready var tilemap = $TileMap
var set_desert = {"sand" : 85, "dirt" : 10, "grass" : 5}
var set_plain = {"sand" : 0, "dirt" : 10, "grass" : 90}
func _ready():
	make_chunk(10,10, set_desert)

func make_chunk(width:int, height:int, set:Dictionary) -> void:
	for i in width:
		for j in height:
			var tile_name:String = set.keys()[get_random_weigths(set)]
			tilemap.set_cell(i, j, tilemap.tile_set.find_tile_by_name(tile_name))	

func get_random_weigths(set:Dictionary) -> int:
	var sum_weigths:float = 0.0
	var offset:float = 0.0
	var index:int = 0
	var rnd:float = randf()
	for value in set.values():
		sum_weigths += value
	for value in set.values():
		if rnd <= (offset + value) / sum_weigths:
			return index
		index += 1
		offset += value	
	return index	

In this example I have a tilemap as a child, which has a tileset with 3 single-tiles called “sand”, “dirt” and “grass”.
So as the player walks, you create random or semi-random “chunks” around them. I don’t see it that easy. The code I put uses Tilemap, which uses Tileset as a resource. And I also used Dictionary. Look at those classes in the manual for more details.