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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/LDtkLoader/Tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace ldtk {

const float alpha;

const IntPoint offset;

auto getPosition() const -> IntPoint;
auto getGridPosition() const -> IntPoint;
auto getWorldPosition() const -> IntPoint;
Expand Down
2 changes: 1 addition & 1 deletion src/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ auto Layer::getEntity(const IID& entity_iid) const -> const Entity& {
}

auto Layer::getCoordIdAt(int x, int y) const -> int {
return (x + y * m_grid_size.x) / getCellSize() ;
return (x / getCellSize()) + (y / getCellSize()) * m_grid_size.x;
}

7 changes: 4 additions & 3 deletions src/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ coordId(l == nullptr ? -1 : l->getCoordIdAt(pos.x, pos.y)),
tileId(tile_id),
flipX(flips & 1),
flipY((flips>>1) & 1),
alpha(a)
alpha(a),
offset(l == nullptr ? -1 : pos.x - (pos.x / l->getCellSize()) * l->getCellSize(), l == nullptr ? -1 : pos.y - (pos.y / l->getCellSize()) * l->getCellSize())
{}

auto Tile::getPosition() const -> IntPoint {
auto cell_size = layer->getCellSize();
auto grid_pos = getGridPosition();
auto offset = layer->getOffset();
return {grid_pos.x * cell_size + offset.x, grid_pos.y * cell_size + offset.y};
auto layer_offset = layer->getOffset();
return {grid_pos.x * cell_size + layer_offset.x + offset.x, grid_pos.y * cell_size + layer_offset.y + offset.y};
}

auto Tile::getGridPosition() const -> IntPoint {
Expand Down
Loading