嗨所以我试图让它变得如此有点UFO位图(绘图/绘画已经照顾过)可以在屏幕上拖动。我似乎无法更新UFO位置,然后从MouseButtonDown()函数重复绘制(鼠标事件处理程序的简化代码)。有关检测拖动和重绘的建议吗?相关功能的代码如下:
void MouseButtonDown(int x, int y, BOOL bLeft)
{
if (bLeft)
{
while(_bMouseMoving == true && _bMouseDragRelease == false) {
_iSaucerX = x - (_pSaucer->GetWidth() / 2);
_iSaucerY = y - (_pSaucer->GetHeight() / 2);
InvalidateRect(_pGame->GetWindow(), NULL, FALSE);
}
// Set the saucer position to the mouse position
_iSaucerX = x - (_pSaucer->GetWidth() / 2);
_iSaucerY = y - (_pSaucer->GetHeight() / 2);
}
else
{
// Stop the saucer
_iSpeedX = 0;
_iSpeedY = 0;
}
}
void MouseButtonUp(int x, int y, BOOL bLeft)
{
_bMouseDragRelease = true;
}
void MouseMove(int x, int y)
{
_bMouseMoving = true;
}
答案 0 :(得分:0)
为了澄清克里斯所说的内容,您只需要获取一次WM_xBUTTONDOWN消息,并且您需要使用它来切换拖动状态,您可以在收到WM_MOUSEMOVE消息时查询该状态。
当您在拖动状态下获取鼠标移动消息时,您将要使ufo所在的矩形和周围的矩形无效。
使矩形无效会导致WM_PAINT消息,您可以在其中重绘不明飞义背后的内容,以及其中新的位置的不明飞行物。
或者你可以在拖动时作弊并使UFO成为光标:)