Repository: ManimCommunity/manim

Issue:
`OpenGLVMobject` does not appear to take into account the order of the list of submobjects when running animations
## Description of bug / unexpected behavior
While this may be intentional, there are some places where it causes problems. For example, 

```py
class ShuffleSubmobjectsExample(Scene):
    def construct(self):
        s= VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
        s2= s.copy()
        s2.shuffle()
        s2.shift(DOWN)
        self.play(Write(s), Write(s2))
```

produces the expected result on cairo:

https://user-images.githubusercontent.com/9102529/124756197-c7fb7f00-df5e-11eb-8f48-2168e9789c45.mp4

but not on opengl:

https://user-images.githubusercontent.com/9102529/124756306-e6617a80-df5e-11eb-9f86-769e95cc68bd.mp4

If you try to add an `invert` method to `OpenGLVMobject` to make `Write` and `Unwrite` reversal possible, the same problem happens (inverting the list does nothing).

## Expected behavior
<!-- Add a clear and concise description of what you expected to happen. -->


## How to reproduce the issue
<!-- Provide a piece of code illustrating the undesired behavior. -->

<details><summary>Code for reproducing the problem</summary>

```py
Paste your code here.
```

</details>


## Additional media files
<!-- Paste in the files manim produced on rendering the code above. -->

<details><summary>Images/GIFs</summary>

<!-- PASTE MEDIA HERE -->

</details>


## Logs
<details><summary>Terminal output</summary>
<!-- Add "-v DEBUG" when calling manim to generate more detailed logs -->

```
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR
```

<!-- Insert screenshots here (only when absolutely necessary, we prefer copy/pasted output!) -->

</details>


## System specifications

<details><summary>System Details</summary>

- OS (with version, e.g Windows 10 v2004 or macOS 10.15 (Catalina)):
- RAM:
- Python version (`python/py/python3 --version`):
- Installed modules (provide output from `pip list`):
```
PASTE HERE
```
</details>

<details><summary>LaTeX details</summary>

+ LaTeX distribution (e.g. TeX Live 2020):
+ Installed LaTeX packages:
<!-- output of `tlmgr list --only-installed` for TeX Live or a screenshot of the Packages page for MikTeX -->
</details>

<details><summary>FFMPEG</summary>

Output of `ffmpeg -version`:

```
PASTE HERE
```
</details>

## Additional comments
<!-- Add further context that you think might be relevant for this issue here. -->



Discussion:

Resolving patch:
diff --git a/manim/animation/creation.py b/manim/animation/creation.py
--- a/manim/animation/creation.py
+++ b/manim/animation/creation.py
@@ -332,9 +332,9 @@ def begin(self) -> None:
         super().begin()
 
     def finish(self) -> None:
+        super().finish()
         if self.reverse:
             self.reverse_submobjects()
-        super().finish()
 
 
 class Unwrite(Write):
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -2433,6 +2433,11 @@ def shuffle(self, recursive=False):
     def invert(self, recursive=False):
         """Inverts the list of :attr:`submobjects`.
 
+        Parameters
+        ----------
+        recursive
+            If ``True``, all submobject lists of this mobject's family are inverted.
+
         Examples
         --------
 
@@ -2440,8 +2445,8 @@ def invert(self, recursive=False):
 
             class InvertSumobjectsExample(Scene):
                 def construct(self):
-                    s= VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
-                    s2= s.copy()
+                    s = VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
+                    s2 = s.copy()
                     s2.invert()
                     s2.shift(DOWN)
                     self.play(Write(s), Write(s2))
diff --git a/manim/mobject/opengl_mobject.py b/manim/mobject/opengl_mobject.py
--- a/manim/mobject/opengl_mobject.py
+++ b/manim/mobject/opengl_mobject.py
@@ -424,6 +424,33 @@ def set_submobjects(self, submobject_list):
         self.add(*submobject_list)
         return self
 
+    def invert(self, recursive=False):
+        """Inverts the list of :attr:`submobjects`.
+
+        Parameters
+        ----------
+        recursive
+            If ``True``, all submobject lists of this mobject's family are inverted.
+
+        Examples
+        --------
+
+        .. manim:: InvertSumobjectsExample
+
+            class InvertSumobjectsExample(Scene):
+                def construct(self):
+                    s = VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
+                    s2 = s.copy()
+                    s2.invert()
+                    s2.shift(DOWN)
+                    self.play(Write(s), Write(s2))
+        """
+        if recursive:
+            for submob in self.submobjects:
+                submob.invert(recursive=True)
+        list.reverse(self.submobjects)
+        self.assemble_family()
+
     def digest_mobject_attrs(self):
         """
         Ensures all attributes which are mobjects are included
@@ -513,6 +540,7 @@ def shuffle(self, recurse=False):
             for submob in self.submobjects:
                 submob.shuffle(recurse=True)
         random.shuffle(self.submobjects)
+        self.assemble_family()
         return self
 
     # Copying


Test patch: