I wondering if its possible to have multiple localized grids in a scene. So for example, a grid that is a 5x5 and another grid that is a 6x6. Then I could take a sprite and give it coordinate points and have it exist in both of the grids in different locations for example. From what I’ve tested and read, while I could have multiple layers, the coordinate points all end up the same no matter where the grids are positioned.
I’m trying something where a sprite is built in a grid and then reconstructed at different positions in the scene.
The building behavior is that the sprite is placed on top of a drawn grid, and then that position is recorded to then be placed in another spawned grid.
This is the script for reconstructing the sprite:
func on_visibility_changed():
print("Node is now visible!", Global.spritePositions)
print('origin', get\_global\_transform().origin)
var grid\_size = 128
# You can place your sprite creation logic here
for sprite\_info in Global.spritePositions:
# Create a new sprite (or appropriate node)
var new\_sprite = Sprite2D.new()
new\_sprite.centered = false # part of what was causing the centering issue
# Set texture and position based on stored info
new\_sprite.texture = sprite\_info\["texture"\]
var grid\_position = sprite\_info\["position"\] # (x, y)
# Convert grid coordinates to pixel position by multiplying with grid\_size
var pixel\_position = Vector2(grid\_position) \* grid\_size
var sprite\_size = new\_sprite.texture.get\_size()
pixel\_position += (Vector2(grid\_size, grid\_size) - sprite\_size) / 2
new\_sprite.position = frame.to\_local(pixel\_position)
new\_sprite.visibility\_layer = 1
# Add to the appropriate grid or container
frame.add\_child(new\_sprite)
This is ideally what I’d want as the scene setup with the numbers in parenthesis representing the position (x,y) and then I could just plug the sprite with the coordinates into the grid
Scene
|__Node2D (600, 900)
| |__tilemaplayer 5x5
|__Node2D (0,0)
|__tilemaplayer 6x6