Skip to content

Commit 842a57e

Browse files
Added documentation for scene updater functions (ManimCommunity#2663)
* added scene updater documentation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8f8e4b1 commit 842a57e

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

manim/scene/scene.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,22 @@ def update_meshes(self, dt):
345345
for mesh in obj.get_family():
346346
mesh.update(dt)
347347

348-
def update_self(self, dt):
348+
def update_self(self, dt: float):
349+
"""Run all scene updater functions.
350+
351+
Among all types of update functions (mobject updaters, mesh updaters,
352+
scene updaters), scene update functions are called last.
353+
354+
Parameters
355+
----------
356+
dt
357+
Scene time since last update.
358+
359+
See Also
360+
--------
361+
:meth:`.Scene.add_updater`
362+
:meth:`.Scene.remove_updater`
363+
"""
349364
for func in self.updaters:
350365
func(dt)
351366

@@ -503,10 +518,50 @@ def remove(self, *mobjects):
503518
self.restructure_mobjects(mobjects, list_name, False)
504519
return self
505520

506-
def add_updater(self, func):
521+
def add_updater(self, func: Callable[[float], None]) -> None:
522+
"""Add an update function to the scene.
523+
524+
The scene updater functions are run every frame,
525+
and they are the last type of updaters to run.
526+
527+
.. WARNING::
528+
529+
When using the Cairo renderer, scene updaters that
530+
modify mobjects are not detected in the same way
531+
that mobject updaters are. To be more concrete,
532+
a mobject only modified via a scene updater will
533+
not necessarily be added to the list of *moving
534+
mobjects* and thus might not be updated every frame.
535+
536+
TL;DR: Use mobject updaters to update mobjects.
537+
538+
Parameters
539+
----------
540+
func
541+
The updater function. It takes a float, which is the
542+
time difference since the last update (usually equal
543+
to the frame rate).
544+
545+
See also
546+
--------
547+
:meth:`.Scene.remove_updater`
548+
:meth:`.Scene.update_self`
549+
"""
507550
self.updaters.append(func)
508551

509-
def remove_updater(self, func):
552+
def remove_updater(self, func: Callable[[float], None]) -> None:
553+
"""Remove an update function from the scene.
554+
555+
Parameters
556+
----------
557+
func
558+
The updater function to be removed.
559+
560+
See also
561+
--------
562+
:meth:`.Scene.add_updater`
563+
:meth:`.Scene.update_self`
564+
"""
510565
self.updaters = [f for f in self.updaters if f is not func]
511566

512567
def restructure_mobjects(

0 commit comments

Comments
 (0)