UIAction.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. export enum EasingEnum {
  2. quadIn = 0,
  3. quadOut = 1,
  4. quadInOut = 2,
  5. cubicIn = 3,
  6. cubicOut = 4,
  7. cubicInOut = 5,
  8. quartIn = 6,
  9. quartOut = 7,
  10. quartInOut = 8,
  11. quintIn = 9,
  12. quintOut = 10,
  13. quintInOut = 11,
  14. sineIn = 12,
  15. sineOut = 13,
  16. sineInOut = 14,
  17. expoIn = 15,
  18. expoOut = 16,
  19. expoInOut = 17,
  20. circIn = 18,
  21. circOut = 19,
  22. circInOut = 20,
  23. elasticIn = 21,
  24. elasticOut = 22,
  25. elasticInOut = 23,
  26. backIn = 24,
  27. backOut = 25,
  28. backInOut = 26,
  29. bounceIn = 27,
  30. bounceOut = 28,
  31. bounceInOut = 29,
  32. smooth = 30,
  33. fade = 31
  34. }
  35. const { ccclass, property } = cc._decorator;
  36. @ccclass
  37. export default class NewClass extends cc.Component {
  38. @property({ type: cc.Enum(EasingEnum) })
  39. public easings: EasingEnum = EasingEnum.smooth;
  40. @property
  41. duration: number = 2;
  42. @property
  43. isScale: boolean = false;
  44. @property
  45. startScale: number = 2;
  46. @property
  47. targetScale: number = 1;
  48. /**初始隐藏 */
  49. @property
  50. isStartHide: boolean = false;
  51. @property
  52. isMove: boolean = false;
  53. @property(cc.Vec3)
  54. startPos: cc.Vec3 = new cc.Vec3(0, 50, 0);
  55. @property(cc.Vec3)
  56. endPos: cc.Vec3 = new cc.Vec3(0, 0, 0);
  57. @property
  58. isInterval: boolean = false;
  59. @property
  60. intervalTime: number = 1;
  61. @property
  62. isLoop: boolean = false;
  63. // LIFE-CYCLE CALLBACKS:
  64. onLoad() {
  65. this.Init();
  66. (this.isInterval) ? this.scheduleOnce(() => { this.TweenFunc(); }, this.intervalTime) : this.TweenFunc();
  67. }
  68. private Init() {
  69. if (this.isMove) this.node.position = this.startPos;
  70. if (this.isScale) this.node.setScale(this.startScale);
  71. if (this.isStartHide) this.node.opacity = 0;
  72. }
  73. private TweenFunc() {
  74. if (this.isStartHide) this.node.opacity = 255;
  75. let tweens = cc.tween();
  76. //, position: this.currentPos
  77. if (this.isScale) tweens.to(this.duration, { scale: this.targetScale }, { easing: EasingEnum[this.easings] });
  78. if (this.isMove) tweens.to(this.duration, { position: this.endPos }, { easing: EasingEnum[this.easings] });
  79. tweens.call(() => {
  80. // this.node.setScale(this.startScale);
  81. console.log('缓动结束回调');
  82. // if (this.callback) this.callback();
  83. });
  84. (this.isLoop) ? cc.tween(this.node).repeatForever(tweens).start() : cc.tween(this.node).repeat(1, tweens).start();
  85. }
  86. // update (dt) {}
  87. }