向量

 this._super()
     var dn = new cc.DrawNode();  //创建一个绘图板
     this.addChild(dn)//显示在界面中                    	   
     var a = cc.p(cc.winSize.width>>1,cc.winSize.height>>1)
     var b = cc.pAdd(a,cc.p(200,0))                      //a点到B点的距离相加
     var  c = cc.pRotateByAngle(b, a, cc.degreesToRadians(90/*角度*/))    
     var num  =0
     setInterval(function(){
         var d = cc.pRotateByAngle(b, a, cc.degreesToRadians(num++))设定一个定时器让每隔100毫秒让角度自加并在每个角度生成一个向量线条 
          dn.drawSegment(a,d,1,cc.color(255,0,0,255))
        },100)
     //dn.drawSegment(a,b,1,cc.color(255,0,0,255))
     //dn.drawSegment(a,c,1,cc.color(255,0,0,255))
 }
drawLine:function(p){
var a = cc.p(cc.winSize.width>>1, cc.winSize.height>>1);
var b = p;
//var c = p
var c = cc.pNormalize(cc.pSub(b, a)) 相减
c = cc.pMult(c, 200) 相乘
c = cc.pAdd(a, c)两个坐标相加
 this.dn.drawSegment(a,c,1,cc.color(255,0,0,255))

你可能感兴趣的:(向量)