最近参考论坛写了个a星算法发现两个问题!

1.不知道为何 加载比较大的地图的时候 a星 用模拟器运气每次点击都比较卡 用的tiled map。图片大小3200*2400 小的地图就都不会 浏览器和手机运行也不会。
2.看了无数的a星算法帖子居然没人写 点击掩码层走到就近位置的算法,我也是毫无头绪 点击障碍物都是直接停止行走 有哪位大神帮忙解决下 下面是a星代码:
cc.Class({
extends: cc.Component,

properties: {
    barrierLayerName: 'Barrier',
},

editor: {
    requireComponent: cc.TiledMap,
},

onLoad: function () {
    this._tiledMap = this.getComponent(cc.TiledMap);
    this._layerBarrier = this._tiledMap.getLayer(this.barrierLayerName);
},

moveToward: function(startTilePos, desTilePos) {
    if (this._isInBarrierLayer(desTilePos)) {
        return [];
    }

    let deltaX = desTilePos.x - startTilePos.x;
    let deltaY = desTilePos.y - startTilePos.y;

    let openList = [];
    let closeList = [];
    let finalList = [];

    let start = {
        x: startTilePos.x,
        y: startTilePos.y,
        h: (Math.abs(deltaX) + Math.abs(deltaY)) * 10,
        g: 0,
        p: null,
    };

    start.f = start.h + start.g;
    openList.push(start);

    while(openList.length !== 0) {
        let parent  = openList.shift();
        closeList.push(parent);

        if (parent.h === 0) {break;}

        for (let i = -1; i <= 1; i++) {
            for (let j = -1; j <= 1; j++) {
                // ==========四方向或八方向开关==========
                if (Math.abs(i) + Math.abs(j) === 8) {continue;}
                // ======================================

                let raw = cc.p(parent.x + i, parent.y + j);

                if (this._isInBarrierLayer(raw)) {continue;}
                if (this._isInList(raw, openList)) {continue;}
                if (this._isInList(raw, closeList)) {continue;}
                let neibour = {
                    x: raw.x,
                    y: raw.y,
                    h: Math.max(Math.abs(raw.x - desTilePos.x), Math.abs(raw.y - desTilePos.y)) * 10,
                    g: parent.g + ((i !== 0 && j !== 0) ? 14 : 10),
                    p: parent,
                };

                neibour.f = neibour.h + neibour.g;
                openList.push(neibour);
            }
        }
        openList.sort(this._sortF);
    }

    let des = closeList.pop();

    while (des.p) {
        des.dx = des.x - des.p.x;
        des.dy = des.y - des.p.y;
        finalList.unshift(des);
        des = des.p;
    }

    return finalList;
},

_isInList: function(tilePosition, list){
    for (let pos of list) {
        if (cc.pointEqualToPoint(pos, tilePosition)) return true;
    }
    return false;
},

_sortF: function(a, b) {
    return a.f - b.f;
},

_isInBarrierLayer: function(tilePosition) {
    let mapSize = this._tiledMap.getMapSize();

    if (tilePosition.x < 0 || tilePosition.x >= mapSize.width) {
        return true;
    }
    if (tilePosition.y < 0 || tilePosition.y >= mapSize.height) {
        return true;
    }
    if (this._layerBarrier.getTileGIDAt(tilePosition)) {
        return true;
    }

    return false;
},

});

1、你有没有做数组的容量清空,c++里vector的用clear清空后,size变成0,但是容量capacity没有释放的,js的数组内存回收我不懂,js里是不是也是要有类似的需要?
2、你点障碍物,先做个判断,找出障碍物前的一个“非障碍物”的坐标A,然后才计算角色坐标和坐标A之间的路径。

点击时是可以知道点击了障碍物但是怎么计算 障碍物前的一个“非障碍物”的坐标 又不能保证点击的障碍物是非障碍物的上一格。还是说等走到了障碍物点去减人物坐标。。。。

A* 算法有蛮多优化的。
比如,孤岛、双叉 可能要根据你的具体场景去写针对性的算法。
大家说的A* 说的只是一个通用的算法