I'm making a game where the character can move in two directions at once - things like up-left, up-right, down-left, etc. This is how I capture multiple keys.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
//Make a bullet that is going Down at the coordinates of the mouse event
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
mainPlayer.playerDirection = direction::down_right;
}
else {
mainPlayer.playerDirection = direction::down;
}
This is fairly straightforward code and works quite well! I have one problem though.
down_right, up_right, and up_left all work using this method. The problem occurs here:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
//Make a bullet that is going Down at the coordinates of the mouse event
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
mainPlayer.playerDirection = direction::down_right;
cout << "downright";
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
mainPlayer.playerDirection = direction::down_left;
cout << "down left\n"; //This code NEVER executes. Ever.
}
else {
mainPlayer.playerDirection = direction::down;
}
}
ALL other key combinations work except S and A. I have tried reversing the roles (A first then S), testing different combinations (down arrow and left arrow works just fine). This specific combination of keys does not work for some odd reason. I am stumped and could really use some help. There could be an easy solution staring me in the face, or it may be a bug in 2.4's code. Thanks!