0 votes

I'm a total noob, so sorry if this is impossible or super basic. I'm trying to make a game where you have a limited number of jumps, I want to show the number of jumps left on the screen. To do this, my idea is to have a bunch of sprites with numbers written on them, with the lowest at the bottom, and the highest at the top. So when you jump, the highest number disappears, revealing the number that's smaller by one. I want to do this by having the sprites be named the number they are, and then making the sprite with the name of the numberofjumps_left variable turn invisible. How can I make an integer a variable, so I can do this? If this is impossible, what's a better way to implement this mechanic?

Here's some rough code of what I'm trying to do.

var number_of_jumps_left = 10

func _physics_process(delta) -> void:
      if Input.is_action_just_pressed("jump"):
            number_of_jumps_left.visible = false
            number_of_jumps_left -= 1
in Engine by (21 points)

1 Answer

+1 vote
Best answer

I don't entirely understand this reasoning.
If You plan to have images of numbers named after those numbers - it will be easier to translate your integer variable to string image path, like this :

number_of_jumps_left -= 1
TextSprite.texture = load("res://numbers/" + str(number_of_jumps_left) + ".png")

TextSprite is exxample name of your Sprite that will change textures
example folder to keep images is "numbers", and images should be named "1" "2" "3" and so on

by (6,367 points)
selected by

Thank you! Finally got this stupid thing working.

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