相关疑难解决方法(0)

提高交错列等距网格上的点击检测性能

我正在研究等距游戏引擎,并且已经为像素完美点击检测创建了算法.访问该项目并注意到点击检测能够检测到点击了哪个边缘.它还会检查y-index以单击最前面的磁贴.

我当前算法的解释:

等距网格由100*65px的平铺图像组成. TileW=100, TileL=50, tileH=15

瓷砖尺寸

地图由三维数组表示map[z][y][x].

平铺中心点(x,y)的计算如下:

//x, y, z are the position of the tile

if(y%2===0) { x-=-0.5; }    //To accommodate the offset found in even rows
this.centerX = (x*tileW) + (tileW/2);
this.centerY = (y*tileL) - y*((tileL)/2) + ((tileL)/2) + (tileH/2) - (z*tileH);
Run Code Online (Sandbox Code Playgroud)

等距网格

用于确定鼠标是否位于磁贴上给定区域内的原型函数:

Tile.prototype.allContainsMouse = function() {
    var dx = Math.abs(mouse.mapX-this.centerX),
        dy = Math.abs(mouse.mapY-this.centerY);

    if(dx>(tileW/2)) {return false;}    //Refer to image
    return (dx/(tileW*0.5) + (dy/(tileL*0.5)) < (1+tileHLRatio));
}
Run Code Online (Sandbox Code Playgroud)

Tile.prototype.allContainsMouse()如果鼠标在绿色范围内,则返回true.通过检查dx是瓷砖宽度的一半来裁剪红色区域

图1


Tile.prototype.topContainsMouse = …
Run Code Online (Sandbox Code Playgroud)

javascript algorithm click collision-detection isometric

10
推荐指数
1
解决办法
1327
查看次数