Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Suspend mobject updating during animations

Grant Sandersona409fd6fe5b0
diff --git a/manimlib/mobject/mobject.py b/manimlib/mobject/mobject.py
index cdf70ae20..1f14cbcd8 100644
--- a/manimlib/mobject/mobject.py
+++ b/manimlib/mobject/mobject.py
@@ -45,6 +45,7 @@ class Mobject(Container):
if self.name is None:
self.name = self.__class__.__name__
self.updaters = []
+ self.updating_suspended = False
self.reset_points()
self.generate_points()
self.init_colors()
@@ -145,13 +146,18 @@ class Mobject(Container):
# Updating
- def update(self, dt=0):
- for updater in self.updaters:
- parameters = get_parameters(updater)
- if "dt" in parameters:
- updater(self, dt)
- else:
- updater(self)
+ def update(self, dt=0, recursive=True):
+ if not self.updating_suspended:
+ for updater in self.updaters:
+ parameters = get_parameters(updater)
+ if "dt" in parameters:
+ updater(self, dt)
+ else:
+ updater(self)
+ if recursive:
+ for submob in self.submobjects:
+ submob.update(dt, recursive)
+ return self
def get_time_based_updaters(self):
return [
@@ -180,6 +186,20 @@ class Mobject(Container):
self.updaters = []
return self
+ def suspend_updating(self, recursive=True):
+ self.updating_suspended = True
+ if recursive:
+ for submob in self.submobjects:
+ submob.suspend_updating(recursive)
+ return self
+
+ def resume_updating(self, recursive=True):
+ self.updating_suspended = False
+ if recursive:
+ for submob in self.submobjects:
+ submob.resume_updating(recursive)
+ return self
+
# Transforming operations
def apply_to_family(self, func):
diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py
index 8be55952c..d7977a5a9 100644
--- a/manimlib/scene/scene.py
+++ b/manimlib/scene/scene.py
@@ -151,7 +151,7 @@ class Scene(Container):
###
def continual_update(self, dt):
- for mobject in self.get_mobject_family_members():
+ for mobject in self.mobjects:
mobject.update(dt)
for continual_animation in self.continual_animations:
continual_animation.update(dt)
@@ -470,6 +470,9 @@ class Scene(Container):
# scene gets added to the scene
if animation.mobject not in self.get_mobject_family_members():
self.add(animation.mobject)
+ # Don't call the update functions of a mobject
+ # being animated
+ animation.mobject.suspend_updating()
moving_mobjects = self.get_moving_mobjects(*animations)
# Paint all non-moving objects onto the screen, so they don't
@@ -500,6 +503,7 @@ class Scene(Container):
def clean_up_animations(self, *animations):
for animation in animations:
animation.clean_up(self)
+ animation.mobject.resume_updating()
return self
def get_mobjects_from_last_animation(self):