Game maker 如何在game maker studio中使用光标(鼠标)将任何对象移动到特定位置

Game maker 如何在game maker studio中使用光标(鼠标)将任何对象移动到特定位置,game-maker,Game Maker,我想通过光标将对象移动到任何其他对象的位置 在这段代码中,苹果对象用光标移动,但它不会停在(八个对象)。在其他情况下,如果我把苹果对象放在除了八个对象以外的任何其他位置,它必须回到起始位置 //同步事件 xtarget = obj_eight.x; ytarget = obj_eight.y; if(x = xtarget and y = ytarget){ obj_applelemon.x = xtarget; obj_applelemon.y = ytarget; } e

我想通过光标将对象移动到任何其他对象的位置

在这段代码中,苹果对象用光标移动,但它不会停在(八个对象)。在其他情况下,如果我把苹果对象放在除了八个对象以外的任何其他位置,它必须回到起始位置

//同步事件

xtarget = obj_eight.x;
ytarget = obj_eight.y;

if(x = xtarget and y = ytarget){
  obj_applelemon.x = xtarget;
  obj_applelemon.y = ytarget;     
}
else{
  x = xstart;
  y = ystart;

   if (mouse_check_button(mb_left)){[enter image description here][1]
   x = mouse_x;
   y = mouse_y;
} 
}

我想知道你的目标是什么。如果我读对了,您正试图使用鼠标将一个项目移动到另一个项目,如果他们将其放置在不是目的地的位置,它应返回其原始位置。如果这是正确的,则执行此操作的代码类似于以下代码:

**Create**:
startX = 0;
startY = 0;
destinationX = 0;
destinationY = 0;
isGrabbed = false;

**mouse Pressed**:
isGrabbed = true;

**mouse Released**:
isGrabbed = false;
//after user releases, check if collision or not
if(place_meeting(x, y, obj_eight)){
    obj_applelemon.x = destinationX;
    obj_applelemon.y = destinationY;     
}
else{
    x = startX;
    y = startY;
}

**Step**:
destinationX = obj_eight.x;
destinationY = obj_eight.y;

//if object is grabbed, move to mouse location
if (isGrabbed){
    x = mouse_x;
    y = mouse_y;
}

//creation of object code
var object = instance_create(x, y, obj_applelemon);
object.startX = x;
object.startY = y;
正在运行代码: 在创建中,我们设置初始开始位置、目标位置变量和鼠标单击变量。如果正在单击对象,则该对象将保持为真,并随鼠标移动,直到松开鼠标。释放鼠标后,它将检查苹果是否与obj_八发生碰撞。如果你试着检查它们是否直接落在八号行星的x和y上,那么要准确地落在那个位置将非常困难

希望这有帮助