Qt Quick Particles Beispiele - Emitter
Dies ist eine Sammlung von Beispielen zur Verwendung von Emittern im QML-Partikel-System.
Dies ist eine Sammlung von kleinen QML-Beispielen für die Verwendung von Emittern im Partikelsystem. Jedes Beispiel ist eine kleine QML-Datei, die einen bestimmten Typ oder eine bestimmte Funktion hervorhebt.
Velocity from motion gibt den Effekt einer starken Partikelbewegung durch die primäre Bewegung der Emitter:
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 ruft die Methoden Burst und Pulse auf zwei identischen Emittern auf.
if (root.lastWasPulse) { burstEmitter.burst(500); root.lastWasPulse = false; } else { pulseEmitter.pulse(500); root.lastWasPulse = true; }
Man beachte, dass Burst als Argument die Anzahl der zu emittierenden Partikel und Pulse als Argument die Anzahl der zu emittierenden Millisekunden annimmt. Dadurch ergibt sich ein leicht unterschiedliches Verhalten, das in diesem Beispiel leicht zu erkennen ist.
Der benutzerdefinierte Emitter verbindet sich mit dem emitParticles-Signal, um beliebige Werte für die Partikeldaten zu setzen, während sie emittiert werden;
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 gekrümmte Partikel in sechs rotierenden Speichen zu emittieren.
Emit mask setzt eine Bildmaske auf den Emitter, um aus einer beliebigen Form zu emittieren.
shape: MaskShape { source: "images/starfish_mask.png" }
Maximal emittiert emittiert nicht mehr als eine bestimmte Anzahl von Partikeln auf einmal. An diesem Beispiel lässt sich leicht erkennen, was passiert, wenn das Limit erreicht ist.
Shape and Direction emittiert Partikel aus einer ungefüllten Ellipse-Form unter Verwendung einer 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 Zentrums der Ellipse geschickt, 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; } }
© 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.