I read in another thread that you should never make textures local temporary objects. So I was wondering, is this the correct way to handle drawing a sprite from another method?
#include <SFML/Graphics.hpp>
void drawSprite(sf::RenderWindow &window, sf::Texture texture) {
sf::Sprite sprite;
sprite.setTexture(texture);
window.draw(sprite);
}
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::Texture texture;
texture.loadFromFile("pTexture.png");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
drawSprite(window, texture);
window.display();
}
return 0;
}