Hello, I'm new to SFML (and C++, I'm a first-year university student). I defined a custom shape outside of the main loop and it wouldn't draw. But, when I define that inside the loop, it works very well.
What's wrong?
(SquareComponent is something I defined myself. I have tried SFML before, but everything was OK that time.)
int main(void)
{
sf::RenderWindow window(sf::VideoMode(WindowWidth, WindowHeight), "SFML", sf::Style::Close | sf::Style::Titlebar);
// SquareComponent thing1({14.f,11.f});
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Black);
SquareComponent thing1({14.f,11.f}); // if defined outside this loop (line 31), it won't draw!
window.draw(thing1);
window.display();
}
}