Game Timer Not Working!

Started by
0 comments, last by SolDirix 11 years, 1 month ago

Hey, i'm trying to make a game in Directx11, however i seem to have a problem with my game timer. I can't get the game to sync to 60 FPS properly. I have an object that is supposed to move 1 pixel each frame, and i want the game to run at 60 FPS, but my timer cannot get the frame rate to run correctly. Here's the code:


ShowWindow(hWnd, nCmdShow);


    // set up and initialize Direct3D
    InitD3D(hWnd);


    // enter the main loop:


p1.x = 0;
p1.y = 0;


animationTime = 0.0f;


QueryPerformanceFrequency(&frequency);


    MSG msg;


QueryPerformanceCounter(&startTime);


    while(TRUE)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);


            if(msg.message == WM_QUIT)
                break;
        }


while(animationTime >= 1.0f / 60.0f)
{
    p1.Update();
    animationTime -= 1.0f / 60.0f;
}


        RenderFrame();


QueryPerformanceCounter(&endTime);
animationTime += (((float)endTime.QuadPart - (float)startTime.QuadPart) / frequency.QuadPart);
QueryPerformanceCounter(&startTime);
    }


    // clean up DirectX and COM
    CleanD3D();


    return msg.wParam;
}
 

The game seems to force the object to move at the right FPS, but it moves about 5 to 7 pixels each half a second or so. I'm not even sure if this is how a timer would be set up. Please help!

View my game dev blog here!

Advertisement

Never mind, I restarted my computer, and it started working.

View my game dev blog here!

This topic is closed to new replies.

Advertisement