libGDX - 创建一个阶段,但它不起作用

时间:2014-05-16 03:15:52

标签: java android libgdx

之前我已经在相同的代码中完成了它,但是当我尝试在丢失屏幕中创建一个新阶段时,它只是不起作用。它崩溃,并没有给正常的应用程序名称已停止"消息,并没有给我任何日志。你们能发现问题吗?

package com.divergent.tapdown.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;

public class LoseScreen implements Screen {

private Stage loseStage;
private TextureAtlas atlas;
private Skin loseSkin;
private BitmapFont loseFont;
private TextButton restartButton;
private Table loseTable;


@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);

    loseStage.act();
    loseStage.draw();

}

@Override
public void resize(int width, int height) {

}

@Override
public void show() {

    loseStage = new Stage();

    Gdx.input.setInputProcessor(loseStage);

    atlas = new TextureAtlas("ui/button.pack");
    loseSkin = new Skin(atlas);
    loseFont = new BitmapFont();

    loseTable = new Table(loseSkin);
    loseTable.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    TextButtonStyle restartStyle = new TextButtonStyle();
    restartStyle.up = loseSkin.getDrawable("button.up");
    restartStyle.down = loseSkin.getDrawable("button.down");
    restartStyle.pressedOffsetX = 1;
    restartStyle.pressedOffsetY = -1;
    restartStyle.font = loseFont;
    restartStyle.fontColor = Color.BLACK;

    restartButton = new TextButton("Restart", restartStyle);
    restartButton.pad(20);

    loseTable.add(restartButton);
    loseStage.addActor(loseTable);

}

@Override
public void hide() {

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {

}

}

0 个答案:

没有答案