var o0 = require('o0'); module.exports = { /* destroyNode: function(node) { node.active = false; var components = node.getComponents(); for(var i = 0;i 0) rotation = 360-rotation; return rotation; }, vectorFromRotation: function(rotation){//rotation between 0-360 var radian = rotation/180*Math.PI; if(rotation<90) return new o0.Vector2(Math.cos(radian),-Math.sin(radian)); if(rotation<180){ radian = Math.PI - radian; return new o0.Vector2(-Math.cos(radian),-Math.sin(radian)); } if(rotation<270){ radian -= Math.PI; return new o0.Vector2(-Math.cos(radian),Math.sin(radian)); } radian = Math.PI*2 - radian;/**/ return new o0.Vector2(Math.cos(radian),Math.sin(radian)); }, nextRotation: function(currentRotation, targetRotation, turningSpeed){//rotation between 0-360 var rotationDifference = currentRotation - targetRotation; if(Math.abs(rotationDifference) <= turningSpeed ||Math.abs(rotationDifference+360) <= turningSpeed ||Math.abs(rotationDifference-360) <= turningSpeed) currentRotation = targetRotation; else if((rotationDifference > 0 && rotationDifference < 180) ||(rotationDifference > - 360 && rotationDifference < -180)) currentRotation -= turningSpeed; else currentRotation += turningSpeed; if(currentRotation >= 360) currentRotation -= 360; if(currentRotation < 0) currentRotation += 360; return currentRotation; }, setGroup:function(component,groupIndex){ if(component.node.groupIndex==groupIndex){ return; } component.node.active = false; component.scheduleOnce(() => { if(component!=null&&component.node!=null){ component.node.groupIndex = groupIndex; component.node.active = true; } }, 0.1);/*用来解决cocos动态改变group的bug */ }, randomBrightColor:function(){ var c = new cc.Color(Math.random()*255, Math.random()*255, Math.random()*255, 255); var rate = 255.0 / Math.max(c.getR(),c.getG(),c.getB(),c.getA()); return new cc.Color(c.getR()*rate,c.getG()*rate,c.getB()*rate,255); }, };