I've also been trying to get this working today.
I'm trying to use basic bounding box collision detection using Rect.intersects(rect, rect).
Here's my method. GraphicObject is a class I defined that stores the bitmap, coordinates, speed etc.
I'm using a normal for loop to iterate through my ArrayList as I'm storing the position of each GraphicObject in
two other lists.
Using java Syntax Highlighting
private void detectCollisions() {
for (int i=0; i <_graphics.size(); i++) {
GraphicObject graphicA = _graphics.get(i);
Rect boxA = new Rect(graphicA.getCoordinates().getX(), graphicA.getCoordinates().getY(),
graphicA.getCoordinates().getX()+graphicA.getGraphic().getWidth(),
graphicA.getCoordinates().getY()+graphicA.getGraphic().getHeight());
for (int j=0; j <_graphics.size(); j++) {
GraphicObject graphicB = _graphics.get(i);
Rect boxB = new Rect(graphicB.getCoordinates().getX(),
graphicB.getCoordinates().getY(),
graphicB.getCoordinates().getX()+graphicB.getGraphic().getWidth(),
graphicB.getCoordinates().getY()+graphicB.getGraphic().getHeight());
if (Rect.intersects(boxA,boxB)) {
_collisionA.add(i);
_collisionB.add(j);
}
}
}
Parsed in 0.043 seconds, using
GeSHi 1.0.8.4
When I run the game it run's as it did before I implemented the collision detection, it seems to have no effect. I've made sure it's being called from the main loop (obviously

). I'm not really sure what the problem is, theres no compile-time or run-time errors or exceptions being thrown. It just doesn't work.
Any help is greatly appreciated
