首页 > 解决方案 > 类型对象“动画”没有属性“mobject”

问题描述

我在这里练习示例

从 SuccessionExample1 开始,只要存在:

Succession(Animation, Mobject(),...

会出现如下错误:

AttributeError: type object 'Animation' has no attribute 'mobject'

查了animation.py,发现self.mobject = mobject,也就是Animation类有mobject属性,是不是那些样本过时了?还是其他原因?

标签: manim

解决方案


这是因为那是旧版本的代码(我在教程中使用了 2 月 3 日的版本),我忘记在你之前的问题中告诉你只渲染更新函数,而不是继承的那些。要使用继承,必须更改代码格式,这是最新版本的代码

在 SuccessionExample1 的情况下:

class SuccessionExample1(Scene):
    def construct(self):
        number_line=NumberLine(x_min=-2,x_max=2)
        text=TextMobject("Text")\
             .next_to(number_line,DOWN)
        dashed_line=DashedLine(
                                number_line.get_left(),
                                number_line.get_right(),
                                color=YELLOW,
                              ).set_stroke(width=11)

        self.add(number_line)
        self.wait(0.3)

        self.play(
                    LaggedStart(
                        *[ShowCreationThenDestruction(dashed_segment)
                        for dashed_segment in dashed_line],
                        run_time=5
                    ),
                    AnimationGroup(
                        Animation(Mobject(),run_time=2.1),
                        Write(text),lag_ratio=1
                    )
            )
        self.wait()

推荐阅读