首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何控制self.play在特定时间点运行

如何控制self.play在特定时间点运行
EN

Stack Overflow用户
提问于 2019-07-16 12:51:48
回答 1查看 1.3K关注 0票数 0

假设有两个self.play语句,第一个语句从1s开始,我希望秒从一开始正好从3s开始。

目前我使用self.wait来控制步骤:

代码语言:javascript
复制
self.wait(1)
self.play...... # first animation
self.wait(2)    # because 1 + 2 = 3
self.play...... # second animation

但是,因为第一个动画需要一些时间(例如1.5秒)才能完成,所以实际上第二个动画将从1+1.5+2= 4.5s开始。

如何才能让第二个self.play start从一开始就以3s的速度运行?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-17 07:06:49

你是说这个吗?

代码语言:javascript
复制
class SuccessionExample(Scene):
    def construct(self):
        number_line=NumberLine(x_min=-2,x_max=2)
        triangle=RegularPolygon(3,start_angle=-PI/2)\
                   .scale(0.2)\
                   .next_to(number_line.get_left(),UP,buff=SMALL_BUFF)
        text_1=TextMobject("1")\
               .next_to(number_line.get_tick(-1),DOWN)
        text_2=TextMobject("2")\
               .next_to(number_line.get_tick(0),DOWN)
        text_3=TextMobject("3")\
               .next_to(number_line.get_tick(1),DOWN)
        text_4=TextMobject("4")\
               .next_to(number_line.get_tick(2),DOWN)

        self.add(number_line)
        self.play(ShowCreation(triangle))
        self.wait(0.3)

        self.play(
                    #The move of the triangle starts
                    ApplyMethod(triangle.shift,RIGHT*4,rate_func=linear,run_time=4),

                    AnimationGroup(
                        Animation(Mobject(),run_time=1),#<- one second pause
                        Write(text_1),lag_ratio=1       #<- then start Write animation
                    ),
                    AnimationGroup(
                        Animation(Mobject(),run_time=2),#<- two seconds pause
                        Write(text_2),lag_ratio=1       #<- then start Write animation
                    ),
                    AnimationGroup(
                        Animation(Mobject(),run_time=3),#<- three seconds pause
                        Write(text_3),lag_ratio=1       #<- then start Write animation
                    ),
                    AnimationGroup(
                        Animation(Mobject(),run_time=4),#<- four seconds pause
                        Write(text_4),lag_ratio=1       #<- then start Write animation
                    ),
            )

        self.wait()
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57050240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档