[SDL] I'm having some issues with SDL_Event.

David Olsen jolynsbass at hotmail.com
Thu Sep 1 10:13:37 PDT 2005


I wouldn't check for global's .type until AFTER having called SDL_PollEvent. 
No knowing what sort of garbage will be sitting in .type, which might be 
causing your crash.
As a side note, it's kind of weird to have your ship go sideways as a result 
of pressing the down arrow(not to mention that the down arrow sets image to 
UP!)
Also make sure that you actually have a valid surface stored where hero 
points . If your bitmap loading failed(perhaps the file is missing...) then 
it will segfault when you run it. Hope this helps!
-Dave
----- Original Message ----- 
From: "Randy" <RSPjk at yahoo.com>
To: <sdl at libsdl.org>
Sent: Thursday, September 01, 2005 10:05 AM
Subject: [SDL] I'm having some issues with SDL_Event.


> Currently the screen opens and then shuts  down,but when it did open if I
> pressed any key it would shut down.Can anyone help me?
> #include "SDL.h"
>
> #include "stdio.h"
> #include <cstdlib>
>
>
>
> bool k = true;
> int main( int argc, char* argv[] )
> {
> atexit(SDL_Quit);
> SDL_Init ( SDL_INIT_VIDEO );
> SDL_Surface* screen;
> screen = SDL_SetVideoMode(1024, 768, 32, SDL_DOUBLEBUF| SDL_ANYFORMAT);
> SDL_Surface* hero;
> SDL_Surface* enemy;
> SDL_Surface* helaser;
> SDL_Surface* enlaser;
> hero = SDL_LoadBMP("ship.bmp");
> enemy = SDL_LoadBMP("enemyship.bmp");
> helaser = SDL_LoadBMP("helaser.bmp");
> enlaser = SDL_LoadBMP("enlaser.bmp");
> SDL_Rect ship;
> ship.x = 500;
> ship.y = 579;
> SDL_Event global;
> enum state { UP = 2,LEFT,RIGHT,DOWN,STOP };
> state image;
> image = STOP;
> while (k == true)
> {
>
>
> SDL_BlitSurface(hero,NULL,screen,&ship);
> if ( global.type == SDL_QUIT )
>   {
>   k = false;
>   SDL_Quit();
>   }
>          while(SDL_PollEvent(&global))
>   {
>      if ( global.type == SDL_KEYDOWN )
>      {
>        if ( global.key.keysym.sym == SDLK_ESCAPE )
> {
> k = false;
> SDL_Quit();
> }
>      }
>
>
>
>        if ( global.key.keysym.sym == SDLK_DOWN )
> {
>               image = UP;
> }
>
>   if(image == UP)
>   {
> ship.x += 1;
>   SDL_BlitSurface(hero,NULL,screen,&ship);
>        SDL_Flip(screen);
>   }
>   }
> }
>
> return (0);
>   }
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
> 




More information about the SDL mailing list