今晚尝试一下Gm的拖拽,发现和之前看过知乎Gms的专栏一篇文章的也是很类似,尝试做一下练习。针对一个obj在step 事件下进行控制。
在使用之前封装了一个小脚本,可以调用点击。其实有点需要吐槽的,按钮那些触控行为,只能加上碰撞和鼠标点击结合使用。具体还不知道还有没有新的方法。
mouse_click
if(collision_point(mouse_x,mouse_y,argument0,0,0) && mouse_check_button(mb_left))
{
return true;
}
return false;
鼠标释放mouse_release
if(collision_point(mouse_x,mouse_y,argument0,0,0) && mouse_check_button_released(mb_left))
{
return true;
}
return false;
第二步:建立一个obj_box 对象。
在create事件,填写拖拽变量
drag = false;
在step事件填写
if(mouse_click(self))
{
// show_message("q");
drag = true;
startPoint = [mouse_x,mouse_y];
}
if(drag)
{
x += mouse_x - startPoint[0];
y += mouse_y - startPoint[1];
startPoint= [mouse_x,mouse_y];//记录上一个位置。
if(mouse_release(self))
{
drag = false;//释放处理
}
}