在AndEngine中滚动一个childscene

Fle*_*exo 5 android scroll scene andengine

我有问题滚动我的childscene.我创建了一个CameraScene,我试图用触摸事件滚动.我的childscene不滚动,但是,如果我滚动连接到引擎的相机,父场景滚动正常.

那么如何让我的子场景滚动而没有附加到myparents场景的对象滚动?

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;
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

use*_*833 0

我不太喜欢 AndEngine,我不确定我是否正确解决了你的问题(在你的代码中没有关于“myparents”或“childscene”的内容),但是当某些东西附加到你的场景时,这意味着它会移动用它。您可以将孩子向另一个方向滚动以保持其位置,但从长远来看,这可能会给您带来麻烦。如果可能的话,尝试将滚动场景和对象分开,这意味着它们不应该是彼此的子对象。相反,如果你想让他们保持联系,就给他们一个共同的父母。如果你现在移动一个物体,兄弟姐妹就不会移动。希望有帮助。