I want to have my program so each event is handled by a method in a separate class. These methods are then called in my main loop. Here's my code. I literally just started SFML so this is copied off the tutorial:
while (source.window.pollEvent(event))
{
if (event.type == sf::Event::TextEntered)
eventHandle.eventKeyPress();
// Close requested event = close the window
if (event.type == sf::Event::Closed)
source.window.close();
}
I have a variable called eventHandle. Here is the method eventKeyPress:
if (source.event.text.unicode < 128){
std::cout << "ASCII character typed: " << static_cast<char>(source.event.text.unicode) << std::endl;
source.shape.move(sf::Vector2f(50, 0));
}
As you can see, I've literally put what I want the event to do inside that method.
I did some testing in debug mode and I know why it's not working, but I don't know how to fix it. So in my main() I have defined the variable:
sf::Event event;
I'm using that in my main function, but I'm using a
different variable in my 'eventKeyPress'. I tried putting 'sf::Event event;' in the source.h class, but it really didn't like it. The computer only likes it if I have the 'sf::Event event;' inside my int main() function.
How do I fix my problem?