Trying make a label show after a hit

Godot Version

4.2.1

Question

Hello there. So for my game, I am trying to make so that a label appers every time the player gets hit. I thought I could use a signal like visibility changed but I didn’t do anything. Would gladly appreciate any help.

Images

Here are some images of the coding and what I am trying to do.

this basically instantiate a scene that’s label and has a script which will be spawned on specified player position like its head

the keyword for this is
floating text
some video you can watch how to make one are these

mind that some of these are in godot 3. but last one is definitely in godot 4

So instead of putting the labels on the character, I make a whole new scene just for the labels?

a scene with label inside where you can instantiate and alter the values to show before add_child
generally like that

Alright I will try this out, also just out of curiosity, would the process be the same if instead of a label I used a sprite 2d?

sprite2d to show text? so there are number 1 to 10?
or you meant to also include sprite2d inside the scene with label?

no not show text, but to show the sprite2d instead. Also, I would like to point out that I am not trying to with numbers, just mainly 3 specific letters.

then it’s quicker, just load the sprite according what you wanted, the value of which to show will just be the address to your resource or just an id to call which texture to show

Ok, do I still need to make a seperate scene for that sprite?

there are many ways to make the texture ready to be used, generally using @export var, but some used @onready var to store the image, then just call it with name from match or enum, you can even put it in array so just call it with it.
it dont have to be a new scene inside a new scene just for a sprite2d, the one you will need to create and will be spawned is enough to change the sprite2d texture to what you wanted
meaning you just swap the texture of this sprite2D node according to what you wanted to show

1 Like

Ok I’ll try that out

Hey, sorry for asking this but I am still a little confused regarding this and how to apply it on gdscript, could you provide me a visual example of how that would look like?

code:

extends Node2D

@export var sprites_texture1:Texture2D
@export var sprites_texture2:Texture2D
@export var sprites_texture3:Texture2D
@onready var sprite_2d:Sprite2D=$Sprite2D
var show_texture=null

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func set_default_value(id):
	match id:
		1:
			show_texture=sprites_texture1
		2:
			show_texture=sprites_texture2
		3:
			show_texture=sprites_texture3

func animate_show(id):
	set_default_value(id)
	sprite_2d.texture=show_texture
#do the floating effect animation here

the tree:
image

the export in inspector dock:
image

to call it from other node, you first have to instantiate this scene then add child
to show what the texture, call this newly instantiated scene animate_show() method to show the floating effect after you done setting the position where it will show

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.