1

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.

Desktop: https://i.stack.imgur.com/6a4m5.png

Android: https://i.stack.imgur.com/mOvo2.png

Here's my 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!

Chance Leachman
  • 207
  • 4
  • 17
  • 1
    Switching Id and asking the same question wouldn't get you a good answer. [Your other post](http://stackoverflow.com/questions/13997962/libgdx-android-spritebatch-not-drawing) – wtsang02 Dec 21 '12 at 23:13

2 Answers2

3

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.

Chance Leachman
  • 207
  • 4
  • 17
0

try to use "Image" actor as background in stage instead of using spritebatch and drawing yourself.

Aliaaa
  • 1,590
  • 2
  • 16
  • 37
  • That did not work either :(. It does the same thing as above. – Chance Leachman Dec 29 '12 at 21:29
  • check your assets folder to be shared properly on both projects. check your game projects are configured. it's better to use gdx-setup tool to make your game projects. – Aliaaa Dec 30 '12 at 09:24