Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove gaps between tiled textures?

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?

like image 899
user2291015 Avatar asked Apr 17 '13 14:04

user2291015


People also ask

How far apart are the tiles on a tile map?

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.

Why do I see lines between my tilemaps in Unity?

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.

What is the best way to combine multiple textures together?

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”.

Do I need to select all the sprites in a tilemap?

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.


2 Answers

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");
like image 95
Nixon Avatar answered Oct 29 '22 03:10

Nixon


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.

like image 21
Julian Avatar answered Oct 29 '22 02:10

Julian