diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-06-18 15:11:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-18 15:11:06 +0200 |
commit | 1d2ed8885dcf0e32f22be8236c88857f6f7720c6 (patch) | |
tree | 73257caa82a6d215da6ce328cb859c3212357e43 /editor | |
parent | e19da5ab6ac1acd965842c5deaa329dad8ea3299 (diff) | |
parent | c75e7f48485207d128c1b62505eeaf0587bcb8cc (diff) |
Merge pull request #19573 from guilhermefelipecgs/fix_animation_preview
[AnimationPlayer] Fix preview for both AnimatedSprite (2D and 3D)
Diffstat (limited to 'editor')
-rw-r--r-- | editor/animation_track_editor_plugins.cpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index 660c69f4a4..d0c91f10d9 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -357,14 +357,28 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se } } else if (Object::cast_to<AnimatedSprite>(object) || Object::cast_to<AnimatedSprite3D>(object)) { - int frame = get_animation()->track_get_key_value(get_track(), p_index); - String animation = "default"; //may be smart and go through other tracks to find if animation is set - Ref<SpriteFrames> sf = object->call("get_sprite_frames"); if (sf.is_null()) { return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); } + List<StringName> animations; + sf->get_animation_list(&animations); + + int frame = get_animation()->track_get_key_value(get_track(), p_index); + String animation; + if (animations.size() == 1) { + animation = animations.front()->get(); + } else { + // Go through other track to find if animation is set + String animation_path = get_animation()->track_get_path(get_track()); + animation_path = animation_path.replace(":frame", ":animation"); + int animation_track = get_animation()->find_track(animation_path); + float track_time = get_animation()->track_get_key_time(get_track(), p_index); + int animaiton_index = get_animation()->track_find_key(animation_track, track_time); + animation = get_animation()->track_get_key_value(animation_track, animaiton_index); + } + Ref<Texture> texture = sf->get_frame(animation, frame); if (!texture.is_valid()) { return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); @@ -430,15 +444,29 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in } else if (Object::cast_to<AnimatedSprite>(object) || Object::cast_to<AnimatedSprite3D>(object)) { - int frame = get_animation()->track_get_key_value(get_track(), p_index); - String animation = "default"; //may be smart and go through other tracks to find if animation is set - Ref<SpriteFrames> sf = object->call("get_sprite_frames"); if (sf.is_null()) { AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); return; } + List<StringName> animations; + sf->get_animation_list(&animations); + + int frame = get_animation()->track_get_key_value(get_track(), p_index); + String animation; + if (animations.size() == 1) { + animation = animations.front()->get(); + } else { + // Go through other track to find if animation is set + String animation_path = get_animation()->track_get_path(get_track()); + animation_path = animation_path.replace(":frame", ":animation"); + int animation_track = get_animation()->find_track(animation_path); + float track_time = get_animation()->track_get_key_time(get_track(), p_index); + int animaiton_index = get_animation()->track_find_key(animation_track, track_time); + animation = get_animation()->track_get_key_value(animation_track, animaiton_index); + } + texture = sf->get_frame(animation, frame); if (!texture.is_valid()) { AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); |