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

允我心安 提交于 2019-12-03 17:38:41

问题


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?

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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/23144367/why-do-i-have-lines-going-across-my-libgdx-game-using-tiled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!