Manim中同一play内两个动画无法同时执行的问题求助
Manim中同时执行两个动画仅缩放生效的问题解决
我编写了如下Manim示例代码:
class IntroToEquation(Scene): def construct(self): equation = MathTex( "2^x=3", substrings_to_isolate="x", font_size=144 ) equation.set_color_by_tex("x", YELLOW) self.play(FadeIn(equation)) self.wait(2) self.play(equation.animate.to_edge(UP, buff=0.5), equation.animate.scale(0.75)) self.wait(1)其中第三个
self.play()包含两个应同时执行的动画,但最终视频中仅缩放动画生效。我查阅资料后认为代码逻辑无误,恳请提供帮助,感谢您的时间。
问题根源在于你连续调用equation.animate的方式:Manim中同一个Mobject的多次animate调用会覆盖前序的动画属性,最终只有最后一个操作生效。
要实现两个动画同时执行,有两种可靠写法:
- 链式调用animate方法(最简洁):将多个动画操作串联在同一个
animate实例后
self.play(equation.animate.to_edge(UP, buff=0.5).scale(0.75))
- 使用AnimationGroup组合动画:如果需要更灵活的动画控制,可创建独立动画对象后组合执行
move_anim = equation.animate.to_edge(UP, buff=0.5) scale_anim = equation.animate.scale(0.75) self.play(AnimationGroup(move_anim, scale_anim, lag_ratio=0))
内容的提问来源于stack exchange,提问作者defrood
相关产品推荐
相关产品推荐

