The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

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:
Now I want that there are only so much sprites visible as much Livepoints the Player has.

in Engine by (378 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:

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 (259 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 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.