Rotate.ts 668 B

123456789101112131415161718192021222324252627282930313233
  1. const { ccclass, property } = cc._decorator;
  2. @ccclass
  3. export default class NewClass extends cc.Component {
  4. @property
  5. private speed: number = 1;
  6. @property
  7. private isRotate: boolean = true;
  8. @property
  9. private isChangeDir: boolean = false;
  10. @property
  11. private isChangeRotateDir: boolean = false;
  12. // LIFE-CYCLE CALLBACKS:
  13. // onLoad () {}
  14. start() {
  15. if ((this.isChangeDir && this.node.parent.x > 0) || (this.isChangeRotateDir && this.node.parent.scaleX < 0)) {
  16. this.speed = -this.speed;
  17. }
  18. }
  19. update(dt) {
  20. if (!this.isRotate) return;
  21. this.node.angle += this.speed;
  22. }
  23. }