[英]I want to make my game pause whenever the users finger is not touching the screen
As I said, I would like to make my game only run when the user is touching the screen. 正如我所说,我想让我的游戏仅在用户触摸屏幕时运行。 So far I have: 到目前为止,我有:
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;
}
Im thinking theres a problem with the 2 cases not being able to work together but im not really sure, im new to java. 我认为这2种情况无法一起工作,但我不确定,这是Java的新问题。 Any suggestions or fixes? 有什么建议或解决方法吗?
@Override protected void onDraw(Canvas canvas) {
if (Playing == true) {
rowSpeed = -2;
rowSpeed -= 0.0002f;
scoreCounter += 0.005;
} else {
rowSpeed = 0;
rowSpeed -= 0f;
scoreCounter += 0;
}
The normal way to do a switch statement is 进行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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.