[SDL] Arrow Keys, and Diagonals...
Max Countryman
maxc at mac.com
Thu Aug 21 20:40:06 PDT 2003
Drake, some code snippets would greatly help me to better understand
what you mean, thanks,
Max
On Thursday, August 21, 2003, at 04:31 PM, Drake Wilson wrote:
> Quoth Max Countryman <maxc at mac.com>, on Thu 21 Aug 2003:
>> I tried adding the keys like this:
>>
>> if ( key_event.key.keysym.sym == SDLK_LEFT + SDLK_UP)
>> spritePosition_x -= 4, spritePosition_y -= 4;
>
> Firstly, keysyms are opaque. They cannot be added together
> arithmetically in any meaningful way.
>
> Secondly, checking for keys being down, per se, is done with
> SDL_GetKeyState, which returns a pointer to an array of Uint8, indexed
> by keysym, indicating whether the given key is pressed (1) or not
> pressed (0). It must be updated by use of SDL_PumpEvents (possibly
> implicit).
>
> Thirdly, if I understand your intent correctly, it would be much
> better accomplished by checking for each key individually, with no
> out-jumping between the checks; this would cause a combination of left
> and up to go left, and up, in the same tick, which seems to be what
> you desire.
>
> Fourthly, it would not be wise IMO to use the key repeat mechanism for
> this, as it appears from your snippet that you might be doing. Your
> particular case would seem to require knowledge of the current state
> of the keys more directly than it does knowledge of when they change
> state (even though the two are theoretically equivalent). It would
> thus seem to me to be a good idea to simply ignore the events
> themselves (though they must still be pumped and discarded) and use
> the SDL_GetKeyState array.
>
> I apologize if this message appears overly harsh; I am simply
> attempting to be as objective as possible.
>
> ---> Drake Wilson
> <mime-attachment>
More information about the SDL
mailing list