粒子动画是在一定范围内随机生成的大量粒子产生运动而组成的动画。动画元素是一个个粒子,这些粒子可以是圆点、图片。开发者可以通过对粒子在颜色、透明度、大小、速度、加速度、自旋角度等维度变化做动画,来营造一种氛围感,比如下雪的动效,雪花飘舞就相当于一个个雪花粒子在做动画。
粒子动画的效果通过Particle组件展现。
基本示例代码和效果如下
1. @Entry
2. @Component
3. struct ParticleExample {
4. build() {
5. Stack() {
6. Text()
7. .width(300).height(300).backgroundColor(Color.Black)
8. Particle({ particles: [
9. {
10. emitter: {
11. particle: {
12. type: ParticleType.POINT, //粒子类型
13. config: {
14. radius: 5 //圆点半径
15. },
16. count: 100, //粒子总数
17. },
18. },
19. },
20. ]
21. }).width(250).height(250)
22. }.width("100%").height("100%").align(Alignment.Center)
23. }
24. }