加分动画
This commit is contained in:
@@ -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",
|
||||
difficulty_ui_res: "resources/Difficulty.lh",
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ export class Block extends Laya.Script {
|
||||
if (this.data.get_checked()) {
|
||||
this.data.set_score(score)
|
||||
if (score > 0)
|
||||
G_ShowScoreTips(score.toString(), this.label_show)
|
||||
G_ShowScoreTips(score.toString(), this.label_show.parent)
|
||||
}
|
||||
else {
|
||||
if (this.data.get_score() != 0)
|
||||
|
||||
@@ -1,14 +1,44 @@
|
||||
import { config } from "../constants/config";
|
||||
import { AutoDestroy } from "./common/AutoDestroy";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@regClass()
|
||||
export class ScoreAdd extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
@property(Laya.Label)
|
||||
public label: Laya.Label
|
||||
|
||||
onAwake(): void {
|
||||
var offset = this.owner.getChildByName("offset")
|
||||
Laya.Tween.to(offset, {y:-200}, 1000, Laya.Ease.strongIn, null, 500)
|
||||
var Label = offset.getChildByName("Label")
|
||||
Laya.Tween.to(Label, {scaleX:1.5, scaleY:1.5}, 500)
|
||||
this.label.scaleX = 0
|
||||
this.label.skewY = 0
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -25,6 +25,10 @@ export class Stage extends Laya.Script {
|
||||
public btn_pause: Laya.Button
|
||||
@property(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)
|
||||
public label_mistake: 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.score_last = 0
|
||||
this.score_current = 0
|
||||
this.onUpdateScore()
|
||||
this.score_last = this.score_current
|
||||
this.label_score.text = `Score: ${this.score_last}`
|
||||
|
||||
this.label_name.text = this.data.get_stageName()
|
||||
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN && config.H_SCREEN)
|
||||
this.label_name.text = ""
|
||||
@@ -197,14 +206,41 @@ export class Stage extends Laya.Script {
|
||||
this.onApplyBlock(this.selectedBlock)
|
||||
}
|
||||
|
||||
onUpdateScore(): number {
|
||||
onUpdateScore(): void {
|
||||
var score = 0
|
||||
var blocks = this.data.get_blocks()
|
||||
for (var i=0; i<blocks.length; i++) {
|
||||
score += blocks[i].get_score()
|
||||
}
|
||||
this.label_score.text = `Score: ${score}`
|
||||
return score
|
||||
if (this.score_current != 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 {
|
||||
@@ -408,7 +444,7 @@ export class Stage extends Laya.Script {
|
||||
blockScore = Utility_CalculateScore(this.data.get_difficulty(), duration)
|
||||
}
|
||||
var b = this.selectedBlock.setShowNumber(showNumber, blockScore)
|
||||
var score = this.onUpdateScore()
|
||||
this.onUpdateScore()
|
||||
this.onSetBlock(this.selectedBlock, true)
|
||||
if (b) {
|
||||
this.data.set_last_hit_time(this.data.get_duration())
|
||||
@@ -429,7 +465,6 @@ export class Stage extends Laya.Script {
|
||||
if (this.getIsComplete()) {
|
||||
console.log("完成关卡", finished, all, progress)
|
||||
this.paused = true
|
||||
this.data.set_score(score)
|
||||
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {//主线关卡更新难度进度
|
||||
user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1)
|
||||
UIManager.getInstance().loadGameDoneUI(true, this.data)
|
||||
|
||||
@@ -8,7 +8,7 @@ export class AutoDestroy extends Laya.Script {
|
||||
public lifeTime: number = 1;
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
onStart(): void {
|
||||
if (this.lifeTime < 1) {
|
||||
this.lifeTime = 1
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { respath } from "../../constants/respath"
|
||||
import { ScoreAdd } from "../ScoreAdd"
|
||||
|
||||
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 obj = parent.addChild(prefab)
|
||||
var Label = obj.getChildByName("offset").getChildByName("Label") as Laya.Label
|
||||
Label.text = text
|
||||
var score = parent.addChild(prefab).getComponent(ScoreAdd)
|
||||
score.onSetText(text)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user