Advertisement

(SDL) Input question

Started by July 20, 2004 01:31 AM
10 comments, last by eedok 20 years, 4 months ago
Thanks guys I understand it now
My Current Project Angels 22 (4E5)
if you don't change:
if(keys[SDLK_SPACE]){addBullet();}

to
if(event.key.keysym.sym == SDLK_SPACE){addBullet();}

it won't work the way you want it to, as keys[SDLK_SPACE] will return true if the spacebar is down, and from what I understand that's not what you want.

EDIT: slightly made changes to your loop
while(done == 0)  {    SDL_Event event;    while ( SDL_PollEvent(&event) )    {      if ( event.type == SDL_QUIT )  {  done = 1;  }      if ( event.type == SDL_KEYDOWN )      {        if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }      }      if(event.type == SDL_KEYUP)      {         if(event.key.keysym.sym == SDLK_SPACE){addBullet();}      }    }    keys = SDL_GetKeyState(NULL);    if ( keys[SDLK_UP] ) { player.accelY(-3); }    if ( keys[SDLK_DOWN] ) { player.accelY(3); }    if ( keys[SDLK_LEFT] ) { player.accelX(-3); }    if ( keys[SDLK_RIGHT] ) { player.accelX(3); }    GameLoop();  }

This topic is closed to new replies.

Advertisement