Hello,
I am encountering a problem with sf::Event::Closed
Let's say i have this code:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow App(sf::VideoMode(600,300,32), "Test");
sf::Event Event;
sf::Image img(10,10,sf::Color(0,0,0));
sf::Sprite Spr;
bool running=true;
App.UseVerticalSync(true);
img.SetSmooth(false);
Spr.SetImage(img);
Spr.SetScale(2,2);
Spr.SetPosition(300,280);
while(running)
{
App.GetEvent(Event);
if(Event.Type==sf::Event::Closed)
running=false;
if(Event.Type==sf::Event::KeyPressed) {if(Event.Key.Code==sf::Key::Escape)running=false;}
if(App.GetInput().IsKeyDown(sf::Key::Left))Spr.Move(-10,0);
if(App.GetInput().IsKeyDown(sf::Key::Right))Spr.Move(10,0);
if(Spr.GetPosition().x<-5) Spr.SetX(600); else if(Spr.GetPosition().x>605) Spr.SetX(0);
App.Clear(sf::Color(0,150,0));
App.Draw(Spr);
App.Display();
}
}
A simple program showing a moving square.
When I run it, 70% of times will instantly exit it.
In the console mode it returns 0, so i think there aren't errors or problem with the code.
I removed
if(Event.Type==sf::Event::Closed)
running=false;
And it worked perfectly, so it seems that the program gets a Closed event from nothing.
Is there a way to fix this or an alternative to sf::Event::Closed?