| 1234567891011121314151617181920212223242526272829 |
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class MoveUpAndDown extends cc.Component {
- @property({ displayName: '移动的相对距离' })
- private moveOffset: cc.Vec3 = cc.Vec3.ZERO;
- @property({ displayName: '移动时间' })
- private duration: number = 0;
- private startPos: cc.Vec3 = cc.Vec3.ZERO;
- start() {
- this.node.getPosition(this.startPos);
- // let pos = cc.Vec3.ZERO;
- // this.startPos.add(this.moveOffset, pos);
-
- // let move1= cc.moveBy(this.duration, cc.v2(this.moveOffset.x, this.moveOffset.y));
- // let move2 = cc.moveBy(this.duration, cc.v2(-this.moveOffset.x, -this.moveOffset.y));
- // let seq= cc.sequence([move1, move2]);
- // this.node.runAction(cc.repeatForever(seq));
-
- cc.tween(this.node).by(this.duration, { y: this.moveOffset.y }).by(this.duration, { y: -this.moveOffset.y }).union().repeatForever().start();
- }
- }
|