0 votes

I have a Player with a

var Livepoints = 20

I want to shoe these Livepoints with small HeartSprites. I have twenty of them. Theier names are like this:
Livepoint1
Livepoint2
Livepoint3
...
Now I want that there are only so much sprites visible as much Livepoints the Player has.

in Engine by (333 points)
edited by

What's the point of updating it if the value hasn't changed?

Ok, then it is doesnt matter when it is upgradet.
(I edit the question)

1 Answer

0 votes
Best answer

Just to make sure I understand you right: you want to display the health of the player by showing hearts on the screen?

I am not sure why you want to name the sprites differently, do the hearts look different?
Assuming that there is only 1 heart sprite, I would approach it like this:

  1. Load the sprite into whatever scene you want to use it in (I guess making a HUD scene with a control node would be best)

Like this:

const HEART = load('path_to_your_heart')
  1. On the HUD scene create something that can hold and organise the hearts, like a HBoxContainer node.

  2. Now you want to create a function that adds a heart sprite to that HBoxContainer for every point of health the player has.

Something like this:

func add_hearts():
    for heart in Lifepoints:
        $HBoxContainer.add_child(HEART.instance())

Once you actually play the game, you want to eventually add some more functionality that whenever the player gets hit or gains a lifepoint, that you empty the entire HBoxContainer and then add the hearts again depending on the new amount of lifepoints.

Hope that helps.

P.S. I don't have Godot open in front of me, but I am reasonably sure it would work like that. But you might need to tinker around with it.

by (244 points)
selected by

But now every heart is on the same place. How can I fix that?

The HBoxContainer should take of that. I assume you are putting the heart into a sprite node? Replace that sprite node with a textureRect node and they should appear next to each other.

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.