diff --git a/export_to_godot_tilemap.js b/export_to_godot_tilemap.js index 23b2344..164cbdb 100644 --- a/export_to_godot_tilemap.js +++ b/export_to_godot_tilemap.js @@ -188,12 +188,19 @@ class GodotTilemapExporter { /** * Tileset should expose columns ... but didn't at the moment so we - * calculate them base on the image width and tileWidth - * return {number} + * calculate them base on the image width and tileWidth. + * Takes into account margin (extra space around the image edges) and + * tile spacing (padding between individual tiles). + * @returns {number} **/ getTilesetColumns(tileset) { // noinspection JSUnresolvedVariable - return Math.floor(tileset.imageWidth / tileset.tileWidth); + const imageWidth = tileset.imageWidth + tileset.tileSpacing - tileset.margin + const tileWidth = tileset.tileWidth + tileset.tileSpacing + const calculatedColumnCount = imageWidth / tileWidth + // Tiled ignores "partial" tiles (extra unaccounted for pixels in the image), + // so we need to return as Math.floor to avoid throwing off the tile indices. + return Math.floor(calculatedColumnCount); } /** diff --git a/export_to_godot_tileset.js b/export_to_godot_tileset.js index 421e867..cfa72a5 100644 --- a/export_to_godot_tileset.js +++ b/export_to_godot_tileset.js @@ -117,11 +117,11 @@ ${this.shapesResources}[resource] 0/texture = ExtResource( 1 ) 0/tex_offset = Vector2( 0, 0 ) 0/modulate = Color( 1, 1, 1, 1 ) -0/region = Rect2( 0, 0, ${this.tileset.imageWidth}, ${this.tileset.imageHeight} ) +0/region = Rect2( ${this.tileset.margin}, ${this.tileset.margin}, ${this.tileset.imageWidth}, ${this.tileset.imageHeight} ) 0/tile_mode = 2 0/autotile/icon_coordinate = Vector2( 0, 0 ) 0/autotile/tile_size = Vector2( ${this.tileset.tileWidth}, ${this.tileset.tileHeight} ) -0/autotile/spacing = 0 +0/autotile/spacing = ${this.tileset.tileSpacing} 0/autotile/occluder_map = [ ] 0/autotile/navpoly_map = [ ] 0/autotile/priority_map = [ ]