0
\$\begingroup\$

I'm trying to make a collision detection system for two ImageViews, but I can't seem to figure it out. I've tried doing several things from StackOverflow and other places, but they don't work. One ImageView stays still and the other moves toward it (it's animated, not a sprite). They don't do anything when the collide, though. Do I need to make them sprites or drawables on a canvas or something?

\$\endgroup\$
1
  • \$\begingroup\$ Hello and welcome to GDSE. It's somewhat hard to answer, because you say that you have used several things, yet you don't mention what you have tried. \$\endgroup\$
    – Katu
    Jul 25, 2014 at 4:33

1 Answer 1

3
\$\begingroup\$

Get information (dimensions, coordinates) of two imageviews, then use rectangle intersection condition. Assume that two rectangles A, B with coordinate of top-left and buttom-right as follow:

Rectangle A: (Xa1, Ya1) ; (Xa2, Ya2)
Rectangle B: (Xb1, Yb1) ; (Xb2, Yb2)

Overlap condition:

((Xb1 - Xa2)(Xb2 - Xa1) <= 0) && ((Yb1 - Ya2)(Yb2 - Ya2) <= 0)

Refer the below site for some guidance:

http://www.kilobolt.com/day-4-collision-detection-part-1.html

It explains bounding shapes that will be used to check for collision. In the case of our robot, we will be using four bounding rectangles.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .