Image tile with SFML

I have a background image, and only 256 x 256 when my window is 800 x 600. I'm not sure how to make the image repeat across the window. I am currently uploading an image using:

sf::Texture Bkg;
if(!Bkg.loadFromFile("darkPurple.png"))
{
    return -1;
}

sf::Sprite Sprite;
Sprite.setTexture(Bkg);

and draw it later:

window.draw(Bkg);

I tried using:

texture.setRepeated(true);

but that didn't seem to help.

Thanks!

+4
source share
1 answer

After loading the image, you need to call setReapeted:

    texture.setRepeated(true);

And after that, when the load texture in your sprite, set the rectangle for the texture to be the size of the screen:

    sprite.setTexture(texture);
    sprite.setTextureRect(sf::IntRect(0,0,800,600);
+6
source

Source: https://habr.com/ru/post/1524876/


All Articles