-
I've got someting like this:
while (window.pollEvent(event))
{
if (event.type == Event::Closed || event.key.code == Keyboard::Escape)
{
window.close();
}
else if (option[1].getGlobalBounds().contains(mouse) &&
eventtype == Event::MouseButtonPressed && event.key.code == Mouse::Left)
{
//many functions based on matrix used in option[]
}
else if (option[2].getGlobalBounds().contains(mouse) &&
event.type == Event::MouseButtonPressed && event.key.code == Mouse::Left)
{
//many functions based on matrix used in option[]
}
//else if (option[3]... else if (option[4]... else if (option[5] (...)
}
Can I use some kind of for loop in window.pollEvent?
-
Can I use some kind of for loop in window.pollEvent?
Do you mean polling events with a for loop? No, the way you are doing it is the correct way.
if (event.type == Event::Closed || event.key.code == Keyboard::Escape)
And this is wrong, you need to ensure the event is a keyboard event before checking the key.
-
Can I use some kind of for loop in window.pollEvent?
This is a really strange question. What are you trying to do/solve?
-
if (event.type == Event::Closed || event.key.code == Keyboard::Escape)
And this is wrong, you need to ensure the event is a keyboard event before checking the key.
Thanks! You've found my main bug. Didn't know why the window crash, when cursor was near left side of screen.
And yep, I meant polling events with a for loop. Thought I can make my code little more beautiful w/o making event for all almost the same options.
edit: If it's still incomprehensible, I wanted to do something like this (I know it won't work):
while (window.pollEvent(event))
{
if (event.type == Event::Closed || event.key.code == Keyboard::Escape)
{
window.close();
}
for (int i=0; i<6; i++)
{
else if (option[i].getGlobalBounds().contains(mouse) &&
eventtype == Event::MouseButtonPressed && event.key.code == Mouse::Left)
{
//many functions based on matrix used in option[]
}
}
}
-
You of course can loop inside another loop. This is C++.
However you shouldn't put your game logic into the event loop.
If you need the state you can use a variable or use sf::Mouse and alike.
-
Got it.