LibGDX Tiled: Moving camera causes tiles to stutter/blur/wave -


i've tried searching on solution problem , have had no luck; although have tried various suggestions detail below along issue.

i've created small , simple sample project test rendering tiled map , setting camera viewport , simple input handling can "pan" around map wasd. problem when try pan around map, weird effects map. these include:

  • tiles "waving." mean when scroll up/down or across screen appear "wavy"
  • glitchy / stuttering screen. camera not appear smooth @ times.
  • tiles changing,(for example, black bars on yellow tiles have 1 pixel of different color yellow on side or top when moving camera. side these "extra" pixels on depends on way camera moves). think called texture bleeding not sure.

the things have tried:

  • pad tiles same color pixel on sides (this gets rid of black horizontal lines on map)
  • set filter linear / nearest (tried combinations)
  • play around viewport
  • change speed of camera

does 1 have ideas of going wrong? wan't make sure understand how render map , move camera without 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(); } } 

here render function should like

@override public void render(float delta) {      gdx.gl.glclearcolor(0, 0, 0, 1);     gdx.gl.glclear(gl20.gl_color_buffer_bit);      // force constant delta     float gamedelta = 0.1f;      // handle input     if (gdx.input.iskeypressed(input.keys.a)) {         player.setx(player.getx() - 200 * gamedelta);     }     if (gdx.input.iskeypressed(input.keys.d)) {         player.setx(player.getx() + 200 * gamedelta);     }     if (gdx.input.iskeypressed(input.keys.w)) {         player.sety(player.gety() + 200 * gamedelta);     }     if (gdx.input.iskeypressed(input.keys.s)) {         player.sety(player.gety() - 200 * gamedelta);     }      // set camera position first     camera.position.set(player.getx(), player.gety(), 0);     // update camera     camera.update();      // set view     renderer.setview(camera);     // last render     renderer.render(); } 

first, need update camera after setting new position. then, try use constant delta instead of actual 1 lead weird camera movement libgdx delta represents amount of time between 2 frames , not constant. should remove wavy effect have in game.

to understand delta issue, recommend reading article http://gameprogrammingpatterns.com/game-loop.html

ideally use entity system framework , specific physicsystem , motionsystem compute player movement , decouple player position computation rendering loop.

libgdx comes ashley, can have @ artemis-odb great project , more complete ashley in opinion.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -