I've tried searching all over for the solution to this problem and have had no luck; although I have tried various suggestions which I will detail below along with the issue.
I've created a very small and simple sample project to test rendering a Tiled map and setting up a camera with a viewport and some simple input handling so I can "pan" around the map with WASD. The problem is that when I try to pan around the map, I get weird effects with the map. These include:
- Tiles "waving." By this I mean when I scroll up/down or across the screen will appear "wavy"
- Glitchy / Stuttering screen. Camera will not appear smooth at times.
- Tiles changing,(for example, the black bars on the yellow tiles will have one pixel of a different color yellow on the side or top when moving the camera. What side these "extra" pixels are on depends on which way the camera moves). I Think this is called texture bleeding but I am not sure.
The things I have tried:
- Pad all tiles with the same color pixel on all sides (This gets rid of black horizontal lines on map)
- Set filter to linear / nearest (Tried all combinations)
- Play around with viewport
- change speed of camera
Does any one have any ideas of what could be going wrong? I just wan't to make sure I understand how to render the map and move the camera properly without any issues before continuing.
Exact Code:
public class GameScreen implements Screen {
final Alpha game;
private OrthographicCamera camera;
private FitViewport viewport;
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;
private Rectangle player;
public GameScreen(final Alpha game) {
this.game = game;
camera = new OrthographicCamera();
viewport = new FitViewport(800, 480, camera);
TmxMapLoader.Parameters params = new TmxMapLoader.Parameters();
params.textureMinFilter = Texture.TextureFilter.Nearest;
params.textureMagFilter = Texture.TextureFilter.Linear;
map = new TmxMapLoader().load("simple_padded_same_color.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
player = new Rectangle(32,32,32,32);
}
@Override
public void render(float delta) {
camera.update();
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// handle input
if (Gdx.input.isKeyPressed(Input.Keys.A)) {
player.setX(player.getX() - 200 * delta);
}
if (Gdx.input.isKeyPressed(Input.Keys.D)) {
player.setX(player.getX() + 200 * delta);
}
if (Gdx.input.isKeyPressed(Input.Keys.W)) {
player.setY(player.getY() + 200 * delta);
}
if (Gdx.input.isKeyPressed(Input.Keys.S)) {
player.setY(player.getY() - 200 * delta);
}
camera.position.set(player.getX(), player.getY(), 0);
renderer.setView(camera);
renderer.render();
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
@Override
public void show() {
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
map.dispose();
renderer.dispose();
}
}