org.andengine.engine.camera.Camera Java Examples

The following examples show how to use org.andengine.engine.camera.Camera. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BatchedPseudoSpriteParticleSystem.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
	this.mSpriteBatch.setIndex(0);

	final Particle<Entity>[] particles = this.mParticles;
	for (int i = this.mParticlesAlive - 1; i >= 0; i--) {
		final Entity entity = particles[i].getEntity();

		/* In order to support alpha changes of the sprites inside the spritebatch,
		 * we have to 'premultiply' the RGB channels of the sprite with its alpha channel. */
		final float alpha = entity.getAlpha();
		final float colorABGRPackedInt = ColorUtils.convertRGBAToABGRPackedFloat(entity.getRed() * alpha, entity.getGreen() * alpha, entity.getBlue() * alpha, alpha);

		this.mSpriteBatch.drawWithoutChecks(this.mTextureRegion, entity, colorABGRPackedInt);
	}
	this.mSpriteBatch.submit();

	this.mSpriteBatch.onDraw(pGLState, pCamera);
}
 
Example #2
Source File: SingleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
	if (super.mScene != null) {
		final Camera secondCamera = this.getSecondCamera();

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

		final int surfaceHeight = this.mSurfaceHeight;

		pGLState.enableScissorTest();

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

			super.mScene.onDraw(pGLState, pFirstCamera);
			pFirstCamera.onDrawHUD(pGLState);
		}

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

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

		pGLState.disableScissorTest();
	}
}
 
Example #3
Source File: BlendFunctionParticleSystem.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	if (this.mBlendingEnabled) {
		pGLState.enableBlend();
		pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
	}
}
 
Example #4
Source File: Engine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(final TouchEvent pSurfaceTouchEvent) {
	/* Let the engine determine which scene and camera this event should be handled by. */
	final Scene scene = this.getSceneFromSurfaceTouchEvent(pSurfaceTouchEvent);
	final Camera camera = this.getCameraFromSurfaceTouchEvent(pSurfaceTouchEvent);

	this.convertSurfaceTouchEventToSceneTouchEvent(camera, pSurfaceTouchEvent);

	if (this.onTouchHUD(camera, pSurfaceTouchEvent)) {
		return true;
	} else {
		/* If HUD didn't handle it, Scene may handle it. */
		return this.onTouchScene(scene, pSurfaceTouchEvent);
	}
}
 
Example #5
Source File: Engine.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
protected boolean onTouchHUD(final Camera pCamera, final TouchEvent pSceneTouchEvent) {
	if(pCamera.hasHUD()) {
		return pCamera.getHUD().onSceneTouchEvent(pSceneTouchEvent);
	} else {
		return false;
	}
}
 
Example #6
Source File: SpriteBatch.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void postDraw(final GLState pGLState, final Camera pCamera) {
	this.mSpriteBatchVertexBufferObject.unbind(pGLState, this.mShaderProgram);

	if(this.mBlendingEnabled) {
		pGLState.disableBlend();
	}

	super.postDraw(pGLState, pCamera);
}
 
Example #7
Source File: ScreenGrabber.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
	if(this.mScreenGrabPending) {
		try {
			final Bitmap screenGrab = ScreenGrabber.grab(this.mGrabX, this.mGrabY, this.mGrabWidth, this.mGrabHeight);

			this.mScreenGrabCallback.onScreenGrabbed(screenGrab);
		} catch (final Exception e) {
			this.mScreenGrabCallback.onScreenGrabFailed(e);
		}

		this.mScreenGrabPending = false;
	}
}
 
Example #8
Source File: Sprite.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	this.getTextureRegion().getTexture().bind(pGLState);

	this.mSpriteVertexBufferObject.bind(pGLState, this.mShaderProgram);
}
 
Example #9
Source File: DrawHandlerList.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(final GLState pGLState, final Camera pCamera) {
	final int handlerCount = this.size();
	for(int i = handlerCount - 1; i >= 0; i--) {
		this.get(i).onDraw(pGLState, pCamera);
	}
}
 
Example #10
Source File: Engine.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void onDrawScene(final GLState pGLState, final Camera pCamera) {
	if (this.mScene != null) {
		this.mScene.onDraw(pGLState, pCamera);
	}

	pCamera.onDrawHUD(pGLState);
}
 
Example #11
Source File: SingleSceneSplitScreenEngine.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
	if(pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
		return this.getFirstCamera();
	} else {
		return this.getSecondCamera();
	}
}
 
Example #12
Source File: DoubleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void convertSurfaceTouchEventToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
	final int surfaceWidthHalf = this.mSurfaceWidth >> 1;

	if (pCamera == this.getFirstCamera()) {
		pCamera.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
	} else {
		pSurfaceTouchEvent.offset(-surfaceWidthHalf, 0);
		pCamera.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
	}
}
 
Example #13
Source File: SpriteBatch.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void postDraw(final GLState pGLState, final Camera pCamera) {
	this.mSpriteBatchVertexBufferObject.unbind(pGLState, this.mShaderProgram);

	if (this.mBlendingEnabled) {
		pGLState.disableBlend();
	}

	super.postDraw(pGLState, pCamera);
}
 
Example #14
Source File: SpriteBatch.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	if (this.mBlendingEnabled) {
		pGLState.enableBlend();
		pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
	}

	this.mTexture.bind(pGLState);

	this.mSpriteBatchVertexBufferObject.bind(pGLState, this.mShaderProgram);
}
 
Example #15
Source File: Engine.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected boolean onTouchHUD(final Camera pCamera, final TouchEvent pSceneTouchEvent) {
	if (pCamera.hasHUD()) {
		return pCamera.getHUD().onSceneTouchEvent(pSceneTouchEvent);
	} else {
		return false;
	}
}
 
Example #16
Source File: ParallaxBackground.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(final GLState pGLState, final Camera pCamera) {
	super.onDraw(pGLState, pCamera);

	final float parallaxValue = this.mParallaxValue;
	final ArrayList<ParallaxEntity> parallaxEntities = this.mParallaxEntities;

	for(int i = 0; i < this.mParallaxEntityCount; i++) {
		parallaxEntities.get(i).onDraw(pGLState, pCamera, parallaxValue);
	}
}
 
Example #17
Source File: FlipGameActivity.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public EngineOptions onCreateEngineOptions() {
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= 17) {
        getWindowManager().getDefaultDisplay().getRealSize(size);
    } else {
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        size.x = displayMetrics.widthPixels;
        size.y = displayMetrics.heightPixels;
    }

    float desiredRatio = (float) (1080.0 / 1920.0);
    final float realRatio = size.x / size.y;

    int measuredWidth;
    int measuredHeight;
    if (realRatio < desiredRatio) {
        measuredWidth = size.x;
        measuredHeight = Math.round(measuredWidth / desiredRatio);
    } else {
        measuredHeight = size.y;
        measuredWidth = Math.round(measuredHeight * desiredRatio);
    }

    _scale = measuredWidth / 1080.0f;

    _cameraWidth = measuredWidth;
    _cameraHeight = measuredHeight;

    return new EngineOptions(
            true,
            ScreenOrientation.PORTRAIT_FIXED,
            new RatioResolutionPolicy(1080, 1920),
            new Camera(0, 0, _cameraWidth, _cameraHeight));
}
 
Example #18
Source File: RectangularShapeCollisionChecker.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private static void fillVertices(final Camera pCamera, final float[] pVertices) {
	pVertices[0 + Constants.VERTEX_INDEX_X] = pCamera.getXMin();
	pVertices[0 + Constants.VERTEX_INDEX_Y] = pCamera.getYMin();

	pVertices[2 + Constants.VERTEX_INDEX_X] = pCamera.getXMax();
	pVertices[2 + Constants.VERTEX_INDEX_Y] = pCamera.getYMin();

	pVertices[4 + Constants.VERTEX_INDEX_X] = pCamera.getXMax();
	pVertices[4 + Constants.VERTEX_INDEX_Y] = pCamera.getYMax();

	pVertices[6 + Constants.VERTEX_INDEX_X] = pCamera.getXMin();
	pVertices[6 + Constants.VERTEX_INDEX_Y] = pCamera.getYMax();

	MathUtils.rotateAroundCenter(pVertices, pCamera.getRotation(), pCamera.getCenterX(), pCamera.getCenterY());
}
 
Example #19
Source File: SpriteBatch.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
	super.preDraw(pGLState, pCamera);

	if(this.mBlendingEnabled) {
		pGLState.enableBlend();
		pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
	}

	this.mTexture.bind(pGLState);

	this.mSpriteBatchVertexBufferObject.bind(pGLState, this.mShaderProgram);
}
 
Example #20
Source File: DoubleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
	final Camera secondCamera = this.getSecondCamera();

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

	final int surfaceHeight = this.mSurfaceHeight;

	pGLState.enableScissorTest();

	/* First Screen. With first camera, on the left half of the screens width. */
	if (super.mScene != null) {
		GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
		GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);

		super.mScene.onDraw(pGLState, pFirstCamera);
		pFirstCamera.onDrawHUD(pGLState);
	}

	/* Second Screen. With second camera, on the right half of the screens width. */
	if (this.mSecondScene != null) {
		GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
		GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);

		this.mSecondScene.onDraw(pGLState, secondCamera);
		secondCamera.onDrawHUD(pGLState);
	}

	pGLState.disableScissorTest();
}
 
Example #21
Source File: Background.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void onDraw(final GLState pGLState, final Camera pCamera) {
	if (this.mColorEnabled) {
		GLES20.glClearColor(this.mColor.getRed(), this.mColor.getGreen(), this.mColor.getBlue(), this.mColor.getAlpha());
		GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // TODO Does this cause problems when multisampling?
	}
}
 
Example #22
Source File: DoubleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
	if (pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
		return this.getFirstCamera();
	} else {
		return this.getSecondCamera();
	}
}
 
Example #23
Source File: SpriteBatch.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void draw(final GLState pGLState, final Camera pCamera) {
	this.begin();

	this.mSpriteBatchVertexBufferObject.draw(GLES20.GL_TRIANGLES, this.mVertices);

	this.end();
}
 
Example #24
Source File: GameActivity.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public EngineOptions onCreateEngineOptions() {

    camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED,
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    engineOptions.getAudioOptions().setNeedsMusic(true);

    return engineOptions;
}
 
Example #25
Source File: SpriteBatch.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void draw(final GLState pGLState, final Camera pCamera) {
	this.begin();

	this.mSpriteBatchVertexBufferObject.draw(GLES20.GL_TRIANGLES, this.mVertices);

	this.end();
}
 
Example #26
Source File: Sprite.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
protected void postDraw(final GLState pGLState, final Camera pCamera) {
	this.mSpriteVertexBufferObject.unbind(pGLState, this.mShaderProgram);

	super.postDraw(pGLState, pCamera);
}
 
Example #27
Source File: Entity.java    From tilt-game-android with MIT License 4 votes vote down vote up
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
	pGLState.pushModelViewGLMatrix();
	{
		this.onApplyTransformations(pGLState);

		final SmartList<IEntity> children = this.mChildren;
		if ((children == null) || !this.mChildrenVisible) {
			/* Draw only self. */
			this.preDraw(pGLState, pCamera);
			this.draw(pGLState, pCamera);
			this.postDraw(pGLState, pCamera);
		} else {
			if (this.mChildrenSortPending) {
				ZIndexSorter.getInstance().sort(this.mChildren);
				this.mChildrenSortPending = false;
			}

			final int childCount = children.size();
			int i = 0;

			{ /* Draw children behind this Entity. */
				for (; i < childCount; i++) {
					final IEntity child = children.get(i);
					if (child.getZIndex() < 0) {
						child.onDraw(pGLState, pCamera);
					} else {
						break;
					}
				}
			}

			/* Draw self. */
			this.preDraw(pGLState, pCamera);
			this.draw(pGLState, pCamera);
			this.postDraw(pGLState, pCamera);

			{ /* Draw children in front of this Entity. */
				for (; i < childCount; i++) {
					children.get(i).onDraw(pGLState, pCamera);
				}
			}
		}
	}
	pGLState.popModelViewGLMatrix();
}
 
Example #28
Source File: Text.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
protected void postDraw(final GLState pGLState, final Camera pCamera) {
	this.mTextVertexBufferObject.unbind(pGLState, this.mShaderProgram);

	super.postDraw(pGLState, pCamera);
}
 
Example #29
Source File: SingleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 4 votes vote down vote up
public Camera getSecondCamera() {
	return this.mSecondCamera;
}
 
Example #30
Source File: Scene.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
protected void onApplyMatrix(final GLState pGLState, final Camera pCamera) {
	pCamera.onApplySceneMatrix(pGLState);
}