Jump to content

Polygon, Graphics


Queue
 Share

Recommended Posts

Hello,

I am currently displaying my Polygon via PIXI.Graphics.drawPolygon() which works fine. Is there any way to display a PIXI.Polygon directily? Because I want to use the "contains()" method in a onDragMove() function.

My current (rather ugly workaround) is drawing the Polygon as a graphic and generating a PIXI.polygon with the same points for the collision check.

var graphic = new PIXI.Graphics();
graphic.beginFill(0x00dd00, 1);
graphic.lineStyle(2, 0x000000, 1);
graphic.drawPolygon(
    [
        new PIXI.Point(100, 500),
        new PIXI.Point(200, 400),
        new PIXI.Point(300, 400),
        new PIXI.Point(200, 500),
        new PIXI.Point(100, 500)
    ]
);
graphic.endFill();
app.stage.addChild(graphic);

poly = new PIXI.Polygon(
    [
        new PIXI.Point(100, 500),
        new PIXI.Point(200, 400),
        new PIXI.Point(300, 400),
        new PIXI.Point(200, 500),
        new PIXI.Point(100, 500)
    ]
);

function onDragMove() {
    if (this.dragging) {
        var newPosition = this.data.getLocalPosition(this.parent);
        this.x = newPosition.x;
        this.y = newPosition.y;
        console.log(poly.contains(this.x, this.y));
    }
}

 

Are there any more convenient approaches?

Best Regards 

Queue

Link to comment
Share on other sites

thats technically right, but sadly the polygon won't be stored as PIXI.Polygon, instead only the Points and some other data is stored inside there. So I cant use "contains()" there aswell. :(

 

edit: my bad, it works. Its in graphicsData[x].shape the output in my console did not show "Polygon" thats why I was confused

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...