hello everybody, i am new in sfml so sorry if i may ask something silly.
i have this:
void GameLoop::loop() {
gameWindow.clear();
sf::Event event{};
while(gameWindow.isOpen()){
while (gameWindow.pollEvent(event)) {
if (event.type == sf::Event::EventType::Closed) //close window
gameWindow.close();
//future events here
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
playerUp = true;
if(!(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)))
playerUp = false;
std::cout << playerUp << std::endl;
gameWindow.display();
}
}
I am trying to modify playerUp that is a bool initialised as false in the constructor.
If i am not wrong, i should have understood that the difference between sf::Keyboard::isKeyPressed (as i am doing) and sf::Event::KeyPressed is that the first consider how long you press a key, while the second is only triggered when i press the key so i should handle with more code the fact that it it not released.
Considering that i want to keep the code clean I opted for isKeyPressed out of eventPoll loop.
when i launch the program this is the output:
0
We got a keyboard without any keys (1)
0
0
0
0
//there are only 0s 'till the end even though i press the key
I tried to use another key beside Up but with no result.
So, what does that message means? what am i doing wrong?
edit: Forgot to say i am using macOS, maybe this is something that have to be known for you to help me.
side question:
if i got it right sf:Event and sf::Keyboard should be part of Window.hpp, but i am not sure.
By the way in the header I included Graphics.hpp as seen in the tutorial to check if sfml was working and it still find those elements i mentioned, why? Could this be the problem of my question?
Also, where can i check the right "category" (window, graphics, audio ...) of the various elements of sfml? for example if i want to know which is the right category of sf::Event, the guide tell me i need to include Event.hpp, but where can i read if it belongs to window rather then graphics and so on.
sorry for my silly questions