0

I am developing a game. I would probably need to do some math in it. I have a character made out of about 5-6 bitmaps together. I want to check its collisions. For example if he hits a bullet, hit platform and all of this stuff. I also want to check if a bitmap is being pressed(like a button). I heard that a rect is good for this but I'm not sure how to use it. can anyone explain how to use the rect for it or if you have a better or easier idea. Thanks!

tshepang
  • 12,111
  • 21
  • 91
  • 136
Baruch
  • 1,618
  • 5
  • 23
  • 42
  • Possible duplicate: http://stackoverflow.com/questions/5914911/pixel-perfect-collision-detection-android – rwilliams Oct 15 '11 at 06:05

2 Answers2

0

Checkout the Playing with graphics in Adroid series of articles. Collision detection is covered specifically in part 7.

rwilliams
  • 21,188
  • 6
  • 49
  • 55
0

Never mind, i found out that the rect class has contains option. for example:

    Rect r = new Rect();
    r.set(left, top, right, bottom);
    if (r.contains(x, y)){
        // this is where it will happen if you touch it
    }
    if (r.contains(r2)){
        //what happens if it collides with rect number 2
    }
//or check intersect        

        if(r2.intersect(r)){
//what happens if it collides with rect number 2
}
Baruch
  • 1,618
  • 5
  • 23
  • 42