Why does the drawn Sprite only appear in the Window when drawn from the main-function, but not when drawn from an external function and how can I change this?
class Class {
private:
sf::Sprite sprite;
public:
Class()
{
sprite = initializeSprite(sprite);
}
};
void Class::draw(sf::RenderWindow& win)
{
win.draw(sprite);
}
int main(int argc, char* argv[])
{
sf::RenderWindow window(sf::VideoMode(1920,1080), "Window");
Class instance;
while(window.isOpen())
{
window.clear();
instance.draw(window);
window.display();
}
return 0;
}
-> Doesn't work.
int main(int argc, char* argv[])
{
sf::RenderWindow window(sf::VideoMode(1920,1080), "Window");
sf::Sprite sprite;
sprite = initializeSprite(sprite);
Class instance;
while(window.isOpen())
{
window.clear();
window.draw(sprite);
window.display();
}
return 0;
}
->Works.
I'm using SFML-2.4.0. It also doesn't work when i use a pointer instead of a reference. What's wrong here?