Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This is a small basic tool for the game. I want small box that reside on one of the corner of the scene. In which I want to show preview of whole game scene.

I have read all the thing and try as much as possible to get the thing done. I use SingleSceneSplitScreenEngine for this purpose. Following is my code snippet.

public class TwoCameraView extends BaseGameActivity implements
            IOnSceneTouchListener {

    private static int CAMERA_WIDTH = 1024;
    private static int CAMERA_HEIGHT = 600;

    private Camera mCamera, mChasingCamera;
    private CameraScene mParentScene;

    private TextureRegion loadingRegion;

    @Override
    public Engine onLoadEngine() {
            mCamera = new Camera(0f, 0f, CAMERA_WIDTH, CAMERA_HEIGHT);
            mChasingCamera = new BoundCamera(0, 0, 100f, 100f, 0, CAMERA_WIDTH, 0,
                            CAMERA_HEIGHT);
            final EngineOptions engineOptions = new EngineOptions(true,
                            ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(
                                            CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
            engineOptions.getTouchOptions().setRunOnUpdateThread(true);
            return new SingleSceneSplitScreenEngine(engineOptions, mChasingCamera);
    }

    private TextureRegion loadTextureRegion(int width, int height, String name) {
            BitmapTextureAtlas BitmapTextureAtlas = new BitmapTextureAtlas(width,
                            height, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
            TextureRegion textureRegion = BitmapTextureAtlasTextureRegionFactory
                            .createFromAsset(BitmapTextureAtlas, this, name, 0, 0);
            getTextureManager().loadTextures(BitmapTextureAtlas);
            return textureRegion;
    }

    @Override
    public void onLoadResources() {
            loadingRegion = loadTextureRegion(1024, 1024, "loading.png");
    }

    @Override
    public Scene onLoadScene() {
            mParentScene = new CameraScene(mCamera);
            mParentScene.attachChild(new Sprite(0f, 0f, loadingRegion.deepCopy()));
            mParentScene.setOnSceneTouchListener(this);
            return mParentScene;
    }

    @Override
    public void onLoadComplete() {
    }

    @Override
    public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
            if (pSceneTouchEvent.isActionMove()) {
                    mChasingCamera.setCenter(pSceneTouchEvent.getX(),
                                    pSceneTouchEvent.getY());
                    return true;
            }
            return false;
    }

}

I have modify the SingleSceneSplitScreenEngine of AndEngine library as per the following.

public class SingleSceneSplitScreenEngine extends Engine {

    private final Camera mSecondCamera;

    public SingleSceneSplitScreenEngine(final EngineOptions pEngineOptions,
                    final Camera pSecondCamera) {
            super(pEngineOptions);
            this.mSecondCamera = pSecondCamera;
    }

    @Deprecated
    @Override
    public Camera getCamera() {
            return super.mCamera;
    }

    public Camera getFirstCamera() {
            return super.mCamera;
    }

    public Camera getSecondCamera() {
            return this.mSecondCamera;
    }

    @Override
    protected void onDrawScene(final GL10 pGL) {
            final Camera firstCamera = this.getFirstCamera();
            final Camera secondCamera = this.getSecondCamera();

            final int surfaceWidth = this.mSurfaceWidth;
            final int surfaceWidthHalf = surfaceWidth >> 1;

            final int surfaceHeight = this.mSurfaceHeight;
            GLHelper.enableScissorTest(pGL);

            /*
             * First Screen. With first camera, on the left half of the screens
             * width.
             */
            {
                    pGL.glScissor(0, 0, surfaceWidth, surfaceHeight);
                    pGL.glViewport(0, 0, surfaceWidth, surfaceHeight);

                    super.mScene.onDraw(pGL, firstCamera);
                    firstCamera.onDrawHUD(pGL);
            }

            /*
             * Second Screen. With second camera, on the right half of the screens
             * width.
             */
            {
                    pGL.glScissor(surfaceWidth - surfaceWidthHalf / 3, surfaceHeight
                                    - surfaceHeight / 3, surfaceWidthHalf / 3,
                                    surfaceHeight / 3);
                    pGL.glViewport(surfaceWidth - surfaceWidthHalf / 3, surfaceHeight
                                    - surfaceHeight / 3, surfaceWidthHalf / 3,
                                    surfaceHeight / 3);

                    super.mScene.onDraw(pGL, secondCamera);
                    secondCamera.onDrawHUD(pGL);
            }

            GLHelper.disableScissorTest(pGL);
    }

    @Override
    protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
            if (pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
                    return this.getFirstCamera();
            } else {
                    return this.getSecondCamera();
            }
    }

    @Override
    protected void convertSurfaceToSceneTouchEvent(final Camera pCamera,
                    final TouchEvent pSurfaceTouchEvent) {
            final int surfaceWidthHalf = this.mSurfaceWidth >> 1;

            if (pCamera == this.getFirstCamera()) {
                    pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent,
                                    this.mSurfaceWidth, this.mSurfaceHeight);
            } else {
                    pSurfaceTouchEvent.offset(-surfaceWidthHalf / 3,
                                    this.mSurfaceHeight / 3);
                    pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent,
                                    surfaceWidthHalf / 3, this.mSurfaceHeight / 3);
            }
    }

    @Override
    protected void updateUpdateHandlers(final float pSecondsElapsed) {
            super.updateUpdateHandlers(pSecondsElapsed);
            this.getSecondCamera().onUpdate(pSecondsElapsed);
    }

    @Override
    protected void onUpdateCameraSurface() {
            final int surfaceWidth = this.mSurfaceWidth;
            final int surfaceWidthHalf = surfaceWidth >> 1;

            this.getFirstCamera().setSurfaceSize(0, 0, surfaceWidthHalf,
                            this.mSurfaceHeight);
            this.getSecondCamera().setSurfaceSize(surfaceWidthHalf, 0,
                            surfaceWidthHalf, this.mSurfaceHeight);
    }
}

Using above method I can able to create corner window view that simulate whole view as I move my finger on the device. As I use split screen engine, it only handle half part of the screen. On next half part finger movement, does not occur any change in window view. Parent scene background show on full screen not half one. if you need more detail then I can provide you.

I got above suggestion from the following post. Two Camera View

If you have enough time then please run this code then only you get better understand my problem. Thanks in advance for your time and efforts.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I have solved this problem and share answer on the following post so other user can take benefit from it.

public class TwoCameraView extends BaseGameActivity implements
            IOnSceneTouchListener {

    private static int CAMERA_WIDTH = 1024;
    private static int CAMERA_HEIGHT = 600;

    private Camera mCamera, mChasingCamera;
    private CameraScene mParentScene;

    private TextureRegion loadingRegion, magnifyCircleRegion;

    @Override
    public Engine onLoadEngine() {
            mCamera = new Camera(0f, 0f, CAMERA_WIDTH, CAMERA_HEIGHT);
            mChasingCamera = new BoundCamera(0, 0, 125f, 125f, 0, CAMERA_WIDTH, 0,
                            CAMERA_HEIGHT);
            final EngineOptions engineOptions = new EngineOptions(true,
                            ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(
                                            CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
            engineOptions.getTouchOptions().setRunOnUpdateThread(true);
            return new SingleSceneSplitScreenEngine(engineOptions, mChasingCamera);
    }

    private TextureRegion loadTextureRegion(int width, int height, String name) {
            BitmapTextureAtlas BitmapTextureAtlas = new BitmapTextureAtlas(width,
                            height, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
            TextureRegion textureRegion = BitmapTextureAtlasTextureRegionFactory
                            .createFromAsset(BitmapTextureAtlas, this, name, 0, 0);
            getTextureManager().loadTextures(BitmapTextureAtlas);
            return textureRegion;
    }

    @Override
    public void onLoadResources() {
            loadingRegion = loadTextureRegion(1024, 1024, "loading.png");
            magnifyCircleRegion = loadTextureRegion(256, 256, "magnifycircle.png");
    }

    @Override
    public Scene onLoadScene() {
            mParentScene = new CameraScene(mCamera);
            mParentScene.attachChild(new Sprite(0f, 0f, loadingRegion.deepCopy()));

            float pX = CAMERA_WIDTH - magnifyCircleRegion.getWidth() * 2f;

            HUD hud = new HUD();
            hud.attachChild(new Sprite(-magnifyCircleRegion.getWidth() * 0.115f,
                            -magnifyCircleRegion.getHeight() * 0.1f, magnifyCircleRegion
                                            .deepCopy()));
            mChasingCamera.setHUD(hud);
            mParentScene.setOnSceneTouchListener(this);
            return mParentScene;
    }

    @Override
    public void onLoadComplete() {
    }

    @Override
    public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
            if (pSceneTouchEvent.isActionMove()) {
                    mChasingCamera.setCenter(pSceneTouchEvent.getX(),
                                    pSceneTouchEvent.getY());
                    return true;
            }
            return false;
    }

}


public class SingleSceneSplitScreenEngine extends Engine {

    private final Camera mSecondCamera;

    public SingleSceneSplitScreenEngine(final EngineOptions pEngineOptions,
                    final Camera pSecondCamera) {
            super(pEngineOptions);
            this.mSecondCamera = pSecondCamera;
    }

    @Deprecated
    @Override
    public Camera getCamera() {
            return super.mCamera;
    }

    public Camera getFirstCamera() {
            return super.mCamera;
    }

    public Camera getSecondCamera() {
            return this.mSecondCamera;
    }


    @Override
    protected void onDrawScene(final GL10 pGL) {
            final Camera firstCamera = this.getFirstCamera();
            final Camera secondCamera = this.getSecondCamera();

            final int surfaceWidth = this.mSurfaceWidth;
            final int surfaceWidthHalf = surfaceWidth >> 1;

            final int surfaceHeight = this.mSurfaceHeight;
            GLHelper.enableScissorTest(pGL);

            /*
             * First Screen. With first camera, on the left half of the screens
             * width.
             */
            {
                    pGL.glScissor(0, 0, surfaceWidth, surfaceHeight);
                    pGL.glViewport(0, 0, surfaceWidth, surfaceHeight);

                    super.mScene.onDraw(pGL, firstCamera);
                    firstCamera.onDrawHUD(pGL);
            }

            /*
             * Second Screen. With second camera, on the right half of the screens
             * width.
             */
            {

                    pGL.glScissor(surfaceWidth - surfaceWidthHalf / 3, surfaceHeight
                                    - surfaceHeight / 3, surfaceWidthHalf / 3,
                                    surfaceHeight / 3);
                    pGL.glViewport(surfaceWidth - surfaceWidthHalf / 3, surfaceHeight
                                    - surfaceHeight / 3, surfaceWidthHalf / 3,
                                    surfaceHeight / 3);

                    super.mScene.onDraw(pGL, secondCamera);
                    secondCamera.onDrawHUD(pGL);
            }

            GLHelper.disableScissorTest(pGL);
    }

    @Override
    protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
            if (pTouchEvent.getX() <= this.mSurfaceWidth) {                 
                    return this.getFirstCamera();
            } else {
                    return this.getSecondCamera();
            }
    }

    @Override
    protected void convertSurfaceToSceneTouchEvent(final Camera pCamera,
                    final TouchEvent pSurfaceTouchEvent) {
            final int surfaceWidthHalf = this.mSurfaceWidth >> 1;

            if (pCamera == this.getFirstCamera()) {
                    pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent,
                                    this.mSurfaceWidth, this.mSurfaceHeight);
            } else {
                    pSurfaceTouchEvent.offset(-surfaceWidthHalf, 0);
                    pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent,
                                    this.mSurfaceHeight - this.mSurfaceHeight / 3,
                                    this.mSurfaceHeight / 3);
            }
    }

    @Override
    protected void updateUpdateHandlers(final float pSecondsElapsed) {
            super.updateUpdateHandlers(pSecondsElapsed);
            this.getSecondCamera().onUpdate(pSecondsElapsed);
    }

    @Override
    protected void onUpdateCameraSurface() {
            final int surfaceWidth = this.mSurfaceWidth;
            final int surfaceWidthHalf = surfaceWidth >> 1;

            this.getFirstCamera().setSurfaceSize(0, 0, surfaceWidthHalf,
                            this.mSurfaceHeight);
            this.getSecondCamera().setSurfaceSize(surfaceWidthHalf, 0,
                            surfaceWidthHalf, this.mSurfaceHeight);
    }
}
share|improve this answer
    
Link-only answers are frowned upon. Say the link goes dead (like right now, I can't load it, no response from server), the answer becomes useless. Please edit your answer and provide at least an overview of the answer inline. –  Sean Middleditch Jun 4 '13 at 17:22
    
Thanks I post full answer of my question. –  Siddharth Jun 4 '13 at 17:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.