mouse position to isometric tile including height

前端 未结 7 968
太阳男子
太阳男子 2021-01-30 22:11

Struggeling translating the position of the mouse to the location of the tiles in my grid. When it\'s all flat, the math looks like this:

this.position.x = Math.         


        
7条回答
  •  悲&欢浪女
    2021-01-30 22:35

    It also matters what else is on the screen. Maths attempts work if your tiles are pretty much uniform. However if you are displaying various objects and want the user to pick them, it is far easier to have a canvas-sized map of identifiers.

    function poly(ctx){var a=arguments;ctx.beginPath();ctx.moveTo(a[1],a[2]);
        for(var i=3;i=0 && my>=0 && mx
    Move around

    Here the "id" is a simple x+1+(y+1)*10 (so it is nice when displayed) and fits into a byte (Uint8Array), which could go up to 15x15 display grid already, and there are wider types available too.

    (Tried to draw it small, and it looked ok on the snippet editor screen but apparently it is still too large here)

提交回复
热议问题