Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for individual tile offsets #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Spheya
Copy link

@Spheya Spheya commented Apr 28, 2024

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
Copy link
Author

Spheya commented Apr 28, 2024

pretty sure this also fixes issue #39

@Madour
Copy link
Owner

Madour commented May 1, 2024

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
Copy link
Owner

Madour commented May 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants