rayxuln / Spine-Runtime-For-Godot-Example

This project is an example for spine-runtime module of Godot.
4 stars 1 forks source link

Automatically generate AnimationPlayer from Spine's animation list #1

Open jonchun opened 4 years ago

jonchun commented 4 years ago

In the current example, it seems that you need to create an AnimationPlayer and add all the tracks automatically and set current_animations.

Here's a WIP that I'm using

    # Generate a default AnimationPlayer with all of the animations loaded from the spine json if an AnimationPlayer node hasn't been provided
    if not anim_player:
        anim_player = AnimationPlayer.new()
        for anim_name in spine_sprite.get_skeleton().get_data().get_animation_names():
            var anim = Animation.new()
            var track_index = anim.add_track(Animation.TYPE_VALUE)
            anim.track_set_path(track_index, ".:current_animations")
            anim.track_insert_key(track_index, 0.0, [anim_name])
            anim_player.add_animation(anim_name, anim)
        spine_sprite.add_child(anim_player)

Saving the anim player can be done with

    var packed_scene = PackedScene.new()
    packed_scene.pack(anim_player)
    ResourceSaver.save("res://anim_player.tscn", packed_scene)
DiscardZhebin commented 3 years ago

In the current example, it seems that you need to create an AnimationPlayer and add all the tracks automatically and set current_animations.

Here's a WIP that I'm using

  # Generate a default AnimationPlayer with all of the animations loaded from the spine json if an AnimationPlayer node hasn't been provided
  if not anim_player:
      anim_player = AnimationPlayer.new()
      for anim_name in spine_sprite.get_skeleton().get_data().get_animation_names():
          var anim = Animation.new()
          var track_index = anim.add_track(Animation.TYPE_VALUE)
          anim.track_set_path(track_index, ".:current_animations")
          anim.track_insert_key(track_index, 0.0, [anim_name])
          anim_player.add_animation(anim_name, anim)
      spine_sprite.add_child(anim_player)

Saving the anim player can be done with

  var packed_scene = PackedScene.new()
  packed_scene.pack(anim_player)
  ResourceSaver.save("res://anim_player.tscn", packed_scene)

thank you very much. to aviod this question, i didnt use AnimationPlayer.. i user get_animation_state().set/add_animation(animation_name) but i lost AnimationTree. thank you for your script