Godot Version
4.4
Question
I have an isometric 2D character I’m trying to animate. I have hundreds of sprite sheets for different angels of all the animations with and without weapons so doing it all in the editor wouldnt be feasible in an appropriate amount of time.
I have a function to load all the sprite sheets but I want to get one working before I try more. I’m now using Sprite2D and AnimationPlayer. Here is what I have so far.
var sprite_texxture: Texture2D = load("res://characters/players/spritesheets/Idle_Unarmed/Idle_Unarmed_Body_090.png")
collision.add_collision(self, sprite_texxture.get_width(), sprite_texxture.get_height())
$Sprite2D.texture = sprite_texxture
$Sprite2D.hframes = 4
$Sprite2D.vframes = 4
$Sprite2D.frame = 0
var animation_library: AnimationLibrary = AnimationLibrary.new()
$AnimationPlayer.add_animation_library("Idle_Unarmed_Body_090", animation_library)
var animation: Animation = Animation.new()
var index: int = animation.add_track(Animation.TYPE_VALUE)
animation.track_set_path(index, ".:frame")
animation.track_insert_key(index, 0.0, 0)
animation.track_insert_key(index, 0.5, 1)
animation.length = 2
animation_library.add_animation("Idle_Unarmed_Body_090", animation)
#$AnimationPlayer.root_node = "Sprite2D"
#$AnimationPlayer.assigned_animation = "Idle_Unarmed_Body_090"
$AnimationPlayer.play("Idle_Unarmed_Body_090")
I know I have to add tracks in the AnimationPlayer but I cant figure out how to do that in gdscript.
If there is a better way to accomplish this I’m all ears.
EDIT
I found a video https://www.youtube.com/watch?v=6Rbsi9-u8YU and have been updating my code. The problem is that I get errors in the log saying animation not found when I play it, so I have to be missing something.