cocos2.4

存储数据
 cc.sys.localStorage.setItem('curBranchRank', -1)//传递数据
 this.curBranchRank = cc.sys.localStorage.getItem('curBranchRank'); // 获取数据

跨脚本监测事件

发送事件的脚本

this.node.emit('onTouchEnd')

监测事件的脚本

    initEvent() {
        for (leti=0; i<this.branchArr.length; i++) {
            this.branchArr[i].on('onTouchStart', () => {
                    
                }),
                this.branchArr[i].on('onTouchEnd', () => {
                    this.checkTouchInt()
                })
        }
    },
转换坐标系

1单层嵌套

convert() {
    // 获取branchs下的birdarr中的鸟的位置 转换为世界坐标
    letnode=this.node.getChildByName('branchs').getChildByName('branch2').getChildByName('text') // --先获取当前局部坐标下节点的局部坐标
​
    letworldPos=node.parent.convertToWorldSpace(newcc.Vec2(node.x, node.y)); //将局部坐标转换为世界坐标 node.parent必须是当前节点的父节点 new cc.Vec2(node.x, node.y)当前节点的坐标
    logoPos=node.parent.convertToNodeSpace(newcc.Vec2(worldPos.x, worldPos.y)) // --将刚才的世界坐标转换成目标对象坐标系下的坐标
},

2??

缓动系统
cc.tween()
            .target(imgBranch)
            .to(0.15, { angle: -2 })//按照顺序执行 旋转角度
            .to(0.25, { angle: -2 })
            .to(0.25, { angle: 2 })
            .to(0.25, { angle: -2 })
            .to(0.15, { angle: 0 })
            .start()

cc.tween()
                .target(bird)
                .delay(2.7+dalayNum)
                .call(() => {
                    cc.log('This is a callback');
                    this.birdStartFly(bird);
                })
                .to(timeInt, { position: cc.v2(localPos.x, localPos.y) })//移动到哪个位置
                .call(() => {//回调
                    
                })
                .start()

cc.tween()
                .target(bird)
                .delay(0.1*i)
                .call(() => {
                    this.birdPlayFly(bird); //起飞
                })
                .to(this.flyTimeInt, { position: cc.v2(moveX, moveY) })
                .call(() => {
                    
                })
                .start()
​
动态创建精灵节点 动态加载图片
initBg() {
        letbg=this.node.getChildByName('bg');
        letnode=newcc.Node(); //新建一个节点
        letspNode=node.addComponent(cc.Sprite); //添加一个精灵属性
        node.parent=bg; //把新建的节点挂载到,当前节点下方
        node.setPosition(cc.v2(0, 0)) //设置新建节点的属性,位置
        leturl=this.changeBgUrl(); //'res/img/bg/bg_1';
     //动态加载图片
        cc.assetManager.getBundle(miniGame30005Mgr文件名.getMiniGameId()).load(url, cc.SpriteFrame, null, (err, sp) => {
            console.log(err, sp);
            sp._rect.height=1334; //设置图片宽高
            spNode.spriteFrame=sp; //设置精灵的图片,图片是上方接受的
        });
    },
​
    changeBgUrl() {
        letyushu=miniGame30005Mgr.level.level%7;
        if (yushu==0) {
            yushu=7;
        }
        console.log(yushu);
        leturl='res/img/bg/bg_'+yushu;
        returnurl;
    },

鼠标事件监听
this.node.getChildByName('click_area').on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值