Drawing bug, frame rate Q

Started by
0 comments, last by dominicoder 18 years, 11 months ago
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?
There are some things so stupid that only an intellect could believe them.
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.

This topic is closed to new replies.

Advertisement