MoveRepeatAction.ts
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { ccclass, property } = cc._decorator;
@ccclass
export default class MoveRepeatAction extends cc.Component {
@property
speed: number = 1;
@property
srcPosX: number = 0;
@property
srcPosY: number = 0;
@property
tempPosX: number = 0;
@property
tempPosY: number = 0;
private readonly _baseTime: number = 1;
onLoad() { }
start() {
}
onEnable() {
let actTime: number = this._baseTime / this.speed;
let ease = cc.easeSineInOut();
let tempAct = cc.moveTo(actTime, cc.v2(this.tempPosX, this.tempPosY)).easing(ease);
let srcAct = cc.moveTo(actTime, cc.v2(this.srcPosX, this.srcPosY)).easing(ease);
this.node.stopAllActions();
let call = cc.callFunc(() => {
this.node.x = this.srcPosX;
this.node.y = this.srcPosY;
})
this.node.runAction(cc.repeatForever(cc.sequence(call, tempAct)));
}
onDisable() {
this.node.stopAllActions();
this.node.x = this.srcPosX;
this.node.y = this.srcPosY;
}
update(dt) { }
}