@@ -104,7 +104,7 @@ class GodotTilemapExporter {
104104 let objectPositionY = object . y - ( object . tile . height / 2 ) ;
105105
106106 this . tileMapsString += `
107-
107+
108108[node name="${ object . name } " type="Sprite" parent="${ layer . name } "]
109109position = Vector2( ${ objectPositionX } , ${ objectPositionY } )
110110texture = ExtResource( ${ textureResourceId } )
@@ -159,7 +159,7 @@ region_rect = Rect2( ${tileOffset.x}, ${tileOffset.y}, ${object.tile.width}, ${o
159159 tileset = {
160160 tileset : tile . tileset ,
161161 tilesetID : null ,
162- tilesetColumns : this . getTilesetColumns ( tile . tileset ) ,
162+ tilesetColumns : getTilesetColumns ( tile . tileset ) ,
163163 layer : layer ,
164164 isEmpty : tile . tileset === null ,
165165 poolIntArrayString : "" ,
@@ -322,33 +322,16 @@ region_rect = Rect2( ${tileOffset.x}, ${tileOffset.y}, ${object.tile.width}, ${o
322322 return secondParam ;
323323 }
324324
325- /**
326- * Tileset should expose columns ... but didn't at the moment so we
327- * calculate them base on the image width and tileWidth.
328- * Takes into account margin (extra space around the image edges) and
329- * tile spacing (padding between individual tiles).
330- * @returns {number }
331- */
332- getTilesetColumns ( tileset ) {
333- // noinspection JSUnresolvedVariable
334- const imageWidth = tileset . imageWidth + tileset . tileSpacing - tileset . margin
335- const tileWidth = tileset . tileWidth + tileset . tileSpacing
336- const calculatedColumnCount = imageWidth / tileWidth
337- // Tiled ignores "partial" tiles (extra unaccounted for pixels in the image),
338- // so we need to return as Math.floor to avoid throwing off the tile indices.
339- return Math . floor ( calculatedColumnCount ) ;
340- }
341-
342325 /**
343326 * Calculate the X and Y offset (in pixels) for the specified tile
344327 * ID within the specified tileset image.
345- *
328+ *
346329 * @param {Tileset } tileset - The full Tileset object
347330 * @param {int } tileId - Id for the tile to extract offset for
348331 * @returns {object } - An object with pixel offset in the format {x: int, y: int}
349332 */
350333 getTileOffset ( tileset , tileId ) {
351- let columnCount = this . getTilesetColumns ( tileset ) ;
334+ let columnCount = getTilesetColumns ( tileset ) ;
352335 let row = Math . floor ( tileId / columnCount ) ;
353336 let col = tileId % columnCount ;
354337 let xOffset = tileset . margin + ( tileset . tileSpacing * col ) ;
0 commit comments