9

I'm using LibGdx and Tiled and when moving around the screen, there are both horizontal and vertical lines appearing on the game. I can post any code you need, if necessary. How do I get these lines to stop?

Still image of said lines

Here's a gfycat gif of the lines:

http://gfycat.com/FastUnnaturalAmericanwirehair

Edit:

Here's a small bitbucket repository, as small as I could get it that has the same glitch in it:

https://bitbucket.org/Chemical_Studios/example-of-line-glitch/src/8eeb153ec02236d836763072611bd7aa55d38495/minimalExample/src/com/weebly/chemicalstudios/minEx/?at=master

Dylan
  • 188
  • 3
  • 12
  • Post a minimal working example if you can. – Anubian Noob Apr 17 '14 at 22:15
  • I'm not sure if this is what you mean or not, but this is the current game file: https://www.dropbox.com/s/nmzfm75atnz5pfi/TinyWorld.jar – Dylan Apr 17 '14 at 22:18
  • Try to make one of these: http://stackoverflow.com/help/mcve – Anubian Noob Apr 17 '14 at 22:19
  • Is this good enough? I tried to keep it as minimal as possible while still replicating the error: https://bitbucket.org/Chemical_Studios/example-of-line-glitch/src/8eeb153ec02236d836763072611bd7aa55d38495?at=master – Dylan Apr 17 '14 at 22:48
  • If you have a small example, post the relavant code in the question. – Anubian Noob Apr 17 '14 at 22:49
  • That's as small as I can get it. I'm not sure what part of the code is actually causing it, as far as I know it's from Tiled. I'm not sure what's causing the problem, at all, sorry – Dylan Apr 17 '14 at 22:52
  • Ok, there's a very large set of issues that could be happening here, and I don't have too much LibGDX experiance. You have seem to have put some effort into this, so I'm going to grab your code and try to find the issue. – Anubian Noob Apr 17 '14 at 23:31
  • If you don't use scaling, see my answer at http://stackoverflow.com/questions/26908317/libgdx-tiledmap-bug-in-render/41251081#41251081 – Lake Dec 20 '16 at 20:59

2 Answers2

13

This is because you need to add a padding to your tiles.

This is a pretty common problem and you are not the first to encounter it. Basically due to rounding errors when scaling and panning around, sometimes you will render the area "between" two tiles, which will result in nothing being rendered -> black background colour comes through.

You basically need to use some tools to add the padding to your tileset. In this forum thread I explained how to do it.

There is also one more questions regarding this topic on stackoverflow here.

Community
  • 1
  • 1
noone
  • 19,520
  • 5
  • 61
  • 76
  • That forum has been closed now so here's a Web Archive link: https://web.archive.org/web/20160715150127/http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=11078&p=49842 – Rolodophone Dec 20 '21 at 23:13
1

When you have rounding errors you can always force the number to snap to the grid you want. In my case that looked like this:

gameCam.position.x = (float) Math.round(player.b2body.getPosition().x * 100f) / 100f;

Because I used a pixels-per-meter constant of 100f throughout the game, to scale everything

  • Same deal here. A 100 made me problems but 10 worked just fine: `position.x = Math.round(position.x * 10) / 10f;` `position.y = Math.round(position.y * 10) / 10f;` – Ilya Gazman Nov 08 '18 at 11:38