I'm trying to animate an object using keyframes programmatically, but I'm having trouble. Here is a sample that I think should work, but doesn't:
# I want to animate a sprite added via code, so let's add the sprite.
var sprite = Sprite.new()
sprite.set_texture(sprite_scene) # defined earlier
sprite.set_pos(Vector2(600, 300))
sprite.set_name("TestSprite") # Will be needed for the track path later
add_child(sprite)
# Now that the sprite is added, I try to animate it
var animation = Animation.new()
animation.set_length(1)
# The animation is to move the sprite to the right for 1 second
animation.add_track(TYPE_VECTOR2)
animation.track_set_path(0, "TestSprite:transform/pos")
animation.track_insert_key(0, 0, Vector2(600, 300))
animation.track_insert_key(0, 1, Vector2(800, 300))
# Now that I created the animation, I add it to my AnimationPlayer
# and play the animation. However, the animation does not play.
animation_player.add_animation("Test", animation)
animation_player.play("Test")
What seems to be wrong with this method?