Original Post
Hey all I am new here, so I have a problem, I am trying to get multiple key imputs in sdl at once, but I am only to in few presses 2 key impust...
I need to get few imputs at once for moving object down + left, or left + up.
Here is the short code for moving an object
I need to get few imputs at once for moving object down + left, or left + up.
Here is the short code for moving an object
while( SDL_PollEvent( &event ) ) {
if(event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym) {
case SDLK_UP: yVel = -1; break;
case SDLK_DOWN: yVel = 1; break;
case SDLK_RIGHT: xVel = 1; break;
case SDLK_LEFT: xVel = -1; break;
}
}
else if(event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym) {
case SDLK_UP: yVel = 0; break;
case SDLK_DOWN: yVel = 0; break;
case SDLK_RIGHT: xVel = 0; break;
case SDLK_LEFT: xVel = 0; break;
}
}
if( event.type == SDL_QUIT ) {
quit = true;
}
}
y += yVel;
x += xVel;
if (( x < 0 ) || ( x + DOT_WIDTH > SCREEN_WIDTH )) {
x -= xVel;
}
if( ( y < 0 ) || ( y + DOT_HEIGHT > SCREEN_HEIGHT ) ) {
y -= yVel;
}