Cocos Creator 计算两点角度、距离
1 // 距离 2 getDistance:function(start, end){ 3 var pos = cc.v2(start.x - end.x, start.y - end.y); 4 var dis = Math.sqrt(pos.x*pos.x + pos.y*pos.y); 5 return dis; 6 },
1 // 角度 2 getAngle:function(start, end){ 3 //计算出朝向 4 var dx = end.x - start.x; 5 var dy = end.y - start.y; 6 var dir = cc.v2(dx,dy); 7 8 //根据朝向计算出夹角弧度 9 var angle = dir.signAngle(cc.v2(1,0)); 10 11 //将弧度转换为欧拉角 12 var degree = angle / Math.PI * 180; 13 14 return -degree 15 },