Farmer.ts 1.2 KB

1234567891011121314151617181920212223242526272829
  1. import { _decorator, Component, Node, Animation, v3, Sprite } from 'cc';
  2. import { TakeAWalk, WalkState } from '../public/TakeAWalk';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('Farmer')
  5. export class Farmer extends Component {
  6. @property({ type: TakeAWalk, tooltip: "散步组件" }) walk: TakeAWalk;
  7. @property({ type: Animation, tooltip: "动画组件" }) animation: Animation;
  8. @property({ type: Sprite, tooltip: "动画组件" }) forwardMask: Sprite;
  9. @property({ type: Sprite, tooltip: "动画组件" }) backMask: Sprite;
  10. update() {
  11. if (this.walk.curTargetPoint && this.walk.curTargetPoint.x > this.node.position.x) {
  12. this.node.setScale(v3(-1, 1, 1));
  13. } else {
  14. this.node.setScale(v3(1, 1, 1));
  15. }
  16. if (this.walk.state == WalkState.Stop) {
  17. if (this.walk.curTargetPoint && this.walk.curTargetPoint.y > this.node.position.y) {
  18. this.animation.play(this.animation.clips[1].name);
  19. this.forwardMask.node.active = !(this.backMask.node.active = true);
  20. } else {
  21. this.animation.play(this.animation.clips[0].name);
  22. this.forwardMask.node.active = !(this.backMask.node.active = false);
  23. }
  24. }
  25. }
  26. }