Java重新启动游戏不起作用(libGDX中的屏幕切换)

时间:2019-02-01 12:17:52

标签: java libgdx screen render

Buttons

在我的GameOverScreen类中,我具有以下方法(呈现“重新启动按钮”并应创建一个新游戏):

@Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0.42f, 0.42f, 0.7f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        game.batch.begin();
        game.batch.draw(AssetManager.gameover,0,0);

        if (Gdx.input.getX() < x + WIDTH + 100 && Gdx.input.getX() > x + 50
                && Gdx.input.getY() < HEIGHT + 150
                && Gdx.input.getY() > HEIGHT + 50)
        {
            game.batch.draw(AssetManager.PlayActive, camera.viewportWidth / 2, camera.viewportHeight - 200, WIDTH, HEIGHT);
            if (Gdx.input.isTouched()){
                game.setScreen(new GameScreen(game));
            }
        } else {
            game.batch.draw(AssetManager.PlayInactive, camera.viewportWidth / 2, camera.viewportHeight - 200, WIDTH, HEIGHT);
        }
}

问题是,当我单击“播放”时,它不会创建新游戏。而是不断地切换屏幕(切换到我之前玩过的游戏以及切换到GameOverScreen。)

我不知道在旧游戏结束后创建新游戏需要更改什么。如果您想查看GameScreen类的代码,请发表评论。我不知道你是否需要它。

这可能与此有关:

public class GameScreen implements Screen {

final FlappyWizardGame game;
OrthographicCamera camera;
private GameWorld world;
private GameRenderer renderer;
private float runTime = 0; 
private float timer = 4.1f;

public GameScreen(FlappyWizardGame game) {
    this.game = game;

    camera = new OrthographicCamera();
    camera.setToOrtho(false, 1280, 720);

    float screenWidth = Gdx.graphics.getWidth();
    float screenHeight = Gdx.graphics.getHeight();
    float gameWidth = 136;
    float gameHeight = screenHeight / (screenWidth / gameWidth);
    int midPointY = (int) (gameHeight / 2);

    Gdx.app.log("GameScreen", "Attached");
    world = new GameWorld(midPointY);
    renderer = new GameRenderer(world, (int) gameHeight, midPointY);

    Gdx.input.setInputProcessor(new InputHandler(world.getWizard()));
}

这里是GameOverScreen

的构造函数
public class GameOverScreen extends GameScreen implements Screen {

protected OrthographicCamera camera;
private String name = "TEST";
private int finalScore = GameWorld.score;
private List<Highscore> highscores;

private TextButton save;
private Stage stage;

private TextField nureintest;

private static final int WIDTH = 280;
private static final int HEIGHT = 80;

private float x = (1600 / 2 -  WIDTH / 2);


public GameOverScreen(FlappyWizardGame game) {
    super(game);
    camera = new OrthographicCamera();
    camera.setToOrtho(false,1280,720);

    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
    // ....
}

1 个答案:

答案 0 :(得分:0)

我忘记将select distinct round(sum(case when year(curdate())=year(billdate) and month(curdate())=month(billdate) then netamount else 0 end)) as MtdAmount, round(sum(case when year(curdate())=year(billdate) then netamount else 0 end)) as YtdAmount from syncbill where cancelled<>'Y' 设置为fuerGameoverScreen

就这么简单。

感谢Morchul。