正如我所说,我想让我的游戏只在用户触摸屏幕时运行。到目前为止,我有:
public boolean onTouchEvent(MotionEvent e) {
// Get finger's X and Y position
float x = e.getX();
float y = e.getY();
if(x > startPlaying.left || x < startPlaying.right && y < startPlaying.bottom && y > startPlaying.top) {
Playing = true;
}
if (Playing == true) {
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
playerX = x;
playerY = y;
case MotionEvent.ACTION_UP:
Playing = false;
}
}
return true;
}
我认为这两个案例不能一起工作的问题但是我不太确定,我是java的新手。有任何建议或修正吗?
@Override protected void onDraw(Canvas canvas) {
if (Playing == true) {
rowSpeed = -2;
rowSpeed -= 0.0002f;
scoreCounter += 0.005;
} else {
rowSpeed = 0;
rowSpeed -= 0f;
scoreCounter += 0;
}
答案 0 :(得分:0)
执行switch语句的常规方法是
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
playerX = x;
playerY = y;
break; // any reason you do not want this?
case MotionEvent.ACTION_UP:
Playing = false;
}