本文共 5658 字,大约阅读时间需要 18 分钟。
public boolean onTouchEvent(MotionEvent e) { act_Main.onKeyNum = 0; float x = e.getX(); float y = e.getY(); switch (e.getAction()) { case MotionEvent.ACTION_DOWN: if (isScreenSaver) { stopAll(); } else { if (!colorEdgeFlag2 && 100 < x && x < SCREEN_WIDTH * 0.84f - SCREEN_WIDTH / 16 * 1.2f && SCREEN_HEIGHT / 12 < y && y < SCREEN_HEIGHT * 11 / 12) { act_Main.playSound(0, 0); screenClick.setCoor1(x, y); elementIndex = screenClick.getElementIndex(); currStart = 0; if (count == 1) { colorEdgeFlag1 = !colorEdgeFlag1; colorEdgeFlag2 = false; } else { if (colorEdgeFlag1) { screenClick.setCoor2(x, y); saveIndex[0] = screenClick.getElementIndex(); colorEdgeFlag2 = true; moveFlag = true; } else { colorEdgeFlag1 = true; colorEdgeFlag2 = false; } } } if (colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { if (hasInertia) { hasInertia = false; curr_angle_speed = 0; } } if (UtilConfigArea.isInArea(x, y, AREA_BUTTON_HELP)) { rightHelpFlag = true; } if (UtilConfigArea.isInArea(x, y, AREA_CONDITION1) && ballSecondMove) { conditionFlag = true; addFlag = true; if (!cubeList.isEmpty()) { cubeList.clear(); } for (int i = 0; i < CUBE_NUM; i++) { double angle = new Random().nextFloat() * 360; tcTempaa = new DW_CubeTexture(CUBE_HALFSIZE, boxShape, dynamicsWorld, 1, 0.15f * (float) Math.sin(Math.toDegrees(angle)), (new Random().nextFloat() + 0.5f) * 1.0f, 0.15f * (float) Math.cos(Math.toDegrees(angle)), ShaderManager.getOnlyTextureShaderProgram()); synchronized (iCubeList) { iCubeList.add(tcTempaa); } } } if (UtilConfigArea.isInArea(x, y, AREA_CONDITION2) && ballSecondMove) { conditionFlag = false; } if (UtilConfigArea.isInArea(x, y, AREA_UPHELP) && ballFisrtMove) { secondMoveFlag = true; } if (UtilConfigArea.isInArea(x, y, AREA_RETURN) && (conditionIndex == 0 || conditionIndex == 1)) { stopAll(); } if (UtilConfigArea.isInArea(x, y, AREA_RIGHT_UP_HELP) && rightHelpFlag) { TIME_SAPN_FLAG = TIME_SAPN_FLAG == 0 ? 1 : 0; switch (TIME_SAPN_FLAG) { case 0: TIME_SPAN = 200f; Toast.makeText(act_Main, "屏保时间间隔为:200秒", Toast.LENGTH_LONG).show(); break; case 1: TIME_SPAN = 3f; Toast.makeText(act_Main, "屏保时间间隔为:3秒", Toast.LENGTH_LONG).show(); break; } } } break; case MotionEvent.ACTION_MOVE: float dx = x - mPreviousX; float dy = y - mPreviousY; if (colorEdgeFlag1 && UtilConfigArea.isInArea(x, y, AREA_CONTENT)) { currStart -= dy * TOUCH_SCALE_FACTOR * 0.005f; } if (colorEdgeFlag1 && !colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { drawElectronCloud.roateX += dy * TOUCH_SCALE_FACTOR; drawElectronCloud.roateY += dx * TOUCH_SCALE_FACTOR; } if (colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { switch (compoundIndex - 2) { case 0: if (Math.abs(dy) > 8) { isTouchMoved = true; curr_angle_speed = ori_angle_speed * (dy / SCREEN_WIDTH); } cp_Salt.roateX += dy * TOUCH_SCALE_FACTOR; cp_Salt.roateY += dx * TOUCH_SCALE_FACTOR; break; case 1: cp_Water.roateX += dy * TOUCH_SCALE_FACTOR; cp_Water.roateY += dx * TOUCH_SCALE_FACTOR; } } break; case MotionEvent.ACTION_UP: timeCount = 0; if (act_Main.bgMusic[0].isPlaying()) { act_Main.bgMusic[0].pause(); } break; } if (colorEdgeFlag2 && UtilConfigArea.isInArea(x, y, AREA_3DVIEW)) { if (isTouchMoved) { isTouchMoved = false; hasInertia = true; curr_acceleratedSpeed = ori_acceleratedSpeed; if (curr_angle_speed > 0) { curr_acceleratedSpeed = -ori_acceleratedSpeed; } } else { auto_adjust = true; } } mPreviousX = x; mPreviousY = y; return true;} 以上代码经过重新组织和优化,主要做了以下工作:
代码内容主要涉及触摸事件处理,包括按下、移动和释放等状态的响应逻辑。代码中涉及的主要功能包括声音播放、区域检测、立方体创建以及一些动画逻辑的处理。
转载地址:http://tasfk.baihongyu.com/