const lotteryContent = require('../data/lotteryNew'); const DWTool = require("../utils/DWTool"); const AlertManager = require('../utils/AlertManager'); const GameModule = require("../utils/GameModule"); cc.Class({ extends: cc.Component, properties: { /// 转盘的title数组 顺时针 richTextArr: [cc.RichText], iconSpriteArr: [cc.Sprite], /// 转盘的node contentNode: cc.Node, maskNode: cc.Node, drawSpriteFrame: [cc.SpriteFrame], drawBgSprite: cc.Sprite, drawPointSprite: cc.Sprite, drawStartButton: cc.Button, /// 指针的 pointNode: cc.Node, ///转盘转的圈数 _rounds: 4, // 转盘转的时间 _cycleTime: 3, /// 是否需要抖动 _pointUp: false, _isUp: false, _timeTotal: 0, }, // 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.drawSpriteFrame[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() { // this.maskNode.on(cc.Node.EventType.TOUCH_END, (event) => { // this.node.destroy(); // }, this); GameEvent.on("draw_done_action",this, () => { this.node.destroy(); }); GameEvent.on("draw_again", this,(againDrawSuccessData) => { this._drawData.drawSuccessData = againDrawSuccessData; this.contentNode.rotation = parseInt(this.contentNode.rotation / 360) * 360; /// 让它重新滚动 this.startDraw(); }); }, onDestroy() { GameEvent.off("draw_done_action", this); GameEvent.off("draw_again", this); }, 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() { GameModule.audioMng.stopBgm(); GameModule.audioMng.playGetDraw(); this.drawStartButton.interactable = false; let pointFinished1 = cc.callFunc(() => { this._pointUp = true; }); let pointFinished2 = cc.callFunc(() => { this.pointNode.rotation = 0; }); let finished = cc.callFunc(() => { GameModule.audioMng.playBgm(); setTimeout(() => { AlertManager.showDrawSuccessAlert(this._drawData, this._typeId); }, 700); }); //// 在动画结束前面0.5秒让指针回到原位 setTimeout(() => { this._pointUp = false; this.pointNode.runAction(cc.sequence(cc.rotateBy(0.3, 40), pointFinished2)).easing(cc.easeCubicActionOut(0.3)); }, (this._cycleTime - 0.5) * 1000); let angle = 22.5 + (this._drawData.drawSuccessData.id - 1) * 45; let totalCycle = -angle + 360 * this._rounds; this.pointNode.runAction(cc.sequence(cc.rotateBy(0.3, -40), pointFinished1)).easing(cc.easeCubicActionOut(0.3)); var rotateAction = cc.rotateBy(this._cycleTime, totalCycle); this.contentNode.runAction(cc.sequence(rotateAction, finished)).easing(cc.easeCubicActionOut(this._cycleTime)); }, update (dt) { /// 如果需要抖动 if (this._pointUp == true) { this._timeTotal += dt; if (this._timeTotal > 0.1) { this._isUp = !this._isUp; if (this._isUp) { this.pointNode.rotation = -42; } else { this.pointNode.rotation = -38; } this._timeTotal = 0; } } }, });