Creator中经常需要计算两个节点的距离,获取两个节点的距离:
首先获取两个节点的坐标:
例如node1的坐标为pos1=cc.v2(1,1);node2的坐标为pos2=cc.v2(2,2);
向量减法: var temp=pos1.sub(pos2);
则 两个点之间的距离是: var dis=Math.abs(temp.mag());
Creator中经常需要计算两个节点的距离,获取两个节点的距离:
首先获取两个节点的坐标:
例如node1的坐标为pos1=cc.v2(1,1);node2的坐标为pos2=cc.v2(2,2);
向量减法: var temp=pos1.sub(pos2);
则 两个点之间的距离是: var dis=Math.abs(temp.mag());