godot-LDtk-import icon indicating copy to clipboard operation
godot-LDtk-import copied to clipboard

'Rectangle of tiles' doesn't import properly

Open nion-ne opened this issue 2 years ago • 4 comments

Unsure if limitation or user error, but marking an area of tiles in either an Intgrid or Autotile layer fails to import appropriately into Godot.

image

It behaves appropriately in editor but doesn't seem to in the generated scene.

LDTK image

Godot image

Using Godot 3.5 Stable with LDtk 1.1.3-64bit

Minimal recreation: The 'AutoLayers 2 stamps' sample map in LDtk uses a 2x2 rectangle of tiles rule in its Intgrid layer.

nion-ne avatar Sep 20 '22 10:09 nion-ne

I'm also having the exact same issue...

stingly avatar Oct 05 '22 23:10 stingly

I've located and fixed the issue - just working up a pull request :)

image

stingly avatar Oct 08 '22 00:10 stingly

I am not able to push up a new branch and not sure of the best way to help... I assume that the repository is locked down, which is understandable... my diff is pretty simple:

/addons/LDtk-Importer/LDtk.gd

func new_tilemap(tilemap_data):
	var flip = int(tile["f"])
	var flipX = bool(flip & 1)
	var flipY = bool(flip & 2)
	var grid_coords = pxCoords_to_gridCoords(tile.px, tilemap_data.__gridSize)
        tilemap.set_cellv(grid_coords, tile.t, flipX, flipY)
        return tilemap
 
#converts pixels to grid coordinates.
func pxCoords_to_gridCoords(pixelValues, gridSize):
       var gridY = floor(pixelValues[1] / gridSize)
       var gridX = floor(pixelValues[0] / gridSize)
       return Vector2(gridX, gridY)

Basically it looks like LDtk references the same tile within the "d" attribute multiple times when a rectangle shape is defined. Consequently the tile is overwritten and will only display the last shape in the applied rectangle. I created a grid coord function to take the pixel value instead, which is accurate, and update the tile based on that.

stingly avatar Oct 08 '22 00:10 stingly

Think I've worked out how to actually contribute!

stingly avatar Oct 24 '22 22:10 stingly