Jump to content

Drag into container and out again


lars
 Share

Recommended Posts

Hello All

I trying to make a object be dragged into a container and then be a child of this container like this:

//places in a pointerup event

let bl = otc.skeleton.findBone("left-hand-bone");

            let point = oc.toGlobal({
                'x': bl.x,
                'y': bl.y
            });

            this.position.set(point.x - (oc.width - 5), point.y - (oc.height - 30));

            // oCon.toLocal(this.position, this.parent, this.newPosition);//this i did not manage to get to work
            oc.addChild(this);//the container where drop the object(this)

            this.position.set(point.x - (oc.width - 30), point.y - (oc.height + 30));

And work fairly ? But then when i want to drag the object out of the container again i gives me som problems:

//placed in a pointerdown event

if (globals.objectUsed) { // if the object is dragged to the new container in first place

  oCon.addChild(this); // send it back to its original container


            this.position.set(e.data.getLocalPosition(oCon).x, e.data.getLocalPosition(oCon).y);
            globals.objectUsed = false;
            isIntersected = false;


        }

It´s kind of work. But the idea is that when the object is placed the first time and I want to drag it back to the original container its should happend when I startDrag(pointerdown), but i have to wait for the pointerup otherwise I still drag the object in its parent container (whichs is having a drag method. Could anyone guide be in the right direction it would be so nice ... hopefully me explaining  its not to much rubbish ?

Regards Lars

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...