Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Events help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 AlexWalters22   Members   -  Reputation: 451

Like
0Likes
Like

Posted 31 March 2012 - 04:44 PM

I have been working on a simple space shoot em up and I have been having some trouble with the movement of my ship. It moves fine when you use the directional keys except that when your first hit them the ship jumps then begins moving fluidly. Another question: whenever I have a direction key presssed down and then hit any other keys, then my ship ceases movement and no longer picks up the key being pressed. I would greatly appreciate help and thanks in advance.

p.s. If you need more information don't be afraid to ask

Sponsor:

#2 wicked357   Members   -  Reputation: 1174

Like
0Likes
Like

Posted 31 March 2012 - 08:47 PM

Maybe some sample code would be helpful.

#3 Nypyren   Crossbones+   -  Reputation: 4497

Like
1Likes
Like

Posted 31 March 2012 - 11:08 PM

It sounds like a symptom of handling repeats instead of down/up.

Think of a word processor. If you hold down a letter, it starts repeating after a certain delay, and then repeats at a different rate until you let go. If you press a second key while holding the first, it stops repeating the first letter. Most desktop operating systems assume that the majority of apps will use the keyboard for text entry, so this is the default behavior. This sounds like the problem you're experiencing.


Here's a basic solution for games:
  • Make a HashSet<Keys> // assuming Winforms. Change to whatever enum you're using if necessary.
  • When you get a keydown event, add that key to the hashset.
  • When you get a keyup event, remove that key from the hashset.
  • Use a game loop to constantly check the hashset.Contains(Keys.Whatever) and perform your processing there. For basic Winforms apps, the "game loop" can be something simple like a Timer firing at a certain rate.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS