Turnable.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import TurnableItem from "./TurnableItem";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class Turnable extends cc.Component {
  5. @property(cc.Node)
  6. node_turn: cc.Node = null;
  7. @property(cc.Node)
  8. node_items: cc.Node[] = [];
  9. @property(cc.Node)
  10. btn_draw: cc.Node = null;
  11. @property(cc.Sprite)
  12. btn_close: cc.Sprite = null;
  13. @property(cc.RichText)
  14. lbl_left: cc.RichText = null;
  15. private isPlaying: boolean = false;
  16. onLoad() {
  17. }
  18. /**
  19. * 初始化奖励和抽奖次数
  20. */
  21. private initData() {
  22. for (let i = 0; i < this.node_items.length; i++) {
  23. let sc = this.node_items[i].getComponent(TurnableItem);
  24. sc.initData(i + "");
  25. }
  26. this.updateLeftTimes();
  27. }
  28. clickDraw() {
  29. if (gData.turnable.leftTimes > 0 && !this.isPlaying) {
  30. this.draw();
  31. }
  32. }
  33. private draw() {
  34. gData.turnable.leftTimes--;
  35. this.node_turn.rotation = 1800;
  36. let index = 2;
  37. let tar = index * 60;
  38. cc.tween(this.node_turn)
  39. .to(3, { rotation: tar }, { easing: 'expoInOut' })
  40. .call(() => {
  41. this.updateLeftTimes();
  42. }, this).start();
  43. }
  44. updateLeftTimes(){
  45. this.lbl_left.string = `剩余:<color=#FFED99>${gData.turnable.leftTimes}</color>次`;
  46. }
  47. update() {
  48. if (!gData.turnable.dataFinish) {
  49. gData.turnable.init();
  50. }
  51. else{
  52. this.initData();
  53. }
  54. }
  55. }