如何在Manim中实现不同动画速度同时播放的复杂动画效果?
- 内容介绍
- 相关推荐
本文共计778个文字,预计阅读时间需要4分钟。
原文:
在 Manim 中,self.play() 默认支持多动画同步启动,但所有动画共享同一时间轴——若直接传入多个 Transform 并设置不同 run_time(如原示例中 transform_point1.run_time=1 与 transform_point2.run_time=2),Manim 会忽略单个动画的 run_time,统一采用最长的 run_time 或报错,导致预期失效。
✅ 正确做法是:使用 .animate 链式语法为每个动画单独指定 run_time。例如:
from manim import * class TwoDotsWithDifferentSpeeds(Scene): def construct(self): point1 = Dot(point=[-3, 0, 0], radius=0.5, color=BLUE) point2 = Dot(point=[3, 0, 0], radius=0.5, color=RED) self.add(point1, point2) # 同时缩放,但 point1 耗时 1s,point2 耗时 2s self.play( point1.animate(run_time=1).scale(1.8), point2.animate(run_time=2).scale(0.3), )
⚠️ 注意:point1.animate(...) 返回的是一个 Animation 对象,而非 Mobject;因此不能在循环中反复调用 point1.animate.scale(...) 并累积到 VGroup——这会导致 animate 被多次触发而引发异常。
本文共计778个文字,预计阅读时间需要4分钟。
原文:
在 Manim 中,self.play() 默认支持多动画同步启动,但所有动画共享同一时间轴——若直接传入多个 Transform 并设置不同 run_time(如原示例中 transform_point1.run_time=1 与 transform_point2.run_time=2),Manim 会忽略单个动画的 run_time,统一采用最长的 run_time 或报错,导致预期失效。
✅ 正确做法是:使用 .animate 链式语法为每个动画单独指定 run_time。例如:
from manim import * class TwoDotsWithDifferentSpeeds(Scene): def construct(self): point1 = Dot(point=[-3, 0, 0], radius=0.5, color=BLUE) point2 = Dot(point=[3, 0, 0], radius=0.5, color=RED) self.add(point1, point2) # 同时缩放,但 point1 耗时 1s,point2 耗时 2s self.play( point1.animate(run_time=1).scale(1.8), point2.animate(run_time=2).scale(0.3), )
⚠️ 注意:point1.animate(...) 返回的是一个 Animation 对象,而非 Mobject;因此不能在循环中反复调用 point1.animate.scale(...) 并累积到 VGroup——这会导致 animate 被多次触发而引发异常。

