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

Brian Barrett brian.ripoff at gmail.com
Thu Sep 1 09:18:29 PDT 2005


this worked on my machine with "ship.bmp" in the same directory
i moved some stuff around

i *think* it does what you want

main problems were your tests for the SDL_Event global or as i renamed it 
"event"
dunno, try it...

#include "SDL.h"
#include "stdio.h"
#include <cstdlib>

int main( int argc, char* argv[] )
{
atexit(SDL_Quit);
SDL_Init( SDL_INIT_VIDEO );

SDL_Surface *screen;

screen = SDL_SetVideoMode( 800, 600, 32, SDL_DOUBLEBUF| SDL_ANYFORMAT );

SDL_Surface *hero,*enemy, *helaser, *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 = 300;
ship.y = 200;

enum State{UP = 2,LEFT,RIGHT, DOWN, STOP};

State image;
image = STOP;
SDL_Event event;
bool running = true; // this doesnt have to be global

while( running ){
SDL_FillRect( screen, NULL, 0 );
SDL_BlitSurface(hero,NULL,screen,&ship);

while(SDL_PollEvent(&event)){

if ( event.type == SDL_QUIT ){ // inside pollevent
running = false;
}

if( event.type == SDL_KEYDOWN ){

if( event.key.keysym.sym == SDLK_ESCAPE ){
running = false;
}
if( event.key.keysym.sym == SDLK_DOWN ){
image = UP;
}

}

}

if( image == UP ){
ship.x += 1;
}

SDL_Flip(screen);
}

SDL_Quit();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050901/8216eff8/attachment-0008.htm>


More information about the SDL mailing list