MPavlak
MPavlak

Reputation: 2221

Pixi js mouse events for top most sprite only

I noticed that in pixi.js version 1.3, as seen in this example, stacking sprites, then click and drag only drags the top most sprite.

    bunny.mousedown = bunny.touchstart = function(data)
    {
//      data.originalEvent.preventDefault()
        // store a refference to the data
        // The reason for this is because of multitouch
        // we want to track the movement of this particular touch
        this.data = data;
        this.alpha = 0.9;
        this.dragging = true;
        this.sx = this.data.getLocalPosition(bunny).x * bunny.scale.x;
        this.sy = this.data.getLocalPosition(bunny).y * bunny.scale.y;
    };

http://jsfiddle.net/dirkk0/cXfpq/

In version 3.0.3, as seen in this example, the same code causes all the sprites under the mouse to be dragged.

http://jsfiddle.net/9tnaa31z/5/

Is there a way to get only the top most sprite or a way to get a list of all the sprites (in the order rendered)?

Upvotes: 0

Views: 1645

Answers (1)

Tahir Ahmed
Tahir Ahmed

Reputation: 5737

I think there may have been a bug in the 3.0.3 version of PIXI. I just tried it out with the latest 3.0.5 and it works as expected i.e. it drags only the top-most Sprite.

Update the External Resources in your fiddle with this latest version of Pixi.js and it should work.

Reference: https://cdnjs.com/libraries/pixi.js.

Upvotes: 1

Related Questions