假设有两个self.play语句,第一个从1s开始,我想秒从开始就恰好3s开始。
当前,我使用self.wait来控制步骤:
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从一开始就精确地在3秒钟开始运行? 预先感谢。
答案 0 :(得分:1)
这是你的意思吗?
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()