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:
- Set the animation on the desired track.
- Set the
timeScale
of the TrackEntry
to 0 to stop the animation from progressing.
- 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.