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

Discussion in 'Programming' started by joz gandoz, Aug 24, 2016.

  1. joz gandoz

    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
     
  2. zircher

    zircher Member

    Joined:
    Jun 21, 2016
    Posts:
    380
    Are you needing help with commands or is your problem that your dragged object is snapping back after you drop it?
     
  3. joz gandoz

    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.
     
  4. sndfnts

    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice