• Advertisement
Sign in to follow this  

Game Timer Not Working!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Edited by Solid_Spy

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement