Quote:Original post by agi_shi
Quote:Original post by Rob Loach
Calling SDL_GetKeyState every tick is quite a lot of work. A polling system will help you out a lot.
It would end up being something like this:SDL_Event event;while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: KeyDown(&event.key.keysym); // Call the KeyDown event. break; case SDL_KEYUP: KeyUp(&event.key.keysym); // Call the KeyUp event. break; case SDL_QUIT: QuitApp(); // quit the app break; }}
Forgive me if that's wrong, I haven't writen C++ in a while (turned to C#). In your KeyUp and KeyDown methods, you could update an array depending on which key was pressed or "un-pressed". Good luck!
Good idea. Maybe a bool array would be nice. Does anyone know how many keys there are on a keyboard? I don't want to count them...
okay. if you do it that way you are just duplicating SDL_GetKeyState.
the way i chose to do is to wrap input into a class.
the only keys you store are the ones relavent ( breakout might have 3, left, right and quit ).
in an update() oer equivelant function you just check wether those keys have been pressed or released, and update your bool array. then provide you won enum like so
enum Keys{
KEY_LEFT,
KEY_RIGHT,
KEY_QUIT,
};
the actual keys these are mapped to can get stored in a file, allowing you to make your program independant of the keys you use while programming