Qt Quick Particles 示例 - 图像粒子
这是一个在 QML 粒子系统中使用 Affectors 的示例集。
这是有关在粒子系统中使用 Affectors 的 QML 小范例集。每个示例都是一个强调特定类型或特征的小 QML 文件。
同时显示ImageParticle 的几个功能。
sprites: [ Sprite { name: "bear" source: "images/bear_tiles.png" frameCount: 13 frameDuration: 120 } ] colorVariation: 0.5 rotationVelocityVariation: 360 colorTable: "images/colortable.png"
Colored 显示了一个简单的ImageParticle ,并带有一些颜色变化。
ImageParticle { anchors.fill: parent source: "qrc:///particleresources/star.png" alpha: 0 alphaVariation: 0.2 colorVariation: 1.0 }
Color Table(色彩表)会根据粒子的生命周期设置颜色,以提供固定的彩虹效果。
source: "qrc:///particleresources/glowdot.png" colorTable: "images/colortable.png" sizeTable: "images/colortable.png"
变形展示了海星粒子的旋转和挤压效果。
ImageParticle { system: sys groups: ["goingLeft", "goingRight"] source: "images/starfish_4.png" rotation: 90 rotationVelocity: 90 autoRotation: true } ImageParticle { system: sys groups: ["goingDown"] source: "images/starfish_0.png" rotation: 180 yVector: PointDirection { y: 0.5; yVariation: 0.25; xVariation: 0.25; } }
旋转演示了 autoRotate 属性,使粒子按其移动方向旋转。
共享演示了多个 ImageParticles 尝试渲染同一个粒子时会发生的情况。下面的ImageParticle 渲染了ListView 内的粒子:
ImageParticle { anchors.fill: parent system: particles source: "images/flower.png" alpha: 0.1 color: "white" rotationVariation: 180 z: -1 }
下面的ImageParticle 放置在列表高亮区内,并在其他ImageParticle 的上方渲染粒子。
ImageParticle { anchors.fill: parent system: particles source: "images/flower.png" color: "red" clip: true alpha: 1.0 }
请注意,由于在此ImageParticle 中设置了颜色和 alpha,因此渲染的粒子颜色不同。由于它没有指定旋转,因此它与另一个ImageParticle 共享旋转,这样花朵在两个 中的旋转方式相同。请注意,您可以在另一个ImageParticle 中撤销旋转,只需明确将 rotationVariation 设置为 0 即可。
Sprites 演示使用图像粒子为每个粒子渲染动画精灵,而不是静态图像。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.