Queue Posted May 20, 2017 Share Posted May 20, 2017 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 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 20, 2017 Share Posted May 20, 2017 I think its somewhere inside "graphics.graphicsData": https://github.com/pixijs/pixi.js/blob/dev/src/core/graphics/Graphics.js#L68 Queue 1 Quote Link to comment Share on other sites More sharing options...
Queue Posted May 20, 2017 Author Share Posted May 20, 2017 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 ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.