Qt Quick Particles 예제 - 이미터

QML 파티클 시스템에서 이미터를 사용한 예제 모음입니다.

파티클 시스템에서 이미터 사용과 관련된 작은 QML 예제 모음입니다. 각 예제는 특정 유형이나 기능을 강조하는 작은 QML 파일입니다.

모션에서 속도는 주로 이미터의 움직임을 통해 강한 파티클 모션 효과를 제공합니다:

Emitter {
    id: trailsNormal
    system: sys1

    emitRate: 500
    lifeSpan: 2000

    y: mouseArea.pressed ? mouseArea.mouseY : circle.cy
    x: mouseArea.pressed ? mouseArea.mouseX : circle.cx

    velocity: PointDirection {xVariation: 4; yVariation: 4;}
    acceleration: PointDirection {xVariation: 10; yVariation: 10;}
    velocityFromMovement: 8

    size: 8
    sizeVariation: 4
}

버스트와 펄스는 두 개의 동일한 이미터에서 버스트와 펄스 메서드를 호출합니다.

    if (root.lastWasPulse) {
        burstEmitter.burst(500);
        root.lastWasPulse = false;
    } else {
        pulseEmitter.pulse(500);
        root.lastWasPulse = true;
    }

버스트는 방출할 파티클 수를 인자로 받고, 펄스는 방출할 밀리초 수를 인자로 받는다는 점에 유의하세요. 이렇게 하면 약간 다른 동작이 발생하며, 이 예제에서 쉽게 확인할 수 있습니다.

커스텀 이미터는 파티클 데이터가 방출될 때 임의의 값을 설정하기 위해 emitParticles 신호에 연결합니다;

onEmitParticles: (particles) => {
    for (var i=0; i<particles.length; i++) {
        let particle = particles[i];
        particle.startSize = Math.max(02,Math.min(492,Math.tan(particle.t/2)*24));
        let theta = Math.floor(Math.random() * 6.0);
        particle.red = theta == 0 || theta == 1 || theta == 2 ? 0.2 : 1;
        particle.green = theta == 2 || theta == 3 || theta == 4 ? 0.2 : 1;
        particle.blue = theta == 4 || theta == 5 || theta == 0 ? 0.2 : 1;
        theta /= 6.0;
        theta *= 2.0*Math.PI;
        theta += sys.convert(sys.petalRotation);//Convert from degrees to radians
        particle.initialVX = sys.petalLength * Math.cos(theta);
        particle.initialVY = sys.petalLength * Math.sin(theta);
        particle.initialAX = particle.initialVX * -0.5;
        particle.initialAY = particle.initialVY * -0.5;
    }
}

이것은 6개의 회전하는 스포크에서 커브 파티클을 방출하는 데 사용됩니다.

Emit mask는 이미터에 이미지 마스크를 설정하여 임의의 모양으로 방출합니다.

shape: MaskShape {
    source: "images/starfish_mask.png"
}

최대 방출은 한 번에 특정 개수 이상의 파티클을 방출하지 않습니다. 이 예시를 통해 한계에 도달하면 어떤 일이 발생하는지 쉽게 확인할 수 있습니다.

모양과 방향은 채우지 않은 타원 모양에서 파티클을 방출합니다. TargetDirection

shape: EllipseShape {fill: false}
velocity: TargetDirection {
    targetX: root.width/2
    targetY: root.height/2
    proportionalMagnitude: true
    magnitude: 0.5
}

이렇게 하면 파티클이 비례하는 속도로 타원의 중심을 향해 이동하면서 타원의 윤곽을 유지하면서 파티클을 보냅니다.

TrailEmitter 는 이 유형을 사용하여 씬에서 연기 파티클을 추가하여 불 파티클을 추적합니다.

onEmitParticles: (particles) => {
    for (var i=0; i<particles.length; i++) {
        let particle = particles[i];
        particle.startSize = Math.max(02,Math.min(492,Math.tan(particle.t/2)*24));
        let theta = Math.floor(Math.random() * 6.0);
        particle.red = theta == 0 || theta == 1 || theta == 2 ? 0.2 : 1;
        particle.green = theta == 2 || theta == 3 || theta == 4 ? 0.2 : 1;
        particle.blue = theta == 4 || theta == 5 || theta == 0 ? 0.2 : 1;
        theta /= 6.0;
        theta *= 2.0*Math.PI;
        theta += sys.convert(sys.petalRotation);//Convert from degrees to radians
        particle.initialVX = sys.petalLength * Math.cos(theta);
        particle.initialVY = sys.petalLength * Math.sin(theta);
        particle.initialAX = particle.initialVX * -0.5;
        particle.initialAY = particle.initialVY * -0.5;
    }
}

예제 프로젝트 @ code.qt.io

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