I'm using LibGDX to make a platformer. I'm using square tiles for the platforms but when they are drawn some of them have gaps between them. When I zoom in/out or move the camera around the gaps move position.
More details:
TexturePacker
with padding.My best guess is that it is a problem when converting the textures to screen coords but have no idea how to fix this and I couldn't find any solution. I have checked and double-checked my precision with tile sizes and lining them up.
Has anyone had the same problem or know how it fix it?
Tiles are lined up 32 pixels apart (e.g. first tile would be x=0 y=0, second x=32 y=0, and so on in both x and y directions). The gaps are not texture artifacts as I have checked this.
When using tilemaps in Unity using pixel art assets sometimes we might experience small tears / lines appearing when we are moving: A vertical line has appeared between 2 tiles that represents our map. The project is URP pipeline Unity 2021.1 Lucky for us there is a solution.
The solution is to use Sprite Atlas which “consolidates several Textures into a single combined Texture” which has the benefit of “Unity can call this single Texture to issue a single draw call instead of multiple draw calls”.
No we need to select all the sprites that are used by our tilemap to be packed together by dragging those to the “Objects for Packing” list in our Sprite Atlas (tip drag the sprites on the name of the list not into the list - I wouldn’t say that it is the best UX solution) : I have dragged 3 sprites that I use in my tilemsp.
I got it fixed by setting the duplicatePadding
field of the TexturePacker.Settings
class to true
.
Example code:
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
import com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings;
Settings settings = new Settings();
settings.maxWidth = 1024;
settings.maxHeight = 1024;
settings.duplicatePadding = true;
TexturePacker.process(settings, "source", "destination", "name");
I know it's a bit late to answer on this post, but when I was looking for a solution I came here.
However, for me I found a much easier way to get rid of the flickering or gaps that appear randomly between the tiles.
I simply added a cast to the very long decimals I got for the player's position:
camera.position.set((int)robot.position.x, (int)robot.position.y, 0);
That made the player move very weirdly and to make him move smoothly again I added a cast to its render method aswell:
batcher.draw(robotSprite, (int)robot.position.x, (int)robot.position.y, 16, 16);
Et voilà! Working perfectly for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With