Game Development Reference
In-Depth Information
X2 = e.getX(1);
Y2 = e.getY(1);
DX2 = X2 - p2X;
}
// 1 or 2 up
if (action == MotionEvent.ACTION_UP
|| action == MotionEvent.ACTION_POINTER_2_UP) {
if (fingers == 1) {
// Swipe
setRotationSpeed(DX1);
} else if (fingers == 2) {
// Pinching
setPinch(DX1, DX2);
}
p1X = p1Y = p2X = p2Y = DX1 = DX2 = 0f;
fingers = 0;
}
return super.onTouchEvent(e);
}
// Pinch: Set Zoom
private void setPinch(float DX1, float DX2) {
// Pinch inwards: zoom in
if (DX1 > 0 && DX2 < 0) {
width *= 0.6;
height *= 0.8;
view.setVideoSize(width, height);
} else {
// Pinch outwards: zoom out
width *= 1.4;
height *= 1.2;
view.setVideoSize(width, height);
}
}
// Swipe Left/right: Set rotation speed
// 0-50 left, 50-100 right
private void setRotationSpeed(float DX) {
if (DX < 0) {
speed -= 20;
} else {
speed += 20;
}
// clamp 0-100
if (speed < 0)
speed = 0;
if (speed > 100)
speed = 100;
view.setRotationSpeed(speed);
}
Search WWH ::




Custom Search