I am developing a game using SDL, and am unable to do continuous motion for my object when a key is held down.
I'm calling SDL_PollEvent() to retrieve all events during a frame, and passing each resulting SDL_Event structure into this function:
void Avatar::handle_input(SDL_Event keyInput){
if( keyInput.type == SDL_KEYDOWN )
{
//Adjust the velocity
switch( keyInput.key.keysym.sym )
{
case SDLK_LEFT: Move(1); break;
case SDLK_RIGHT: Move(2); break;
}
}
The problem is that when I hold down the right or left arrow keys, the avatar only moves once instead of moving continuously for as long as I hold down the key. How can I make the motion continue for as long as the key is held down?