The game I am currently working on has a very weird rendering error. It loads text from a file and sets a specific tile to a certain text (If you get what I mean). It has this very weird rendering error though.
http://s24.postimg.org/6grobszwh/Error.jpg
The textures move a couple of pixels to the right. This is what my spritesheet looks like.
http://s16.postimg.org/rly6uv8wh/Error_2.jpg
And the some snippets of the code.
Loading the map:
public void LoadWallsMap(String filename, int tileSize) {
this.tileSize = tileSize;
try {
@SuppressWarnings("resource")
BufferedReader br = new BufferedReader(new FileReader("res/maps/" + filename));
mapWidth = Integer.parseInt(br.readLine());
mapHeight = Integer.parseInt(br.readLine());
mapWalls = new int[mapHeight][mapWidth];
for (int row = 0; row < mapHeight; row++) {
String line = br.readLine();
String[] tokens = line.split(" ");
for (int column = 0; column < mapWidth; column++) {
mapWalls[row][column] = Integer.parseInt(tokens[column]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
And rendering the map:
public void renderWallsMap(Graphics g) {
for (int row = 0; row < mapHeight; row++) {
for (int column = 0; column < mapWidth; column++) {
int x = mapWalls[row][column];
if(x == 1) renderTile(Tile.wallTop, x, y, column, row, g);
if(x == 2) renderTile(Tile.wallTopMiddle, x, y, column, row, g);
if(x == 3) renderTile(Tile.wallSide, x, y, column, row, g);
if(x == 4) renderTile(Tile.wallBottom, x, y, column, row, g);
if(x == 5) renderTile(Tile.wallBottomMiddle, x, y, column, row, g);
}
}
}
public void renderTile(Tile tile, int x, int y, int column, int row, Graphics g) {
tile.render(x + column * tileSize, y + row * tileSize, g);
}
Any help would be much appreciated.
Thanks Toby