Login | Register

Draggable Objects Method 2

February 13, 2010, 08:08 by Aspen
[loading]
-->
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.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games