Efficiently getting isometric grid positions within a bounding box

前端 未结 6 1480
夕颜
夕颜 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:18

    I'm student doing XNA games for hobby. I'm working on classical 2D game based on squares (Project Squared). This game of yours reminded me on my work so I decided to help you.

    I think it should be done using math, not graphics as you mentioned.

    First you should know which square (position on grid) is on start of "blue box" (probably selection box) and end of selection. So now you know an beginning and ending of your list.

    Since in your game squares probably have static size (or you zoom camera, but never increase width/height) you can calculate which squares are in your selection box easily.

    Now, you know that your squares are 45° moved r/l.

    (I'm talking about XNA like coordsys - up left 0,0)

    If ( selectedStartSquare.selectionY <= square.height )
        startY = selectedStartSquare.selectionY
    else startY = selectedStartSquare.selectionY + 1; 
    
    if (selectedEndSquare.selectionY > square.height)
        endY = -||-.selectionY
    else endY = -||- + 1;
    

    this will give you the start and end height indexes of squares. Same thing you need to do for X indexes.

    Now you have all you need to get all squares. Go through X from selectedStartSquare.X to endX and trough Y with for loop from selectedStartSquare.Y to endY but change start every time ( startYIndex++ every loop)

    This is just a close example since I never worked with Isometric games. This will probably need some tweaking but I "think!!" this should work. (Wrote this before sleep and without even a paper since I was in bed already... good luck)

    Sorry for my English, I'm from Croatia so...

提交回复
热议问题