Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Window will closes automatically when idle  (Read 1773 times)

0 Members and 1 Guest are viewing this topic.

Fuhans

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Window will closes automatically when idle
« on: June 26, 2013, 10:00:09 pm »
Hai, i have create the game using this library.. but, when i run the game and idle it about 15 seconds, it closes automatically, i already assigned that when the user press "Escape" then window close, otherwise it will stay open.. but, why the window will closes automatically? please help.

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Window will closes automatically when idle
« Reply #1 on: June 26, 2013, 10:08:16 pm »
Maybe posting a minimal and complete code would help us in finding your problem?

Fuhans

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Window will closes automatically when idle
« Reply #2 on: June 26, 2013, 10:18:56 pm »
while(App.isOpen())
{
   sf::Event currentEvent;
   initGraphics(App);

          while(App.pollEvent(currentEvent))
     {

               if (currentEvent.type == sf::Event::Closed && currentEvent.key.code == sf::Keyboard::Escape)
               {
           App.close();
                }
          }
 }

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Window will closes automatically when idle
« Reply #3 on: June 26, 2013, 10:34:20 pm »
Hmm...pretty bare bones that should run just fine.  If anything your line to close the window should be:
if (currentEvent.type == sf::Event::Closed || currentEvent.key.code == sf::Keyboard::Escape)
Should be OR ( || ) not AND ( && ) otherwise your window will only close when you press 'Escape' AND click the 'X' in the title bar.

But unless you got something weird going on in your initGraphics() method it might just be your debugger or dev environment.  What happens if you just run the *.exe file the compiler creates?

Fuhans

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Window will closes automatically when idle
« Reply #4 on: June 26, 2013, 10:41:22 pm »
The program in .exe file is not automatically close, just on when run the program from the visual studio 2010 still close automatically..  Thanks anyway..

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Window will closes automatically when idle
« Reply #5 on: June 26, 2013, 10:50:15 pm »
It's gotta be an issue with vs2010 then.

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Window will closes automatically when idle
« Reply #6 on: June 27, 2013, 12:29:00 am »
currentEvent.key.code is defined only when the current event is an sf::Event::KeyPressed (/KeyReleased).