TweenNormal.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 TweenNormal extends cc.Component {
  38. @property
  39. duration: number = 2;
  40. @property
  41. startScale: number = 1;
  42. @property
  43. targetScale: number = 1;
  44. // @property(cc.Vec2)
  45. // Pos1: cc.Vec2 = new cc.Vec2(0, 50);
  46. // @property(cc.Vec2)
  47. // Pos2: cc.Vec2 = new cc.Vec2(0, 0);
  48. // currentPos: cc.Vec2 = new cc.Vec2(0, 0);
  49. @property
  50. intervalTime: number = 1;
  51. @property
  52. isLoop: boolean = true;
  53. @property({ type: cc.Enum(EasingEnum) })
  54. public easings: EasingEnum = EasingEnum.smooth;
  55. callback: Function = null;
  56. onLoad() {
  57. this.Tweens();
  58. }
  59. /**
  60. * 播放缩放动画
  61. */
  62. public Tweens() {
  63. let tweens = cc.tween();
  64. //, position: this.currentPos
  65. tweens.to(this.duration, { scale: this.targetScale }, { easing: EasingEnum[this.easings] });
  66. tweens.call(() => {
  67. this.node.setScale(this.startScale);
  68. // console.log('缓动结束回调');
  69. if (this.callback) this.callback();
  70. });
  71. (this.isLoop) ? cc.tween(this.node).repeatForever(tweens).start() : cc.tween(this.node).repeat(1, tweens).start();
  72. }
  73. }