liajoy Posted January 3, 2019 Share Posted January 3, 2019 Hello! `Sprite` support `containsPoint` method, But it just check the point is in the sprite area depend on width and height not by imageData. For example, if the sprite image is a totally transparent image, `containsPoint` should always return false. My thought maybe like this 1. extract `imageData` from `app.stage` 2. check the pixel relative to the point is alpha Any better advise to do this? Thank you! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 3, 2019 Share Posted January 3, 2019 Here, two threads for you: https://github.com/pixijs/pixi.js/issues/5311 SUMMARY: there are several ways, but nothing is packaged in pixi, because their authors weren't ready to publish it. You have to do it and be a hero who makes a plugin. Quote Link to comment Share on other sites More sharing options...
liajoy Posted January 4, 2019 Author Share Posted January 4, 2019 thanks! Quote Link to comment Share on other sites More sharing options...
liajoy Posted January 4, 2019 Author Share Posted January 4, 2019 hello again! I've saw those 'guide'. Thanks so much. I just want to know if some point is contained of some sprite. Seems there's no need to concern about shader? Another question is `extract.pixels()` will return something wrong if the displayObject shifted and out of the box. Seems it didn't count the `transform` of displayObject? const circle = new PIXI.Graphics(); circle.x = 200; circle.beginFill(0xabcdef); circle.drawCircle(0, 0, 100); circle.endFill(); const pixels = app.renderer.extract.pixels(circle); // [0, ...0] So in some situation, `extract.pixels()` doesn't work perfectly, use 2d canvas is the only way to get the correct pixels? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 4, 2019 Share Posted January 4, 2019 > Another question is `extract.pixels()` will return something wrong if the displayObject shifted and out of the box Known bug, its too difficult to fix because all my possible fixes were very big, difficult , and thy were rejected. Try use your own code based on `extract`: manually call `renderer.render` and `readPixels` instead. As for graphics, why do you need extract it? Its already have perfect containsPoint() method. For graphics containsPoint() exists, for sprites you can analyze original textures and make a packed bitmap out of them, no need to use `extract` at all. 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.