Android AndEngine系列不会与其他人发生冲突

时间:2014-03-27 19:29:10

标签: android andengine

我的身体:

lineFixtureDef = PhysicsFactory.createFixtureDef(
                            1,     // density
                            0.75f,  // elasticity
                            0.5f, // friction
                            false); // isSensor

                    lBody = PhysicsFactory.createLineBody(physicsWorld, line5, lineFixtureDef);
                    lBody.setUserData("lineBody");

我的联系人听众:

                @Override
                public void beginContact(Contact contact) {
                    // TODO Auto-generated method stub

                    final Fixture x1 = contact.getFixtureA();
                    final Fixture x2 = contact.getFixtureB();

                    if (x1.getBody().getUserData().equals("pSprite") && x2.getBody().getUserData().equals("eSprite"))
                    {
                        Log.i("CONTACT", "BETWEEN PLAYER AND MONSTER!");
                        lost();
                    } else if(x1.getBody().getUserData().equals("eSprite") && x2.getBody().getUserData().equals("lineBody"))
                    {
                        Log.i("CONTACT", "BETWEEN LINE AND MONSTER!");
                        mScore += 1;
                        mText.setText(" "+mScore+"");
                    }
                }

现在当pSprite与eSprite发生冲突时,lost();工作..但如果线和eSprite碰撞没有任何反应..

1 个答案:

答案 0 :(得分:0)

 if (x1.getBody().getUserData().equals("pSprite") && x2.getBody().getUserData().equals("eSprite"))
                    {
                        Log.i("CONTACT", "BETWEEN PLAYER AND MONSTER!");
                        lost();
                    } else if(x1.getBody().getUserData().equals("eSprite") && x2.getBody().getUserData().equals("pSprite"))
                    {
                        Log.i("CONTACT", "BETWEEN PLAYER AND MONSTER!");
                        mScore += 1;
                        mText.setText(" "+mScore+"");
                    }

 if (x1.getBody().getUserData().equals("lineBody") && x2.getBody().getUserData().equals("eSprite"))
                    {
                        Log.i("CONTACT", "BETWEEN LINE AND MONSTER!");
                        lost();
                    } else if(x1.getBody().getUserData().equals("eSprite") && x2.getBody().getUserData().equals("lineBody"))
                    {
                        Log.i("CONTACT", "BETWEEN LINE AND MONSTER!");
                        mScore += 1;
                        mText.setText(" "+mScore+"");
                    }