0 votes

I'm making a game and I want it to have a life counter (in number) and by taking damage logically decreasing the life on the label

in Engine by (12 points)

Do you have a question? What have you made already? If you're stuck on some part, bec specific about what you tried and what didn't work.

The Godot tutorial game has examples of using labels and updating them:
https://docs.godotengine.org/en/stable/getting_started/step_by_step/your_first_game.html

I was researching before and watching some videos and I tried set_text, but nothing changed, in that part that I crashed, because I want it to be showing life in number and when colliding with the enemy, take 1 when taking damage

Well, you wouldn't use set_text(), you'd get a reference to your Label node and set its text with label_node.text = str(some_number). But again, I can't tell you what you may or may not be doing wrong without any more information. And if you crashed, it was for a reason, and the error message is very important - it tells you what is wrong.

1 Answer

0 votes

Something like:

var life = 0
var new_label = Label.new()

func _ready():
    add_child(new_label)
    life = 100
    new_label.text = str(life)

func do_damage(amount):
    life -= amount
    new_label.text = str(life)
by (320 points)

I tested the label and it was in the center of the player, how can I change the label's place to be on top of his head? and i can change color?

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 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 webmaster@godotengine.org with your username.