So I am making a tiled game and I need to connect textures correctly based on whats next to it.
With tiles that had connection really close to the edge of the tile I could just use the 4 bit meathod ie:
x 1 x
8 x 2
x 4 x
But for tiles with more detail I need to have corners too. I have seen people use the 8 bit meathod ie:
1 2 4
128 x 8
64 32 16
But really I can only see 48 different tile combos.
Is there a way I can separate corners and u d l r. Something like this:
x 1 x 8 x 1
8 x 2 x x x
x 4 x 4 x 2
Or is there a better way all together to do this.
This is what I have tried so far but this only uses 32/48 tiles and doesn't work for special corner cases.
public class RockTile extends Tile {
int y;
public RockTile(int id) {
super(id);
y = 7;
}
public TextureRegion getTexture(Level level, int xLoc, int yLoc){
int u = (level.getTile(xLoc, yLoc + 1) != this) ? 1 : 0;
int r = (level.getTile(xLoc + 1, yLoc) != this) ? 2 : 0;
int d = (level.getTile(xLoc, yLoc - 1) != this) ? 4 : 0;
int l = (level.getTile(xLoc - 1, yLoc) != this) ? 8 : 0;
int bit = u + r + d + l;
int ur = (level.getTile(xLoc + 1, yLoc + 1) != this) ? 1 : 0;
int dr = (level.getTile(xLoc + 1, yLoc - 1) != this) ? 2 : 0;
int dl = (level.getTile(xLoc - 1, yLoc - 1) != this) ? 4 : 0;
int ul = (level.getTile(xLoc - 1, yLoc + 1) != this) ? 8 : 0;
int corner = ul + ur + dl + dr;
if (bit == 0) {
if (corner != 0)
return Game.splitTiles[y + 1][corner];
else
return Game.splitTiles[y][bit];
} else {
if (corner != 0)
if (dl > 0 && l == 0 && d == 0)
return Game.splitTiles[y + 2][bit];
else
return Game.splitTiles[y][bit];
else
return Game.splitTiles[y + 2][bit];
}
}
}
If you need anything else let me know.
EDIT: Side question because I've seemed to have stumped you guys. If I decided to use the 8 bit method what would be the best and fastest way to make a lookup table for that.