0

My tile-sheet has tiles that are 64x64, however between each tile there is a 10px gap and i need to account for that gap when setting the texture rectangle in the image in order to draw that tile

I tried simply adding the space upon setting the texture rectangle but the image still looks distorted

for (auto y = 0u; y < map.getTileCount().y; ++y)
            {
                for (auto x = 0u; x < map.getTileCount().x; ++x)
                {
                    auto posX = static_cast<float>(x * map.getTileSize().x); 
                    auto posY = static_cast<float>(y * map.getTileSize().y);
                    sf::Vector2f position(posX, posY);

                    tileSprite.setPosition(position); 

                    auto tileID = tiles[y * map.getTileCount().x + x].ID; //the id of the current tile

                    if (tileID == 0)
                    {
                        continue; //empty tile
                    }

                    auto i = 0;
                    while (tileID < tileSets[i].getFirstGID())
                    {
                        ++i;
                    }

                    auto relativeID = tileID - tileSets[i].getFirstGID(); 

                    auto tileX = relativeID % tileSets[i].getColumnCount();
                    auto tileY = relativeID / tileSets[i].getColumnCount();

                    textureRect.left = tileX * tileSets[i].getTileSize().x; //i am guessing this is where
                    // i should account for the spacing 
                    textureRect.top = tileY * tileSets[i].getTileSize().y;

                    tileSprite.setTexture(mTextureHolder.get(Textures::SpriteSheet));
                    tileSprite.setTextureRect(textureRect);

                    mMapTexture.draw(tileSprite);
                }
            }

The code itself is working and its drawing the tiles in the correct sizes, if i use a normal 64x64 tileset without any spacing the final image looks right however with spacing included the tiles are cut out. How do i add the gap between the tiles when setting the texture rectangle?

this is how it looks:

this is how it should look:

(NOTE: The "how it should look" image is from the Tiled editor )

Wiz
  • 15
  • 4
  • Would it be easier to change the tilesheet to remove those spaces? There are a number of reasons why it's standard practice to keep all tiles in a sheet as compact as possible (including ease of processing, as you have found). – 0x5453 Jul 10 '19 at 18:23
  • You are right, i managed to find a python script for gimp and used it to remove all the spaces, everything works perfectly now! – Wiz Jul 10 '19 at 18:41

1 Answers1

0

Removing the spaces with a python script i found and gimp fixed the problem, however if anyone knows how to account for the spacing feel free to answer as i might need it someday

Wiz
  • 15
  • 4