Hi, I'm a beginner and I'm essentially hacking up the display tutorial into a separate class and I think I broke something. For the record the tutorial worked fine, I'm using visual studio 2010 and I recompiled SFML for it.
I attempted to split some of the code into a class called "Game", and when I did that the window no longer constantly displayed. The window flashes for a second, and closes. From what I can tell it seems like while(App.GetEvent()) isn't doing anything after I moved it into the Game class. Here's the code.
main.cpp
/* main.cpp */
#include "Game.h"
int main()
{
Game game;
game.init();
while (game.run())
{
game.handleEvents();
}
std::cout << "DONE\n"; //test
system("pause");
return EXIT_SUCCESS;
}
game.cpp
/* Game.cpp */
#include "Game.h"
void Game::init()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
App.SetFramerateLimit(60);
std::cout << "INIT\n";
}
void Game::handleEvents()
{
while(App.GetEvent(Event)) //WTF?
{
if (Event.Type == sf::Event::Closed)
running = false;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
running = false;
std::cout << " EVENT-loop\n"; //test
}
App.Clear();
App.Display();
std::cout << "loop-check\n"; //test
running = false; //test: no infinite loop
}
bool Game::run()
{
return running;
}
and the console output after running it is this:
INIT
loop-check
DONE
Press any key to continue . . .
I added cout statements and the while loop is being ignored. I'm assume this has something to do with my lack of knowledge on c++ classes. This issue is driving me crazy, any help would be good. Thanks.
edit: forgot to mention that the sf::Event variable I'm using for the broken while loop is defined in Game.h as a private member variable for the Game class. I know the issue is in that while loop but I can't quite figure it out.