• RuntimesGodot
  • How do I "freeze" an animation reliably?

I tried doing a few steps like this:

func setPlayerProfile():

var profile_state = SpineSprite.get_animation_state().set_animation("head_size", false,0)
profile_state.set_time_scale(0)
profile_state.set_track_time(slider.value)

However, I've either had the animation not respond or the animation plays from beginning to end. I'm trying to use the whole keyframe to work with a Slider in Godot.

Related Discussions
...

To reliably "freeze" an animation in Spine using Godot, you can set the timeScale of the TrackEntry to 0 and then manually set the trackTime to the desired frame. Here is a step-by-step approach to achieve this:

  1. Set the animation on the desired track.
  2. Set the timeScale of the TrackEntry to 0 to stop the animation from progressing.
  3. Manually set the trackTime to the desired frame using the slider value.

Here is an example of how you can achieve this in GDScript:

func set_player_profile():
    var animation_state = $SpineSprite.get_animation_state()
    var profile_state = animation_state.set_animation(0, "head_size", false)
    profile_state.set_time_scale(0)  # Freeze the animation
    profile_state.set_track_time(slider.value)  # Set the animation to the desired frame

Make sure that the slider.value is within the range of the animation's duration. This approach ensures that the animation is frozen at the specific frame you want to display.

Additionally, ensure that you are not holding onto the TrackEntry instance outside the function, as TrackEntry instances are reused internally and may become invalid once the animation completes.

If you need to update the frame dynamically as the slider value changes, you can connect the slider's value changed signal to a function that updates the trackTime:

func _on_slider_value_changed(value):
    var animation_state = $SpineSprite.get_animation_state()
    var profile_state = animation_state.get_current(0)  # Get the current TrackEntry on track 0
    if profile_state:
        profile_state.set_track_time(value)

This way, the animation frame will update in real-time as you move the slider.

Was a dumb typo in my code somewhere else, whoopsie. Sorry about that!

  • Nate оценил это.