如何完成“继续”我把它放在 if 语句之后?

发布于 2024-12-16 15:57:10 字数 1301 浏览 2 评论 0原文

我发表了一个声明,如果这是真的,它会继续,我想停止这个“继续”并发表另一个声明,例如达阵和触地。

这是我的代码

private void updateRunning(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    int len = touchEvents.size();

    for (int i = 0; i < len; i++) {
        TouchEvent event = touchEvents.get(i);

        if (event.type != TouchEvent.TOUCH_UP)
            continue;
        world.doodle.DOODLE_Y = 3;
        touchPoint.set(event.x, event.y);
        guiCam.touchToWorld(touchPoint);

        if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
            Assets.clicks();
            state = GAME_PAUSED;
            return;
        }

    }

    world.update(deltaTime, game.getInput().getAccelX());
    if (world.score != lastScore) {
        lastScore = world.score;
        scoreString = "" + lastScore;
    }
    if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
        state = GAME_LEVEL_END;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
        state = GAME_OVER;
        if (lastScore >= Settings.highscores[4])
            scoreString = "new highscore: " + lastScore;
        else
            scoreString = "score: " + lastScore;
        Settings.addScore(lastScore);
        Settings.save(game.getFileIO());
    }
}

I made a statement and if it is true it continues, I want to stop this "continue" and make another statement for example touchdown and touchup.

here is my code

private void updateRunning(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    int len = touchEvents.size();

    for (int i = 0; i < len; i++) {
        TouchEvent event = touchEvents.get(i);

        if (event.type != TouchEvent.TOUCH_UP)
            continue;
        world.doodle.DOODLE_Y = 3;
        touchPoint.set(event.x, event.y);
        guiCam.touchToWorld(touchPoint);

        if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
            Assets.clicks();
            state = GAME_PAUSED;
            return;
        }

    }

    world.update(deltaTime, game.getInput().getAccelX());
    if (world.score != lastScore) {
        lastScore = world.score;
        scoreString = "" + lastScore;
    }
    if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
        state = GAME_LEVEL_END;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
        state = GAME_OVER;
        if (lastScore >= Settings.highscores[4])
            scoreString = "new highscore: " + lastScore;
        else
            scoreString = "score: " + lastScore;
        Settings.addScore(lastScore);
        Settings.save(game.getFileIO());
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再浓的妆也掩不了殇 2024-12-23 15:57:10

对你所问的问题有点困惑,但也许是一个else if

if (event.type == TouchEvent.TOUCH_UP) {
    /* do something for TOUCH_UP event */
} else if (event.type == TouchEvent.TOUCH_DOWN) {
    /* do something for TOUCH_DOWN event */
} else {
    /* do something else */
}

执行后,您无法停止继续

Little confused by what you are asking, but perhaps an else if?

if (event.type == TouchEvent.TOUCH_UP) {
    /* do something for TOUCH_UP event */
} else if (event.type == TouchEvent.TOUCH_DOWN) {
    /* do something for TOUCH_DOWN event */
} else {
    /* do something else */
}

You can't stop a continue after you execute it.

゛清羽墨安 2024-12-23 15:57:10

尝试在您希望其停止的位置添加 break;

Try adding break; where you want it to stop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文