The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hello!
I'm trying to get though tutorial - 2D game on official site
I'm stuck at this step:

First, we get the list of animation names from the AnimatedSprite2D's frames property. This returns an Array containing all three animation names: ["walk", "swim", "fly"]

The code for this step:

func _ready():
$AnimatedSprite2D.play()
var mob_types = $AnimatedSprite2D.get_sprite_frames().get_animation_names()
$AnimatedSprite2D.animation = mob_types[randi() % mob_types.size()]

Link: https://docs.godotengine.org/en/stable/getting_started/first_2d_game/04.creating_the_enemy.html

So my problem is that it doesn't suggest getspriteframes() on a dropdown list when I type. It's just not there. I have no idea what I'm doing wrong. The only idea is that it's about version - I'm using 4.0. Documentation should be up-to-date, but maybe it's not?

Godot version 4.0
in Engine by (15 points)

1 Answer

+1 vote
Best answer

Hmmm... Looks like a lot of the node property setter/getter functions are no longer offered by the code hinting system. I assume that was a conscious decision (perhaps on the way to deprecation?) but I'm not really sure.

A few things. First get_sprite_frames() should still work if you just add it to your code (without the hint). Also, it's just the getter for the sprite_frames property, which you could use instead (and will get code hints for that).

by (22,674 points)
selected by

It works, actually!
Thank you.

I saw sprite_frames on the list, but I don't know how to use it instead, sadly.

Great - glad it works. And, for reference, the above code using direct property access (so, without the getter), would look like:

$AnimatedSprite2D.sprite_frames.get_animation_names()

That helped a lot. Now I get it!
Thanks a lot :)

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.