rp_11001/assets/Game/scripts/game/FreeSpinAdd.ts
TJH d8f70ea441
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m12s
音效资源添加,小游戏中小游戏界面可以点击快速跳过
2025-12-29 15:40:00 +08:00

80 lines
2.8 KiB
TypeScript

import { _decorator, Button, Component, Label, Node, Prefab, sp, Sprite, Tween, tween, UIOpacity, v3, Vec3 } from 'cc';
import { NodePoolManager } from '../../../Loading/scripts/manager/NodePoolManager';
import { AudioManager } from 'db://assets/Loading/scripts/manager/AudioManager';
const { ccclass, property } = _decorator;
@ccclass('FreeSpinAdd')
export class FreeSpinAdd extends Component {
@property(Prefab)
freeSpinAddPre: Prefab = null;
freeSpinAddUI: Node = null;
freeSpinAddSpine: sp.Skeleton | null = null;
freeSpinEnterTitleSp: Sprite | null = null;
freeCountLabel: Label | null = null;
freeCount: number = 0;
closeCallBack: (() => void) | null = null;
show(freeCount: number, closeCallBack: (() => void) | null = null) {
this.freeSpinAddUI = NodePoolManager.instance.getNodeFromPoolStatic('freeSpinAdd', this.freeSpinAddPre);
this.freeSpinAddSpine = this.freeSpinAddUI.getChildByName('spine').getComponent(sp.Skeleton);
let numNode = this.freeSpinAddSpine.node.getChildByName('NumNode');
this.freeCountLabel = numNode.getChildByName('Label').getComponent(Label);
let titleNode = this.freeSpinAddSpine.node.getChildByName('TitleNode');
this.freeSpinEnterTitleSp = titleNode.getChildByName('SpriteFREESPINWON').getComponent(Sprite);
this.freeSpinAddUI.on(Node.EventType.TOUCH_START, this.onTouch, this);
this.freeCount = freeCount;
this.freeCountLabel.string = `+ ${freeCount}`;
this.node.addChild(this.freeSpinAddUI);
this.playAnimation();
this.closeCallBack = closeCallBack;
}
async onTouch() {
if (!this.freeSpinAddUI) return; // 添加节点存在检查
this.onClose()
}
playAnimation() {
this.freeSpinAddSpine.clearTracks();
this.freeSpinAddSpine.setAnimation(0, 'animation', true);
this.freeSpinAddSpine.node.setScale(0, 0, 0)
this.freeSpinAddSpine.node.getComponent(UIOpacity).opacity = 0
tween(this.freeSpinAddSpine.node)
.to(0.5, { scale: new Vec3(1, 1, 1) })
.call(() => {
this.scheduleOnce(() => {
this.onClose();
}, 5)
})
.start()
tween(this.freeSpinAddSpine.node.getComponent(UIOpacity))
.to(0.5, { opacity: 255 })
.start()
}
// 加入回调
onClose() {
this.unscheduleAllCallbacks();
tween(this.freeSpinAddSpine.node.getComponent(UIOpacity))
.to(0.5, { opacity: 0 })
.call(() => {
this.freeSpinAddUI.removeFromParent();
NodePoolManager.instance.putNodeToPool('freeSpinAdd', this.freeSpinAddUI);
this.closeCallBack && this.closeCallBack();
})
.start()
}
}