Calculating how many isometric tiles to render on screen

by flooblebit   Last Updated June 22, 2018 18:13 PM

So I was following this post here on Stack Overflow (drawing-isometric-game-worlds) and I ported my existing tile renderer to draw isometrically, but I have one problem:

My "culling" technique no longer works due to making it isometric

The answer presents many ways to render, I chose the Diamond Approach

for (i = 0; i < tile_map.size; i++):
    for (j = tile_map[i].size; j >= 0; j--):
        draw(
            tile_map[i][j],
            x = (j * tile_width / 2) + (i * tile_width / 2)
            y = (i * tile_height / 2) - (j * tile_height / 2)
        )

Normally to render a tile map it would be like this:

for (i = 0; i < tile_map.size; i++):
    for (j = tile_map[i].size; j >= 0; j--):
        draw(
            tile_map[i][j],
            x = j * tile_width
            y = i * tile_height
        )

And then I added a technique to clip so we only render whats on screen:

x0 := floor(cam_x / tile_width)
x1 := x0 + (cam_w / tile_width)

y0 := floor(cam_y / tile_height)
y1 := y0 + (cam_h / tile_height) + 1

Which makes perfect sense: we calculate how many tiles we can fit on the screen from the camera position.

But how this maps into the isometric world is not so clear to me. How can I calculate these "corner points" in an isometric way?

I tried this:

x0 := floor(cam_x / tile_width_half)
x1 := x0 + (cam_w / tile_width_half)

y0 := floor(cam_y / tile_height_half)
y1 := y0 + (cam_h / tile_height_half) + 1

And it almost works, except it goes in reverse? Where am I going wrong with my Math, or could someone explain the concept in a bit more detail?

Tags : java 2d isometric


Related Questions


Scrolling background tiles in an isometric environment?

Updated February 19, 2017 01:13 AM




render map with objects in slick2d

Updated May 23, 2015 21:05 PM