0

I'm working on a top down RPG game using LibGDX, and am creating an Ortho.. camera for my game. However in doing so, only my tile textures render now. This is how the render code looks:

Camera initialized as new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

(note that the camera. calls are actually in the world.update method, I just figured I would minimize the amount of code needed on here)

Updating/Rendering:

camera.position.set(getPlayer().getPosition().x, getPlayer().getPosition().y, 0);
camera.update();
batch.setProjectionMatrix(world.getCamera().combined);
batch.begin();
world.render(batch);
batch.end();

the world's render method ends up calling this:

public void render(SpriteBatch batch, float x, float y, float w, float h) {
    batch.draw(region, x, y, w, h);
}

Where region is a TextureRegion

Without the camera, it all works just fine, so I am very confused as to why textures only render in order now (my tile textures are rendered below entities) Does anyone have any idea why this might be? In case you want to see more code, I also have this on my github: CLICK HERE

BossLetsPlays
  • 121
  • 1
  • 14
  • You have a couple methods called on `camera`, but then you set the batch's projection matrix with `world.getCamera`. Are these the same camera? – Tenfour04 Sep 04 '14 at 01:07
  • @Tenfour04 Yes, the `camera.` calls are copied from the `world.update` I just figured I would minimize the code needed to go on here – BossLetsPlays Sep 04 '14 at 02:21

2 Answers2

2

I hadn't realized this later, but I was commenting out a lot of rendering lines, line by line to see if I could find what was wrong, it turns out that my debugging tool I made (which renders collision bounds using a ShapeRenderer) was messing it up because apparently, a ShapeRenderer cannot be used between a batch.begin and a batch.end

I figured this out with the help of this badlogicgames forum post

BossLetsPlays
  • 121
  • 1
  • 14
  • Great tip. I too was using a `ShapeRenderer` for debugging and was wondering why none of the `Sprite`'s were being drawn... – Eric Mar 22 '15 at 15:56
0

Can't get much out of the code but are you using this at the root of the render structure?

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Nine Magics
  • 444
  • 4
  • 3
  • Yes I am, it all worked fine when I was using one spritebatch per texture, but then I read that it could all be done with one so that I could use the camera, so I switched it to use just one batch, and thats how it broke, if that helps? – BossLetsPlays Sep 05 '14 at 22:41