Hi folks,
I have run into an issue with a tile grid I cannot seem to solve: gaps / lines appear between tiles when I rotate the grid. I think it has something to do with texture filtering, but cannot figure out how to solve it. The grid is a spaceship built out of tiles (hence why the grid has to rotate).
Here’s how the tile grid looks without rotating:
And here’s how it looks while rotating:
I’m using LibGDX and the textures are on a texture atlas with the following pack settings:
{
wrapX: Repeat,
wrapY: Repeat,
filterMin: Linear,
filterMag: Linear
}
This is the code I use to render the ship / grid:
Matrix4 m4 = new Matrix4();
void drawShip(Ship ship, SpriteBatch batch) {
float shipX = ship.body.getPosition().x * Constants.BOX2D_TO_SCREEN;
float shipY = ship.body.getPosition().y * Constants.BOX2D_TO_SCREEN;
float angle = ship.body.getAngle();
m4.setToTranslation(shipX, shipY, 0);
m4.rotateRad(0, 0, 1, angle);
batch.setTransformMatrix(m4);
int designWidthPx = ship.design.width * Constants.CELL_SIZE_PX;
int designHeightPx = ship.design.height * Constants.CELL_SIZE_PX;
for (int x = 0; x < ship.design.width; x++) {
for (int y = 0; y < ship.design.height; y++) {
Module module = ship.cells[x][y].module;
if (module != null && ship.design.cells[x][y].topLeft) {
TextureRegion tex = module.texture;
batch.draw(tex, x * Constants.CELL_SIZE_PX - designWidthPx / 2 - Constants.CELL_SIZE_PX / 2, y
* Constants.CELL_SIZE_PX - designHeightPx / 2 - Constants.CELL_SIZE_PX / 2,
Constants.CELL_SIZE_PX / 2, Constants.CELL_SIZE_PX / 2, Constants.CELL_SIZE_PX,
Constants.CELL_SIZE_PX, 1f, 1f, directionToDegrees(ship.design.cells[x][y].direction));
}
}
}
m4.idt();
batch.setTransformMatrix(m4);
}
public float directionToDegrees(int direction) {
return -90f * direction;
}
Does anyone have an idea on how I could resolve this?