Godot: SpriteFrames::_get_frames() just return a new empty Array

Created on 5 Sep 2018  路  4Comments  路  Source: godotengine/godot

Godot version:
master

Issue description:

Looking through the SpriteFrames code, I found that the _get_frames() does not do what it is supposed.
https://github.com/godotengine/godot/blob/93a888e81ed7cc1f02d8833273a63ae987c58c04/scene/2d/animated_sprite.cpp#L240-L243

Steps to reproduce:
Get the frames of a SpriteFrames, something like:

print($AnimatedSprite.frames._get_frames())

It wil print:

[]

And allocate one new Array() just for that.

Minimal reproduction project:

Not needed, just look at the code snipped in the issue description.

enhancement core

Most helpful comment

Those methods were deprecated in 2.1 (albeit without the proper deprecation warnings we now use), but we forgot to remove them in 3.0. Will do now.

All 4 comments

That is odd, but there is a line in there about compatibility, but couldn't get much further than than. So it seems it is just dangling there for some reason?

https://github.com/godotengine/godot/blob/93a888e81ed7cc1f02d8833273a63ae987c58c04/scene/2d/animated_sprite.cpp#L315

It at least looks like you couldn't expect that to return the frames, given the way SpriteFrames is organized. It would expect you to at least pass in the name of the animation. I would think this is something that would've been more sensible if the AnimatedSprite contained the animations, and then each animation's SpriteFrames just handled like they do now, but only for one animation. Then that frames member might make sense and could be made to be accessible directly.

It does certainly look like some of the data got mixed up and it could use a reworking. Consider that if it did do something, the shortest code to it would look like frames.frames... yep. X)

I'd venture something for it, but I'm not knowledgeable enough yet to properly bind things and such, or know what the compatibility it is referring to, it doesn't seem like it goes anywhere.

But at least in GDScript the work-around would be to write a function like:

extends AnimatedSprite

func _ready(): print(get_frames("default"))


func get_frames(anim_name):

    assert(frames.has_animation(anim_name))

    var frame_list = []

    for i in frames.get_frame_count(anim_name):
        frame_list.append(frames.get_frame(anim_name, i))

    return frame_list

yea I'd guess that the get_frames is defunct now intentionally, we just have a bad habit of not commenting the intention of empty functions.

Those methods were deprecated in 2.1 (albeit without the proper deprecation warnings we now use), but we forgot to remove them in 3.0. Will do now.

Was this page helpful?
0 / 5 - 0 ratings