problem with release dont take direction

I have a pretty fat problem so to speak I need to know how to move objects or instances of objects by left click, I leave attached image to be understood better because what I really need is once I have selected and caught with the mouse to release it go to the address where I have released it with a fixed speed I hope you can help me, thank you very much in advance.
I leave an image with explain.
I have this code but is not precise and contained many bugs:

xPr = x // no los mueva de este lugar siempre tienen que ir en el lugar antes de alterar el codigo de x e y
yPr = y

x = mouse_x
y = mouse_y

if x == xPr
and y == yPr
{
speed = 0
}else
{
speed = 6 // elige la que quieras
direction = point_direction(xPr,yPr,x,y) // indica que la x e y anterior sean direccionadas con las actuales
}
 

Attachments

flerpyderp

Member
The following code checks if the object is selected, if it is not then clicking on it makes it so. Releasing the mouse button deselects it and stores the coordinates of the mouse. If the object is ever outside a specified range from these coordinates, it will move within that range then stop.

Create:
Code:
selected = false;
newX = x;
newY = y;
Step:
Code:
if  (!selected)
{
     if (position_meeting(mouse_x,mouse_y,id)) && (mouse_check_button_pressed(mb_left))
     {
          selected = true;
     }
}
else
{
     if (mouse_check_button_released(mb_left))
     {
          selected = false;
          newX = mouse_x;
          newY = mouse_y;
     }
}

var range = 10; //Change to suit

if (distance_to_point(newX,newY) > range)
{
     speed = 6;
     direction = point_direction(x,y,newX,newY);
}
else speed = 0;
 
Last edited:
The code is really good, but I need that when you release it, go out of the room, once you have taken the direction and the speed does not stop when you reach the point of the mouse, but continue out of the room.
 
The following code checks if the object is selected, if it is not then clicking on it makes it so. Releasing the mouse button deselects it and stores the coordinates of the mouse. If the object is ever outside a specified range from these coordinates, it will move within that range then stop.

Create:
Code:
selected = false;
newX = x;
newY = y;
Step:
Code:
if  (!selected)
{
     if (position_meeting(mouse_x,mouse_y,id)) && (mouse_check_button_pressed(mb_left))
     {
          selected = true;
     }
}
else
{
     if (mouse_check_button_released(mb_left))
     {
          selected = false;
          newX = mouse_x;
          newY = mouse_y;
     }
}

var range = 10; //Change to suit

if (distance_to_point(newX,newY) > range)
{
     speed = 6;
     direction = point_direction(x,y,newX,newY);
}
else speed = 0;
 
The code is really good, but I need that when you release it, go out of the room, once you have taken the direction and the speed does not stop when you reach the point of the mouse, but continue out of the room.
 

flerpyderp

Member
The code is really good, but I need that when you release it, go out of the room, once you have taken the direction and the speed does not stop when you reach the point of the mouse, but continue out of the room.
In that case, simply removing the line "else speed = 0" would suffice. However, much of that code is unnecessary for this purpose. Here is the modified code:
Code:
if  (!selected)
{
    if (position_meeting(mouse_x,mouse_y,id)) && (mouse_check_button_pressed(mb_left))
    {
         selected = true;
    }
}
else
{
    if (mouse_check_button_released(mb_left))
    {
          speed = 6;
          direction = point_direction(x,y,mouse_x,mouse_y);
    }
}
Remember to destroy objects after they leave the room if they are no longer required.
 
Perfect this is all i need thanks so much, tomorrow i have to present 1 beta for a bussines man to finance my game and needed this for my game thanks really.

In that case, simply removing the line "else speed = 0" would suffice. However, much of that code is unnecessary for this purpose. Here is the modified code:
Code:
if  (!selected)
{
    if (position_meeting(mouse_x,mouse_y,id)) && (mouse_check_button_pressed(mb_left))
    {
         selected = true;
    }
}
else
{
    if (mouse_check_button_released(mb_left))
    {
          speed = 6;
          direction = point_direction(x,y,mouse_x,mouse_y);
    }
}
Remember to destroy objects after they leave the room if they are no longer required.
 
Top