I’m trying to make an infinite scrolling background for my 2d top-down game, but for some reason, when it goes back to its original position, it causes the tilemap to kinda stutter/disapear for a second. Here is the code I’m using. I’m also moving it diagonally; it looks better.
extends TileMapLayer
@export var speed := 16.0
@export var tile_size := 128.0
func _process(delta):
position -= Vector2(1, 1).normalized() * speed * delta
if position.x <= -tile_size:
position.x += tile_size
if position.y <= -tile_size:
position.y += tile_size
Is the tile’s center at position or is it the edge of the tile? Subtracting a full tile_size would only be right, if the tiling starts at the edge of the tile.
You probably also want to use some sort of modulus operation instead of infinitely incrementing position. For this you can use % or fposmod().