ikaruga

interaction/dragging example seems hacky

Recommended Posts

Here's the code in question:

https://pixijs.io/examples/#/interaction/dragging.js

bunny
        .on('pointerdown', onDragStart)
        .on('pointermove', onDragMove);

function onDragStart(event) {
    // store a reference to the data
    // the reason for this is because of multitouch
    // we want to track the movement of this particular touch
    this.data = event.data;
}

// this is the example onDragMove
function onDragMove() {
    if (this.dragging) {
        const newPosition = this.data.getLocalPosition(this.parent);
        this.x = newPosition.x;
        this.y = newPosition.y;
    }
}

// why doesn't this work?
function onDragMoveModified(event) {
    if (this.dragging) {
        const newPosition = event.data.getLocalPosition(this.parent);
        this.x = newPosition.x;
        this.y = newPosition.y;
    }
}

 

As per the docs for the InteractionEvent, the `event.data` presumably has the data for the current drag event. https://pixijs.download/dev/docs/PIXI.InteractionEvent.html

Can someone explain to me why we have to store the start `event.data` in the current object? I don't understand why using the latest event (as in onDragMoveModified) doesn't work? To clarify, when you try that code, the result is jumpiness on multi touch

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.