鼠标拖拽
使用这个功能,可以在游戏中拖拽一个实例。可以应用于窗口、按钮、物件之类~
CREATE 事件:
drag = 0;
LEFT PRESSED 事件:
drag = 1;
lastx = mouse_x;
lasty = mouse_y;
LEFT RELEASED 事件:
drag=0;
STEP事件:
if (drag == 1)
{
if(lastx != mouse_x)
{
if(mouse_x > lastx)
{
offset = mouse_x - lastx;
x = x + offset;
}
else if(mouse_x < lastx)
{
offset = lastx - mouse_x;
x = x - offset;
}
if(mouse_y > lasty)
{
offset = mouse_y - lasty;
y = y + offset;
}
else if(mouse_y < lasty)
{
offset = lasty - mouse_y;
y = y - offset;
}
}
}
lastx = mouse_x;
lasty = mouse_y; 这个和WIN32消息处理很像啊^^ 这样阿^^
页:
[1]