0
\$\begingroup\$

For the life of me I cannot figure out why these lines keep appearing on my rendered tiled map. Every time I resize my libgdx window, the tiled map creates lines all across the screen.

I have adjusted camera viewport, camera projection, camera zoom, etc, and I cannot figure anything out.


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
import com.prevail.mmorpg.PrevailGame;
import com.prevail.mmorpg.gfx.player.Player;
import com.prevail.mmorpg.gfx.player.Player.Direction;
import com.prevail.mmorpg.net.ClientNetworkState;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class PlayingScreen extends GameScreen {

    public Player player = new Player();

    private OrthographicCamera camera;

    private TmxMapLoader mapLoader;
    private TiledMap map;
    private OrthogonalTiledMapRenderer renderer;
    private final int[] renderBackground = { 0, 1, 2 };
    private final int[] renderForeground = { 3, 4, 5 };

    private float cameraTime;

    public PlayingScreen(PrevailGame game) {
        super(game);
        this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

        Player.initializeAppearanceConstructors(game.getData());

        this.mapLoader = new TmxMapLoader();
        this.map = mapLoader.load("maps/Starter Map.tmx");
        this.renderer = new OrthogonalTiledMapRenderer(map);
        this.player.map = map;
    }

    @Override
    public void enterScreen() {
        this.game.writeRawMessage(Unpooled.buffer(1).writeByte(1));
        PrevailGame.CLIENT_STATE = ClientNetworkState.PLAYING;

        player.setAppearance("1", "2", null, "5");
        player.faceDirection(Direction.SOUTH);
    }

    @Override
    public void renderScreen(SpriteBatch batch, float delta) {
        batch.setTransformMatrix(this.camera.view);
        batch.setProjectionMatrix(this.camera.projection);

        OrthographicCamera camera = (OrthographicCamera) this.camera;
        if (camera.position.equals(player.getLocation())) {
            cameraTime = 0;
        } else {
            camera.position.lerp(player.getLocation(), MathUtils.clamp(cameraTime, 0.0f, 1.0f));
            camera.update();
        }
        renderer.setView(camera);
        renderer.render(renderBackground);
        player.render(batch, delta);
        renderer.render(renderForeground);

        if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
            player.setRunning(true);
        } else {
            player.setRunning(false);
        }
        cameraTime += delta;
    }

    @Override
    public void resize(int width, int height) {
        super.resize(width, height);

        this.camera = new OrthographicCamera(width, height);
    }

    @Override
    public void leaveScreen() {

    }

    @Override
    public boolean scrolled(float amountX, float amountY) {
        OrthographicCamera camera = (OrthographicCamera) this.camera;

        float newValue = camera.zoom + (amountY / 100f);
        if (newValue < 0.15f) {
            newValue = 0.15f;
        } else if (newValue > 2f) {
            newValue = 2f;
        }
        camera.zoom = newValue;

        camera.update();
        return super.scrolled(amountX, amountY);
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        Vector3 clickCoordinates = new Vector3(screenX, screenY, 0);
        Vector3 position = camera.unproject(clickCoordinates);

        int gx = (int) (position.x / (int) 32) * 32;
        int gy = (int) (position.y / (int) 32) * 32;

        ByteBuf walkRequestPacket = Unpooled.buffer(10);
        walkRequestPacket.writeShort(gx / 32);
        walkRequestPacket.writeShort(gy / 32);
        this.game.writePacket(10, walkRequestPacket);
        return super.touchDown(screenX, screenY, pointer, button);
    }

    @Override
    public boolean keyDown(int keyCode) {
        return super.keyDown(keyCode);
    }

    @Override
    public boolean keyUp(int keyCode) {
        return super.keyUp(keyCode);
    }

}

Without Resizing window: enter image description here

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Does this past Q&A help? \$\endgroup\$ Commented Feb 27, 2021 at 19:27
  • \$\begingroup\$ No, I'm sorry it does not. It only helps when moving the character and not resizing the window :( \$\endgroup\$ Commented Mar 1, 2021 at 14:13

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.