Jump to content
  • Advertisement
Sign in to follow this  
Elof Valantor

Thread.Sleep and reading inputs

This topic is 3776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've started a quick little project just for fun on the side of my studies and so far I've been able to overcome any issues I've faced. But this one is starting to bug me. I'm making a kind of space invaders type game in the console window (crazy I know). It's going okay so far. I've got the scrolling across the screen working, got the inputs working, got sound working, am almost ready to start work on the bullets and collisions and things. Now I'm using Thread.Sleep to control frame rates. In my main program loop I check for user inputs. If any keys are pressed whilst the program is "sleeping" they do NOT get discarded. Instead they all get processed once the program wakes up. This is causing the players ship to go the wrong way or to appear stuck or whatever, making the game annoying and un-responsive unless you're lighting fast and only tap the keys for a milli-second. I would like to know how I can discard any inputs that occur during the sleep period, or how to only allow the first of those inputs to run and discard the rest (probably preferable as it gives more time to listening for inputs). I tried a do-while loop using Console.KeyAvailable == true to try and catch all the excess inputs in a fast loop that would negate them all but it just broke the program (not to mention it wouldn't work if the player just held a key down). Also I've encountered a delay of a second or so in the program registering inputs and acting on them. Is KeyAvailable slow in picking up key presses? Might there be a better way to tell if the keyboard is in use? Thanks.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!