Weird tilemap rendering not working

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

Can you give more details on what the problem is? The image doesn’t show enough to understand what to look for.

Okay, sorry. Look at the first image, can you see there are black walls. The middle ones are slightly to the right, when I want them to just be straight. I dont understand why it is happening. They should be drawn probably in the spritesheet (image below)

Hope that helps

ah right, i didnt realize that the image was a link to a larger image.


    tile.render(x + column * tileSize, y + row * tileSize, g);

…this looks a little strange. x appears to be a tile type which you are getting out of your map, but then you are adding it onto the drawing position also, so i imagine that could be what is shifting them. It looks like you should either change the renderTile() to not use the x and y, or change:


if(x == 1) renderTile(Tile.wallTop, x, y, column, row, g);

..to..

if(x == 1) renderTile(Tile.wallTop, 0, 0, column, row, g);

Oh im so stupid, I just needed to change a variable name and now it works fine. Thanks alot.

Toby