Skip to content

Commit

Permalink
Merge pull request #11 from devharts/develop
Browse files Browse the repository at this point in the history
Take into account tile spacing (padding between tiles)
  • Loading branch information
MikeMnD authored Jul 1, 2020
2 parents 26c825a + 149923c commit c856bd6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions export_to_godot_tilemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions export_to_godot_tileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [ ]
Expand Down

0 comments on commit c856bd6

Please sign in to comment.