Jump to content
  • Advertisement
Sign in to follow this  
Plerion

[GDI+] Lagging movement

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

Hello!

Im using GDI+ to draw some images. This image can move around. But the problem is that movement is pretty laggy. Sometimes it jumps around instead of moving fluently. I wonder what is the reason for that. Is it because i use GetTickCount() to calculate the difference between two frames? Or is it because of GDI+? Thats my code:

while(m_isRunning)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Render();
Sleep(5);
}



To update the player:

void Player::Update(DWORD dwDiff)
{
if(!GetFocus())
return;

LPBYTE keys = new BYTE[256];
GetKeyboardState(keys);
if(keys[VK_LEFT] & 0x80)
{
if(m_position.X - dwDiff * 0.2f > 0)
m_position.X -= dwDiff * 0.2f;
}

if(keys[VK_RIGHT] & 0x80)
{
if(m_position.X + dwDiff * 0.2f < 525)
m_position.X += dwDiff * 0.2f;
}
}




void Renderer::RenderImgObject(ImageObject* pObj, Graphics& g, UINT& diff)
{
if(!pObj)
return;
if(!pObj->GetImage())
return;
if(pObj->GetPosition().X < 0)
return;
pObj->Update(diff);
PointF& pos = pObj->GetPosition();
g.DrawImage(pObj->GetImage(), pos.X, pos.Y, pObj->GetWidth(), pObj->GetHeight());
}



Is there something wrong?

Greetings
Plerion

Share this post


Link to post
Share on other sites
Advertisement
Could be both. GDI+ is not the best choice for realtime-rendering, but you can probably tweak it by using low quality rendering.

GetTickCount() returns milliseconds, but the accuracy is 5 ms or more according to the docs. A better approach might be using QueryPerformanceCounter. There are various threads here covering this problem.

Hope that helps

unbird

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!