DrawCycleScroll.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const lotteryContent = require('../data/lotteryNew');
  2. const DWTool = require("../utils/DWTool");
  3. const AlertManager = require('../utils/AlertManager');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. /// 转盘的title数组 顺时针
  8. richTextArr: [cc.RichText],
  9. iconSpriteArr: [cc.Sprite],
  10. /// 转盘的node
  11. contentNode: cc.Node,
  12. drawSpriteFrame: [cc.SpriteFrame],
  13. drawBgSprite: cc.Sprite,
  14. drawPointSprite: cc.Sprite,
  15. ///转盘转的圈数
  16. _rounds: 4,
  17. // 转盘转的时间
  18. _cycleTime: 3,
  19. },
  20. // LIFE-CYCLE CALLBACKS:
  21. onLoad () {
  22. this.node.active = false;
  23. },
  24. start () {
  25. this._localDrawDatas = lotteryContent;
  26. for (let i = 0; i < lotteryContent.length; ++ i) {
  27. let drawData = lotteryContent[i];
  28. /// 根据类型获取抽奖icon
  29. this.iconSpriteArr[i].SpriteFrame = this.SpriteFrame[drawData.type - 1];
  30. this.richTextArr[i].string = `<b><color=#4d371f>${drawData.desc}</c></b>`
  31. }
  32. this.setUpNotification();
  33. },
  34. // hb 抽中的红包金额单位分 是 [long] 查看
  35. // 4 id 抽中的id 是 [long] 查看
  36. // 5 name 抽中的名字 是 [string] 查看
  37. // 6 opt 抽中的具体值(金币倍数或者钻石(type=1该值为金币倍数,type=2该值为钻石)) 是 [int] 查看
  38. // 7 roomId 抽中的明星所在的房间ID 是 [string] 查看
  39. // 8 starId 抽中的明细id 是 [string] 查看
  40. // 9 type
  41. init(drawData, typeId) {
  42. this.node.active = true;
  43. this._drawData = drawData;
  44. this._typeId = typeId;
  45. this.setUpSprite(typeId);
  46. },
  47. setUpNotification() {
  48. GameEvent.on("draw_done_action",this, () => {
  49. this.node.destroy();
  50. });
  51. GameEvent.on("draw_again", this,(againDrawSuccessData) => {
  52. this._drawData.drawSuccessData = againDrawSuccessData;
  53. /// 让它重新滚动
  54. this.startDraw();
  55. });
  56. },
  57. setUpSprite(typeId) {
  58. /// 1 2 3
  59. let bgPath = './textures/draw/draw_cycle_bg_' + typeId;
  60. let pointPath = './textures/draw/draw_point_' + typeId;
  61. DWTool.loadResSpriteFrame(bgPath)
  62. .then((spriteFrame) => {
  63. this.drawBgSprite.spriteFrame = spriteFrame;
  64. });
  65. DWTool.loadResSpriteFrame(pointPath)
  66. .then((spriteFrame) => {
  67. this.drawPointSprite.spriteFrame = spriteFrame;
  68. });
  69. },
  70. startDraw() {
  71. // 完成
  72. this.scheduleOnce(function() {
  73. AlertManager.showDrawSuccessAlert(this._drawData, this._typeId);
  74. }, this._cycleTime + 0.5);
  75. let angle = 22.5 + (this._drawData.drawSuccessData.id - 1) * 45;
  76. var rotateAction = cc.rotateBy(this._cycleTime, angle + 360 * this._rounds);
  77. this.contentNode.runAction(rotateAction).easing(cc.easeCubicActionOut(this._cycleTime));
  78. },
  79. // update (dt) {},
  80. });