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/o开发者_Python百科verhead that might create with 15-20 objects on screen being able to be touched..
Any help is much appreciated!
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.
精彩评论