[SDL] Problem with fill up the event queue...

Jonathan Dearborn grimfang4 at gmail.com
Thu Sep 24 10:01:59 PDT 2009


You should try using SDL_PollEvent()...
while (!gameover)
{
     /* look for an event */
    while (SDL_PollEvent(&evento))
    {
         if(evento.type == SDL_QUIT || evento.key.keysym.sym== SDLK_ESCAPE)
        {
            gameover=1;
            break;
        }


        /*pass the event to jugador class to process the movement*/
        jug.rebre_moviment(&evento);
    }

...  // The rest of the stuff

}


Jonny D


On Thu, Sep 24, 2009 at 12:42 PM, Daniel Guzmán
<daniel.guzman85 at gmail.com> wrote:
> Hello i'm Daniel,and I'm starting to learn the SDL API but im stuck for
> about 2 days.
>
> I'm trying to make a simple game using sprites in C++ I have a main.cpp and
> a class named "jugador.cpp" (or player.cpp) to handle the properties of the
> player. My main looks like this:
>
> int main ( int argc, char *argv[] )
> {
>     SDL_Surface *screen;
>     SDL_Event evento;
>     int colorkey, gameover;
>     gameover = 0;
>
>     /* initialize SDL */
>     SDL_Init(SDL_INIT_VIDEO);
>
>     /* set the title bar */
>     SDL_WM_SetCaption("SDL Sprite", "SDL Sprite");
>
>     /* create window */
>     screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
>     colorkey = SDL_MapRGB(screen->format, 255, 0, 255);
>
>     //Create  JUGADOR CLASS
>     jugador jug(colorkey);
>
>     /* message pump */
>     while (!gameover)
>     {
>         /* look for an event */
>         if (SDL_WaitEvent(&evento))
>         {
>           if(evento.type == SDL_QUIT || evento.key.keysym.sym== SDLK_ESCAPE)
> gameover=1;
>         }
>
>      /*pass the event to jugador class to process the movement*/
>         jug.rebre_moviment(&evento);
>
>         /* draw the jugador */
>         jug.dibuixar(screen);
>
>         /* update the screen */
>         SDL_UpdateRect(screen, 0, 0, 0, 0);
>         SDL_Delay(20);
>     }
>
>   SDL_Quit();
>
>   return 0;
> }
>
> So if a event is polled i pass the EVENT to the "jug" object using
> jug.rebremoviment(&evento) and it process the movement, then i paint the
> player in the new position using jug.dibuixar(screen). All works very well!
> BUT!!! when I move the MOUSE  at the same time im pressing the WASD
> direction keys to move my player and i do some crazy movement with my mouse
> it seems that it fills de event queue and when I stop moving the mouse and
> pressing the keys the player DONT stop! it continues moving doing the rest
> events in the event queue for about a second or two..
>
> Well im new to the game programming world and i need help on that i cant
> figure myself how to not fill up the queue, and make the movement fast and
> smooth.
>
> Thank you for your help and sorry for my poor english.
> If you need some code of the "jugador" class just tell me, i did not include
> it because the message will be very large :).
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>



More information about the SDL mailing list