1

There is an awful flickering that happens occasionally on my screen from top to bottom. It only happens when the camera moves around (which follows my player character). It does not matter where I am on the map for this to happen. If I stop moving at the right moment, the lines will remain visible until I start moving again. I've added a screenshot so you can see what it looks like:

Flickering

If you look closely, you might notice that the lines represent a part of my "mountain wall" tile (That tile is used a little bit lower in the map):

Mountain Wall

I've tried putting the cam.update() in the beginning of the update() method, as some other people on StackOverflow have suggested, but that doesn't seem to work. I have also made sure that there is absolutely no space in between tiles in the tileset image. Most questions I see about this issue experience a different kind of flickering than I am.

Here is the code of my screen and all the rendering that happens:

    public PlayScreen(MyGame game){
        cam = new OrthographicCamera();
        batch = new SpriteBatch();
        gameMap = new TestMap(startMap);
        player = new Player(this);

        Gdx.input.setInputProcessor(this);
    }

    public void update(float delta){
        player.update(delta);

        Rectangle playerRect = player.getNextRectangle(delta);
        Rectangle teleportRect = gameMap.teleportTo(playerRect);

        if(!gameMap.isColliding(playerRect)){
            player.setPosition(playerRect);
        }
        if(teleportRect != null){
            player.setPosition(teleportRect);
        }

        cam.viewportHeight = Gdx.graphics.getHeight() / zoomLevel;
        cam.viewportWidth = Gdx.graphics.getWidth() / zoomLevel;

        cam.position.x = player.getX() + (player.getWidth() / 2);
        cam.position.y = player.getY() + (player.getHeight() / 2);
        cam.update();
    }

    @Override
    public void render(float delta) {
        update(delta);

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        gameMap.render(cam);

        Gdx.graphics.setTitle("FPS: "+Gdx.graphics.getFramesPerSecond());
        gameMap.getMapRenderer().getBatch().begin();
        player.draw(gameMap.getMapRenderer().getBatch());
        gameMap.getMapRenderer().getBatch().end();
    }
Tipsi
  • 404
  • 4
  • 12

0 Answers0