Drag And Drop <ask> How to make drag and drop object ?

J

joz gandoz

Guest
Please help me how to make drag and drop object ?
There are two object, simply called it obj_one as source and obj_two as destination. I want to drag/move obj_one to target, obj_two.

1. When left mouse is clicked and hold, I can move obj_one to destination object.
2. When left click is released, and before reaching target it will back to position start.
3. After obj_one reach target or make collision with obj_two : obj_two destroyed, obj_one will snap to obj_two position and no more drag obj_one again.

===

What I have done for obj_one

create event : set variable drag to false

step event :
if drag is equal to true jump to position (mouse_x,mouse_y)
if drag is equal to false jump to start position

left button event :
set variable drag to true

left released event :
set variable drag to false

===

thank you for your help
 

zircher

Member
Are you needing help with commands or is your problem that your dragged object is snapping back after you drop it?
 
J

joz gandoz

Guest
I need help to complete task, especially in task 3.
" After obj_one reach target or make collision with obj_two : "obj_two" destroyed, "obj_one" will snap to "obj_two position" and no more drag "obj_one" again.".
I have done task 1 & 2, but I have no idea how to complete task 3 .
Sorry for my English.
 
S

sndfnts

Guest
Hi,

You can try:
a) create: set variables "pos_x" and "pos_y" to x and y, respectively. set variable "draggable" to true
b) step event: change "jump to start" to (jump to position)
c) left button: add condition "if draggable is true"
d) add a "collision with obj_two" event: (applies to self) set "pos_x" and "pos_y" to other.x and other.y and jump to (pos_x, pos_y), (applies to self) set "drag" to false and set "draggable" to false. (applies to other) destroy instance

(a and b) lets you set where you want to keep the object when "drag" is false instead of sticking to the starting position.
(a) introduces a "draggable" variable (are we allowed to drag? initially yes)
(c) modifies left button. it will set drag to true if we are allowed to
(d) sets the stored position from (0) to obj_two's position, jumps to the stored position, sets "drag" and draggable to false, and destroys the other object
 
Top