import { _decorator, Component, Node, Animation, v3, Sprite } from 'cc'; import { TakeAWalk, WalkState } from '../public/TakeAWalk'; const { ccclass, property } = _decorator; @ccclass('Farmer') export class Farmer extends Component { @property({ type: TakeAWalk, tooltip: "散步组件" }) walk: TakeAWalk; @property({ type: Animation, tooltip: "动画组件" }) animation: Animation; @property({ type: Sprite, tooltip: "动画组件" }) forwardMask: Sprite; @property({ type: Sprite, tooltip: "动画组件" }) backMask: Sprite; update() { if (this.walk.curTargetPoint && this.walk.curTargetPoint.x > this.node.position.x) { this.node.setScale(v3(-1, 1, 1)); } else { this.node.setScale(v3(1, 1, 1)); } if (this.walk.state == WalkState.Stop) { if (this.walk.curTargetPoint && this.walk.curTargetPoint.y > this.node.position.y) { this.animation.play(this.animation.clips[1].name); this.forwardMask.node.active = !(this.backMask.node.active = true); } else { this.animation.play(this.animation.clips[0].name); this.forwardMask.node.active = !(this.backMask.node.active = false); } } } }