How do I switch the texture of my sprites once?

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

Hello.
My idea for my game is that the player can switch to different modes and I am planning to have different sprites for the player to switch to. I tried doing Input.is_action_pressed to switch to a different sprite texture and when I press that button again it returns it back to the previous texture. The problem I am having is that when I press it, the texture switches back and forth too fast. I think the problem is because the inputs are under the _physics_process(delta) function. Is there any way for me to switch to a different texture once?

Sorry if my question is already answered or it seems stupid. I couldn’t find an answer on google and I am pretty new to game development. Thanks.

:bust_in_silhouette: Reply From: Magso

The function isn’t the problem,

Input.is_action_pressed 

will return true while a key is pressed.
You’re looking for

Input.is_action_just_pressed

which will return true for only a single frame.