There are lots of ways you could do this. Here’s an outline for one…
- Add a
RichTextLabel as a child of your enemy
- Set the visibility to
- Using either an
Tween, adjust all of the label properties you want over time (visibility, scale, rotation, position, …)
- When the enemy takes damage…
- Set the
text / bbcode_text property of the
Label / RichTextLabel to the value you want to display
- Start the
AnimationPlayer / Tween to animate the various properties as needed.
Good suggestions. Also, avoid animating the font size (use the
scale instead as suggested by Jgodfrey). From experience, every time you change the font size it will save the resource changes to the disk and potentially lag your game.
godot_dev_ | 2022-08-19 15:41
so here what i made what i think you told me to do
here is a video with short example of what i made:
There is two functions one for displaying damage when i click on enemy another for passive damage, but as you can see text appears only once per click. How to make new instances of text per click and remove them after animation is finished?
Here is a code of how i calling animation
$Area2D/AnimationPlayer.play("text floating ")
$Area2D/AnimationPlayer/DamageLabel.text = "your dmg = " + str (dmg)
$Area2D/PasiveDamageAnimation/PassiveDamageLabel.text = "pas damage =" + str (dmg)
I’d probably set up a dedicated scene explicitly for showing this animated damage value and then just instantiate it, position it, and start it wherever it’s needed. Further, I’d just have the scene destroy itself when the animation finishes.
For example, your scene could be setup like this (
And, the Node2D could have the following script:
$Label.text = "Damage = %s" % damage_val
yield() followed by
queue_free() will cause the scene to destroy itself when the damage animation finishes playing.
Then, just instantiate the damage scene, position it as needed, and call the
show_damage(). For example, this places a new instance at each mouse-click position and passes in a random damage value.
var damage_scene = preload("res://Damage.tscn")
var pos = get_global_mouse_position()
var d = damage_scene.instance()
d.position = pos
Then, just season the underlying animation to taste. You could animate visibility, scale, rotation, position, color, … Whatever you need.
jgodfrey | 2022-08-20 22:29
Thank you very much, you helped a lot