简体   繁体   English

每当用户的手指不触摸屏幕时,我都想让游戏暂停

[英]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.

相关问题 我想制作一个“暂停/设置”屏幕 - I want to make a Pause/settings screen 让最后一根手指触摸屏幕 - Getting the last finger touching the screen 在 Android 上,当第一根手指从屏幕上松开时,如何判断第二根手指的位置,该手指没有移动但正在触摸屏幕 - On Android, how can I tell the location of a second finger that isn't moving but is touching the screen when the first finger releases from the screen 每当我回到游戏的介绍屏幕时,Java applet就会冻结 - Java applet freezes whenever I go back to intro screen of my game 我正在尝试在播放屏幕(用户在其中玩游戏)的顶部创建一个暂停屏幕 - I am trying to create a pause screen ontop of my playscreen (where the user plays the game) OnTouchEvent:我想在用另一个手指在屏幕上移动时识别触摸 - OnTouchEvent: I want to recognize touches while moving with an another finger on the screen 如何在Android touchlistener中同时检测到触摸屏幕上的次要手指? - how to detect the secondary finger on touching the screen not at same time in android touchlistener? Android:当另一个手指已经触摸屏幕时,是否可以处理点击? - Android: Is it possible to handle a click while another finger is already touching the screen? 我想暂停并恢复我的程序 - I want to pause and resume my program 如何在Screen libgdx中暂停游戏? - How to pause the game in Screen libgdx?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM