PDA

View Full Version : Quick Sdl Question


feminista
02-02-2005, 01:59 AM
Okay, I have a few SDL sprites who move when I hit the arrow keys, according to this code:

int spd = 5;

if ( keys[SDLK_UP] *&& (vikings1.yget() >= 200) ) { vikings1.yadd(-spd); }
if ( keys[SDLK_DOWN] ) { vikings1.yadd(spd); }
if ( keys[SDLK_LEFT] ) { vikings1.xadd(-spd); }
if ( keys[SDLK_RIGHT] ) { vikings1.xadd(spd); }

spd is how many pixels they move at a time, and the 200 is a limit on vertical height.

The problem that I have is that when I press and hold right, and then press left (or any other combination of opposite directions, the new one doesn't override the old one. Now, I did try something along these lines:

if ( keys[SDLK_UP] *&& (vikings1.yget() >= 200) ) {
*if (keys[SDLK_DOWN]) { vikings1.yadd(-2*spd); }
*else { vikings1.yadd(-spd); }
}

However, that's not at all what I want, and it only works in one direction anyway.

So, how precisely would I get these keys to behave the nice, normal way (i.e. each keypress in an opposing direction overriding the last, regardless of hardware capabilities)?

Data
02-02-2005, 08:27 AM
uhm if you keep a key pressed I think some keyrepeat is kicking in.
so the key "pressed" at a regular interval.
there is a function that disables it.