美文网首页
cocos creator自动转向

cocos creator自动转向

作者: 神大人korose | 来源:发表于2018-03-21 09:02 被阅读0次
        // use this for initialization
        onLoad: function () {
            this.height = 640;
            this.width = 1136;
            this.lastPoint = cc.p(0,this.height);
            
        },
        //
        update: function (dt) {
            var curPoint = this.node.parent.getPosition();
            if (this.curPoint == this.lastPoint)  //  
            {  
                return ;  
            }  
            var dx = curPoint.x - this.lastPoint.x;  
            var dy = curPoint.y - this.lastPoint.y;  
            var angle = Math.atan(dx/dy);  
            var degree = angle*180/Math.PI;  
            if (degree) {
                if(dy<0){  
                    degree += 180;  
                }  
                cc.log(degree);
                this.node.rotation = degree;  
            }
        
            this.lastPoint = curPoint;  //保存当前的坐标给下一轮刷新使用  
        },
    

    相关文章

      网友评论

          本文标题:cocos creator自动转向

          本文链接:https://www.haomeiwen.com/subject/fmybqftx.html