A simple way to drag objects around in a game.
For the object you want to drag...
1. Add a Create Event
canDrag=false;
2. Add a Step Event
if (mouse_check_button(mb_left)==true)
{
if (position_meeting(mouse_x,mouse_y,self))
{
canDrag=true;
}
}
if (mouse_check_button(mb_left)==false)
{
canDrag=false;
}
if canDrag=true
{
x=mouse_x;
y=mouse_y;
}
Explaination:
If the mouse is over the object and the LMB is pressed, toggle the object to draggable. When the object is draggable, set the object's x and y equal to the mouse's x and y. When the LMB is released, toggle the object to not draggable.
Weakness:
When first clicked on, the object's origin will jump to the mouse point.
.
Users logged in:
Comments
Loading comments...