Reputation: 97
I have a problem with implementing player movement using SFML on macos. Player movement works when i use this piece of code:
keyRight = event.type == Event::KeyPressed && event.key.code == sf::Keyboard::Right;
keyLeft = event.type == Event::KeyPressed && event.key.code == sf::Keyboard::Left;
keyUp = event.type == Event::KeyPressed && event.key.code == sf::Keyboard::Up;
keyDown = event.type == Event::KeyPressed && event.key.code == sf::Keyboard::Down;
but it won't work if I use this:
keyRight= sf::Keyboard::isKeyPressed(sf::Keyboard::Right);
keyLeft= sf::Keyboard::isKeyPressed(sf::Keyboard::Left);
keyUp= sf::Keyboard::isKeyPressed(sf::Keyboard::Up);
keyDown= sf::Keyboard::isKeyPressed(sf::Keyboard::Down);
I wanna use the second method because the first one seems to not work with diagonal movement (it just cant register two keys pressed at once.) Where am I making a mistake?
Upvotes: 0
Views: 302
Reputation: 97
For every mac user with same issue I’ve managed to resolve mine. Since os catalina you have to re-give your compiler (or project) permissions to monitor inputs. More of it here: https://en.sfml-dev.org/forums/index.php?topic=26395.0
You can either click it every time you change anything in your build or use event based movement.
Upvotes: 1