Qt Quick パーティクルの例 - エミッター
これは、QML パーティクルシステムにおけるエミッターの使用例を集めたものです。

これは、パーティクルシステムにおけるエミッターの使用に関連する、簡単な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
}「Burst」と「pulse」は、2つの同一のエミッターに対してそれぞれ「burst」メソッドと「pulse」メソッドを呼び出します。
if (root.lastWasPulse) {
burstEmitter.burst(500);
root.lastWasPulse = false;
} else {
pulseEmitter.pulse(500);
root.lastWasPulse = true;
}「burst」は放出するパーティクルの数を引数として取り、「pulse」は放出する時間をミリ秒単位で引数として取る点に注目してください。これにより、わずかに異なる挙動が生じますが、このサンプルではそれが容易に確認できます。
「Custom Emitter」は、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"
}「Maximum emitted」は、一度に放出されるパーティクルの数を特定の数以下に制限します。この例では、制限に達したときに何が起こるかを簡単に確認できます。
「Shape」と「Direction」は、塗りつぶされていない楕円形状から、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;
}
}© 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.