lito
Newish
Posts: 1
|
Post by lito on Sept 13, 2003 0:28:44 GMT -5
Hi, Just for the record, i'm the same guy that posted the redbook question. I've been programming a pong. I want the paddle to move left at constant speed while the player is pressing the left key. Right in case he's pressing right. And stay still if he's not pressing anything. My aproach was along the lines of. -------- while playing speed# = 0 key = inscankey() if key = vk_left then speed# = maxspeed# endif if key = vk_left then speed# = -maxspeed# endif while synctimer(10) gosub update 'moves everything and draws it wend wend ------- But I find the paddle moves by jumps (and it doesn't have to do with the maxspeed# because the computer controlled paddle moves smoothly). I guess what i need is a way to identify when a key has been pressed or lifted and modify speed# only when such an event happens. Any suggestions? Thanks for the help, this forum rules (if you build it they will come).
|
|
|
Post by Tom Mulgrew on Sept 14, 2003 20:46:28 GMT -5
Hi, You need to use ScanKeyDown() rather than InScanKey(). E.g:
speed# = 0 if ScanKeyDown (VK_LEFT) then speed# = maxspeed# endif if ScanKeyDown (VK_RIGHT) then speed# = -maxspeed# endif
InScanKey() buffers and returns keystrokes, and is useful for text input (e.g. "Type your name here:").
In most games you don't care about keystrokes, and windows keystroke processing (buffering, typematic repeat rates e.t.c), you just want to know whether a key is currently down or up.
ScanKeyDown () returns true if a key is being pressed, and false if it isn't.
-Tom
|
|