40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
const { ccclass } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class CatBounce extends cc.Component {
|
|
private baseY: number = 0;
|
|
private baseScaleX: number = 1;
|
|
private baseScaleY: number = 1;
|
|
|
|
onLoad() {
|
|
this.baseY = this.node.y;
|
|
this.baseScaleX = this.node.scaleX;
|
|
this.baseScaleY = this.node.scaleY;
|
|
}
|
|
|
|
start() {
|
|
this.playBounce();
|
|
}
|
|
|
|
public playBounce() {
|
|
this.node.stopAllActions();
|
|
this.node.y = this.baseY;
|
|
this.node.scaleX = this.baseScaleX;
|
|
this.node.scaleY = this.baseScaleY;
|
|
|
|
cc.tween(this.node)
|
|
.repeatForever(
|
|
cc.tween()
|
|
.to(0.1984, { y: this.baseY - 4, scaleX: this.baseScaleX * 1.08, scaleY: this.baseScaleY * 0.94 }, { easing: "sineInOut" })
|
|
.to(0.2381, { y: this.baseY + 8, scaleX: this.baseScaleX * 0.93, scaleY: this.baseScaleY * 1.08 }, { easing: "sineInOut" })
|
|
.to(0.1786, { y: this.baseY - 2, scaleX: this.baseScaleX * 1.03, scaleY: this.baseScaleY * 0.98 }, { easing: "sineInOut" })
|
|
.to(0.2183, { y: this.baseY, scaleX: this.baseScaleX, scaleY: this.baseScaleY }, { easing: "sineOut" })
|
|
)
|
|
.start();
|
|
}
|
|
|
|
onDestroy() {
|
|
this.node.stopAllActions();
|
|
}
|
|
}
|