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

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.