本章节效果图
1. 搭建场景树
打开UI场景,依照下图搭建场景树
- “TextureInfoBoard”:
TextureRect
类型,用于在UI上显示图片 - “LabelCurrent”:
Label
类型,用于显示本局成绩 - “LabelRecord”:
Label
类型,用于显示历史最好成绩 - “AnimationPlayer”:
AnimationPlayer
类型,信息板动画容器
2. 设置AnimationPlayer
一共需要2个动画
本动画时长为5帧,让信息板从下向上弹出来,AnimationPlayer
的使用前面章节已经介绍过,此处不再赘述。
这个动画只需要一帧
3. InfoBoard脚本
#InfoBoard.gd
extends TextureRect
func _ready():
add_to_group("GAME_STATE")
func on_game_over():
$LabelCurrent.text = str(GameData.score)#显示本局成绩
$LabelRecord.text = str(GameData.load_record())#显示历史最好成绩
$AnimationPlayer.play("show")#显示计分板
4. 运行
运行Game场景