A second way to drag objects around in a game.
For the object you want to drag...
1. Add a Create Event
canDrag=false;
diffX=0;
diffY=0;
2. Add a Step Event
if (mouse_check_button(mb_left)==true)
{
if (position_meeting(mouse_x,mouse_y,self))
{
canDrag=true;
diffX=mouse_x-x;
diffY=mouse_y-y;
}
}
if (mouse_check_button(mb_left)==false)
{
canDrag=false;
}
if canDrag=true
{
x=mouse_x-diffX;
y=mouse_y-diffY;
}
Strength:
Smoother dragging compared to method 1. The object doesn't suddenly jump when first clicked on.
Weakness:
You will drag the object by its edge.
.
Users logged in:
Comments
Loading comments...