Java Code Examples for org.andengine.input.touch.TouchEvent#getPointerID()

The following examples show how to use org.andengine.input.touch.TouchEvent#getPointerID() . 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: BaseOnScreenControl.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
	final int pointerID = pSceneTouchEvent.getPointerID();
	if (pointerID == this.mActivePointerID) {
		this.onHandleControlBaseLeft();

		switch (pSceneTouchEvent.getAction()) {
			case MotionEvent.ACTION_UP:
			case MotionEvent.ACTION_CANCEL:
				this.mActivePointerID = BaseOnScreenControl.INVALID_POINTER_ID;
		}
	}
	return false;
}
 
Example 2
Source File: BaseOnScreenControl.java    From tilt-game-android with MIT License 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 == BaseOnScreenControl.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 = BaseOnScreenControl.INVALID_POINTER_ID;
				this.onHandleControlKnobReleased();
				return true;
			}
			break;
		default:
			if (this.mActivePointerID == pointerID) {
				this.updateControlKnob(pTouchAreaLocalX, pTouchAreaLocalY);
				return true;
			}
			break;
	}
	return true;
}
 
Example 3
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 4
Source File: ClickDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	switch (pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			this.prepareClick(pSceneTouchEvent);
			return true;
		case TouchEvent.ACTION_MOVE:
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				final long moveTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();
				if (moveTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
					return true;
				}
			}
			return false;
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				final long upTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();

				boolean handled;
				if (upTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
					this.mDownTimeMilliseconds = Long.MIN_VALUE;
					this.mClickDetectorListener.onClick(this, this.mPointerID, pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
					handled = true;
				} else {
					handled = false;
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;

				return handled;
			} else {
				return false;
			}
		default:
			return false;
	}
}
 
Example 5
Source File: BaseOnScreenControl.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) {
	final int pointerID = pSceneTouchEvent.getPointerID();
	if(pointerID == this.mActivePointerID) {
		this.onHandleControlBaseLeft();

		switch(pSceneTouchEvent.getAction()) {
			case MotionEvent.ACTION_UP:
			case MotionEvent.ACTION_CANCEL:
				this.mActivePointerID = INVALID_POINTER_ID;
		}
	}
	return false;
}
 
Example 6
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 7
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 8
Source File: ClickDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	switch(pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			this.prepareClick(pSceneTouchEvent);
			return true;
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
			if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
				boolean handled = false;
				final long upTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();

				if(upTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
					this.mDownTimeMilliseconds = Long.MIN_VALUE;
					this.mClickDetectorListener.onClick(this, pSceneTouchEvent.getPointerID(), pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
					handled = true;
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;
				return handled;
			} else {
				return false;
			}
		default:
			return false;
	}
}
 
Example 9
Source File: ContinuousHoldDetector.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();

	switch (pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			if (this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
				this.prepareHold(pSceneTouchEvent);
				return true;
			} else {
				return false;
			}
		case TouchEvent.ACTION_MOVE:
		{
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > this.mTriggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > this.mTriggerHoldMaximumDistance;
				return true;
			} else {
				return false;
			}
		}
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
		{
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				if (this.mTriggering) {
					this.triggerOnHoldFinished(motionEvent.getEventTime() - this.mDownTimeMilliseconds);
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;
				return true;
			} else {
				return false;
			}
		}
		default:
			return false;
	}
}
 
Example 10
Source File: ClickDetector.java    From tilt-game-android with MIT License 4 votes vote down vote up
private void prepareClick(final TouchEvent pSceneTouchEvent) {
	this.mDownTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getDownTime();
	this.mPointerID = pSceneTouchEvent.getPointerID();
}
 
Example 11
Source File: ContinuousHoldDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();

	switch(pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			if(this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
				this.prepareHold(pSceneTouchEvent);
				return true;
			} else {
				return false;
			}
		case TouchEvent.ACTION_MOVE:
		{
			if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > this.mTriggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > this.mTriggerHoldMaximumDistance;
				return true;
			} else {
				return false;
			}
		}
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
		{
			if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				if(this.mTriggering) {
					this.triggerOnHoldFinished(motionEvent.getEventTime() - this.mDownTimeMilliseconds);
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;
				return true;
			} else {
				return false;
			}
		}
		default:
			return false;
	}
}
 
Example 12
Source File: ClickDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
private void prepareClick(final TouchEvent pSceneTouchEvent) {
	this.mDownTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getDownTime();
	this.mPointerID = pSceneTouchEvent.getPointerID();
}