I'm trying to build a simple game where TileMapRenderer renders a labyrinth, a ball moves in it and camera follows it. I'm currently having the following bug:



For some reason, the game renders the world incorrectly. The gamescreen is cleared with the following method:

private void clearScreen() {
    Gdx.gl.glClearColor(1, 0, 0, 1);

Which is basically red, and the camera seems to show it incorrectly while moving.

Camera movement method:

public void moveCamera() {
            player.body.getPosition().y, 0);

    // LEFT
    if(GameInfo.camera.position.x < GameInfo.WINDOW_WIDTH / 2){
        GameInfo.camera.position.x = GameInfo.WINDOW_WIDTH / 2;

    // UP
    if(GameInfo.camera.position.y > GameInfo.WORLD_HEIGHT_PIXELS / 100.0f - GameInfo.WINDOW_HEIGHT / 2) {
        GameInfo.camera.position.y = GameInfo.WORLD_HEIGHT_PIXELS / 100.0f - GameInfo.WINDOW_HEIGHT / 2;

    // DOWN
    if(GameInfo.camera.position.y < GameInfo.WINDOW_HEIGHT / 2) {
        GameInfo.camera.position.y = GameInfo.WINDOW_HEIGHT / 2;

    // RIGHT
    if(GameInfo.camera.position.x > GameInfo.WORLD_WIDTH_PIXELS / 100.0f - GameInfo.WINDOW_WIDTH / 2f) {
        GameInfo.camera.position.x = GameInfo.WORLD_WIDTH_PIXELS / 100.0f - GameInfo.WINDOW_WIDTH / 2f;

As you can see, I'm using Box2D physics for the ball.

Setting up the camera:

public static OrthographicCamera camera = new OrthographicCamera();

public static void setCamera() {
    camera.setToOrtho(false, 8.0f, 4.5f);

Rendering method:

public void render () {
            player.body.getPosition().x - player.radius,
            player.body.getPosition().y - player.radius,
            player.radius,                   // originX
            player.radius,                   // originY
            player.radius * 2,               // width
            player.radius * 2,               // height
            1.0f,                          // scaleX
            1.0f,                          // scaleY
            player.body.getTransform().getRotation() * MathUtils.radiansToDegrees,
            0,                             // Start drawing from x = 0
            0,                             // Start drawing from y = 0
            player.texture.getWidth(),       // End drawing x
            player.texture.getHeight(),      // End drawing y
            false,                         // flipX
            false);                        // flipY
    Game.world.step(1/60f, 8, 3);

It's not only while moving either. As soon as the game starts, the red block is visible like seen in the first picture.

Also the red blocks seem to always be coming from left and down, never from up or right...

What could be wrong in here?



For some reason, Tiled (the software I did the TiledMap with) was bugging out. I had a background layer below everything and I had just painted it with a brush with a light blue texture. I deleted the background layer and used the bucket fill tool instead, saved it and it started working right away.

So for some reason according to Tiled, everything was painted properly. But as soon as the TiledMapRenderer started rendering it, the clear screen started overrunning some parts.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.