目的很简单,通过上下左右方向键,控制小人的走动,使用的是贴图的方式,程序一切正常,只是有一个问题:当一直按住某一方向键不放时小人可以连续顺畅的移动,此时突然改变方向,也是按住不放,小人总要顿一下,再开始流畅的移动。
  感觉应该是判断按键是否连续按住的原因,只是不知道怎么可以解决这一个“迟钝”的问题。
  部分代码:
void CGameDebugView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
// TODO: Add your message handler code here and/or call default
int ret;if(nChar==38)
    ret=ex_hero.Move(UP);
else
    if (nChar==40)
       ret=ex_hero.Move(DOWN);
    else
       if (nChar==37)
      ret=ex_hero.Move(LEFT);
       else
    if (nChar==39)
       ret=ex_hero.Move(RIGHT);
}

解决方案 »

  1.   

    可以绕过消息机制直接读取键盘按键,用DirectInput或者GetAsyncKeyState
      

  2.   

    void CGameDebugView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default

    preTime=Time;
    Time=GetTickCount();
    if (Time-preTime<500)
    {
    return;
    }
            ...................
    }这样子吗,这样肯定没用啊,变成连续按着就无效了啊,原来的程序只是在“变方向”这一个瞬间有停顿而已