RandomPut.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const { ccclass, property } = cc._decorator;
  2. @ccclass
  3. export default class RandomPut extends cc.Component {
  4. @property
  5. private isDirection: boolean = false;
  6. @property
  7. private isAngle: boolean = false;
  8. @property
  9. private isFanzhuan: boolean = false;
  10. // LIFE-CYCLE CALLBACKS:
  11. onEnable() {
  12. }
  13. start() {
  14. let left = (Math.random() > 0.5) ? true : false;
  15. if (this.isDirection) {
  16. let posX = Math.abs(this.node.x);
  17. this.node.x = (left) ? posX : -posX;
  18. let angles = Math.abs(this.node.angle);
  19. this.node.angle = (left) ? angles : -angles;
  20. console.log('isDirection:', this.node.x, left, ' this.node.angle', this.node.angle);
  21. }
  22. if (this.isAngle) {
  23. let angle = Math.abs(this.node.angle);
  24. this.node.angle = (left) ? angle : -angle;
  25. }
  26. if (this.isFanzhuan) {
  27. let scaleX = Math.abs(this.node.scaleX);
  28. this.node.scaleX = (left) ? scaleX : -scaleX;
  29. }
  30. }
  31. // update (dt) {}
  32. }