MoveUpAndDown.ts 990 B

1234567891011121314151617181920212223242526272829
  1. const { ccclass, property } = cc._decorator;
  2. @ccclass
  3. export default class MoveUpAndDown extends cc.Component {
  4. @property({ displayName: '移动的相对距离' })
  5. private moveOffset: cc.Vec3 = cc.Vec3.ZERO;
  6. @property({ displayName: '移动时间' })
  7. private duration: number = 0;
  8. private startPos: cc.Vec3 = cc.Vec3.ZERO;
  9. start() {
  10. this.node.getPosition(this.startPos);
  11. // let pos = cc.Vec3.ZERO;
  12. // this.startPos.add(this.moveOffset, pos);
  13. // let move1= cc.moveBy(this.duration, cc.v2(this.moveOffset.x, this.moveOffset.y));
  14. // let move2 = cc.moveBy(this.duration, cc.v2(-this.moveOffset.x, -this.moveOffset.y));
  15. // let seq= cc.sequence([move1, move2]);
  16. // this.node.runAction(cc.repeatForever(seq));
  17. cc.tween(this.node).by(this.duration, { y: this.moveOffset.y }).by(this.duration, { y: -this.moveOffset.y }).union().repeatForever().start();
  18. }
  19. }