[SDL] Keyboard movement: Can't use two keys at once?

DARKGuy . dark.guy.2008 at gmail.com
Thu Sep 14 01:34:11 PDT 2006


YAY! that worked like a charm! :D

Uint8 *keystate = NULL;
keystate = SDL_GetKeyState(NULL);
if ( keystate[SDLK_UP] ) Player1->py -= 3;
if ( keystate[SDLK_DOWN] ) Player1->py += 3;
if ( keystate[SDLK_LEFT] ) Player1->px -= 3;
if ( keystate[SDLK_RIGHT] ) Player1->px += 3;

^_^ thanks a bunch! :D

On 9/14/06, Rasmus Neckelmann <neckelmann at gmail.com> wrote:
>
> On 9/14/06, DARKGuy . <dark.guy.2008 at gmail.com> wrote:
> > [snip]
> > but I don't see how
> > SDL_KEYUP would help me in this case...
>
> When you receive a SDL_KEYDOWN event for 'up arrow' you can set a
> 'Ship Moving Up' flag, and later when you receive a SDL_KEYUP event
> for 'up arrow' you can clear it.
>
> Alternatively you can use the SDL_GetKeyState() function to get a
> snapshot of the entire keyboard state. Then you can have logic like:
>
> "if up-arrow is pressed then move ship up"
>
> etc...
>
> --
> Regards,
> Rasmus Neckelmann
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060914/ac99c665/attachment-0008.htm>


More information about the SDL mailing list