1
Graphics / Re: how to set background.
« on: July 13, 2021, 07:20:50 pm »
The problem here is that while using the .setTexture() function and an sf::Texture the .setTexture() function expects to be given a pointer so:
RenderWindow window(VideoMode(1024, 786, 32), "Test 32");
Texture texture;
texture.loadFromFile("background.png");
Sprite sprite;
Vector2u size = texture.getSize();
sprite.setTexture(&texture); //This is where you add an & to designate texture as a pointer
sprite.setOrigin(size.x / 2, size.y / 2);
while (window.isOpen())
{
Event e;
while (window.pollEvent(e))
{
if (e.type == Event::Closed)
window.close();
}
window.draw(sprite);
window.display();
}
RenderWindow window(VideoMode(1024, 786, 32), "Test 32");
Texture texture;
texture.loadFromFile("background.png");
Sprite sprite;
Vector2u size = texture.getSize();
sprite.setTexture(&texture); //This is where you add an & to designate texture as a pointer
sprite.setOrigin(size.x / 2, size.y / 2);
while (window.isOpen())
{
Event e;
while (window.pollEvent(e))
{
if (e.type == Event::Closed)
window.close();
}
window.draw(sprite);
window.display();
}