1
\$\begingroup\$

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

playerimage.buildDrawingCache();
Bitmap bplay1 = playerimage.getDrawingCache();
brickimg.buildDrawingCache(); 
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?

\$\endgroup\$

closed as off-topic by bummzack, Seth Battin, Josh Oct 8 '14 at 15:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – bummzack, Seth Battin, Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\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
2
\$\begingroup\$

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

Rect myViewRect = new Rect();
myView.getHitRect(myViewRect);

Rect otherViewRect1 = new Rect();
otherView1.getHitRect(otherViewRect1);

Rect otherViewRect2 = new Rect();
otherView2.getHitRect(otherViewRect2);

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

if (Rect.intersects(myViewRect, otherViewRect2)) {
  // Intersects otherView2
} 
\$\endgroup\$

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