LibGDX Best way to avoid gaps in textures?

What is the actual solution to this problem? It only happens sometimes, with the right camera-offset. This is probably due to a rounding error, but how do I fix this?

  • I’ve tried filtering linear instead of nearest, making the gaps consistently visible although only slightly.
  • I’ve tried sampling more, but that also only yielded moderate (at best) results.

So… How does JGO avoid this?

I used to get this and it was just due to how i rendered my tiles, it is most likely (without seeing code) due to some scaling factor if you have it or just that you need to find a better way to draw your tiles because it could actually be some white pixels from your sprite sheet being drawn on screen and when you pull the tiles its slightly off center.

It is definitely not white pixels from the spritesheet. However, it is very likely due my camera using floating-point precision, and then being rounded off weirdly.
My rendering code is as follows:


	@Override
	public void render(float delta) {
		batch.begin();
		
		for (int x = 0; x < level.getLength(); x++) {
			for (int y = 0; y < level.getHeight(); y++) {
				if (level.isBrick(x, y)) {
					if (!level.isBrick(x, y+1)) {
						batch.draw(
								grass, 
								x*Settings.PIXELS_PER_BLOCK_SCALED-camera.getOffset()*Settings.PIXELS_PER_BLOCK_SCALED, 
								y*Settings.PIXELS_PER_BLOCK_SCALED,
								Settings.PIXELS_PER_BLOCK_SCALED,
								Settings.PIXELS_PER_BLOCK_SCALED);
					} else {
						batch.draw(
								block, 
								x*Settings.PIXELS_PER_BLOCK_SCALED-camera.getOffset()*Settings.PIXELS_PER_BLOCK_SCALED, 
								y*Settings.PIXELS_PER_BLOCK_SCALED,
								Settings.PIXELS_PER_BLOCK_SCALED,
								Settings.PIXELS_PER_BLOCK_SCALED);
					}
				}
			}
		}

camera#getOffset() returns a float.
Settings.PIXELS_PER_BLOCK_SCALED is an int.

Casting to an integer early helped this problem. I’m now only passing integers to SpriteBatch, and that seems to work just fine.