Qt Quick Particles Beispiele – Emitter

Dies ist eine Sammlung von Beispielen zur Verwendung von Emittern im QML-Partikelsystem.

Sich krümmende Teilchen, die ein blumenähnliches Muster mit sechs rotierenden Speichen bilden

Dies ist eine Sammlung kleiner QML-Beispiele zur Verwendung von Emittern im Partikelsystem. Jedes Beispiel ist eine kleine QML-Datei, die einen bestimmten Typ oder eine bestimmte Funktion hervorhebt.

„Velocity from motion“ erzeugt den Effekt einer starken Partikelbewegung, indem in erster Linie die Emitter bewegt werden:

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
}

„Burst“ und „Pulse“ rufen die Methoden „burst“ und „pulse“ für zwei identische Emitter auf.

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

Beachten Sie, dass „burst“ ein Argument für die Anzahl der auszustrahlenden Partikel und „pulse“ ein Argument für die Dauer der Emission in Millisekunden benötigt. Dies führt zu einem leicht unterschiedlichen Verhalten, das in diesem Beispiel gut zu erkennen ist.

„Custom Emitter“ wird mit dem Signal „emitParticles“ verbunden, um bei der Emission beliebige Werte für die Partikeldaten festzulegen;

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;
    }
}

Dies wird verwendet, um kurvenförmige Partikel in sechs rotierenden Speichen zu emittieren.

„Emit mask“ legt eine Bildmaske für den Emitter fest, um Partikel in einer beliebigen Form emittieren zu können.

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

„Maximum emitted“ emittiert nicht mehr als eine bestimmte Anzahl von Partikeln gleichzeitig. An diesem Beispiel lässt sich leicht erkennen, was passiert, wenn das Limit erreicht ist.

„Shape and Direction“ emittiert Partikel aus einer nicht gefüllten Ellipse und verwendet dabei einen TargetDirection

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

Dadurch werden die Partikel mit proportionaler Geschwindigkeit in Richtung des Ellipsenzentrums gesendet, wobei der Umriss der Ellipse beibehalten wird, während sie sich zum Zentrum bewegen.

TrailEmitter verwendet diesen Typ, um Rauchpartikel hinzuzufügen, die den Feuerpartikeln in der Szene folgen.

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;
    }
}

Beispielprojekt @ 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.