Qt Quick Particles 示例 - 图像粒子

这是一组使用 QML 粒子系统中 Affectors 的示例。

色彩斑斓的星形微粒,从明亮的中心向外散发出彩虹般的色泽

这是一组与粒子系统中使用“影响器”(Affectors)相关的小型 QML 示例。每个示例都是一个简短的 QML 文件,重点展示特定类型或功能。

“All at once”同时展示了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; }
}

“Rotation”演示了 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 设置了颜色和透明度,因此渲染出的粒子颜色与其他不同。由于未指定旋转参数,它会与其他ImageParticle 共享旋转角度,因此两处的花朵旋转方向一致。请注意,您可以在另一个ImageParticle 中取消旋转效果,只需显式将rotationVariation设置为0即可。

Sprites 演示了如何使用图像粒子来渲染动画精灵,而不是为每个粒子使用静态图像。

示例项目 @ code.qt.io

© 2026 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.