QScaleAction.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import QEasing, { EaseType } from "./QEasing";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class QScaleAction extends QEasing {
  5. @property()
  6. delay: number = 0;
  7. @property()
  8. fromScale: cc.Vec2 = cc.Vec2.ZERO;
  9. @property(cc.Vec2)
  10. targetScale: cc.Vec2 = cc.Vec2.ZERO;
  11. @property()
  12. duration: number = 0;
  13. @property()
  14. loop: boolean = false;
  15. @property()
  16. revert: boolean = false;
  17. private _tween: cc.Tween = null;
  18. onLoad(){
  19. this.node.scaleX = this.fromScale.x;
  20. this.node.scaleY = this.fromScale.y;
  21. let delayTween: cc.Tween = cc.tween();
  22. delayTween.delay(this.delay);
  23. let actionTween: cc.Tween = cc.tween();
  24. if(this.revert){
  25. actionTween.to(this.duration*0.5, {scaleX: this.targetScale.x, scaleY: this.targetScale.y}, {easing: this._getEase()});
  26. actionTween.to(this.duration*0.5, {scaleX: this.fromScale.x, scaleY: this.fromScale.y}, {easing: this._getEase()});
  27. }else{
  28. actionTween.to(this.duration, {scaleX: this.targetScale.x, scaleY: this.targetScale.y}, {easing: this._getEase()});
  29. }
  30. this._tween = cc.tween(this.node);
  31. this._tween.then(delayTween);
  32. this._tween.then(actionTween);
  33. if(this.loop){
  34. this._tween.repeatForever();
  35. }
  36. }
  37. onEnable() {
  38. this.node.scaleX = this.fromScale.x;
  39. this.node.scaleY = this.fromScale.y;
  40. this._tween.start();
  41. }
  42. }