Ive created a game where you move a rectangle and dodge other falling rectangles from the sky. Though everytime the rectangles intersect nothing happens.
if(mSquare.intersect(jSquare)){
canvas.drawColor(Color.BLACK);
or
collision = mSquare.intersect(jSquare);
if(collision==true){ canvas.drawColor(Color.RED);
} this always returns false no matter where the rectangles are.......
There are a lot of ways to do this, the simplest would be to get the bounding
Rectfor eachBitmapand on each time step to check for a collision usingRect.intersect()method.Something like this:
Additionally there are many other (better) ways to do this, especially when dealing with objects that aren’t rectangles and when you have lots of objects on the screen. Check out this post for a good discussion
Also the book “Beginning Android Games” has a great chapter about collision detection and the book is well worth a read if you are considering writing a game.