5

I have a problem scrolling my childscene. I have created a CameraScene which i am trying to scroll with a touch event. My childscene is not scrolling, however, if i scroll on the camera attached to the engine the parent scene scrolls fine.

So how do i get my child scene to scroll without the objects attached to myparents scene scrolls along?

public StatsScene(Context context, VertexBufferObjectManager vbo) {
    super(new SmoothCamera(0, 0, WITDH, HEIGHT, 0, SPEEDY, 0));

    this.setOnSceneTouchListener(new IOnSceneTouchListener() {
        @Override
        public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
            if(pSceneTouchEvent.getAction() == MotionEvent.ACTION_DOWN) {
                mTouchY = pSceneTouchEvent.getMotionEvent().getY();
            }
            else if(pSceneTouchEvent.getAction() == MotionEvent.ACTION_MOVE) {
                float newY = pSceneTouchEvent.getMotionEvent().getY();

                mTouchOffsetY = (newY - mTouchY);

                float newScrollX = getCamera().getCenterX();
                float newScrollY = getCamera().getCenterY() - mTouchOffsetY;

                getCamera().setCenter(newScrollX, newScrollY);

                mTouchY = newY;
            }
            return true;
        }
    });
}
Flexo
  • 2,506
  • 3
  • 21
  • 32

2 Answers2

0

I'm not really into AndEngine and I'm not sure if I get your problem right (in your code is nothing about "myparents" or "childscene"), but when something is attached to your scene, then this implies it will move with it. You could scroll your children in the other direction to maintain their position, but that could get you into trouble in the longterm. If it is possible, try to seperate your scrolling scene and your objects, meaning, that they shouldn't be children of each other. Instead, if you want them to keep them related, give them a common parent. If you move one object now, the siblings won't. Hope that helps.

user1841833
  • 141
  • 1
  • 1
  • 3
0

From your description I would think that your parent scene is the one getting your the input so I'm guessing, please correct me if I'm wrong, that you are setting your child scene something like this:

mMainScene.attachChild(mChildScene);

In this case you will have to deal with deviating the input to the child instead of the parent. However, you have a few options here:

  1. If your child scene occupies full screen and you don't need to worry about updating/drawing your parent scene, simply swap scenes with

    mEngine.setScene(mChildScene);

  2. If you do need to keep drawing and updating your parent scene check the MenuScene pre-made class and Scene.setChildScene() method, there is one example on how using this in the AndengineExamples project I think. Using this class will let you take the input on the child scene but still drawing and updating your main scene, it even let's you set your child in a modal way.

Oscar Rene
  • 361
  • 2
  • 6