Qt Quick Particles 示例 - 发射器
这是在 QML 粒子系统中使用 Emitters 的示例集。
这是有关在粒子系统中使用发射器的 QML 小范例集。每个示例都是一个强调特定类型或特征的小 QML 文件。
运动速度(Velocity from motion)主要通过移动发射器来产生强烈的粒子运动效果:
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; }
请注意,burst 的参数是要发射的粒子数量,而 pulse 的参数是要发射的毫秒数。这两种方法的行为略有不同,在本例中很容易看到。
自定义发射器连接到 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; } }
这用于发射六个旋转辐条中的曲线粒子。
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; } }
© 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.