Saturday, April 6, 2024

Godot dynamicFont

 This is a short entry, but it fixes the problem I had with the localization files. It was due to the font not properly found, after "hardcoding it" into the project for each node, it worked. Here's the change and the proof, in case someone has the same problem in the future (or even just a reminder for me)



Also, here's the PS Vita with the multilanguage working:



Extra: The Lifebar Node working:
- Root: Control Node (Lifebar), with children nodes: Tween, HBoxContainer (Bars), and a Label (Number)
- Besides, the Bars node also has children Nodes: MarginContainer (Count), and TextureProgress.
And the code for the attached script,
```
extends Control

var hearts = 4 setget set_hearts
var max_hearts = 4

onready var number_label = $Number
onready var bar = $Bars/TextureProgress
onready var tween = $Tween

var animated_health = 0

func _ready():
    var PlayerStats = get_parent().get_node("Stats")
    var player_max_health = PlayerStats.max_health
    bar.max_value = player_max_health
    update_health(player_max_health)


    self.max_hearts = PlayerStats.max_health
    self.hearts = PlayerStats.health
    # warning-ignore:return_value_discarded
    PlayerStats.connect("health_changed", self, "set_hearts")
    # warning-ignore:return_value_discarded
    PlayerStats.connect("max_health_changed", self, "set_max_hearts")



func set_hearts(value):
    hearts = clamp(value, 0, max_hearts)
    update_health(value)


func update_health(new_value):
    tween.interpolate_property(self, "animated_health", animated_health, new_value, 0.2, Tween.TRANS_LINEAR, Tween.EASE_IN)
    if not tween.is_active():
        tween.start()
    number_label.text = str(new_value)


func _process(delta):
    var round_value = round(animated_health)
    bar.value = round_value
```

No comments:

Post a Comment