I’m having a little bit of difficulty setting the (x,y) coordinate bounds to detect when a particular bitmap is being clicked on or not.
For example if the bitmap’s position is (100,300),say. i.e. top left corner is at this point, then if the user touches the screen at point (X,Y), then the simple conditional:
if((Math.abs(X-midX)<bitmap.getWidth()/2)&&
Math.abs(Y-midY)<bitmap.getHeight()<bitmap.getHeight()/2){
//the bitmap has been clicked on
}
Where midX is defined as (100+(100+bitmap.getWidth()))/2 i.e. the mid x point and similar definition for midY.
Is this a correct way to do this? Because some of my bitmaps are not behaving as I would expect when I try to touch/click them.
While I enjoy doing this kind of maths, this time I would recommend going ‘the easy way’. Set up a Rect/RectF with your image bounds and use rectF.contains(float x, float y) or rect.contains(int x, int y) instead. That is, if onClick is not an option here, of course.