AndEngine unregisterTouchArea(this) throws outOfBoundException

when i try to unregister touch area by touching it, it throws me an exception.

here is my code:

        Rectangle a = new Rectangle(500, 500, 200, 200, getVertexBufferObjectManager()){
        @Override
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
                float pTouchAreaLocalX, float pTouchAreaLocalY) {
            // TODO Auto-generated method stub
            if(pSceneTouchEvent.isActionUp()){
                System.out.println("bum");
                TestScene.this.unregisterTouchArea(this);
            }
            return super
                    .onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
        }
    };

    this.attachChild(a);
    this.registerTouchArea(a);

And here is the exception that it throws me:

02-02 16:05:52.241: W/dalvikvm(28930): threadid=11: thread exiting with uncaught exception (group=0x415bcba8)
02-02 16:05:52.241: E/AndroidRuntime(28930): FATAL EXCEPTION: UpdateThread
02-02 16:05:52.241: E/AndroidRuntime(28930): Process: com.example.testing, PID: 28930
02-02 16:05:52.241: E/AndroidRuntime(28930): java.lang.IndexOutOfBoundsException:     Invalid index 1, size is 1
02-02 16:05:52.241: E/AndroidRuntime(28930):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at java.util.ArrayList.get(ArrayList.java:308)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.entity.scene.Scene.onSceneTouchEvent(Scene.java:354)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.engine.Engine.onTouchScene(Engine.java:454)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.engine.Engine.onTouchEvent(Engine.java:440)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.input.touch.controller.BaseTouchController$TouchEventRunnablePoolItem.run(BaseTouchController.java:102)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at     org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:54)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.util.adt.pool.RunnablePoolUpdateHandler.onHandlePoolItem(RunnablePoolUpdateHandler.java:1)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.util.adt.pool.PoolUpdateHandler.onUpdate(PoolUpdateHandler.java:88)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.input.touch.controller.BaseTouchController.onUpdate(BaseTouchController.java:62)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.engine.Engine.onUpdate(Engine.java:588)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.engine.Engine.onTickUpdate(Engine.java:552)
02-02 16:05:52.241: E/AndroidRuntime(28930):    at org.andengine.engine.Engine$UpdateThread.run(Engine.java:842)

i am using andEngine anchorcenter. Does somebody know how to fix it? Thanks

Answers


boolean isTouchRegister = true;
Rectangle a = new Rectangle(500, 500, 200, 200, getVertexBufferObjectManager()){
        @Override
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
                float pTouchAreaLocalX, float pTouchAreaLocalY) {
            // TODO Auto-generated method stub
            if(pSceneTouchEvent.isActionUp() && isTouchRegister){
                System.out.println("bum");
           //     TestScene.this.unregisterTouchArea(this);
                  isTouchRegister = false
            }
            return isTouchRegister;
        }
    };

this.attachChild(a);
this.registerTouchArea(a);

Need Your Help

http url input parameters

http url

Is this a valid http url

How to start a Node.js app on system boot?

node.js raspbian init.d

I'm working on a Raspberry Pi running Raspbian running a Node.js app and trying to get it to start when the Pi boots. I found a couple of examples but I can't seem to get it working. My current c...