How do I set a touch listener in a child scene in AndEngine?

Posted by Siddharth on Game Development See other posts from Game Development or by Siddharth
Published on 2012-06-15T14:10:58Z Indexed on 2012/06/15 15:28 UTC
Read the original article Hit count: 486

Filed under:

In my game, I want to implement touch listener for my child scene objects. Basically I tried all the possible way to implement this that I have usually done for my normal scenes, but those methods do not work here. Could somebody provide some guidance for setting touch area listener in child scene?

Here is my code:

    menuScene.setTouchAreaBindingEnabled(true);

    menuScene.registerTouchArea(resumeButtonSprite);
    menuScene.registerTouchArea(retryButtonSprite);
    menuScene.registerTouchArea(exitButtonSprite);

    menuScene.setOnAreaTouchListener(new IOnAreaTouchListener() {

        @Override
        public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
                ITouchArea pTouchArea, float pTouchAreaLocalX,
                float pTouchAreaLocalY) {
            System.out.println("Touch");
            return true;
        }
    });

In this code, menuScene was a child scene activity.

Also after research I found that my engine was stopped while the child scene was activated so the touch event is not detected. I want to implement a pause menu in my game so any desirable solution for a pause menu implementation would help.

© Game Development or respective owner

Related posts about andengine