Qt Quick Ejemplos de partículas: emisores

Esta es una recopilación de ejemplos que utilizan emisores en el sistema de partículas de QML.

Partículas curvas que forman un motivo similar a una flor con seis radios giratorios

Se trata de una recopilación de pequeños ejemplos en QML relacionados con el uso de emisores en el sistema de partículas. Cada ejemplo es un pequeño archivo QML que destaca un tipo o una característica concreta.

La velocidad derivada del movimiento produce un efecto de movimiento intenso de las partículas, principalmente mediante el desplazamiento de los emisores:

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» y «pulse» invocan los métodos «burst» y «pulse» en dos emisores idénticos.

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

Fíjate en que «burst» toma como argumento el número de partículas que se van a emitir, y «pulse» toma como argumento el número de milisegundos durante los que se van a emitir. Esto da lugar a un comportamiento ligeramente diferente, que se aprecia fácilmente en este ejemplo.

«Custom Emitter» se conecta a la señal «emitParticles» para establecer valores arbitrarios en los datos de las partículas a medida que se emiten;

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

Esto se utiliza para emitir partículas que describen curvas en seis radios giratorios.

«Emit mask» establece una máscara de imagen en el emisor para emitir partículas con una forma arbitraria.

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

«Máximo emitido» no emite más de un número determinado de partículas a la vez. Este ejemplo permite ver fácilmente qué ocurre cuando se alcanza el límite.

«Shape and Direction» emite partículas desde una forma de elipse sin rellenar, utilizando un TargetDirection

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

Esto envía las partículas hacia el centro de la elipse a una velocidad proporcional, manteniendo el contorno de la elipse a medida que se desplazan hacia el centro.

TrailEmitter utiliza ese tipo para añadir partículas de humo que sigan a las partículas de fuego en la escena.

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

Proyecto de ejemplo en 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.