Sign in to follow this  
KaiSkews

2D Movement

Recommended Posts

KaiSkews    102
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.

The keyboard input is done by WindowProc and the Movement Function is about this : (shortened)


[code]void KCharacter::Move()
{
switch(Direction)
{
case 0:

y += 5;

this->DrawCharacter();


....

}

[/code]

Someone got an idea ?

Thanks in advance !

Share this post


Link to post
Share on other sites
boogyman19946    1487
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 this post


Link to post
Share on other sites
KaiSkews    102
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 this post


Link to post
Share on other sites
RoyCHill    92
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this