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

Sahan Chandrasekara sahanthegamecreator at gmail.com
Thu Sep 14 04:20:39 PDT 2006


so how would you do that with switch/case?

On 9/14/06, DARKGuy . <dark.guy.2008 at gmail.com> wrote:
>
> 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
> >
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>
>
>


-- 
Sahan Chandrasekara

Get a free sony psp at http://psps.freepay.com/?r=30890215 (not a scam)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060914/17d1744b/attachment-0008.htm>


More information about the SDL mailing list