Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document migration from 3.x for AnimationPlayer.add_animation #86611

Open
chun1617 opened this issue Dec 29, 2023 · 5 comments
Open

Document migration from 3.x for AnimationPlayer.add_animation #86611

chun1617 opened this issue Dec 29, 2023 · 5 comments

Comments

@chun1617
Copy link

Tested versions

Windows 10 - Godot_v4.2-stable_win64

System information

Windows 10 - Godot_v4.2-stable_win64

Issue description

When I try to use add_animation in AnimationPlayer, it looks like doesn't have it anymore. Is it changed to others?

Steps to reproduce

$AnimationPlayer.add_animation

Minimal reproduction project (MRP)

animation_player.add_animation(anim_name, anim)

@AThousandShips
Copy link
Member

AThousandShips commented Dec 29, 2023

You need to use the AnimationLibrary interface, use get_animation_library

Instructions for this should be added to this page, which arguably makes this an issue for the documentation

@chun1617
Copy link
Author

chun1617 commented Dec 29, 2023

You need to use the AnimationLibrary interface, use get_animation_library

Instructions for this should be added to this page, which arguably makes this an issue for the documentation

May I ask how could I use get_animation_library to add new animation frame?
I tried the following code but look like is wrong:

func setup_animations(data: Dictionary) -> void:
	var anim_library = animation_player.get_animation_library("")

	for anim_name in data["animations"].keys():
		var anim = Animation.new()
		anim.length = data["animations"][anim_name]["frames"].size() * 0.05
		var track_index = anim.add_track(Animation.TYPE_VALUE)

		for frame in data["animations"][anim_name]["frames"]:
			var frame_number = frame["y"] * sprite.hframes + frame["x"]
			var frame_time = frame_number * 0.05
			anim.track_set_path(track_index, String(sprite.get_path()) + ":frame")
			anim.track_insert_key(track_index, frame_time, frame_number)

		anim_library.add_animation(anim_name, anim)

	animation_player.set_animation_library(anim_library)

@AThousandShips
Copy link
Member

You can't set it, you just update it directly, see the documentation

No need to call any set method (there isn't one, you can have multiple libraries)

@AThousandShips
Copy link
Member

But while the documentation for migration from 3.x should mention this I'd say that you should ask in the other community channels for support 🙂, this is for reporting bugs

@AThousandShips
Copy link
Member

Let's keep this open to handle the documentation, or open one on the documentation page

@AThousandShips AThousandShips changed the title godot 4.2 doesn't have AnimationPlayer.add_animation anymore? Document migration from 3.x for AnimationPlayer.add_animation Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants