How can I ignore keyboard input?

Kamochan
03-19-2002, 11:18 AM
I am writing an rpg that uses the keyboard to move the character around on the worldmap. My problem is the program is accepting keystrokes faster than the picture can update.

Is there a way to tell the computer to ignore keyboard input while the screen code is executing?

I am using the KeyDown Property to get the input

thanks

Iceplug
03-19-2002, 01:59 PM
You can set a form public boolean variable -
Dim LoadingPicture as Boolean.
Set this to true while the picture is loading
Set this to false when finished loading.
Place this directly after the KeyDown procedure...
If LoadingPicture Then Exit Sub

You can set Me.Enabled=False while loading the picture and Me.Enabled=True after loading it also.:)

Kamochan
03-19-2002, 03:22 PM
Thanks for the suggestion, but it didn't work. I am not loading a picture from the hard drive. Rather, I am using a bitblt loop to paint 200 tiles onto the screen.

The lag occurs when the variable controlling the character's x-position (y-position) updates faster than the screen refreshes. Eventually, the character can walk on water and is restricted from walking on certain land areas.

I don't know why this is happenning since the lines for the update of the character position variables occurs after the entire loop completes.

I'm pretty sure it's a synchronization problem since if I press the arrow keys one at a time I can do it 400 times (yes, I counted 400 times) and the screen stays consistent with the character. However, if I hold the arrow keys down it works fine for a while, but then it goes out of sync.

Pookie
03-19-2002, 07:01 PM
It's a bit hard to say without seeing the code.

You say there is a loop which the screen is draw up, which event is this loop in or is this loop in it's own sub. As if it's not in the keydown event, then the two can be firing at different times.

One thing you can do is record any keypresses from keydown event and read them in your loop then execute any movents from the loop and not in the keydown event.


KeyDown Event:

If keycode=vbkeydown then
godown=true
end if


KeyUp Event:

If keycode=vbkeydown then
godown=false
end if


Then in your main loop, before you update the screen, you check godown to see if char can go down, move him if so then redraw the screen....

Kamochan
03-19-2002, 07:52 PM
Thanks for your help guys. I actually figured out the system was lagging on the tile-drawing because I was accidentally drawing ALL TILES in my matrix (the world map) rather than just those on the screen.

Your system begins to lag when you draw 2500 tiles every 10 ms instead of just 200... tee hee.

The program works fine (for now) but I really want to thank everyone on this board for being so helpful. In a matter of one weekend I've learned so much. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum