So far I’ve set up a scene where the game will duplicate these river nodes wherever the player goes, and I’m trying to add some grass tiles around each river node as a background.
I followed this guys tutorial https://www.youtube.com/watch?v=-zf7b7x4Oww
and ended up with this piece of code
extends TileMapLayer
var grid_size = 7
var atlas_coords = Vector2(0, 0)
func _ready():
for x in grid_size:
for y in grid_size:
set_cell(Vector2i(0, 0), 0, atlas_coords, 0)
but instead of setting the tile grass like this:
it only spawns one tile of grass.
How do I fix this?
or do I have to manually place each piece of grass. ( - _ ; )
(btw sorry if I don’t reply, it’s almost time for me to sleep as of posting this.)
So, your problem is you never change your atlas_coord variable
Try something like this.
extends TileMapLayer
var grid_size := 7
var atlas_coords : Vector2
func _ready():
for x in grid_size:
for y in grid_size:
#this should change atlas_coords
#between (0,0) and (7,7)
atlas_coords = Vector2(x - 1,y - 1)
set_cell(Vector2i(0, 0), 0, atlas_coords, 0)
However, that won’t work either since your (0,0) coord isn’t your top left, but rather where the one grass tile spawned. So, what I wrote will spawn those tiles 7 tiles from that one tile right and down.
What you really need to do rather than just arbitrarily creating grid_size. Is find the rect2 of the tilemap layer you want to populate that and cycle through its coords.