Created
September 19, 2021 20:49
-
-
Save nonunknown/884d106204b624a7ba19aa4dda6e7651 to your computer and use it in GitHub Desktop.
[Godot 4] Convert AnimatedSprite to AnimationPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tool | |
extends Control | |
@export var gen:bool = false : | |
set(value): | |
if !value: return | |
print("test") | |
self.convert() | |
gen = false | |
pass | |
func convert() -> void: | |
print("Converting") | |
var animated_res:Resource = load("res://anims/CharacterAnims.tres") | |
var data:Array = animated_res.get("animations") | |
# print(data) | |
var anim_player:AnimationPlayer = AnimationPlayer.new() | |
add_child(anim_player) | |
anim_player.owner = self | |
for anim_info in data: | |
var animation:Animation = Animation.new() | |
var err = anim_player.add_animation(anim_info.name, animation) | |
if err: | |
print_debug("Error adding animation") | |
break | |
# animation.set_track | |
var index:int = animation.add_track(Animation.TYPE_VALUE,0) | |
animation.track_set_path(index, "Sprite:texture") | |
for i in range(anim_info.frames.size()): | |
var texture = anim_info.frames[i] | |
animation.track_insert_key(index, i * 0.1, texture) | |
if i == anim_info.frames.size() -1: | |
animation.length = i * 0.1 | |
print(anim_info.name) | |
# break | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment