震屏效果:
// 震屏效果
// 参数:duration 震屏时间
shakeEffect: function (node,duration) {
node.runAction(
cc.repeatForever(
cc.sequence(
cc.moveTo(0.02, cc.v2(5, 7)),
cc.moveTo(0.02, cc.v2(-6, 7)),
cc.moveTo(0.02, cc.v2(-13, 3)),
cc.moveTo(0.02, cc.v2(3, -6)),
cc.moveTo(0.02, cc.v2(-5, 5)),
cc.moveTo(0.02, cc.v2(2, -8)),
cc.moveTo(0.02, cc.v2(-8, -10)),
cc.moveTo(0.02, cc.v2(3, 10)),
cc.moveTo(0.02, cc.v2(0, 0))
)
)
);
setTimeout(() => {
node.stopAllActions();
node.setPosition(0,0);
}, duration*1000);
},
求旋转角度
/**
*
* @param {number} x1 参照点x坐标
* @param {number} y1 参照点y坐标
* @param {number} x2 目标点x坐标
* @param {number} y2 目标点y坐标
*/
getVectorRadians( x1, y1, x2, y2){
let len_y = y2 - y1;
let len_x = x2 - x1;
let tan_yx = tan_yx = Math.abs(len_y)/Math.abs(len_x);
let angle = 0;
if(len_y > 0 && len_x < 0) {
angle = Math.atan(tan_yx)*180/Math.PI - 90;
} else if (len_y > 0 && len_x > 0) {
angle = 90 - Math.atan(tan_yx)*180/Math.PI;
} else if(len_y < 0 && len_x < 0) {
angle = -Math.atan(tan_yx)*180/Math.PI - 90;
} else if(len_y < 0 && len_x > 0) {
angle = Math.atan(tan_yx)*180/Math.PI + 90;
}
return angle;
},
VScode统计代码行数。但是包含注释等。
^b*[^:b#/]+.*$