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