Sign in to follow this  
liajoy

Sprite's containsPoint method check alpha

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.