Back to project page ssniper-andengine.
The source code is released under:
Apache License
If you think the Android project ssniper-andengine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.cladophora.ssniper; /*from w ww .ja va 2 s . com*/ import android.opengl.GLES20; import org.andengine.engine.Engine; import org.andengine.engine.camera.Camera; import org.andengine.engine.options.EngineOptions; import org.andengine.input.touch.TouchEvent; import org.andengine.opengl.util.GLState; public class ScopeEngine extends Engine { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== private final Camera mSecondCamera; private int scopeSize = 400; // =========================================================== // Constructors // =========================================================== public ScopeEngine(final EngineOptions pEngineOptions, final Camera pSecondCamera) { super(pEngineOptions); this.mSecondCamera = pSecondCamera; int height = (int) pSecondCamera.getHeight(); switch(height) { case 800: scopeSize = 400; break; case 1080: scopeSize = 500; break; case 1600: scopeSize = 600; break; default: scopeSize = 400; break; } } // =========================================================== // Getter & Setter // =========================================================== @Deprecated @Override public Camera getCamera() { return super.mCamera; } public Camera getFirstCamera() { return super.mCamera; } public Camera getSecondCamera() { return this.mSecondCamera; } // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onDrawScene(final GLState pGLState, final Camera pCamera) { if(super.mScene != null) { final Camera secondCamera = this.getSecondCamera(); final int surfaceWidth = this.mSurfaceWidth; final int surfaceHeight = this.mSurfaceHeight; final int glY = (this.mSurfaceHeight - scopeSize); pGLState.enableScissorTest(); /* First Screen. With first camera, on the left half of the screens width. */ { GLES20.glScissor(0, 0, surfaceWidth, surfaceHeight); GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); super.mScene.onDraw(pGLState, pCamera); pCamera.onDrawHUD(pGLState); } /* Second Screen. With second camera, on the right half of the screens width. */ { GLES20.glScissor(0, glY, scopeSize, scopeSize); GLES20.glViewport(0, glY, scopeSize, scopeSize); super.mScene.onDraw(pGLState, secondCamera); secondCamera.onDrawHUD(pGLState); } pGLState.disableScissorTest(); } } @Override protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) { return this.getFirstCamera(); } @Override protected void convertSurfaceToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) { pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight); } @Override protected void onUpdateUpdateHandlers(final float pSecondsElapsed) { super.onUpdateUpdateHandlers(pSecondsElapsed); this.getSecondCamera().onUpdate(pSecondsElapsed); } @Override protected void onUpdateCameraSurface() { final int surfaceWidth = this.mSurfaceWidth; final int scopeSize = 400; this.getFirstCamera().setSurfaceSize(0, 0, surfaceWidth, this.mSurfaceHeight); this.getSecondCamera().setSurfaceSize(0, 0, scopeSize, scopeSize); } // =========================================================== // Methods // =========================================================== // =========================================================== // Inner and Anonymous Classes // =========================================================== }