Animation
image 组件的 animation 平台允许在显示器上使用动画图像(例如 GIF 文件)。
动画支持 file 平台 的所有选项,并增加了
lambda 方法:next_frame()、prev_frame() 和 set_frame() 以更改显示的图像。
image: - platform: animation file: "animation.gif" id: my_animation resize: 100x100 type: RGB565动画可以像 image 组件一样使用 display 组件的 image() 函数进行渲染。
要显示动画的下一帧,调用 id(my_animation).next_frame();要显示上一帧,使用
id(my_animation).prev_frame()。要显示特定帧,使用 id(my_animation).set_frame(int frame)。
这些可以与所有 Lambdas 结合使用:
display: - platform: ... # ... lambda: |- // 切换到显示的动画下一帧。 id(my_animation).next_frame(); // 在位置 [x=0,y=0] 绘制动画 my_animation it.image(0, 0, id(my_animation), COLOR_ON, COLOR_OFF);此外,你还可以使用 animation.next_frame、animation.prev_frame 或 animation.set_frame 操作。
NOTE
要在不依赖显示器绘制周期的情况下绘制下一帧动画,请使用一个 interval:
interval: - interval: 5s then: animation.next_frame: my_animationanimation 平台支持 file 平台 的所有选项,例如
file、type、resize 和 transparency。file 选项指向动画图像(例如 GIF 文件),其
帧将被嵌入。此外,还提供以下选项:
-
loop (可选):如果要对动画的子集进行循环(例如火焰动画,火焰 “开始”、然后”燃烧”和”熄灭”),你可以指定一些要循环的帧。
- start_frame (可选, int):达到
end_frame时要循环回去的帧。默认为动画中的 第一帧。 - end_frame (可选, int):循环中显示的最后帧;达到此帧时将循环回到
start_frame。默认为动画中的最后一帧。 - repeat (可选, int):指定循环运行的次数。达到计数后,动画
将继续从
end_frame之后的下一帧开始,或者如果end_frame是最后一帧,则从头开始。默认为”无限循环”。
- start_frame (可选, int):达到
animation.next_frame 操作
Section titled “animation.next_frame 操作”将动画移动到下一帧。这等价于 lambda 调用
id(my_animation).next_frame();。
- id (必填, ID):要动画化的动画的 ID。
animation.prev_frame 操作
Section titled “animation.prev_frame 操作”将动画移动到上一帧。这等价于 lambda 调用
id(my_animation).prev_frame();。
- id (必填, ID):要动画化的动画的 ID。
animation.set_frame 操作
Section titled “animation.set_frame 操作”将动画移动到特定帧。这等价于 lambda 调用
id(my_animation).set_frame(frame);。
- id (必填, ID):要动画化的动画的 ID。
- frame (必填, int):要显示的下一帧的帧索引。