Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have lines going across my libgdx game using Tiled?

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

like image 339
Dylan Avatar asked Apr 17 '14 22:04

Dylan


2 Answers

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.

like image 145
noone Avatar answered Oct 14 '22 05:10

noone


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

like image 22
James Coker Avatar answered Oct 14 '22 06:10

James Coker