两个实体之间的碰撞

时间:2013-12-15 06:51:33

标签: java android box2d andengine

我正在学习动力学。我正在创建一个示例游戏。在这个游戏中有一个heliChopter,可以午餐mesile。有一个leaser枪根据helichopter的运动改变它的旋转。有导弹午餐按钮。导弹午餐按钮发射导弹。我想检测一下leaser gun和mesile之间的碰撞。但我知道碰撞必须在onupdatemanaged()函数中检测到。我想玩一些破坏动画像爆炸!并在此功能中播放破坏的声音。请给我一些想法。

`private void addMesie(float x, final float f) {
    tempx = x;
    tempy = f;
 this.mesile = new AnimatedSprite(x, f, this.MesileTextureRegion,     this.getVertexBufferObjectManager()){
                        @Override
                        protected void onManagedUpdate(float pSecondsElapsed) {

                                super.onManagedUpdate(pSecondsElapsed);
                                this.setPosition(tempx , tempy);
                                if(laserCannon.collidesWith(this)){

                                }

                        }


                };
                this.mesile.animate(new long[]{100,100,100,100});
                this.mesile.setVisible(false);
                this.mScene.attachChild(mesile);

        }`

1 个答案:

答案 0 :(得分:0)

要在onManageUpdate中处理碰撞,请尝试使用ContactListener来检测不同对象的碰撞。在这里你也可以轻松播放声音。

相关问题