Godot Version
4.2.2
Question
` Hello! I’m incredibly new to Godot and I’m near confused at every turn! Currently, I am trying to make a menu where a AnimatedSprite2D will change its appearance in responde to the A and D keys, and it will change through a list that will expand as I work on my little project more.
Currently, my major issue is that I can’t find a way to make the Animated Sprite 2D’s frame counter tick up or down. The code I have is:
extends AnimatedSprite2D
func _ready():
pass
func _process(delta):
pass
func _input(IconShift):
if Input.is_key_pressed(KEY_D):
$AnimatedSprite2D.frame(1)
elif Input.is_key_pressed(KEY_A):
$AnimatedSprite2D.frame(0)
The reason I want to do it through a variable rather than changing the image name is because I want it to be easy for me to add in new icons later by just placing into my spritesheet. Earlier I had something like “$AnimatedSprite2D.frame = $AnimatedSprite2D.frame + 1:” but nothing I’ve tried seems to work. Anything I’ve tried to mathematically increase or decrease the frame of the sprite has resulted in “Attempt to call function ‘frame’ in base ‘null instance’ on a null instance.”
I have no clue what this means or how to fix it.
TLDR/Clarification: What is the easiest way to have a sprite change it’s appearance based on a spritesheet by just one frame at a time?