Jump to content

  • Log In with Google      Sign In   
  • Create Account


Game Timer Not Working!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Solid_Spy   Members   -  Reputation: 357

Like
0Likes
Like

Posted 13 March 2013 - 02:31 AM

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, 13 March 2013 - 02:34 AM.


Sponsor:

#2 Solid_Spy   Members   -  Reputation: 357

Like
0Likes
Like

Posted 13 March 2013 - 04:02 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS