Skip to main content
added 201 characters in body
Source Link

This way is works, but in case you need more key strokes(like 3 or more keys pressed) this code are going to be more complicated. I suggest you to redesign your code to first detect events and then after that, update your game. You are doing both at the same time.

Simple example:

bool tPressed = false;
bool upPressed = false;

while(SDL_PollEvent(&event)) { //NOTE THIS CAN be runned more than one time at a game loop
//HANDLE t and up variables here
}

//NOTE Now all of your events are been handled, you can update your.
if(tPressed && upPressed) {
//Do the doings case both key are pressed
}

This design is pretty common to handle multiple keys pressed and also presented by official SDL documentation in this link: https://www.libsdl.org/release/SDL-1.2.15/docs/html/guideinputkeyboard.html

This way is works, but in case you need more key strokes(like 3 or more keys pressed) this code are going to be more complicated. I suggest you to redesign your code to first detect events and then after that, update your game. You are doing both at the same time.

Simple example:

bool tPressed = false;
bool upPressed = false;

while(SDL_PollEvent(&event)) { //NOTE THIS CAN be runned more than one time at a game loop
//HANDLE t and up variables here
}

//NOTE Now all of your events are been handled, you can update your.
if(tPressed && upPressed) {
//Do the doings case both key are pressed
}

This way is works, but in case you need more key strokes(like 3 or more keys pressed) this code are going to be more complicated. I suggest you to redesign your code to first detect events and then after that, update your game. You are doing both at the same time.

Simple example:

bool tPressed = false;
bool upPressed = false;

while(SDL_PollEvent(&event)) { //NOTE THIS CAN be runned more than one time at a game loop
//HANDLE t and up variables here
}

//NOTE Now all of your events are been handled, you can update your.
if(tPressed && upPressed) {
//Do the doings case both key are pressed
}

This design is pretty common to handle multiple keys pressed and also presented by official SDL documentation in this link: https://www.libsdl.org/release/SDL-1.2.15/docs/html/guideinputkeyboard.html

Source Link

This way is works, but in case you need more key strokes(like 3 or more keys pressed) this code are going to be more complicated. I suggest you to redesign your code to first detect events and then after that, update your game. You are doing both at the same time.

Simple example:

bool tPressed = false;
bool upPressed = false;

while(SDL_PollEvent(&event)) { //NOTE THIS CAN be runned more than one time at a game loop
//HANDLE t and up variables here
}

//NOTE Now all of your events are been handled, you can update your.
if(tPressed && upPressed) {
//Do the doings case both key are pressed
}