MoveUpAndDown.ts 707 B

12345678910111213141516171819202122232425
  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. cc.tween(this.node).to(this.duration, { position: pos }).to(this.duration, { position: cc.v3(this.startPos) }, cc.easeSineOut())
  14. .union().repeatForever().start();
  15. }
  16. }