Jump to content
  • Advertisement
Sign in to follow this  

Drawing bug, frame rate Q

This topic is 4740 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

I've finally rendered graphics to the screen:) All I have is a background and one those icons that's placed to next to the choices on a menu. I have it moving up and down the list when the up and down keys are pressed. However, it's screwy for lack of a better word. Sometimes it moves into a position that's completely away from the choices, and other times it just shifts instantly between choices and whatnot. I'm thinking it might be a frame update problem, because it's surely updating many times a second, and the key is pressed down for a couple frames. I looked on the internet and found a little bit on frame limits by nehe, but I don't think I implemented it correctly because I changed the denominator under CLK_TCK to 1 and it's still updating many times. Here is my main loop:
bool TitleScreen::Run()
{
	while(Msg.message != WM_QUIT && isPlaying)
	{
		movement_timer = 0;
		if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&Msg);
			DispatchMessage(&Msg);
		}
		else
		{
			time_now = clock();
			if(time_now - movement_timer > CLK_TCK/25) 
			{
				movement_timer = time_now;
				getInputAndUpdate();
			}
			
			D3D_device->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_RGBA(0,0,192,255),1.0f,0);
			D3D_device->BeginScene();
			sprite->Begin(NULL);

			drawBG();
			drawIcon();

			sprite->End();
			D3D_device->EndScene();
			D3D_device->Present(NULL,NULL,NULL,NULL);
		}
	}
	return false;

}


Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Should you be setting movement_timer to 0 every loop?
That seems to defeat the purpose of doing: movement_timer = time_now;
I don't know what clock() returns, but if it's a huge number, when you check if(time_now - movement_timer > CLK_TCK/25), movement_timer is always 0, so it'll prolly always be true, and you'll always check for input.
Try making movement_timer local and static or initialize it to 0 once elsewhere.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!