0 votes

Hello everyone. I am using a modulate to change the color tint of the enemy sprite. After a timer runs out, I want the sprite to become normal again, removing the color from modulate. How is this done?

func _on_Hitbox_area_entered(area):
if area.is_in_group("Enemy_damager"):
    modulate = Color.red

func _on_StunTimer_timeout():
Godot version v3.5.1
in Engine by (35 points)

1 Answer

0 votes

You could create a variable to store the original value of the modulate member (suppose we call it oldModulate), and before setting the value of modulate to Color.red, save the modulate as so: oldModulate = self.modulate. Then, when the timer runs out, in your _on_StunTimer_timeout function, you could do self.modulate = oldModulate. This would bring it back to normal, and supports the feature to also have a custom modulate before turning red (it might be green, for example, from some other effect before it turns red). You may want to consider using a Tween to have the red color fade out back to normal using interpolate_property using the initial value of Color.red and the target value as oldModulate for your modulate property.

by (568 points)
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.