# 2D Movement

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

## Recommended Posts

Hi, me again having troubles, again.

I'm still working on my 2D Topview game.

I'm having problems with the movement. The movement itself looks fluently, even if it could be approved at some points but thats for later. What really **** is that, when i go in one direction, then change the direction
the player stops for about a second before moving again. I don't know where that should come from.

void KCharacter::Move() { switch(Direction) { case 0: y += 5; this->DrawCharacter(); .... } 

Someone got an idea ?

##### Share on other sites
I believe this has to do with how Windows sends the WM_KEYDOWN messages to your window. If you'll notice, the same thing happens when you type in text: if you press a letter key, it'll type it once, pause for a second, and then just keep spitting out the letter. I don't know if there is a way to handle this in the WindowProc (other than setting the system's key repeat delay), but the way you can solve it is to have your loop check if a key is held down on every frame and advance the character like so (this means you'll have to keep track of the key being held down).

##### Share on other sites
Oh I see... good point. Tried several other possibilities for key input, they all have the same problem. I'll report back when i figured it out.

Thanks !

##### Share on other sites
You might be looking for something like GetAsyncKeyState();

##### Share on other sites
A suggestion is try to find a better key state handler

while keydown()
{
switch (keybutton)
{
case A:
...
case B:
....
case Z:
....
}
while keyup()
{

case A:
...
case B:
....
case Z:
....
}

I would look for something like that.
[response time 15 minutes]

##### Share on other sites
GetAsyncKeyState() was the key, thanks. Works like a charm.