문제

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!

도움이 되었습니까?

해결책 2

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
}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top