Auto tile procedural generation and parallax background dropping fps

Godot Version

4.3
Question

So I’m using procedural generation with tile map of size 16 on 256x256.
If i just leave this fps is good (100+) but if i add parallax2d to generate it infinitely fps drops to 30ish and if player is standing at corner of one tile where other corners meet fps is below 5 and way to optimize this?

My tile generation:

extends Node2D

@onready var tileMap =$Parallax2D/Layer0
const Map_size = Vector2(128,128)
const LAND_CAP = 0.2
func _ready():
	generateWorld()

func generateWorld():
	var noise = FastNoiseLite.new()
	noise.seed = 1 #randi()
	
	var cells : Array = []
	for x in range(0,Map_size.x):
		for y in range(0,Map_size.y):
			var a = noise.get_noise_2d(x,y)
			if a<LAND_CAP:
				cells.append(Vector2(x,y))
			else:
				tileMap.set_cell(Vector2(x,y),1,Vector2(0,0),0)
	tileMap.set_cells_terrain_connect(cells,0,0,true)

And then if im standing between one of those 256x256 map fps increases to about 30-40. I have been trying and nothing is working please help!!!

Historically, games that have large tile maps handle sections in chunks, not with parallax. Old video, but Godot specific and still relevant.

1 Like

Did try loading and unloading chunks but what happned was since i was doing those 2 process every frame. It was forming a trail and gotten very laggy,after that I modified it little and added this to check if for chunk changes but it is slow player could basically walk out of map while it slowly trails behind before it gets erased after chunk is certain distance.

var newChunk = Vector2i(floori(player.position.x/width),floori(player.position.y/width))
	if newChunk!=current_chunk:
		current_chunk = newChunk 
		generate_chunk(current_chunk)

(2024-09-02_23-09-01.mp4 - Google Drive)