Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 02-02-2005, 01:59 AM   #1
feminista
Abandonia nerd

 
Join Date: Dec 2004
Location: ,
Posts: 50
Default

Okay, I have a few SDL sprites who move when I hit the arrow keys, according to this code:

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:

Code:
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)?
feminista is offline                         Send a private message to feminista
Reply With Quote
Old 02-02-2005, 08:27 AM   #2
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

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.
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Done Quick Skumpaq Blah, blah, blah... 1 21-11-2005 06:27 PM
Help Plz Quick Desperate one Troubleshooting 1 17-04-2005 06:16 PM
Quick Art TheVoid Music, Art, Movies 89 02-03-2005 11:31 AM
Quick Question 1988YJLaredo Troubleshooting 3 21-12-2004 05:54 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 11:30 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.