Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3978

interaction/dragging example seems hacky

$
0
0

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


Viewing all articles
Browse latest Browse all 3978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>