Brief pause after keypress

Posted by user36324 on Game Development See other posts from Game Development or by user36324
Published on 2013-10-25T01:51:34Z Indexed on 2013/10/25 4:17 UTC
Read the original article Hit count: 241

Filed under:
|
|
|
|

After i press and hold the key it goes forward once then pauses for a second or less then goes forward on forever. My problem is the brief pause I cant locate the issue. Thanks for your help.

    while(game){
        while (SDL_PollEvent(&e)){
            mainChar.manageEvents(e);
        }
        background.renderChar();
        mainChar.renderChar();
        SDL_RenderPresent(ren);

    }
void Character::manageEvents(SDL_Event event)
{
    switch(event.type){
        case SDL_KEYDOWN:
            KEYS[event.key.keysym.sym] = true;
            printf("true");
            handleInput();
            break;
        case SDL_KEYUP:
            KEYS[event.key.keysym.sym] = false;
            printf("false");
            break;
        default:
            break;
    }
}
void Character::handleInput()
{
    if(KEYS[SDLK_a]) { 
        dst.x--;
    }
    if(KEYS[SDLK_d]) { 
        dst.x++;
    }
    if(KEYS[SDLK_w]) { 
        dst.y++;
    }
    if(KEYS[SDLK_s]) { 
        dst.y--;
    }
}

© Game Development or respective owner

Related posts about c++

Related posts about movement