@@ -0,0 +1,2034 @@
+package com.blarg.gdx.graphics;%0A%0Aimport com.badlogic.gdx.graphics.Texture;%0Aimport com.badlogic.gdx.graphics.g2d.TextureRegion;%0A%0Apublic class AutoGridTextureAtlas extends TextureAtlas %7B%0A%09public final int tileWidth;%0A%09public final int tileHeight;%0A%09public final int tileBorder;%0A%0A%09public AutoGridTextureAtlas(Texture texture, int tileWidth, int tileHeight, int tileBorder) %7B%0A%09%09this(texture, tileWidth, tileHeight, tileBorder, TEXCOORD_EDGE_BLEED_OFFSET);%0A%09%7D%0A%0A%09public AutoGridTextureAtlas(Texture texture, int tileWidth, int tileHeight, int tileBorder, float edgeCoordOffset) %7B%0A%09%09super(texture, edgeCoordOffset);%0A%09%09this.tileWidth = tileWidth;%0A%09%09this.tileHeight = tileHeight;%0A%09%09this.tileBorder = tileBorder;%0A%0A%09%09generateGrid();%0A%09%7D%0A%0A%09private void generateGrid() %7B%0A%09%09int actualTileWidth = tileWidth + tileBorder;%0A%09%09int actualTileHeight = tileHeight + tileBorder;%0A%0A%09%09int tilesX = (texture.getWidth() - tileBorder) / (tileWidth + tileBorder);%0A%09%09int tilesY = (texture.getHeight() - tileBorder) / (tileHeight + tileBorder);%0A%0A%09%09for (int y = 0; y %3C tilesY; ++y)%0A%09%09%7B%0A%09%09%09for (int x = 0; x %3C tilesX; ++x)%0A%09%09%09%7B%0A%09%09%09%09// pixel location/dimensions%0A%09%09%09%09int left = tileBorder + x * actualTileWidth;%0A%09%09%09%09int top = tileBorder + y * actualTileHeight;%0A%09%09%09%09int right = left + actualTileWidth - tileBorder;%0A%09%09%09%09int bottom = top + actualTileHeight - tileBorder;%0A%0A%09%09%09%09// texture coordinates%0A%09%09%09%09// HACK: subtract edgeCoordOffset from the bottom right edges to%0A%09%09%09%09//       get around floating point rounding errors (adjacent tiles will%0A%09%09%09%09//       slightly bleed in otherwise)%0A%09%09%09%09float u = (left - tileBorder + edgeCoordOffset) / (float)texture.getWidth();%0A%09%09%09%09float v = (top - tileBorder + edgeCoordOffset) / (float)texture.getHeight();%0A%09%09%09%09float u2 = ((float)right + tileBorder - edgeCoordOffset) / (float)texture.getWidth();%0A%09%09%09%09float v2 = ((float)bottom + tileBorder - edgeCoordOffset) / (float)texture.getHeight();%0A%0A%09%09%09%09TextureRegion tile = new TextureRegion();%0A%09%09%09%09tile.setTexture(texture);%0A%09%09%09%09tile.setRegion(u, v, u2, v2);%0A%09%09%09%09tiles.add(tile);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%7D%0A

add AutoGridTextureAtlas