From 5d8735ac3fd0799793343bf79b493258fd6e91be Mon Sep 17 00:00:00 2001 From: Java <64042936+CppJavaCoder@users.noreply.github.com> Date: Wed, 26 Mar 2025 15:12:40 -0500 Subject: [PATCH] Update MapLayer.cpp Fix u v idIndex / tileCountY should be idIndex / tileCountX. This should fix tilesets that don't have the same rows as columns. --- SDL2Example/src/MapLayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SDL2Example/src/MapLayer.cpp b/SDL2Example/src/MapLayer.cpp index 6594e6e..f2e07f9 100644 --- a/SDL2Example/src/MapLayer.cpp +++ b/SDL2Example/src/MapLayer.cpp @@ -82,7 +82,7 @@ bool MapLayer::create(const tmx::Map& map, std::uint32_t layerIndex, const std:: //tex coords auto idIndex = (tileIDs[idx].ID - ts.getFirstGID()); float u = static_cast(idIndex % tileCountX); - float v = static_cast(idIndex / tileCountY); + float v = static_cast(idIndex / tileCountX); u *= mapTileSize.x; //TODO we should be using the tile set size, as this may be different from the map's grid size v *= mapTileSize.y; @@ -131,4 +131,4 @@ void MapLayer::draw(SDL_Renderer* renderer) const { SDL_RenderGeometry(renderer, s.texture, s.vertexData.data(), static_cast(s.vertexData.size()), nullptr, 0); } -} \ No newline at end of file +}