Skip to content

Commit

Permalink
[godot] Fixes #2670, animation tracks must be set to discrete, so we …
Browse files Browse the repository at this point in the history
…only get a single name/loop change for each key.
  • Loading branch information
badlogic committed Nov 6, 2024
1 parent c3d510e commit b610bd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion spine-godot/spine_godot/SpineAnimationTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void SpineAnimationTrack::_bind_methods() {
}

SpineAnimationTrack::SpineAnimationTrack() : loop(false),
animation_changed(false),
track_index(-1),
mix_duration(-1),
hold_previous(false),
Expand Down Expand Up @@ -231,6 +232,9 @@ void SpineAnimationTrack::setup_animation_player() {
reset_animation_ref->add_track(Animation::TYPE_VALUE);
reset_animation_ref->track_set_path(1, NodePath(".:loop"));
reset_animation_ref->track_insert_key(1, 0, false);
reset_animation_ref->value_track_set_update_mode(0, Animation::UPDATE_DISCRETE);
reset_animation_ref->value_track_set_update_mode(1, Animation::UPDATE_DISCRETE);

#if VERSION_MAJOR > 3
animation_library->add_animation(reset_animation_ref->get_name(), reset_animation_ref);
animation_library->add_animation("-- Empty --", reset_animation_ref);
Expand Down Expand Up @@ -262,6 +266,9 @@ Ref<Animation> SpineAnimationTrack::create_animation(spine::Animation *animation
animation_ref->track_set_path(1, NodePath(".:loop"));
animation_ref->track_insert_key(1, 0, !loop);

animation_ref->value_track_set_update_mode(0, Animation::UPDATE_DISCRETE);
animation_ref->value_track_set_update_mode(1, Animation::UPDATE_DISCRETE);

return animation_ref;
}

Expand Down Expand Up @@ -416,7 +423,8 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
if (animation_player->is_playing()) {
auto current_entry = animation_state->getCurrent(track_index);
bool should_set_mix = mix_duration >= 0;
bool should_set_animation = !current_entry || (animation_name != current_entry->getAnimation()->getName().buffer() || current_entry->getLoop() != loop);
bool should_set_animation = !current_entry || (animation_name != current_entry->getAnimation()->getName().buffer() || current_entry->getLoop() != loop) || animation_changed;
animation_changed = false;

if (should_set_animation) {
if (!EMPTY(animation_name)) {
Expand Down Expand Up @@ -446,14 +454,17 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
}

void SpineAnimationTrack::set_animation_name(const String &_animation_name) {
if (debug) print_line(String("Animation name changed"));
animation_name = _animation_name;
animation_changed = true;
}

String SpineAnimationTrack::get_animation_name() {
return animation_name;
}

void SpineAnimationTrack::set_loop(bool _loop) {
animation_changed = true;
loop = _loop;
}

Expand Down
4 changes: 3 additions & 1 deletion spine-godot/spine_godot/SpineAnimationTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ class SpineAnimationTrack : public Node {
protected:
// These are not exposed in the inspector, see SpineAnimationTrackInspectorPlugin.
// Instead, they are are keyed by the animations created in setup_animation_player
// and primarily used for animation player editor support like scrubbing.
// and primarily used for animation player editor support like scrubbing and playing
// back the .
String animation_name;
bool loop;
bool animation_changed;

// These can be set by the user.
int track_index;
Expand Down

0 comments on commit b610bd7

Please sign in to comment.