0

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

在虫子精灵的 onAreaTouched 中,我将血精灵附在其中。一切正常,但动画后我没有从中删除血精灵。

注意:我也检查过 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
4

2 回答 2

0

==在下面的评论之后编辑==我认为条件语句

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

只被调用一次,就在加血之后。如果血液当时不在瓷砖索引 6 上,它将永远不会被移除。

于 2013-04-16T16:41:14.587 回答
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;
        }
    };
于 2013-04-16T19:35:28.770 回答