franniss 发表于 2010-1-20 00:41:24

鼠标拖拽

使用这个功能,可以在游戏中拖拽一个实例。
可以应用于窗口、按钮、物件之类~

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;

lw 发表于 2010-1-20 19:34:13

这个和WIN32消息处理很像啊^^

franniss 发表于 2010-1-20 20:14:32

这样阿^^
页: [1]
查看完整版本: 鼠标拖拽