DrawCycleScroll.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. const lotteryContent = require('../data/lotteryNew');
  2. const DWTool = require("../utils/DWTool");
  3. const AlertManager = require('../utils/AlertManager');
  4. const GameModule = require("../utils/GameModule");
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. /// 转盘的title数组 顺时针
  9. richTextArr: [cc.RichText],
  10. iconSpriteArr: [cc.Sprite],
  11. /// 转盘的node
  12. contentNode: cc.Node,
  13. maskNode: cc.Node,
  14. drawSpriteFrame: [cc.SpriteFrame],
  15. drawBgSprite: cc.Sprite,
  16. drawPointSprite: cc.Sprite,
  17. drawStartButton: cc.Button,
  18. /// 指针的
  19. pointNode: cc.Node,
  20. ///转盘转的圈数
  21. _rounds: 4,
  22. // 转盘转的时间
  23. _cycleTime: 3,
  24. /// 是否需要抖动
  25. _pointUp: false,
  26. _isUp: false,
  27. _timeTotal: 0,
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. onLoad () {
  31. this.node.active = false;
  32. },
  33. start () {
  34. this._localDrawDatas = lotteryContent;
  35. for (let i = 0; i < lotteryContent.length; ++ i) {
  36. let drawData = lotteryContent[i];
  37. /// 根据类型获取抽奖icon
  38. this.iconSpriteArr[i].spriteFrame = this.drawSpriteFrame[drawData.type - 1];
  39. this.richTextArr[i].string = `<b><color=#4d371f>${drawData.desc}</c></b>`;
  40. }
  41. this.setUpNotification();
  42. },
  43. // hb 抽中的红包金额单位分 是 [long] 查看
  44. // 4 id 抽中的id 是 [long] 查看
  45. // 5 name 抽中的名字 是 [string] 查看
  46. // 6 opt 抽中的具体值(金币倍数或者钻石(type=1该值为金币倍数,type=2该值为钻石)) 是 [int] 查看
  47. // 7 roomId 抽中的明星所在的房间ID 是 [string] 查看
  48. // 8 starId 抽中的明细id 是 [string] 查看
  49. // 9 type
  50. init(drawData, typeId) {
  51. this.node.active = true;
  52. this._drawData = drawData;
  53. this._typeId = typeId;
  54. this.setUpSprite(typeId);
  55. },
  56. setUpNotification() {
  57. // this.maskNode.on(cc.Node.EventType.TOUCH_END, (event) => {
  58. // this.node.destroy();
  59. // }, this);
  60. GameEvent.on("draw_done_action",this, () => {
  61. this.node.destroy();
  62. });
  63. GameEvent.on("draw_again", this,(againDrawSuccessData) => {
  64. this._drawData.drawSuccessData = againDrawSuccessData;
  65. this.contentNode.rotation = parseInt(this.contentNode.rotation / 360) * 360;
  66. /// 让它重新滚动
  67. this.startDraw();
  68. });
  69. },
  70. onDestroy() {
  71. GameEvent.off("draw_done_action", this);
  72. GameEvent.off("draw_again", this);
  73. },
  74. setUpSprite(typeId) {
  75. /// 1 2 3
  76. let bgPath = './textures/draw/draw_cycle_bg_' + typeId;
  77. let pointPath = './textures/draw/draw_point_' + typeId;
  78. DWTool.loadResSpriteFrame(bgPath)
  79. .then((spriteFrame) => {
  80. this.drawBgSprite.spriteFrame = spriteFrame;
  81. });
  82. DWTool.loadResSpriteFrame(pointPath)
  83. .then((spriteFrame) => {
  84. this.drawPointSprite.spriteFrame = spriteFrame;
  85. });
  86. },
  87. startDraw() {
  88. GameModule.audioMng.stopBgm();
  89. GameModule.audioMng.playGetDraw();
  90. this.drawStartButton.interactable = false;
  91. let pointFinished1 = cc.callFunc(() => {
  92. this._pointUp = true;
  93. });
  94. let pointFinished2 = cc.callFunc(() => {
  95. this.pointNode.rotation = 0;
  96. });
  97. let finished = cc.callFunc(() => {
  98. GameModule.audioMng.playBgm();
  99. setTimeout(() => {
  100. AlertManager.showDrawSuccessAlert(this._drawData, this._typeId);
  101. }, 700);
  102. });
  103. //// 在动画结束前面0.5秒让指针回到原位
  104. setTimeout(() => {
  105. this._pointUp = false;
  106. this.pointNode.runAction(cc.sequence(cc.rotateBy(0.3, 40), pointFinished2)).easing(cc.easeCubicActionOut(0.3));
  107. }, (this._cycleTime - 0.5) * 1000);
  108. let angle = 22.5 + (this._drawData.drawSuccessData.id - 1) * 45;
  109. let totalCycle = -angle + 360 * this._rounds;
  110. this.pointNode.runAction(cc.sequence(cc.rotateBy(0.3, -40), pointFinished1)).easing(cc.easeCubicActionOut(0.3));
  111. var rotateAction = cc.rotateBy(this._cycleTime, totalCycle);
  112. this.contentNode.runAction(cc.sequence(rotateAction, finished)).easing(cc.easeCubicActionOut(this._cycleTime));
  113. },
  114. update (dt) {
  115. /// 如果需要抖动
  116. if (this._pointUp == true) {
  117. this._timeTotal += dt;
  118. if (this._timeTotal > 0.1) {
  119. this._isUp = !this._isUp;
  120. if (this._isUp) {
  121. this.pointNode.rotation = -42;
  122. } else {
  123. this.pointNode.rotation = -38;
  124. }
  125. this._timeTotal = 0;
  126. }
  127. }
  128. },
  129. });