Sign in to follow this  
lars

Drag into container and out again

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

Share this post


Link to post
Share on other sites

why do you use "width" and "height" there? I think any drag examples does not use it: https://pixijs.io/examples/#/projection/basic.js (this is for custom plugin, but the drag code is good) 

Do you know that position of spine object is not left-top point? Also, W/H can change every frame.

Share this post


Link to post
Share on other sites

Hi Ivan

My drag and is not included in my example, it´s work ok, only, some attemp to add a object from one container to another container, and atemp to get it back to the original container 🙂

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.