QRotation.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import QEasing, { EaseType } from "./QEasing";
  2. const {ccclass, property} = cc._decorator;
  3. @ccclass
  4. export default class QRotateAction extends QEasing {
  5. @property()
  6. delay: number = 0;
  7. @property({tooltip: "初始角度,顺时针为负数"})
  8. angle: number = 0;
  9. @property()
  10. duration: number = 0;
  11. @property()
  12. loop: boolean = false;
  13. @property()
  14. revert: boolean = false;
  15. private _originAngle: number = 0;
  16. private _tween: cc.Tween = null;
  17. onLoad(){
  18. this._originAngle = this.node.angle;
  19. let delayTween:cc.Tween = cc.tween().delay(this.delay);
  20. let actionTween: cc.Tween = cc.tween();
  21. if(this.revert){
  22. actionTween.by(this.duration/2,{angle: this.angle}).by(this.duration/2, {angle: -this.angle}, {easing: this._getEase()});
  23. }else{
  24. actionTween.by(this.duration, {angle: this.angle}, {easing: this._getEase()});
  25. }
  26. this._tween = cc.tween(this.node);
  27. this._tween.then(delayTween);
  28. this._tween.then(actionTween);
  29. if(this.loop){
  30. this._tween.repeatForever();
  31. }
  32. }
  33. onEnable(){
  34. this.node.angle = this._originAngle;
  35. this._tween.start();
  36. }
  37. }