org.andengine.input.touch.TouchEvent Java Examples

The following examples show how to use org.andengine.input.touch.TouchEvent. 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: Camera.java    From tilt-game-android with MIT License 6 votes vote down vote up
public void convertSceneTouchEventToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	this.convertAxisAlignedSceneToSurfaceTouchEvent(pSceneTouchEvent, pSurfaceWidth, pSurfaceHeight);

	final float rotation = this.mRotation;
	if (rotation == 0) {
		/* Nothing. */
	} else if (rotation == 180) {
		pSceneTouchEvent.setY(pSurfaceHeight - pSceneTouchEvent.getY());
		pSceneTouchEvent.setX(pSurfaceWidth - pSceneTouchEvent.getX());
	} else {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, -rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}
}
 
Example #2
Source File: Camera.java    From tilt-game-android with MIT License 6 votes vote down vote up
public void convertSurfaceTouchEventToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float relativeX;
	final float relativeY;

	final float surfaceTouchEventX = pSurfaceTouchEvent.getX();
	final float surfaceTouchEventY = pSurfaceTouchEvent.getY();

	final float rotation = this.mRotation;
	if (rotation == 0) {
		relativeX = surfaceTouchEventX / pSurfaceWidth;
		relativeY = 1 - (surfaceTouchEventY / pSurfaceHeight);
	} else if (rotation == 180) {
		relativeX = 1 - (surfaceTouchEventX / pSurfaceWidth);
		relativeY = surfaceTouchEventY / pSurfaceHeight;
	} else {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = surfaceTouchEventX;
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = surfaceTouchEventY;

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!

		relativeX = Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
		relativeY = 1 - (Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] / pSurfaceHeight);
	}

	this.convertAxisAlignedSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, relativeX, relativeY);
}
 
Example #3
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public void convertSurfaceToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float relativeX;
	final float relativeY;

	final float surfaceTouchEventX = pSurfaceTouchEvent.getX();
	final float surfaceTouchEventY = pSurfaceTouchEvent.getY();

	final float rotation = this.mRotation;
	if(rotation == 0) {
		relativeX = surfaceTouchEventX / pSurfaceWidth;
		relativeY = surfaceTouchEventY / pSurfaceHeight;
	} else if(rotation == 180) {
		relativeX = 1 - (surfaceTouchEventX / pSurfaceWidth);
		relativeY = 1 - (surfaceTouchEventY / pSurfaceHeight);
	} else {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = surfaceTouchEventX;
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = surfaceTouchEventY;

		MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1);

		relativeX = Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
		relativeY = Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] / pSurfaceHeight;
	}

	this.convertAxisAlignedSurfaceToSceneTouchEvent(pSurfaceTouchEvent, relativeX, relativeY);
}
 
Example #4
Source File: LevelModeCompleteScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
LevelModeCompleteScene() {

        Text levelCompleteTextShape = new Text((float) (camera.getWidth() * 0.05), (float) (camera.getHeight() * 0.05),
                resourcesManager.levelModeCompleteFont, "Level Mode\nCompleted", vbom);
        levelCompleteTextShape.setScaleCenter(0, 0);
        attachChild(levelCompleteTextShape);

        Sprite cup = new Sprite(0, 0, resourcesManager.levelModeCup, vbom);
        cup.setPosition(camera.getWidth() / 2 - cup.getWidth() / 2, camera.getHeight() * 0.4f);
        attachChild(cup);
        attachChild(new ConfettiParticleSystem(vbom, camera.getWidth()));
        setOnSceneTouchListener(new IOnSceneTouchListener() {

                @Override
                public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {

                    onBackKeyPressed();

                    return false;
                }
            });
    }
 
Example #5
Source File: CameraScene.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
	if (this.mCamera == null) {
		return false;
	} else {
		this.mCamera.convertSceneTouchEventToCameraSceneTouchEvent(pSceneTouchEvent);

		final boolean handled = super.onSceneTouchEvent(pSceneTouchEvent);

		if (handled) {
			return true;
		} else {
			this.mCamera.convertCameraSceneTouchEventToSceneTouchEvent(pSceneTouchEvent);
			return false;
		}
	}
}
 
Example #6
Source File: CameraScene.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
	if(this.mCamera == null) {
		return false;
	} else {
		this.mCamera.convertSceneToCameraSceneTouchEvent(pSceneTouchEvent);

		final boolean handled = super.onSceneTouchEvent(pSceneTouchEvent);

		if(handled) {
			return true;
		} else {
			this.mCamera.convertCameraSceneToSceneTouchEvent(pSceneTouchEvent);
			return false;
		}
	}
}
 
Example #7
Source File: HoldDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void triggerOnHoldStarted() {
	this.mTriggering = true;

	if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
		this.mHoldDetectorListener.onHoldStarted(this, this.mPointerID, this.mHoldX, this.mHoldY);
	}
}
 
Example #8
Source File: HoldDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void prepareHold(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();
	this.mDownTimeMilliseconds = System.currentTimeMillis();
	this.mDownX = motionEvent.getX();
	this.mDownY = motionEvent.getY();
	this.mMaximumDistanceExceeded = false;
	this.mPointerID = pSceneTouchEvent.getPointerID();
	this.mHoldX = pSceneTouchEvent.getX();
	this.mHoldY = pSceneTouchEvent.getY();

	if (this.mTriggerHoldMinimumMilliseconds == 0) {
		this.triggerOnHoldStarted();
	}
}
 
Example #9
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 #10
Source File: ScrollDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void triggerOnScrollFinished(final float pDistanceX, final float pDistanceY) {
	this.mTriggering = false;

	if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
		this.mScrollDetectorListener.onScrollFinished(this, this.mPointerID, pDistanceX, pDistanceY);
	}
}
 
Example #11
Source File: MenuScene.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
	if(this.mSelectedMenuItem != null) {
		this.mSelectedMenuItem.onUnselected();
		this.mSelectedMenuItem = null;
	}
	return false;
}
 
Example #12
Source File: SingleSceneSplitScreenEngine.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void convertSurfaceToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
	final int surfaceWidthHalf = this.mSurfaceWidth >> 1;

	if(pCamera == this.getFirstCamera()) {
		pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
	} else {
		pSurfaceTouchEvent.offset(-surfaceWidthHalf, 0);
		pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
	}
}
 
Example #13
Source File: HoldDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void triggerOnHoldFinished(final long pHoldTimeMilliseconds) {
	this.mTriggering = false;

	if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
		this.mHoldDetectorListener.onHoldFinished(this, pHoldTimeMilliseconds, this.mPointerID, this.mHoldX, this.mHoldY);
	}
}
 
Example #14
Source File: DoubleSceneSplitScreenEngine.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 #15
Source File: BaseTouchController.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void onRecycle() {
	super.onRecycle();
	final TouchEvent touchEvent = this.mTouchEvent;
	touchEvent.getMotionEvent().recycle();
	touchEvent.recycle();
}
 
Example #16
Source File: ScrollDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void triggerOnScrollFinished(final float pDistanceX, final float pDistanceY) {
	this.mTriggering = false;
	
	if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
		this.mScrollDetectorListener.onScrollFinished(this, this.mPointerID, pDistanceX, pDistanceY);
	}
}
 
Example #17
Source File: BaseOnScreenControl.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
	final int pointerID = pSceneTouchEvent.getPointerID();

	switch(pSceneTouchEvent.getAction()) {
		case MotionEvent.ACTION_DOWN:
			if(this.mActivePointerID == INVALID_POINTER_ID) {
				this.mActivePointerID = pointerID;
				this.updateControlKnob(pTouchAreaLocalX, pTouchAreaLocalY);
				return true;
			}
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL:
			if(this.mActivePointerID == pointerID) {
				this.mActivePointerID = INVALID_POINTER_ID;
				this.onHandleControlKnobReleased();
				return true;
			}
			break;
		default:
			if(this.mActivePointerID == pointerID) {
				this.updateControlKnob(pTouchAreaLocalX, pTouchAreaLocalY);
				return true;
			}
			break;
	}
	return true;
}
 
Example #18
Source File: HoldDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * When {@link #isHolding()} this method will call through to {@link IHoldDetectorListener#onHoldFinished(HoldDetector, long, int, float, float).
 */
@Override
public void reset() {
	if (this.mTriggering) {
		this.triggerOnHoldFinished(System.currentTimeMillis() - this.mDownTimeMilliseconds);
	}

	this.mTriggering = false;
	this.mMaximumDistanceExceeded = false;
	this.mDownTimeMilliseconds = Long.MIN_VALUE;
	this.mPointerID = TouchEvent.INVALID_POINTER_ID;
}
 
Example #19
Source File: ZoomCamera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void applySceneToCameraSceneOffset(final TouchEvent pSceneTouchEvent) {
	final float zoomFactor = this.mZoomFactor;
	if(zoomFactor != 1) {
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
		Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();

		MathUtils.scaleAroundCenter(Camera.VERTICES_TMP, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!

		pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
	}

	super.applySceneToCameraSceneOffset(pSceneTouchEvent);
}
 
Example #20
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 #21
Source File: DoubleSceneSplitScreenEngine.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected Scene getSceneFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
	if (pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
		return this.getFirstScene();
	} else {
		return this.getSecondScene();
	}
}
 
Example #22
Source File: Scene.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private Boolean onAreaTouchEvent(final TouchEvent pSceneTouchEvent, final float sceneTouchEventX, final float sceneTouchEventY, final ITouchArea touchArea) {
	final float[] touchAreaLocalCoordinates = touchArea.convertSceneToLocalCoordinates(sceneTouchEventX, sceneTouchEventY);
	final float touchAreaLocalX = touchAreaLocalCoordinates[Constants.VERTEX_INDEX_X];
	final float touchAreaLocalY = touchAreaLocalCoordinates[Constants.VERTEX_INDEX_Y];

	final boolean handledSelf = touchArea.onAreaTouched(pSceneTouchEvent, touchAreaLocalX, touchAreaLocalY);
	if(handledSelf) {
		return Boolean.TRUE;
	} else if(this.mOnAreaTouchListener != null) {
		return this.mOnAreaTouchListener.onAreaTouched(pSceneTouchEvent, touchArea, touchAreaLocalX, touchAreaLocalY);
	} else {
		return null;
	}
}
 
Example #23
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 #24
Source File: SingleSceneSplitScreenEngine.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 #25
Source File: Engine.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected boolean onTouchScene(final Scene pScene, final TouchEvent pSceneTouchEvent) {
	if (pScene != null) {
		return pScene.onSceneTouchEvent(pSceneTouchEvent);
	} else {
		return false;
	}
}
 
Example #26
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 #27
Source File: HoldDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
protected void prepareHold(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();
	this.mDownTimeMilliseconds = System.currentTimeMillis();
	this.mDownX = motionEvent.getX();
	this.mDownY = motionEvent.getY();
	this.mMaximumDistanceExceeded = false;
	this.mPointerID = pSceneTouchEvent.getPointerID();
	this.mHoldX = pSceneTouchEvent.getX();
	this.mHoldY = pSceneTouchEvent.getY();

	if(this.mTriggerHoldMinimumMilliseconds == 0) {
		this.triggerOnHoldStarted();
	}
}
 
Example #28
Source File: Camera.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void convertAxisAlignedSceneToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float xMin = this.getXMin();
	final float xMax = this.getXMax();
	final float yMin = this.getYMin();
	final float yMax = this.getYMax();

	final float relativeX = (pSceneTouchEvent.getX() - xMin) / (xMax - xMin);
	final float relativeY = 1 - (pSceneTouchEvent.getY() - yMin) / (yMax - yMin);

	final float x = relativeX * pSurfaceWidth;
	final float y = relativeY * pSurfaceHeight;

	pSceneTouchEvent.set(x, y);
}
 
Example #29
Source File: BaseTouchController.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onRecycle() {
	super.onRecycle();
	final TouchEvent touchEvent = this.mTouchEvent;
	touchEvent.getMotionEvent().recycle();
	touchEvent.recycle();
}
 
Example #30
Source File: Camera.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void convertAxisAlignedSceneToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
	final float xMin = this.getXMin();
	final float xMax = this.getXMax();
	final float yMin = this.getYMin();
	final float yMax = this.getYMax();

	final float relativeX = (pSceneTouchEvent.getX() - xMin) / (xMax - xMin);
	final float relativeY = (pSceneTouchEvent.getY() - yMin) / (yMax - yMin);

	pSceneTouchEvent.set(relativeX * pSurfaceWidth, relativeY * pSurfaceHeight);
}