添加控件到Hud屏幕
那么,我们应该如何正确添加控件到HUD屏幕呢?
HUD屏幕是游戏中最常打开的屏幕,因此我们需要添加控件到HUD屏幕。
当然,我们也经常使用HUD、开始屏幕测试控件。
首先,我们先添加控件一个控件:
RP/ui/hud_screen.json
1
2
3
4
"test": { "type": "label", "text": "hello world"}
上面的控件只是举例,你可以换成其他类型的控件!
添加一个控件就是如此简单,但是现在控件还不能在HUD屏幕上显示。
所以我们接下来在 root_panel 控件使用
RP/ui/hud_screen.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{"test": { "type": "label", "text": "hello world"},"root_panel": { "modifications": [ { "array_name": "controls", "operation": "insert_back", "value": [ {"test@hud.test": {}} ] } ]}
代码中,控件都在同一个文件,因此我们可以把
我们在 root_panel 执行修改操作,相当于在 controls 添加控件,不过这样也不会影响到其他HUD控件的使用。
modifications 属性执行的修改操作为 insert_back,也就是添加控件到 controls 底部。
我们也可以添加多个控件到 root_panel,只需要在