totalWin修改
This commit is contained in:
parent
51633de04d
commit
d3207a0658
@ -29,10 +29,13 @@
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 84
|
||||
},
|
||||
{
|
||||
"__id__": 86
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 86
|
||||
"__id__": 88
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
@ -152,7 +155,7 @@
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"_enabled": false,
|
||||
"__prefab": {
|
||||
"__id__": 6
|
||||
},
|
||||
@ -1870,6 +1873,42 @@
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "1aRlJri8NNoK1cqeRtKXM0"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 87
|
||||
},
|
||||
"_alignFlags": 45,
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_bottom": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_verticalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 1080,
|
||||
"_originalHeight": 1920,
|
||||
"_alignMode": 2,
|
||||
"_lockFlags": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "f1rfjSbvdLa767bqtNRt81"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
|
||||
@ -17,6 +17,13 @@ export class TotalWin extends Component {
|
||||
NumNodeOpacityCom: UIOpacity | null = null;
|
||||
scoreLabel: Label | null = null; // 分数节点
|
||||
winScore: number = 0; // 最终赢分
|
||||
currentScore: number = 0; // 当前赢分
|
||||
scrollTime: number = 5;
|
||||
isScrolling: boolean = true; // 分数是否在滚动
|
||||
|
||||
// 添加一个标记来区分是否是点击跳过
|
||||
isSkipByTouch: boolean = false;
|
||||
|
||||
btn: Button | null = null;
|
||||
|
||||
closeCallBack: (() => void) | null = null;
|
||||
@ -41,60 +48,112 @@ export class TotalWin extends Component {
|
||||
|
||||
let btnNode = this.totalWinSpine.node.getChildByName('BtnNode');
|
||||
this.btn = btnNode.getChildByName('btnCollect').getComponent(Button);
|
||||
|
||||
this.resetState()
|
||||
this.btn.node.on(Button.EventType.CLICK, this.onClose, this);
|
||||
|
||||
this.winScore = winScore;
|
||||
this.scoreLabel.string = gold2cash(winScore);
|
||||
// this.scoreLabel.string = gold2cash(winScore);
|
||||
this.startScoreAni()
|
||||
this.btn.node.active = false;
|
||||
this.node.addChild(this.totalWinUINode);
|
||||
this.playAnimation();
|
||||
AudioManager.instance.playSFX('Total_Settle_Sound');
|
||||
|
||||
this.totalWinUINode.on(Node.EventType.TOUCH_START, this.onTouch, this);
|
||||
|
||||
this.closeCallBack = closeCallBack;
|
||||
}
|
||||
|
||||
resetState() {
|
||||
this.currentScore = 0;
|
||||
this.isScrolling = true;
|
||||
|
||||
this.scoreLabel.node.scale = v3(1, 1, 1);
|
||||
Tween.stopAllByTarget(this.scoreLabel.node);
|
||||
}
|
||||
|
||||
startScoreAni() {
|
||||
// 修改这里的滚动逻辑
|
||||
let startTime = 0;
|
||||
|
||||
|
||||
let updateScore = function (dt: number) {
|
||||
startTime += dt;
|
||||
let progress = Math.min(startTime / this.scrollTime, 1);
|
||||
|
||||
let easedProgress = this.easeOutQuad(progress);
|
||||
this.currentScore = this.winScore * easedProgress;
|
||||
|
||||
this.updateScoreLabel();
|
||||
|
||||
if (progress >= 1) {
|
||||
this.updateScoreLabel();
|
||||
this.unschedule(updateScore);
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
this.schedule(updateScore, 0.01);
|
||||
}
|
||||
|
||||
// 添加缓动函数
|
||||
easeOutQuad(t: number): number {
|
||||
return t * (2 - t);
|
||||
}
|
||||
|
||||
updateScoreLabel() {
|
||||
if (this.scoreLabel) this.scoreLabel.string = gold2cash(this.currentScore);
|
||||
}
|
||||
|
||||
async onTouch() {
|
||||
console.log('touch')
|
||||
if (!this.totalWinUINode) return; // 添加节点存在检查
|
||||
if (this.isScrolling) {
|
||||
this.isSkipByTouch = true;
|
||||
|
||||
// 立即完成当前动画
|
||||
this.isScrolling = false;
|
||||
this.unscheduleAllCallbacks();
|
||||
|
||||
// 直接设置为最终分数
|
||||
this.currentScore = this.winScore;
|
||||
this.updateScoreLabel();
|
||||
|
||||
this.btn.node.active = true
|
||||
}
|
||||
}
|
||||
|
||||
playAnimation() {
|
||||
this.totalWinSpine.clearTracks();
|
||||
this.totalWinSpine.setAnimation(0, 'animation', true);
|
||||
this.totalWinSpine.node.setScale(0, 0, 0)
|
||||
this.totalWinSpine.node.getComponent(UIOpacity).opacity = 0
|
||||
tween(this.totalWinSpine.node)
|
||||
.to(0.5, { scale: new Vec3(1, 1, 1) })
|
||||
.call(() => {
|
||||
this.btn.node.active = true;
|
||||
this.scheduleOnce(() => {
|
||||
this.onClose();
|
||||
}, 5)
|
||||
})
|
||||
.start()
|
||||
|
||||
tween(this.totalWinSpine.node.getComponent(UIOpacity))
|
||||
.to(0.5, { opacity: 255 })
|
||||
.call(() => {
|
||||
this.scheduleOnce(() => {
|
||||
this.onClose();
|
||||
}, 6)
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
// 加入回调
|
||||
onClose() {
|
||||
this.btn.node.off(Button.EventType.CLICK, this.onClose, this);
|
||||
this.scheduleOnce(() => {
|
||||
AudioManager.instance.playSFX('Total_Settle_Sound_End');
|
||||
}, 0.5)
|
||||
AudioManager.instance.playSFX('Total_Settle_Sound_End');
|
||||
|
||||
this.btn.node.active = false;
|
||||
this.unscheduleAllCallbacks();
|
||||
tween(this.totalWinSpine.node)
|
||||
.to(0.5, { scale: new Vec3(0, 0, 0) })
|
||||
|
||||
tween(this.totalWinSpine.node.getComponent(UIOpacity))
|
||||
.to(0.5, { opacity: 0 })
|
||||
.call(() => {
|
||||
this.totalWinUINode.off(Node.EventType.TOUCH_START, this.onTouch, this);
|
||||
this.totalWinUINode.removeFromParent();
|
||||
NodePoolManager.instance.putNodeToPool('totalWinUI', this.totalWinUINode);
|
||||
this.closeCallBack && this.closeCallBack();
|
||||
})
|
||||
.start()
|
||||
|
||||
tween(this.totalWinSpine.node.getComponent(UIOpacity))
|
||||
.to(0.5, { opacity: 0 })
|
||||
.start()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user