Qt Quick Particles 예제 - 시스템

이 문서는 QML 입자 시스템에서 어펙터를 사용하는 예제 모음입니다.

파란색 배경에 검은색 테두리가 있는 원형 입자들로, 여러 화가들이 그려진 모습을 보여준다

이 문서는 파티클 시스템에서 Affector를 사용하는 것과 관련된 간단한 QML 예제 모음입니다. 각 예제는 특정 유형이나 기능을 강조하는 작은 QML 파일로 구성되어 있습니다.

'동적 비교' 예제는 파티클 시스템을 사용하는 것과, Image 타입을 동적으로 인스턴스화하는 다음 코드를 통해 유사한 효과를 얻는 것을 비교합니다.

Item {
    id: fakeEmitter
    function burst(number) {
        while (number > 0) {
            let item = fakeParticle.createObject(root)
            item.lifeSpan = Math.random() * 5000 + 5000
            item.x = Math.random() * (root.width / 2) + (root.width / 2)
            item.y = 0
            number--
        }
    }

    Component {
        id: fakeParticle
        Image {
            id: container
            property int lifeSpan: 10000
            width: 32
            height: 32
            source: "qrc:///particleresources/glowdot.png"
            PropertyAnimation on y { from: -16; to: root.height - 16; duration: container.lifeSpan; running: true }
            SequentialAnimation on opacity {
                running: true
                NumberAnimation { from: 0; to: 1; duration: 500 }
                PauseAnimation { duration: container.lifeSpan - 1000 }
                NumberAnimation { from: 1; to: 0; duration: 500 }
                ScriptAction { script: container.destroy(); }
            }
        }
    }
}

Image 객체에는 무작위로 색상을 지정할 수 없다는 점에 유의하십시오.

'시작'과 '중지'는 단순히 ` ParticleSystem`의 실행 및 일시 중지 상태를 설정합니다. 시스템은 중지되거나 일시 중지된 상태에서는 시뮬레이션을 수행하지 않지만, '재시작'을 하면 시뮬레이션이 처음부터 다시 시작되고, '일시 중지 해제'를 하면 중단된 지점부터 시뮬레이션이 재개됩니다.

'시간 기반 그룹 변경'은 ` ParticleGroup ` 유형을 잘 보여주는 예시입니다. 일반적으로 문자열 이름으로 그룹을 참조하는 것만으로도 충분하지만, 그룹에 속성을 설정하여 추가적인 효과를 낼 수 있습니다. 첫 번째 그룹에는 가변적인 지속 시간이 설정되어 있지만, 항상 두 번째 그룹으로 전환됩니다.

ParticleGroup {
    name: "fire"
    duration: 2000
    durationVariation: 2000
    to: {"splode":1}
}

두 번째 그룹에는 ' TrailEmitter '가 적용되어 있으며, 세 번째 그룹으로 입자 방출을 위한 고정 지속 시간이 설정되어 있습니다. ' TrailEmitter '를 ' ParticleGroup'의 직접 자식으로 배치하면, 해당 그룹을 자동으로 추적 대상으로 선택합니다.

ParticleGroup {
    name: "splode"
    duration: 400
    to: {"dead":1}
    TrailEmitter {
        group: "works"
        emitRatePerParticle: 100
        lifeSpan: 1000
        maximumEmitted: 1200
        size: 8
        velocity: AngleDirection {angle: 270; angleVariation: 45; magnitude: 20; magnitudeVariation: 20;}
        acceleration: PointDirection {y:100; yVariation: 20}
    }
}

세 번째 그룹에는 어펙터(Affector)가 직접 자식으로 배치되어 있어, 어펙터가 자동으로 이 그룹을 대상으로 삼습니다. 어펙터를 사용하면 입자가 이 그룹에 진입하는 즉시, 해당 입자의 x, y 좌표를 사용하여 다른 이미터에서 버스트(burst) 함수를 호출할 수 있습니다.

ParticleGroup {
    name: "dead"
    duration: 1000
    Affector {
        once: true
        onAffected: (x, y)=> worksEmitter.burst(400,x,y)
    }
}

만약 TrailEmitter 가 여러 개의 이미터(emitter)를 사용하는 데 적합하지 않다면, 동일한 이미지 그룹( ParticleSystem )과 이미지 파티클을 계속 사용하면서 이미터를 동적으로 생성할 수도 있습니다.

for (var i = 0; i < 8; i++) {
    let obj = emitterComp.createObject(root)
    obj.x = x
    obj.y = y
    obj.targetX = Math.random() * 240 - 120 + obj.x
    obj.targetY = Math.random() * 240 - 120 + obj.y
    obj.life = Math.round(Math.random() * 2400) + 200
    obj.emitRate = Math.round(Math.random() * 32) + 32
    obj.go()
}

참고로, 무지개색 창이 흩날리는 이 효과는 TrailEmitter 를 사용하는 것이 더 적합합니다. 이 예제에서는 개념을 더 간단하게 설명하기 위해 동적 이미터를 사용했을 뿐입니다.

'Multiple Painters'는 개별 파티클의 페인트 순서를 제어하는 방법을 보여줍니다. 하나의 ImagePainter 내 파티클의 페인트 순서는 엄격하게 정의되어 있지 않지만, ImageParticle 객체는 Qt Quick 항목에 대한 일반적인 Z 순서 규칙을 따릅니다. 이 예제를 통해, 동일한 논리적 입자의 서로 다른 부분을 각각 그리는 한 쌍의 ImageParticles를 사용하여 검은색 테두리 위쪽의 입자 내부를 칠할 수 있습니다.

예제 프로젝트 @ 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.