加分动画

This commit is contained in:
2025-05-27 14:59:33 +08:00
parent 0d47e04a6f
commit b6126cebad
11 changed files with 167 additions and 53 deletions

View File

@@ -1,12 +1,10 @@
{ {
"_$ver": 1, "_$ver": 1,
"_$id": "pl8y75ht", "_$id": "w86l3m5x",
"_$type": "Box", "_$type": "Box",
"name": "ScoreAdd", "name": "ScoreAdd",
"x": 885, "width": 116,
"y": 510, "height": 116,
"width": 150,
"height": 60,
"centerX": 0, "centerX": 0,
"centerY": 0, "centerY": 0,
"_$comp": [ "_$comp": [
@@ -17,40 +15,34 @@
}, },
{ {
"_$type": "c910a064-d127-442e-a884-b5289c488647", "_$type": "c910a064-d127-442e-a884-b5289c488647",
"scriptPath": "../src/views/ScoreAdd.ts" "scriptPath": "../src/views/ScoreAdd.ts",
"label": {
"_$ref": "2eibhgkk"
}
} }
], ],
"_$child": [ "_$child": [
{ {
"_$id": "chd952dx", "_$id": "2eibhgkk",
"_$type": "Box", "_$type": "Label",
"name": "offset", "name": "Label",
"y": -60, "x": 55,
"width": 150, "y": -42,
"width": 200,
"height": 60, "height": 60,
"_$child": [ "anchorX": 0.5,
{ "anchorY": 0.5,
"_$id": "7popbrt7", "centerX": -3,
"_$type": "Label", "text": "+150",
"name": "Label", "font": "res://7322bbf9-175b-4a25-a0d7-72d369894de2",
"x": 75, "fontSize": 60,
"y": 30, "color": "rgba(29, 92, 220, 1)",
"width": 150, "bold": true,
"height": 60, "align": "center",
"anchorX": 0.5, "valign": "middle",
"anchorY": 0.5, "padding": "0,0,0,0",
"text": "+150", "stroke": 16,
"font": "res://7322bbf9-175b-4a25-a0d7-72d369894de2", "strokeColor": "rgba(255, 255, 255, 1)"
"fontSize": 60,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0",
"stroke": 16,
"strokeColor": "rgba(255, 255, 255, 1)"
}
]
} }
] ]
} }

View File

@@ -1,3 +1,3 @@
{ {
"uuid": "a07d56a7-b6d8-40b9-97c2-6c2b0e294ff1" "uuid": "cc3e3def-73ab-4c93-91ca-15fe9360c857"
} }

View File

@@ -0,0 +1,50 @@
{
"_$ver": 1,
"_$id": "r3lhk79l",
"_$type": "Box",
"name": "ScoreAdd_H",
"x": 3,
"y": 3,
"width": 90,
"height": 90,
"centerX": 0,
"centerY": 0,
"_$comp": [
{
"_$type": "bdb0e671-99fa-47a5-9101-7ec008b1d25d",
"scriptPath": "../src/views/common/AutoDestroy.ts",
"lifeTime": 2
},
{
"_$type": "c910a064-d127-442e-a884-b5289c488647",
"scriptPath": "../src/views/ScoreAdd.ts",
"label": {
"_$ref": "4337viuh"
}
}
],
"_$child": [
{
"_$id": "4337viuh",
"_$type": "Label",
"name": "Label",
"x": 42,
"y": -42,
"width": 200,
"height": 45,
"anchorX": 0.5,
"anchorY": 0.5,
"centerX": -3,
"text": "+150",
"font": "res://7322bbf9-175b-4a25-a0d7-72d369894de2",
"fontSize": 45,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0",
"stroke": 16,
"strokeColor": "rgba(255, 255, 255, 1)"
}
]
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "79c5a2f1-0c0d-484c-ad6f-f31b3f3fcbd2"
}

View File

@@ -10,5 +10,6 @@
}, },
"splash": { "splash": {
"fit": "center" "fit": "center"
} },
"stat": true
} }

View File

@@ -24,7 +24,10 @@ export const respath = {
} }
}, },
score_add_ui_res: "resources/ScoreAdd.lh", score_add_ui_res: function func(): string {
return config.H_SCREEN ? "resources/ScoreAdd_H.lh" : "resources/ScoreAdd.lh"
},
common_tips_ui_res: "resources/CommonTips.lh", common_tips_ui_res: "resources/CommonTips.lh",
difficulty_ui_res: "resources/Difficulty.lh", difficulty_ui_res: "resources/Difficulty.lh",

View File

@@ -127,7 +127,7 @@ export class Block extends Laya.Script {
if (this.data.get_checked()) { if (this.data.get_checked()) {
this.data.set_score(score) this.data.set_score(score)
if (score > 0) if (score > 0)
G_ShowScoreTips(score.toString(), this.label_show) G_ShowScoreTips(score.toString(), this.label_show.parent)
} }
else { else {
if (this.data.get_score() != 0) if (this.data.get_score() != 0)

View File

@@ -1,14 +1,44 @@
import { config } from "../constants/config";
import { AutoDestroy } from "./common/AutoDestroy";
const { regClass, property } = Laya; const { regClass, property } = Laya;
@regClass() @regClass()
export class ScoreAdd extends Laya.Script { export class ScoreAdd extends Laya.Script {
declare owner : Laya.Box; declare owner : Laya.Box;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次 @property(Laya.Label)
public label: Laya.Label
onAwake(): void { onAwake(): void {
var offset = this.owner.getChildByName("offset") this.label.scaleX = 0
Laya.Tween.to(offset, {y:-200}, 1000, Laya.Ease.strongIn, null, 500) this.label.skewY = 0
var Label = offset.getChildByName("Label")
Laya.Tween.to(Label, {scaleX:1.5, scaleY:1.5}, 500) var d = this.owner.getComponent(AutoDestroy)
d.lifeTime = 2
} }
onStart(): void {
var wait = 0
var duration = 300
Laya.Tween.to(this.label, {scaleX: 1, scaleY: 1}, duration, Laya.Ease.strongIn, null, wait)
wait += duration
duration = 300
Laya.Tween.to(this.label, {y:-102}, duration, Laya.Ease.strongIn, null, wait)
wait += duration
duration = 300
Laya.Tween.to(this.label, {alpha:0}, duration, Laya.Ease.strongIn, null, wait)
wait += duration
}
public onSetText(text: string): void {
this.label.text = text
}
} }

View File

@@ -25,6 +25,10 @@ export class Stage extends Laya.Script {
public btn_pause: Laya.Button public btn_pause: Laya.Button
@property(Laya.Label) @property(Laya.Label)
public label_score: Laya.Label; public label_score: Laya.Label;
private score_last: number
private score_current: number
private score_step: number
private score_animation_wait_frame = 0
@property(Laya.Label) @property(Laya.Label)
public label_mistake: Laya.Label; public label_mistake: Laya.Label;
@property(Laya.Label) @property(Laya.Label)
@@ -162,7 +166,12 @@ export class Stage extends Laya.Script {
this.btn_new.visible = this.data.get_stageType() == config.STAGE_TYPE.MAIN this.btn_new.visible = this.data.get_stageType() == config.STAGE_TYPE.MAIN
} }
this.score_last = 0
this.score_current = 0
this.onUpdateScore() this.onUpdateScore()
this.score_last = this.score_current
this.label_score.text = `Score: ${this.score_last}`
this.label_name.text = this.data.get_stageName() this.label_name.text = this.data.get_stageName()
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN && config.H_SCREEN) if (this.data.get_stageType() == config.STAGE_TYPE.MAIN && config.H_SCREEN)
this.label_name.text = "" this.label_name.text = ""
@@ -197,14 +206,41 @@ export class Stage extends Laya.Script {
this.onApplyBlock(this.selectedBlock) this.onApplyBlock(this.selectedBlock)
} }
onUpdateScore(): number { onUpdateScore(): void {
var score = 0 var score = 0
var blocks = this.data.get_blocks() var blocks = this.data.get_blocks()
for (var i=0; i<blocks.length; i++) { for (var i=0; i<blocks.length; i++) {
score += blocks[i].get_score() score += blocks[i].get_score()
} }
this.label_score.text = `Score: ${score}` if (this.score_current != score) {//分数发生变化
return score this.score_current = score
this.score_step = Math.ceil((this.score_current - this.score_last)/24)
if (this.score_current > this.score_last)
this.score_animation_wait_frame = 54
else
this.score_animation_wait_frame = 0
this.data.set_score(score)
}
}
onLateUpdate(): void {
this.score_animation_wait_frame --
if (this.score_animation_wait_frame < 0)
this.score_animation_wait_frame = 0
if (this.score_animation_wait_frame <= 0) {
if (this.score_current != this.score_last) {
if (this.score_current > this.score_last) {
this.score_last += this.score_step
if (this.score_last > this.score_current)
this.score_last = this.score_current
this.label_score.text = `Score: ${this.score_last}`
}
else {
this.label_score.text = `Score: ${this.score_current}`
this.score_last = this.score_current
}
}
}
} }
onUpdateMistake(): void { onUpdateMistake(): void {
@@ -408,7 +444,7 @@ export class Stage extends Laya.Script {
blockScore = Utility_CalculateScore(this.data.get_difficulty(), duration) blockScore = Utility_CalculateScore(this.data.get_difficulty(), duration)
} }
var b = this.selectedBlock.setShowNumber(showNumber, blockScore) var b = this.selectedBlock.setShowNumber(showNumber, blockScore)
var score = this.onUpdateScore() this.onUpdateScore()
this.onSetBlock(this.selectedBlock, true) this.onSetBlock(this.selectedBlock, true)
if (b) { if (b) {
this.data.set_last_hit_time(this.data.get_duration()) this.data.set_last_hit_time(this.data.get_duration())
@@ -429,7 +465,6 @@ export class Stage extends Laya.Script {
if (this.getIsComplete()) { if (this.getIsComplete()) {
console.log("完成关卡", finished, all, progress) console.log("完成关卡", finished, all, progress)
this.paused = true this.paused = true
this.data.set_score(score)
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {//主线关卡更新难度进度 if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {//主线关卡更新难度进度
user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1) user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1)
UIManager.getInstance().loadGameDoneUI(true, this.data) UIManager.getInstance().loadGameDoneUI(true, this.data)

View File

@@ -8,7 +8,7 @@ export class AutoDestroy extends Laya.Script {
public lifeTime: number = 1; public lifeTime: number = 1;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次 //组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void { onStart(): void {
if (this.lifeTime < 1) { if (this.lifeTime < 1) {
this.lifeTime = 1 this.lifeTime = 1
} }

View File

@@ -1,10 +1,10 @@
import { respath } from "../../constants/respath" import { respath } from "../../constants/respath"
import { ScoreAdd } from "../ScoreAdd"
export function G_ShowScoreTips(text: string, parent: any): void { export function G_ShowScoreTips(text: string, parent: any): void {
Laya.loader.load(respath.score_add_ui_res).then((go)=>{ Laya.loader.load(respath.score_add_ui_res()).then((go)=>{
var prefab = go.create() var prefab = go.create()
var obj = parent.addChild(prefab) var score = parent.addChild(prefab).getComponent(ScoreAdd)
var Label = obj.getChildByName("offset").getChildByName("Label") as Laya.Label score.onSetText(text)
Label.text = text
}) })
} }