5

I have a background image and it's only 256 x 256 when my window is 800 x 600. I'm not sure how to get the image to repeat itself across the whole window. I currently load the image in with:

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

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

and the draw it later with:

window.draw(Bkg);

I tried to use:

texture.setRepeated(true);

but that didn't seem to help.

Thanks!

ryandonohue
  • 189
  • 4
  • 22
  • As a side note, if you're trying to color your background, you don't need a jpg, you can just use this: `window.clear(sf::Color(128,0,128));` provided that "window" is a RenderWindow object. – Dovahkiin Dec 19 '16 at 00:03

1 Answers1

7

After you load the image you need to call setReapeted:

    texture.setRepeated(true);

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

    sprite.setTexture(texture);
    sprite.setTextureRect(sf::IntRect(0,0,800,600);
AlexxanderX
  • 266
  • 1
  • 5
  • 25