Archived

This topic is now archived and is closed to further replies.

Danamal

Constant framerate, but random jumps when moving

Recommended Posts

I am currently trying to learn direct draw and direct input for C#. I haven't found many good tutorials or books. What I have learned is from looking at crappy sample applications. I used a tutorial at: http://www.kuhnstall.de/tutorials/dx9sharp2.html to learn how to do direct input. I added direct input into my game loop. When I press an arrow key it is supposed to move my guy. It seems to work fine, but it will jump ahead toward the direction I am moving at random times. In the function that processes the input I have: if(state[Key.DownArrow]) players[0].Y+=timeDelta*Player.ySpeed; This is where timeDelta comes from: // Figure how much time has passed since the last time. int tickCurrent = Environment.TickCount; int tickDifference = tickCurrent - tickLast; // Don't update if no time has passed. if (0 == tickDifference) return; tickLast = tickCurrent; timeDelta = tickDifference / 1000.0f; Why does it seem to work fine, then all of the sudden the Player jumps ahead? I suspected that it was a loss of FPS, but the FPS stays near the refresh rate the whole time. [edited by - Danamal on July 26, 2003 3:26:04 PM] [edited by - Danamal on July 26, 2003 4:43:22 PM] [edited by - Danamal on July 26, 2003 5:50:42 PM] [edited by - Danamal on July 26, 2003 5:59:06 PM]

Share this post


Link to post
Share on other sites
Does it really jump ahead, or is it almost smooth, with tiny shocks. if it''s the latter, this might solve it:
Do you do your timing before the other frame stuff? then move it to the end of the frame. I don''t really know why, but it makes it go much smoother.

change this:
void DoFrame()
{
dotiming();

domotion();
renderframe();
}

to this:

void DoFrame()
{
domotion();
renderframe();

dotiming();
}


My Site

Share this post


Link to post
Share on other sites
players[0].Y+=timeDelta*Player.ySpeed;

I am assuming timeDelta is a float since you are dividing by 1000.0f. Are players[0].Y and Player.ySpeed also floats? If not, you could be running into rounding issues.

Share this post


Link to post
Share on other sites
They are big jumps. I know it isn't a rounding error or a timing error because I have done ...X+=3 just to see if it still does jump and it does. I wonder if maybe DirectInput- gets backed up when polling the keyboard although it is always quick and responsive.

[edited by - Danamal on July 26, 2003 11:17:17 PM]

Share this post


Link to post
Share on other sites
That is a good idea, but it doesn't solve the problem at hand. I believe it is some sort of direct input problem. Does anyone know of a place for a really good tutorial? Take a look at the numbers I am getting:

0.01, 307.4,600
0.01, 309.4,600
0.02, 311.4,600
0.01, 595.4,600
0.01, 597.4,600
0.01, 599.4,600
0.01, 601.4,600
0.01, 603.4,600

The first number is the time that has passed since the last frame. The second number is the x value. The third is the y. In this time frame I was moving to the right.

Update: I had it write to a file everytime it captured input and here is what it looks like when it skips:

0.01, 27,315.6
Getting input
0.02, 29,313.6
Getting input
Getting input
Getting input
Getting input
Getting input
0.01, 49,293.6
Getting input
0.01, 51,291.6
Getting input
0.01, 53,289.6

Why does it do this? How do I fix it?

[edited by - Danamal on July 27, 2003 6:35:06 PM]

Share this post


Link to post
Share on other sites