LDtkLoader icon indicating copy to clipboard operation
LDtkLoader copied to clipboard

Add support for individual tile offsets

Open Spheya opened this issue 1 year ago • 3 comments

new field Tile::offset to represent the offset of the tile's position in pixels. also the Layer::getCoordAt function gave wrong results when the position wasn't the exact coordinate of the grid, so that's fixed as well.

Spheya avatar Apr 28 '24 15:04 Spheya

pretty sure this also fixes issue https://github.com/Madour/LDtkLoader/issues/39

Spheya avatar Apr 28 '24 15:04 Spheya

Hello, thank you for the PR. I am not sure I understand what does the Tile offset represents.

Looking at the code, you specify the tile offset as:

{
  pos.x - (pos.x / l->getCellSize()) * l->getCellSize(), 
  pos.y - (pos.y / l->getCellSize()) * l->getCellSize()
}

However, this can be simplified as just

{
  pos.x, 
  pos.y
}

which is the Tile position.

Madour avatar May 01 '24 14:05 Madour

Ah, I think I understand what you are trying to do now. In the scenario where layer cell size is not the same as tileset cell size, you are trying to get the difference as an offset right ?

Though I still don't understand why it is needed.

To test, I created a Tile layer with a cell size of 10 px and a layer offset of (10, -5). Then I painted tiles of size 16x16 px. Then I rendered those tiles using :

for (const auto& tile : layer_tiles.allTiles()) {
    auto vertices = tile.getVertices();
    // render the vertices
}

And it resulted in a correct rendering, that matches what was displayed in the editor.

Madour avatar May 01 '24 18:05 Madour