cocosjs怎么做椭圆旋转菜单

JavaScript08

cocosjs怎么做椭圆旋转菜单,第1张

根据网上的代码,利用Polygon绘制覆盖物,方法如下

function createSectorArea(point2, radius, sDegree, eDegree, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts){

var points = []

var step = ((eDegree - sDegree) / 50) || 50

points.push(point2)

for (var i = sDegreei <eDegree + 0.0001i += step) {

points.push(EOffsetBearing(point2, radius, i))

}

points.push(point2)

var polygon = new BMap.Polygon(

points , {strokeColor:strokeColour, strokeWeight:strokeWeight, strokeOpacity:Strokepacity, fillColor: fillColour, fillOpacity:fillOpacity})

return polygon

}

function EOffsetBearing(point3, dist, bearing) {

var latConv = map.getDistance(point3, new BMap.Point(point3.lng + 0.01, point3.lat)) * 50

var lngConv = map.getDistance(point3, new BMap.Point(point3.lng, point3.lat + 0.01)) * 50

var lat = dist * Math.cos(bearing * Math.PI / 180) / latConv

var lng = dist * Math.sin(bearing * Math.PI / 180) / lngConv

return new BMap.Point(point3.lng + lng, point3.lat + lat)

}

按照课程做的第一节 https://www.jianshu.com/p/c61f3ec0c66c

刚做完背景这步,加上飞机之后,效果有问题,背景可以正常滚动,鼠标点不到飞机,飞机随着背景滚下去了,谁知道问题出在哪里,麻烦给我留言,不胜感激

所以换了另一种方式做,两张图片,首尾可以无缝连接的两张图,图1铺满主场景,图2放在图1的上面,主场景看到的是图1,两张图一起滚动,图1刚好滚下去时,把图1和图2的位置初始化,这样看到的是无限的滚动。

cc.Class({

    extends: cc.Component,

    properties: {

        bgImage1: {     

            default: null,        // The default value will be used only when the component attaching       

            type: cc.Node, // optional, default is typeof default

        },

        bgImage2: {     

            default: null,        // The default value will be used only when the component attaching       

            type: cc.Node, // optional, default is typeof default

        },

    },    

    update (dt) {        

        this.bgImage1.y -= Math.ceil(cc.winSize.height*0.001)    //下移两张图片的位置

        this.bgImage2.y -= Math.ceil(cc.winSize.height*0.001)

        if(this.bgImage1.y < -cc.winSize.height){        //当第一张图片的y小于负的二分之一屏幕高度,就是它刚好离开视窗的时候,此时恢复两张图片的初始位置            

            this.bgImage1.y = 0      //第一张置于中间

            this.bgImage2.y = cc.winSize.height    //第二张放着第一张的上面

        }

    },

})

发现cocos 特别坑的一点是,只拿到脚本源码,还是做不出来,因为要配合场景中的各种组件的属性配置!!!!

有时间把分步骤都截图上来,给同是初学者的亲们分享一下,要不然初学者想入门太难了

要先用cocos编辑器执行安装cocos的提示,安装好了里面会生成cocos.d.ts的文件,就会有提示了。

安装 Cocos Creator API 适配插件