how to stop animation player from decrease fps?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

when i use animationplayer my fps drop to 15 ~30 fps

with this code

func _ready() -> void:
	if critical_damage == true:
		$crit.text = str(damage_display)
		$AnimationPlayer.play("crit_damage_display")

	elif magic_damage == true:
		$magic.text = str(damage_display)
		$AnimationPlayer.play("mana_damage_display")

	elif ad_damage == true:
			$basic.text = str(damage_display)
			$AnimationPlayer.play("damage_display")

	elif miss_damage == true:
		$miss.text = "miss"
		$AnimationPlayer.play("miss_display")

but when i didt use animationplayer with this code

func _process(delta: float) -> void:
	if critical_damage == true:
		$crit.visible = true
		$crit.text = str(damage_display)
		$crit.rect_global_position.y -= move_speed*delta
		alpa_color -= 5
		$crit.self_modulate = Color8(255,255,255,alpa_color)
		if alpa_color <=0:
			queue_free()
		
	elif magic_damage == true:
		$magic.visible = true
		$magic.text = str(damage_display)
		$magic.rect_global_position.y -= move_speed*delta
		alpa_color -= 5
		$magic.self_modulate = Color8(255,255,255,alpa_color)
		if alpa_color <=0:
			queue_free()
			
	elif ad_damage == true:
		$basic.visible = true
		$basic.text = str(damage_display)
		$basic.rect_global_position.y -= move_speed*delta
		alpa_color -= 5
		$basic.self_modulate = Color8(255,255,255,alpa_color)
		if alpa_color <=0:
			queue_free()
			
	elif miss_damage == true:
		$miss.visible = true
		$miss.text = "miss"
		$miss.rect_global_position.y -= move_speed*delta
		alpa_color -= 5
		$miss.self_modulate = Color8(255,255,255,alpa_color)
		if alpa_color <=0:
			queue_free()

my fps is 50 ~60
but i cant move easily. what should i do, to make animationplayer stop drop fps so much

So it runs at 15-30 fps only if you play the animation from _ready?
Which animation is making it run slowly?

Zylann | 2020-04-05 22:07

yes, my fps become 15~30.
any animation . all animation just duplicated from first animation, just change color and text. and my game just 2d TD game.

in this picture, i just use one tower, u get around 20 ~45 fps.

Imgur: The magic of the Internet
enter image description here

but when i did’t use animation player, my fps 50~60, even i use 10 tower or more
Imgur: The magic of the Internet
enter image description here

potatobanana | 2020-04-05 22:56

Which properties are being altered by the animations in question? Animating some properties can have a significant performance impact.

Calinou | 2020-04-07 12:58

rect_position
custom_fonts/font:size
self_modulate
rect_size
custom_styles/normal
custom_colors/fonts_color
custom_colors/font_outline_modulate
visible

potatobanana | 2020-04-07 14:13

:bust_in_silhouette: Reply From: Zylann

I believe animating customfonts/font:size is the culprit. It’s not as cheap as scale, at the moment font size litterally regenerates the whole font atlas to fit characters of different size.

I have the same problem. Now that you mention it, animating custom font’s size really has a significant impact on my game. I’ll try to get a workaround that. Thank you!

ndriqa | 2021-09-18 00:42