I made two bitmaps based off of two ImageViews using this code:

Bitmap bplay1 = playerimage.getDrawingCache();
Bitmap bbrick1 = brickimg.getDrawingCache(); 

I tried getting the height and width of each bitmap for collision detection, but it made the app crash. This is what I used for it:

int w1 = bplay1.getWidth();
int h1 = bplay1.getHeight(); 
int w2 = bbrick1.getWidth();
int h2 = bbrick1.getHeight();

Is there a different way to get the coordinates of a bitmap to test collision detection?

  • \$\begingroup\$ is anything getting executed in a thread ? maybe when you are trying to get image stats they are not loaded yet \$\endgroup\$ – TomTsagk Aug 26 '14 at 9:14

You should be able to use Rect.intersects(Rect, Rect), like this example:

Rect myViewRect = new Rect();

Rect otherViewRect1 = new Rect();

Rect otherViewRect2 = new Rect();

if (Rect.intersects(myViewRect, otherViewRect1)) {
  // Intersects otherView1

if (Rect.intersects(myViewRect, otherViewRect2)) {
  // Intersects otherView2
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.