squidGame/tgx-games-client/assets/module_arean/level3/script/RewardChest.ts

69 lines
1.8 KiB
TypeScript

import { _decorator, Component, Node, Animation, UIOpacity, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('RewardChest')
export class RewardChest extends Component {
@property(Node)
chestNode: Node = null!;
@property(Node)
lightEffect: Node = null!;
@property(UIOpacity)
maskOpacity: UIOpacity = null!;
@property(Node)
particles: Node = null!;
start() {
// 初始化
if (this.particles) {
this.particles.active = false;
}
this.playAppearAnimation();
}
playAppearAnimation() {
// 背景遮罩渐入
if (this.maskOpacity) {
tween(this.maskOpacity)
.to(0.3, { opacity: 180 })
.start();
}
// 宝箱从小变大
if (this.chestNode) {
this.chestNode.scale = new Vec3(0.1, 0.1, 0.1);
tween(this.chestNode)
.to(0.5, { scale: new Vec3(1, 1, 1) }, {
easing: 'backOut'
})
.start();
}
// 光效旋转
if (this.lightEffect) {
this.lightEffect.angle = 0;
tween(this.lightEffect)
.by(3, { angle: 360 })
.repeatForever()
.start();
}
}
playOpenAnimation() {
if (this.chestNode) {
tween(this.chestNode)
.by(0.1, { position: new Vec3(0, 5, 0) })
.by(0.1, { position: new Vec3(0, -5, 0) })
.by(0.1, { scale: new Vec3(0.1, 0.1, 0.1) })
.by(0.1, { scale: new Vec3(-0.1, -0.1, -0.1) })
.call(() => {
if (this.particles) {
this.particles.active = true;
}
})
.start();
}
}
}