我设计了一个计时器来实现动画, 可是动画效果越来越慢, 这是为什么呢?
// 计时器回调函数
void CBREW_TimerApp::P_Timer(CBREW_TimerApp* pMe)
{
x += 0.5;
y += 0.5;
ISHELL_PostEvent(pMe->m_pIShell, AEECLSID_BREW_TIMER, EVT_TIMER, 0, 0);
}
boolean CBREW_TimerApp::onEvent(AEEEvent evt, uint16 wParam, uint32 dwParam)
{
switch(evt)
{
case EVT_APP_START:
{
IDISPLAY_ClearScreen(m_pIDisplay); // 清屏
g_pIImage = ISHELL_LoadImage(m_pIShell, "Player.png");
IIMAGE_Draw(g_pIImage, x, y);
IDISPLAY_Update(m_pIDisplay); // 更新
ISHELL_SetTimer(m_pIShell, CurTime, (PFNNOTIFY)P_Timer, this);
return TRUE;
}
case EVT_APP_SUSPEND:
return TRUE;
case EVT_APP_RESUME:
return TRUE;
case EVT_APP_MESSAGE:
return(TRUE);
case EVT_KEY:
{
switch(wParam)
{
case AVK_CLR:
return TRUE;
case AVK_UP:
case AVK_DOWN:
case AVK_LEFT:
case AVK_RIGHT:
case AVK_SELECT:
break;
default:
break;
}
break;
}
case EVT_COMMAND:
{
break;
}
case EVT_APP_STOP:
ISHELL_CancelTimer(m_pIShell, (PFNNOTIFY)P_Timer, this);
IIMAGE_Release(g_pIImage); // 释放
return TRUE;
case EVT_TIMER: // 计时器消息
//画图片
IDISPLAY_ClearScreen(m_pIDisplay);
IIMAGE_Draw(g_pIImage, x, y);
IDISPLAY_Update(m_pIDisplay);
ISHELL_SetTimer(m_pIShell, CurTime, (PFNNOTIFY)P_Timer, this); // 重新开启计时器, 实现循环
return TRUE;
default:
break;
}
return FALSE;
}
------解决方案--------------------------------------------------------
你这个timer实现的有点诡异
常见的做法是ISHELL_SetTimer(m_pIShell, CurTime, (PFNNOTIFY)P_Timer, this);
然后在P_Timer函数实现里面直接做你的EVT_TIMER里面的事情
就是说P_Timer的实现类似于:
void CBREW_TimerApp::P_Timer(CBREW_TimerApp* pMe)
{
x += 0.5;
y += 0.5;
IDISPLAY_ClearScreen(m_pIDisplay);
IIMAGE_Draw(g_pIImage, x, y);
IDISPLAY_Update(m_pIDisplay);
ISHELL_SetTimer(m_pIShell, CurTime, (PFNNOTIFY)P_Timer, this); // 重新开启计时器, 实现循环
}
这样就不需要你这个异步的EVT_TIMER的消息处理了
你试试看 ,可能会好一点
------解决方案--------------------------------------------------------
楼主接timer消息的话是会延迟,毕竟要向消息队列放置消息,并再次取出
另外休眠模式时是通过降了电压降了频率吧,所以会慢很多
------解决方案--------------------------------------------------------
尝试一下:
1)直接调用IShell_settimer而不是发送事件
2)处理EVT_APP_NO_SLEEP事件,直接返回TRUE
------解决方案--------------------------------------------------------
SLEEP了
------解决方案--------------------------------------------------------
直接用ISHELL_SETTimer试一下,不用发消息
------解决方案--------------------------------------------------------
补充一下ISHELL_PostEvent是异步调用的