LibGDX:Android的SpriteBatch没有图纸图纸、LibGDX、Android、SpriteBatch

2023-09-04 13:41:34 作者:不忘初心、方得始终

我有一个很难得到一个spriteBatch在LibGDX呈现。这表明,当我运行它在桌面上,而不是在Android上。我精灵我想要呈现的是明星的背景。

I'm having a hard time getting a spriteBatch to render in LibGDX. It shows when I run it for the desktop, but not on Android. I sprite I'm trying to render is the star background.

桌面: https://m.xsw88.com/allimgs/daicuo/20230904/8967.png

Android版本: https://m.xsw88.com/allimgs/daicuo/20230904/8968.png

Android: https://m.xsw88.com/allimgs/daicuo/20230904/8968.png

下面是我的code:

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

    update(delta);

    spriteBatchBack.begin();
    sprite.draw(spriteBatchBack);
    spriteBatchBack.end();

    stage.act(delta);
    stage.draw();
}

public void update(float delta) {
    scrollTimer += delta * 0.03f;
    if (scrollTimer > 1.0f)
        scrollTimer = 0.0f;

    sprite.setU(scrollTimer);
    sprite.setU2(scrollTimer + 1);
}

int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();

@Override
public void resize(int width, int height) {
    if (stage == null) {
        stage = new Stage(width, height, true);
        stage.clear();
        addMusic();
        addBackground();
        addScence();
        stage.addActor(play);
        stage.addActor(options);
        stage.addActor(quit);
        stage.addActor(logoHead);
        stage.addActor(lblPlay);
        stage.addActor(lblOptions);
        stage.addActor(lblQuit);
    }
    Gdx.input.setInputProcessor(stage);
}

public void addBackground() {
    spriteBatchBack = new SpriteBatch();
    Texture spriteTexture = new Texture(
            Gdx.files.internal("pictures/menuBackground.png"));

    spriteTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
    sprite = new Sprite(spriteTexture, 0, 0, spriteTexture.getWidth(), spriteTexture.getHeight());
    sprite.setSize(width, height);
}

如果有什么重要的东西,我离开了,评论,让我知道。谢谢!

If there's anything important that I am leaving out, comment and let me know. Thanks!

推荐答案

我发现我的问题。它原来是简单的,我用的手机不支持Open GL 2.0。为了解决这个问题我重新大小我所有的纹理-的电源两种,并更改了配置设置的Open GL 1.1。

I found my problem. It turned out to be simply that the phones I used didn't support Open GL 2.0. To fix this I re-sized all my textures to the power-of-two, and changed the configuration settings to Open GL 1.1.