Cocos Creator转盘抽奖

抽奖效果

在这里插入图片描述

搭建

素材
在这里插入图片描述
在这里插入图片描述

节点层级
在这里插入图片描述
控制脚本

const { ccclass, property } = cc._decorator;
@ccclass
export default class Choujiang extends cc.Component {

    @property(cc.Integer)
    num: number = 6;//转盘中分区数量
    
    @property(cc.Integer)
    rotateTime: number = 10;//转盘动画旋转次数

    @property(cc.Integer)
    time: number = 5;//抽奖动画持续时间

    isChoujiang: boolean = false;//是否正在抽奖

    @property(cc.Label)
    jianping: cc.Label = undefined;//中奖信息节点

    private StartChoujiang() {
        this.isChoujiang = true;
        // 随机确定奖品分区
        let index = Math.floor(Math.random() * this.num);
        // 过场动作
        let targetAngle = this.rotateTime * 360 + index * (360 / this.num);
        this.node.rotation %= 360;
        console.log(index * (360 / this.num));
        // 过场动作+缓入缓出
        let action = cc.rotateTo(this.time, targetAngle).easing(cc.easeCubicActionInOut());
        // 添加动作结束回调,显示中奖信息
        this.node.runAction(cc.sequence(action, cc.callFunc(() => {
            this.jianping.string = index.toString();
            this.isChoujiang = false;
        })));
    }

    public btnCallBack() { //按钮回调
        if (!this.isChoujiang) {
            this.StartChoujiang();
            this.jianping.string = "";
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值