const lotteryContent = require('../data/lotteryNew'); const DWTool = require("../utils/DWTool"); const AlertManager = require('../utils/AlertManager'); cc.Class({ extends: cc.Component, properties: { /// 转盘的title数组 顺时针 richTextArr: [cc.RichText], iconSpriteArr: [cc.Sprite], /// 转盘的node contentNode: cc.Node, drawSpriteFrame: [cc.SpriteFrame], drawBgSprite: cc.Sprite, drawPointSprite: cc.Sprite, ///转盘转的圈数 _rounds: 4, // 转盘转的时间 _cycleTime: 3, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.active = false; }, start () { this._localDrawDatas = lotteryContent; for (let i = 0; i < lotteryContent.length; ++ i) { let drawData = lotteryContent[i]; /// 根据类型获取抽奖icon this.iconSpriteArr[i].SpriteFrame = this.SpriteFrame[drawData.type - 1]; this.richTextArr[i].string = `${drawData.desc}` } this.setUpNotification(); }, // hb 抽中的红包金额单位分 是 [long] 查看 // 4 id 抽中的id 是 [long] 查看 // 5 name 抽中的名字 是 [string] 查看 // 6 opt 抽中的具体值(金币倍数或者钻石(type=1该值为金币倍数,type=2该值为钻石)) 是 [int] 查看 // 7 roomId 抽中的明星所在的房间ID 是 [string] 查看 // 8 starId 抽中的明细id 是 [string] 查看 // 9 type init(drawData, typeId) { this.node.active = true; this._drawData = drawData; this._typeId = typeId; this.setUpSprite(typeId); }, setUpNotification() { GameEvent.on("draw_done_action",this, () => { this.node.destroy(); }); GameEvent.on("draw_again", this,(againDrawSuccessData) => { this._drawData.drawSuccessData = againDrawSuccessData; /// 让它重新滚动 this.startDraw(); }); }, setUpSprite(typeId) { /// 1 2 3 let bgPath = './textures/draw/draw_cycle_bg_' + typeId; let pointPath = './textures/draw/draw_point_' + typeId; DWTool.loadResSpriteFrame(bgPath) .then((spriteFrame) => { this.drawBgSprite.spriteFrame = spriteFrame; }); DWTool.loadResSpriteFrame(pointPath) .then((spriteFrame) => { this.drawPointSprite.spriteFrame = spriteFrame; }); }, startDraw() { // 完成 this.scheduleOnce(function() { AlertManager.showDrawSuccessAlert(this._drawData, this._typeId); }, this._cycleTime + 0.5); let angle = 22.5 + (this._drawData.drawSuccessData.id - 1) * 45; var rotateAction = cc.rotateBy(this._cycleTime, angle + 360 * this._rounds); this.contentNode.runAction(rotateAction).easing(cc.easeCubicActionOut(this._cycleTime)); }, // update (dt) {}, });