Java LibGDX加载屏幕不工作

Java LibGDX加载屏幕不工作,java,libgdx,Java,Libgdx,我用java编写了一段代码,用于我的LibGDX游戏的加载屏幕: public class LoadingScreen extends AbstractScreen { private Stage stage; private Image logo; private Image loadingFrame; private Image loadingBarHidden; private Image screenBg; private Image

我用java编写了一段代码,用于我的LibGDX游戏的加载屏幕:

public class LoadingScreen extends AbstractScreen {

    private Stage stage;

    private Image logo;
    private Image loadingFrame;
    private Image loadingBarHidden;
    private Image screenBg;
    private Image loadingBg;

    private float startX, endX;
    private float percent;

    private Actor loadingBar;

    public LoadingScreen(BloodyMess game) {
        super(game);
    }

    @Override
    public void show() {
        System.out.println("3");

        Constants c = new Constants();
        // Tell the manager to load assets for the loading screen
        game.manager.load("data/loading.pack", TextureAtlas.class);
        // Wait until they are finished loading
        game.manager.finishLoading();

        // Initialize the stage where we will place everything
        stage = new Stage();

        // Get our textureatlas from the manager
        TextureAtlas atlas = game.manager.get("data/loading.pack", TextureAtlas.class);

        // Grab the regions from the atlas and create some images
        logo = new Image(atlas.findRegion("libgdx-logo"));
        loadingFrame = new Image(atlas.findRegion("loading-frame"));
        loadingBarHidden = new Image(atlas.findRegion("loading-bar-hidden"));
        screenBg = new Image(atlas.findRegion("screen-bg"));
        loadingBg = new Image(atlas.findRegion("loading-frame-bg"));

        // Add the loading bar animation
        Animation anim = new Animation(0.05f, atlas.findRegions("loading-bar-anim"));
        anim.setPlayMode(PlayMode.LOOP_REVERSED);
        loadingBar = new LoadingBar(anim);

        // Or if you only need a static bar, you can do
        // loadingBar = new Image(atlas.findRegion("loading-bar1"));

        // Add all the actors to the stage
        stage.addActor(screenBg);
        stage.addActor(loadingBar);
        stage.addActor(loadingBg);
        stage.addActor(loadingBarHidden);
        stage.addActor(loadingFrame);
        stage.addActor(logo);

        // Add everything to be loaded
        System.out.println("6");
        c.guy_1_face = new Texture(Gdx.files.internal("guy_1_face.png"));
    }

    @Override
    public void resize(int width, int height) {
        // Set our screen to always be XXX x 480 in size
        width = 480 * width / height;
        height = 480;
        stage.getViewport().update(width, height, false);

        // Make the background fill the screen
        screenBg.setSize(width, height);

        // Place the logo in the middle of the screen and 100 px up
        logo.setX((width - logo.getWidth()) / 2);
        logo.setY((height - logo.getHeight()) / 2 + 100);

        // Place the loading frame in the middle of the screen
        loadingFrame.setX((stage.getWidth() - loadingFrame.getWidth()) / 2);
        loadingFrame.setY((stage.getHeight() - loadingFrame.getHeight()) / 2);

        // Place the loading bar at the same spot as the frame, adjusted a few
        // px
        loadingBar.setX(loadingFrame.getX() + 15);
        loadingBar.setY(loadingFrame.getY() + 5);

        // Place the image that will hide the bar on top of the bar, adjusted a
        // few px
        loadingBarHidden.setX(loadingBar.getX() + 35);
        loadingBarHidden.setY(loadingBar.getY() - 3);
        // The start position and how far to move the hidden loading bar
        startX = loadingBarHidden.getX();
        endX = 440;

        // The rest of the hidden bar
        loadingBg.setSize(450, 50);
        loadingBg.setX(loadingBarHidden.getX() + 30);
        loadingBg.setY(loadingBarHidden.getY() + 3);
    }

    @Override
    public void render(float delta) {
        // Clear the screen
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        System.out.println("5");
        if (game.manager.update()) { // Load some, will return true if done
                                        // loading
            System.out.println("4");
            game.setScreen(new MainMenu(game));

        }

        // Interpolate the percentage to make it more smooth
        percent = Interpolation.linear.apply(percent, game.manager.getProgress(), 0.1f);

        // Update positions (and size) to match the percentage
        loadingBarHidden.setX(startX + endX * percent);
        loadingBg.setX(loadingBarHidden.getX() + 30);
        loadingBg.setWidth(450 - 450 * percent);
        loadingBg.invalidate();

        System.out.println("2");

        // Show the loading screen
        stage.act();
        stage.draw();
    }

    @Override
    public void hide() {
        // Dispose the loading assets as we no longer need them
        game.manager.unload("data/loading.pack");
    }
}
问题是它没有运行主菜单屏幕,正如您所看到的,我在控制台中有一些带有数字的调试代码,它只输出3,然后是6,但没有其他输出。有人能告诉我为什么它没有加载我的主菜单屏幕或运行代码中的任何其他内容吗?仅供参考,我没有写太多这样的东西,我是从这里得到的:

编辑:我的所有值都在一个名为常量的文件中,所有内容都从那里加载。如果你需要更多的信息,我会编辑操作

非常感谢


卢克

从评论中可以看出,你在
BloodyMess

@Override 
public void render() { }
内部渲染方法放置

super.render();
当您需要调用super类的render方法来处理抽象屏幕的render方法时,这将开始工作


我希望这能有所帮助:)

如评论中所示,您在
血案中有

@Override 
public void render() { }
内部渲染方法放置

super.render();
当您需要调用super类的render方法来处理抽象屏幕的render方法时,这将开始工作


我希望这能有所帮助:)

而且我对LibGDX非常陌生,所以我真的很想听到建设性的批评。我猜你没有将活动屏幕设置为加载屏幕。”3'和6'仅在加载屏幕构造器中打印。我看不出你的比赛的切入点。它可能是你创建LoadingScreen实例的地方。@williammerrison我有这样一个:
game.setScreen(新主菜单(游戏))正确,但您需要将加载屏幕设置为其他地方的主屏幕,以便LIBGDX的游戏类可以调用加载屏幕的
render
方法。在某个地方,你有代码将加载屏幕设置为游戏屏幕,对吗?类似于
setScreen(新加载屏幕(游戏))
@williamorrison是的,
公共类BloodyMess扩展游戏{public AssetManager=new AssetManager();@Override public void create(){setScreen(new LoadingScreen(this));}@Override public void render(){}
另外,我是LibGDX的新手,所以我真的很想听到建设性的批评。我猜你没有将活动屏幕设置为加载屏幕。”3'和6'仅在加载屏幕构造器中打印。我看不出你的比赛的切入点。它可能是你创建LoadingScreen实例的地方。@williammerrison我有这样一个:
game.setScreen(新主菜单(游戏))正确,但您需要将加载屏幕设置为其他地方的主屏幕,以便LIBGDX的游戏类可以调用加载屏幕的
render
方法。在某个地方,你有代码将加载屏幕设置为游戏屏幕,对吗?类似于
setScreen(新加载屏幕(游戏))
@williamorrison是的,
public class BloodyMess扩展游戏{public AssetManager manager=new AssetManager();@Override public void create(){setScreen(new LoadingScreen(this));}@Override public void render(){}
谢谢!!我真的是个新手,哈哈哈!!我对这个很陌生,哈哈