CocosCreator常用API函数库(二)_多边形包含判定的函数API使用方法实例

版权声明:⎝⎝⎝MaximilianLiu⎠⎠⎠ https://blog.csdn.net/MaximilianLiu/article/details/79343528
//该函数方法:根据点的信息顺序连接构成多边形,然后进行判定该点是否在多边形内
getAnchorLocation: function (number) {
//Intersection.pointInPolygon
var polyWorPos = this.node.getChildByName( "up").convertToWorldSpaceAR(cc.Vec2.ZERO);
var polyHeight = this.node.getChildByName( "up").height;
var polyWidth = this.node.getChildByName( "up").width;
var pos;
pos = this.player.calulateNextPoint(); //nextBlock有关系的
//顺序连接点,然后构成多边形
var polygon = [cc.v2(polyWorPos.x - polyWidth / 2, polyWorPos.y),
cc.v2(polyWorPos.x, polyWorPos.y + polyHeight / 2),
cc.v2(polyWorPos.x + polyWidth / 2, polyWorPos.y),
cc.v2(polyWorPos.x, polyWorPos.y - polyHeight / 2)
];
//判断是否该点是否在多边形中
if (cc.Intersection.pointInPolygon(pos, polygon)) {
return pos;
} else {
return null;
}
},

猜你喜欢

转载自blog.csdn.net/MaximilianLiu/article/details/79343528