openPrizeAnimEven.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { _decorator, Component, Node, Animation, find, EventHandler } from 'cc';
  2. import { Sound } from '../core/sound/Sound';
  3. import { ConfigData } from '../Data/ConfigData';
  4. import { g } from '../Data/g';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('openPrizeAnimEven')
  7. export class openPrizeAnimEven extends Component {
  8. // @property({ tooltip: "跑马灯动画结束回调", type: EventHandler })
  9. // public animationEndFun: EventHandler;
  10. @property({ tooltip: "闪烁动画结束回调", type: EventHandler })
  11. public animation0EndFun: EventHandler;
  12. @property({ tooltip: "转盘抽奖音效控制器", type: Sound }) public turntableSound: Sound;
  13. private tempAnimation: Animation;
  14. private upSpeed = 0;//跑马灯圈数
  15. private temp_Number = 0;
  16. private prizeNum = 0;//获奖奖品序号(1~8)
  17. public prizeArryConfig = [];//奖品展示排序配置
  18. start() {
  19. this.tempAnimation = this.node.getComponent(Animation);
  20. this.prizeArryConfig = ConfigData.configMap.get("turntable").showOrder;
  21. }
  22. //设置中奖序号
  23. public setPrizeNum(prizeNum: number) {
  24. this.prizeNum = this.prizeArryConfig.indexOf(prizeNum) + 1;
  25. }
  26. public test(speed: number) {
  27. this.turntableSound.play();
  28. if (this.tempAnimation.getState('openPrize').speed >= 3 || this.upSpeed >= 5) {
  29. this.upSpeed += speed == 3 ? 1 : 0;
  30. if (this.upSpeed >= 5) {
  31. let temp = this.prizeNum < 6 ? (this.prizeNum + 8) : this.prizeNum;
  32. this.temp_Number = this.temp_Number == 0 ? temp + 1 : this.temp_Number;
  33. this.temp_Number--;
  34. if (this.temp_Number < 6) {
  35. this.tempAnimation.getState('openPrize').speed = this.tempAnimation.getState('openPrize').speed - ((this.temp_Number - 1) * 0.2 + 0.1);
  36. if (this.temp_Number == 0) {
  37. // this.animationEndFun.emit([]);
  38. this.tempAnimation.stop();
  39. this.tempAnimation.play('openPrize0')
  40. this.upSpeed = 0;
  41. }
  42. }
  43. }
  44. } else {
  45. this.tempAnimation.getState('openPrize').speed = speed;
  46. }
  47. }
  48. public animation0Times = 8;
  49. public animation0End() {
  50. this.turntableSound.play();
  51. this.animation0Times--;
  52. if (this.animation0Times <= 0) {
  53. this.tempAnimation.stop();
  54. this.animation0Times = 8;
  55. this.animation0EndFun.emit([]);
  56. }
  57. }
  58. }