Rendering isometric tiles

Hi all, I’m trying to render some diamond shaped tiles and all’s going well except I’m not sure how to render the correct section of the map. I started with the method I use for rendering normal square tiles which is start rendering from the player’s x coordinate -screen width/2 and the same for y axis and that way I can calculate where to render from and to, but I suppose that wouldn’t work for diamond shaped tiles. I’ll give you some code so you an understand where I’m up to:


int xOffset = player.x - (WIDTH >> 1);
int yOffset = player.y - (HEIGHT >> 1);

This is to offset the screen in a square tiled map that I’m currently stuck using ^


int xStart = xOffset / 40;
int yStart = yOffset / 20;
int xExtent = (Game.WIDTH + 39) / 40;
int yExtent = (Game.HEIGHT + 19) / 20;
		
for(int y = yStart; y <= yStart + yExtent; y++) {
	for(int x = xStart; x <= xStart + xExtent; x++) {
		getTile(x, y).draw(screen, (x * 40 / 2) + (y * 40 / 2) - xOffset, (y * 20 / 2) - (x * 20 / 2) - yOffset);
	}
}

Here’s the method for rendering the diamond tiles ^

So the second code sample renders the tiles in the correct position, however the entire scene is shifted across the scene due to the fact that I’m not sure what xOffset and yOffset should be. Does anybody know what they should be?

Thanks

Paul

It seems about right exept the offset division.

It depends on how high the tiles are.
Like how it shows now, says the visual tiles are 40 and 20 times smaller then the sizes calculated, this does not seem right.
Calculate the diffrence between the tile size calculated (how much does an player move on an tile) and the tiles rendered.

Please put up some screenies.

Here is how a i calculate isometric and screen space and vice versa:

This is my drawing code:


int sx = (int)(pos.x + pos.y) * (width) / 2 - (int)Game.camera.x;
int sy = (int)(pos.y - pos.x) * (height) / 2 - (int)Game.camera.y - 16;