1
General / Check events outside event-loop
« on: February 18, 2016, 11:17:30 pm »
I want to write an input-manager to implement some functions: isKeyReleased etc
My idea was to have a function called update, this function polls for events and "saves" them.
Then later I can call isKeyReleased to check the event:
Update function:
and then I want for example check the event type:
So in my HandleInput function in main:
But it is not working! I don't know where the problem is.
Is there a possibility to "save" the polled events and check them later?
My idea was to have a function called update, this function polls for events and "saves" them.
Then later I can call isKeyReleased to check the event:
Update function:
void InputManager::update(sf::RenderWindow& mainWindow)
{
rWindow = &mainWindow;
while (rWindow->pollEvent(iEvent))
{
}
}
{
rWindow = &mainWindow;
while (rWindow->pollEvent(iEvent))
{
}
}
and then I want for example check the event type:
bool InputManager::isEventType(sf::Event::EventType eventType)
{
if (iEvent.type == eventType)
return true;
else
return false;
}
{
if (iEvent.type == eventType)
return true;
else
return false;
}
So in my HandleInput function in main:
InputManager::update(mainWindow);
if (InputManager::isEventType(sf::Event::KeyPressed))
std::cout << "Key Pressed" << std::endl;
if (InputManager::isEventType(sf::Event::KeyPressed))
std::cout << "Key Pressed" << std::endl;
But it is not working! I don't know where the problem is.
Is there a possibility to "save" the polled events and check them later?