From 15431fa2017d7997481fb393471884d3fbdeac50 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Fri, 2 Oct 2020 16:33:01 +0800 Subject: [PATCH] Fix bug using z_index in VGroup Solve the problem in https://github.com/ManimCommunity/manim/issues/327 --- manim/mobject/mobject.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index b93f0d40b0..03e193aacc 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -132,6 +132,14 @@ def add(self, *mobjects): if self in mobjects: raise ValueError("Mobject cannot contain self") self.submobjects = list_update(self.submobjects, mobjects) + + # This will introduce another use_z_index flag + # There may be better solutions + # But for now, this is the easiest solution + if self.use_z_index: + self.submobjects = sorted(self.submobjects, + key=lambda m: m.z_index) + return self def add_to_back(self, *mobjects):