金币飞往目标位置

金币飞往目标位置

//创建获得星星效果
    createStarEffect(cNode, count, goldNum) {
        //创建的节点,个数,金币数量

        //在哪个位置进行创建世界坐标
        let icon = cc.find("Canvas/homeUI/top/starGroup/starIcon");
        //创建节点所在的世界坐标
        let cWpos = cNode.parent.convertToWorldSpaceAR(cNode.position);
        //对应当前节点的相对位置
        let cNpos = this.node.convertToNodeSpaceAR(cWpos);

        //目标位置的世界坐标
        let tWpos = icon.parent.convertToWorldSpaceAR(icon.position);
        //对应当前节点的相对位置
        let tNpos = this.node.convertToNodeSpaceAR(tWpos)

        //金币移动速度
        let moveSpeed = 1000;
        let random1 = 200;
        if (count >= 30) {
            count = 30;
        };
        //将收益平分至每一份
        // let addNum = Math.floor(goldNum / count) + 1;
        //停留时间
        let standingTime = 0.2;
        for (let i = 0; i < count; i++) {
            //随机位置
            let dircetion = Math.random() > 0.5 ? 1 : -1;
            let random_x = Math.floor(Math.random() * (random1 * dircetion) + cNpos.x);
            let random_y = Math.floor(Math.random() * (random1 * dircetion) + cNpos.y);
            let distance = cNpos.sub(tNpos).mag();

            if (this.newStarEffectNodePool.size() > 0) {
                let node = this.newStarEffectNodePool.get();

                node.parent = this.node;
                node.position = cNpos;

                //飞往生成位置
                cc.tween(node)
                    .to(standingTime, { position: cc.v2(random_x, random_y) })
                    .call(() => {

                        //飞往目标位置
                        cc.tween(node)
                            .to(distance / moveSpeed + i / 50, { position: tNpos }, { easing: "sineIn" })
                            .call(() => {
                                //最后结算收入
                                if (i == count - 1) {
                                    this.gameRules.updateStarLabel(goldNum);
                                };
                                this.onNodeKill(node);
                            })
                            .start();

                    })
                    .start();

            };

        };

    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值