- Godot Engine Game Development Projects
- Chris Bradfield
- 181字
- 2021-06-18 18:51:30
Updating UI via GDScript
Add a script to the HUD node. This script will update the UI elements when their properties need to change, updating the score text whenever a coin is collected, for example. Refer to the following code:
extends CanvasLayer
signal start_game
func update_score(value):
$MarginContainer/ScoreLabel.text = str(value)
func update_timer(value):
$MarginContainer/TimeLabel.text = str(value)
The Main scene's script will call these functions to update the display whenever there is a change in value. For the MessageLabel, you also need a timer to make it disappear after a brief period. Add a Timer node and change its name to MessageTimer. In the Inspector, set its Wait Time to 2 seconds and check the box to set One Shot to On. This ensures that, when started, the timer will only run once, rather than repeating. Add the following code:
func show_message(text):
$MessageLabel.text = text
$MessageLabel.show()
$MessageTimer.start()
In this function, you display the message and start the timer. To hide the message, connect the timeout() signal of MessageTimer and add this:
func _on_MessageTimer_timeout():
$MessageLabel.hide()
- AutoCAD快速入門與工程制圖
- 機(jī)器學(xué)習(xí)及應(yīng)用(在線實(shí)驗(yàn)+在線自測)
- Java實(shí)用組件集
- 自主研拋機(jī)器人技術(shù)
- 西門子S7-200 SMART PLC實(shí)例指導(dǎo)學(xué)與用
- JSP從入門到精通
- Implementing AWS:Design,Build,and Manage your Infrastructure
- Storm應(yīng)用實(shí)踐:實(shí)時事務(wù)處理之策略
- Mastering Game Development with Unreal Engine 4(Second Edition)
- Dreamweaver CS6精彩網(wǎng)頁制作與網(wǎng)站建設(shè)
- 單片機(jī)技能與實(shí)訓(xùn)
- 寒江獨(dú)釣:Windows內(nèi)核安全編程
- 傳感器原理與工程應(yīng)用
- 自適應(yīng)學(xué)習(xí):人工智能時代的教育革命
- 網(wǎng)絡(luò)安全概論