Android游戏编程 - 精灵碰撞

时间:2014-04-10 15:00:11

标签: android sprite collision

我正在尝试检测zombieSpriteList中的一个Object的thezombiesprite是否与我的theplayersprite对象发生冲突。我尝试使用以下代码,但我的游戏在开始时崩溃了......

public void checkForCollision(){
                for (int i = 0; i<zombieSpriteList.size(); i++){
                    ZombieSprite thezombiesprite = zombieSpriteList.get(i);
                       Rect mySprite = thezombiesprite.getBounds(); //create rect for every sprite in array

                            Rect myOtherSprite = theplayersprite.getBounds();
                              if(mySprite.intersect(myOtherSprite)){ //check if they touch
                                collision = true;
                         }

                  }
              }

在ZombieSprite&amp; PlayerSprite:

public Rect getBounds(){
           return new Rect(x, y, x+width, y+height);
         }

0 个答案:

没有答案