0 votes

Take a look at the below function I have. It adds a 64x64 Sprite in the game but multiple times. I want to somehow connect the Image with a variable that keeps my lifepoints. For example 3 lifepoints will mean 3 hearts on screen and so on. How am I supposed to do something like that ?

>    func resistanceDisplay():
>       var t = Texture.new()
>       t=load("res://Textures/Heart.png")
>       resistancelabel.add_image(t,64,64) #resistancelabel just refers to RichTextLabel
Godot version v3.2
in Engine by (414 points)

1 Answer

0 votes
Best answer

If you want to display hearts in UI, you can use HBoxContainer or VBoxContainer (based on direction of your healthbar). To add one heart you need to add new TextureRect. To take one heart you can simply remove first child of box container (but make sure that you have hearts there).

Then to add heart:

var heart := TextureRect.new()
heart.texture = load("res://Textures/Heart.png")
boxcontainer.add_child(heart)

And to take heart:

if boxcontainer.get_child_count() > 0:
    boxcontainer.get_child(0).queue_free()
by (1,646 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.