I'm writing a little 2D android game based on the SurfaceView
Object, so I draw my whole game on a canvas
. I designed a ball as a png
and draw it on the canvas with this method:
canvas.drawBitmap(bmp, posX, posY, null);
Now my problem is that I do not know how I can receive touch events for this ball. My png is 64x64 pixel but the ball is only 32x32 pixel and in the middle of the image. I only want to receive touch events if the ball (32x32) is touched and not the bitmap (64x64). How can I do this? I can register an OnTouchListener
for the SurfaceView
but how can I detect the ball touch?
An other problem is that a ball is a simple object. What if I have some unregular objects which are not describeable through a radius or something else? Do I use the right "technology" with pngs at all for building controls for a canvas or is there a better/easier way?
That is a typical problem for me on all platforms (JS, Android, iOS) and I do not know the best way to solve it. That's why I used some other tags for this question. Isn't there a cross-platform solution so I can solve this problem forever?