使用SFML平铺图像

rya*_*hue 4 c++ textures sprite repeat sfml

我有一个背景图像,当我的窗口是800 x 600时,它只有256 x 256.我不知道如何让图像在整个窗口重复出现.我目前正在加载图片:

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

sf::Sprite Sprite;
Sprite.setTexture(Bkg);
Run Code Online (Sandbox Code Playgroud)

并在以后绘制:

window.draw(Bkg);
Run Code Online (Sandbox Code Playgroud)

我试着用:

texture.setRepeated(true);
Run Code Online (Sandbox Code Playgroud)

但这似乎没有帮助.

谢谢!

小智 6

加载图像后,需要调用setReapeted:

    texture.setRepeated(true);
Run Code Online (Sandbox Code Playgroud)

之后,在精灵中加载纹理时,将纹理矩形设置为您的屏幕大小:

    sprite.setTexture(texture);
    sprite.setTextureRect(sf::IntRect(0,0,800,600);
Run Code Online (Sandbox Code Playgroud)