1

I've currently been thinking about how I could register only touch events on the visible (non-transparent) parts of a .PNG image.

-I've been testing around with AndEngine and it seems they have multiple options: I've tried any I could find to no avail.

-I could very possibly create my own method of checking a given touched area's transparency I suppose, but not sure how much work/overhead that might create with 15-20 objects on screen being able to be touched..

Any help is much appreciated!

1 Answer 1

1

One simple way to do it would be to grab the the pixel color at the touch location. Then you can check if the pixel is transparent:

int color = Bitmap.getPixel(x,y); // x and y are the location of the touch event in Bitmap space int alpha = Color.getAlpha(color); boolean isTransparent = (alpha==0); 

Note: Depending on how you implement your touch listener will might need to convert the x,y location of the touch event to the x,y coordinates of the image view.

Sign up to request clarification or add additional context in comments.

4 Comments

Haha, I just edited to ask how this works. Thanks for the quick reply! I'll definitely try it in hopes that it's not too costly!
If you attach a onTouchListener to each object then you only have to check the all the objects only the object that was touched.
Very true, very helpful. This should work, I just have to find a way to traverse back from a TiledTextureRegion in andEngine to get the actual color attributes of a given Bitmap.pixel()
slayton, just realized getAlpha() should be alpha() I think :-D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.