Efficiently getting isometric grid positions within a bounding box

前端 未结 6 1479
夕颜
夕颜 2021-02-05 10:57

\"Isometric

I have an isometric grid system who\'s coordinates start from [0,0] in the left hand corner of t

6条回答
  •  故里飘歌
    2021-02-05 11:25

    Considering the regular layout of the tiles, can't you simply start from the top left corner of the selector box, hittest to find which tile, and then move along to the next tile according to how they are spaced.

    For example, if your tiles are 32x16, you would start at the corner, and move along 32, then when you reach the end, go along the next row.

    tile spacing

    eg, in a strange kind of pseudocode...

    var altRow = false;
    var selectedTiles = [];
    for (int y = selectorBox.top; y < selectorBox.top+selectorBox.height; y+=TILE_HEIGHT/2) {
        for (int x = selectorBox.left ; x < selectorBox.left+selectorBox.width; x+= TILE_WIDTH) {
            selectedTiles.add(tileAtPoint(x + (altRow ? - TILE_WIDTH/2 : 0), y);
        }
        altRow = !altRow;
    }
    

提交回复
热议问题