diff options
| author | Max Hilbrunner <mhilbrunner@users.noreply.github.com> | 2018-07-03 18:06:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-03 18:06:15 +0200 |
| commit | b21c1f64cdbbb762e6ede25eed1fbd1dec4b91a6 (patch) | |
| tree | 25414d464c93a845c9dc1f44c0e05c7b61713b87 /scene/2d/animated_sprite.cpp | |
| parent | 5885e1c6ddfaa90ad71ffab1923abaceeadee18d (diff) | |
| parent | 4d78e16bc1bf265da32858a38aa75a1233421da4 (diff) | |
Merge pull request #18634 from groud/fix_control_child_of_node2d
Fixes the bad calculation of margin & anchors when child of Node2D
Diffstat (limited to 'scene/2d/animated_sprite.cpp')
| -rw-r--r-- | scene/2d/animated_sprite.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 54194ff543..e3d1592be0 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -59,15 +59,36 @@ bool AnimatedSprite::_edit_use_pivot() const { } Rect2 AnimatedSprite::_edit_get_rect() const { + return _get_rect(); +} + +bool AnimatedSprite::_edit_use_rect() const { if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) { - return Node2D::_edit_get_rect(); + return false; + } + Ref<Texture> t; + if (animation) + t = frames->get_frame(animation, frame); + if (t.is_null()) + return false; + + return true; +} + +Rect2 AnimatedSprite::get_anchorable_rect() const { + return _get_rect(); +} + +Rect2 AnimatedSprite::_get_rect() const { + if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) { + return Rect2(); } Ref<Texture> t; if (animation) t = frames->get_frame(animation, frame); if (t.is_null()) - return Node2D::_edit_get_rect(); + return Rect2(); Size2 s = t->get_size(); Point2 ofs = offset; @@ -80,10 +101,6 @@ Rect2 AnimatedSprite::_edit_get_rect() const { return Rect2(ofs, s); } -bool AnimatedSprite::_edit_use_rect() const { - return true; -} - void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture> &p_frame, int p_at_pos) { Map<StringName, Anim>::Element *E = animations.find(p_anim); |