Hi, after I got my double buffering problems fixed, I found another
problem that I can’t seem to figure out the cause of. I am using the
SDL keyboard routines to check to see if any of the arrow keys are
pushed. All work fine except for the right key. I have 2 variables
that increment or decrement by 5 depending on the key pushed. They are
playerY and playerX. For some reason when the value of playerX reaches
105 it starts incrementing by 30 even when I don’t push a key. Doing so
makes the bitmap go off the side of the screen.
Sorry if this is not an SDL related problem, but I don’t know what’s
wrong. Posted below is the code for reading in key presses.
void hover::steerInput(void)
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_QUIT )
return;
}
keys = SDL_GetKeyState(NULL);
cerr << " in Key loop" << endl;
if ( keys[SDLK_UP] == SDL_PRESSED )
{
playerY -= 5;
}
if ( keys[SDLK_LEFT] == SDL_PRESSED )
{
playerX -= 5;
}
else if ( keys[SDLK_DOWN] == SDL_PRESSED )
{
playerY += 5;
}
else if ( keys[SDLK_RIGHT] == SDL_PRESSED )
{
playerX += 5;
}
else if ( keys[SDLK_q] == SDL_PRESSED )
{
freeVidMem();
SDL_Quit();
exit(0);
}
cerr << "playerX = " << playerX << endl;
}
Mike.