I started learning SDL recently, and now I'm working on my first project. Problem is, I've come to a bit of a dead end...
I'm making a copy of pong, and I'm stuck on how to make the paddle continue to move when the key is being held.
Basically, it will only move once when the key is pressed, and won't continue to move while the key is being held.
This is what I have so far:
cpp
while (SDL_PollEvent (&this->event))
{
if (event.type == SDL_QUIT)
SDL_Quit ();
if (event.type == SDL_KEYDOWN)
{
Uint8 *KeyStates = SDL_GetKeyState (NULL);
if (KeyStates [SDLK_UP])
this->offset.y -= 10;
if (KeyStates [SDLK_DOWN])
this->offset.y += 10;
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00 ));
apply_surface(offset.x, offset.y, surface, screen);
SDL_Flip (surface);
}
}
Thanks in advance