AnimatedSprite onAreaTouch内的AnimatedSprite没有删除Andengine

时间:2013-04-16 11:35:03

标签: android andengine

我是Andengine的新手。我已经检查了所有在stackoverflow上删除精灵问题,但我的情况有点不同。我有两个动画精灵。我正在制作简单的动画bug,它正在移动。当玩家点击bug时,血液会从中流出。所以我有两个AnimatedSprite,bug和血。

在onAreaTouched中的bug精灵我正在附上血精灵。一切正常,但血精灵我没有在动画后删除它。

注意:我也检查了onAnimationEnd函数

请帮助!感谢

final AnimatedSprite bug= new AnimatedSprite(10, 10, 48, 64, this.mBugTextureRegion, this.getVertexBufferObjectManager()){
        @Override
        public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {


            final AnimatedSprite blood= new AnimatedSprite(pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), mBloodTextureRegion, this.getVertexBufferObjectManager());


            //removing bug
            scene.detachChild(this);

            blood.setScale(2);
            blood.animate(100, false);
            scene.attachChild(blood);
            //blood.dispose();
            //this.dispose();
            //this=null;


            if(blood.getCurrentTileIndex() == 6){
                runOnUpdateThread(new Runnable() {
                @Override                
                public void run() {
                    //face.dispose();


                    //scene.unregisterTouchArea(blood);
                    scene.detachChild(blood);


                }
               });                
            }



            return true;
        }
    };





 04-16 21:44:10.440: D/AndEngine(6272): FPS: 57.68 (MIN: 9 ms | MAX: 33 ms)
 04-16 21:44:11.361: I/ActivityManager(194): Starting: Intent {     act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.sonyericsson.home/.HomeActivity } from pid 194
 04-16 21:44:11.371: D/AndEngine(6272): PathModifierExample.onPause @(Thread: 'main')
 04-16 21:44:11.391: D/AndEngine(6272): PathModifierExample.onPauseGame @(Thread: 'main')
 04-16 21:44:11.451: I/WindowManager(194): Setting rotation to 0, animFlags=1
 04-16 21:44:11.451: I/ActivityManager(194): Config changed: { scale=1.0 imsi=410/6 loc=en_US touch=3 keys=1/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=133 themeResource=null}
 04-16 21:44:11.631: W/IInputConnectionWrapper(6272): showStatusIcon on inactive InputConnection
 04-16 21:44:11.822: I/ActivityManager(194): No longer want com.google.android.gm (pid 2712): hidden #16
 04-16 21:44:11.852: W/SurfaceComposerClient(194): Destroying surface while a transaction is open. Client 0x1954c0: destroying surface 135, mTransactionOpen=1
 04-16 21:44:13.944: D/dalvikvm(194): GC_EXPLICIT freed 246K, 44% free 6159K/10887K, external 5271K/6582K, paused 117ms

2 个答案:

答案 0 :(得分:0)

==在以下评论之后编辑== 我认为有条件的陈述

 if(blood.getCurrentTileIndex() == 6){

只是在加入血液后才被召唤一次。如果此时血液不在瓷砖指数6上,它将永远不会被移除。

答案 1 :(得分:0)

好的,我明白了。可能对其他人有帮助。

  final AnimatedSprite bug= new AnimatedSprite(10, 10, 48, 64, this.mBugTextureRegion, this.getVertexBufferObjectManager()){
        @Override
        public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {


            final AnimatedSprite blood= new AnimatedSprite(pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), mBloodTextureRegion, this.getVertexBufferObjectManager());
            //final EngineLock engineLock = this.getEngineLock();
            //engineLock.lock();

            /* Now it is save to remove the entity! */
            scene.detachChild(this);

            scene.attachChild(blood);
            blood.setScale(2);
            blood.animate(100, false , new IAnimationListener (){

                @Override
                public void onAnimationStarted(
                        AnimatedSprite pAnimatedSprite,
                        int pInitialLoopCount) {
                    // TODO Auto-generated method stub


                }

                @Override
                public void onAnimationFrameChanged(
                        AnimatedSprite pAnimatedSprite, int pOldFrameIndex,
                        int pNewFrameIndex) {
                    // TODO Auto-generated method stub


                }

                @Override
                public void onAnimationLoopFinished(
                        AnimatedSprite pAnimatedSprite,
                        int pRemainingLoopCount, int pInitialLoopCount) {
                    // TODO Auto-generated method stub


                }

                @Override
                public void onAnimationFinished(
                        AnimatedSprite pAnimatedSprite) {
                    // TODO Auto-generated method stub
                    runOnUpdateThread(new Runnable() {
                        @Override
                        public void run() {
                            scene.detachChild(blood);
                        }
                });



                }});

            return true;
        }
    };