0
votes

I am maing a small game using SFML, anyway, my issue is that when rendering the sprite, and moving with float values. The sprite has a white background that 1 pixel one whichever side is moving gets shown.

Here is my Spritesheet class:

Spritesheet::Spritesheet(std::string t) {
    this->texture.loadFromFile(t);
    this->sprite.setTexture(this->texture);
}

sf::Sprite Spritesheet::getSprite(int x, int y, int width, int height) {
    sf::Sprite spt;
    spt.setTexture(this->texture);
    spt.setTextureRect(sf::IntRect(x, y, width, height));
    return spt;
}

void Spritesheet::setSprite(std::string t) {
    this->texture.loadFromFile(t);
    this->sprite.setTexture(this->texture);
}

And then the player class which is the class that draws the sprite:

Player::Player(int x, int y) {
    // Some other code
    this->spritesheet.setSprite("./res/img/tiles.png");
    this->sprite = this->spritesheet.getSprite(48, 48, 16, 16);
    this->sprite.setPosition(x, y);
    this->sprite.scale(4, 4);
}

// Further down

void Player::render(RenderWindow& g) {
    g.draw(this->sprite);
}

enter image description here

I have also tried using the sprite function setColor but that changes the texture color aswell.

2
I never use sfml, but this doesn't looks like issue with sprite to me. maybe some buffering issue? - apple apple
@appleapple I really don't know I've searched around for a while and have not found anything. - tygzy

2 Answers

0
votes

I've had a problem similar to this before. To fix it I had added a clock before the display so that I could be sure that the display was finished before I could display it again.

sf::Clock clock;
while (clock.getElapsedTime().asMilliseconds() < 100);
        clock.restart();
0
votes

maybe its FPS, i had a similar issue when i did not set a max fps, try window.setFramerateLimit(60); maybe it would fix it