SFML community forums

Help => Graphics => Topic started by: isaiah0311 on August 13, 2020, 10:16:03 pm

Title: Sprite is showing outside texture rect
Post by: isaiah0311 on August 13, 2020, 10:16:03 pm
void Graphics::render(unsigned char id, float x, float y) {
        sf::Sprite sprite;
        sprite.setTexture(*tileset);

        sf::IntRect rect;
        rect.left = id % 16 * 16;
        rect.top = id / 16 * 24;
        rect.width = 16;
        rect.height = 24;

        sprite.setTextureRect(rect);
        sprite.setScale(sf::Vector2f(2.0f, 2.0f));
        sprite.setPosition(sf::Vector2f(x, y));

        window->draw(sprite);
}

There is one texture for the game, it's a 16 x 16 tile sheet with each tile having a size of 16 x 24px. When I display a tile, it will show a thin line of the tile below it. I can't figure out why it would display more than the 16 x 24. Please help.
Title: Re: Sprite is showing outside texture rect
Post by: Stauricus on August 13, 2020, 11:45:30 pm
did you set texture smooth to be true?
Title: Re: Sprite is showing outside texture rect
Post by: isaiah0311 on August 14, 2020, 12:00:58 am
No, should I?
Title: Re: Sprite is showing outside texture rect
Post by: isaiah0311 on August 14, 2020, 12:37:51 am
Solved the issue. I had anti-aliasing set to 16. By setting to 8 or lower it removes this issue. I had not had this problem before when working with 16 x 16px tiles, only 16 x 24px.
Title: Re: Sprite is showing outside texture rect
Post by: Hapax on August 15, 2020, 11:24:20 pm
This is an issue that can occur if all co-ordinates are not integers; if you have, for example, fractional positions or not pixel perfect scaling, when choosing a colour to use for a pixel, it can be given a choice and may choose as you did not intend.