How to remove gaps between tiled textures?

user2291015 picture user2291015 · Apr 17, 2013 · Viewed 7.4k times · Source

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:

  • Tiles are 32x32 and I have tried both 32x32 and 64x64.
  • 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.
  • I use the 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?

Answer

Nixon picture Nixon · Mar 4, 2015

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");