DrawCycleScroll.js 4.7 KB

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