aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-09-20 15:28:14 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-21 07:11:25 +0200
commitef98f5a80369e3f014585edc3dd63a2ec331d1ea (patch)
tree4e6abd6afb7ba04422a1acc9d11c2f8ff21169c1 /examples
parent4114b9dcff68cdebc36e3b4818d4463d62421ecf (diff)
CustomEmitter/Affector now affect whole lists at once
Better performance potential (fewer drops to JS, possibility of more optimzed JS). Change-Id: If386f06ac8714162a5bfc6b5eef7f2e67f9dae95 Reviewed-on: http://codereview.qt-project.org/5189 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/particles/affectors/customaffector.qml48
-rw-r--r--examples/declarative/particles/emitters/customemitter.qml21
2 files changed, 39 insertions, 30 deletions
diff --git a/examples/declarative/particles/affectors/customaffector.qml b/examples/declarative/particles/affectors/customaffector.qml
index 35708b7864..e9aea62a5a 100644
--- a/examples/declarative/particles/affectors/customaffector.qml
+++ b/examples/declarative/particles/affectors/customaffector.qml
@@ -71,7 +71,7 @@ Item {
property real speed: 1.5
width: parent.width
height: parent.height - 100
- onAffectParticle:{
+ onAffectParticles:{
/* //Linear movement
if (particle.r == 0){
particle.r = Math.random() > 0.5 ? -1 : 1;
@@ -86,14 +86,17 @@ Item {
}
*/
//Wobbly movement
- if (particle.r == 0.0){
- particle.r = Math.random() + 0.01;
+ for (var i=0; i<particles.length; i++) {
+ var particle = particles[i];
+ if (particle.r == 0.0) {
+ particle.r = Math.random() + 0.01;
+ }
+ particle.rotation += speed * particle.r * dt;
+ particle.r -= particle.rotation * coefficient;
+ if (particle.r == 0.0)
+ particle.r -= particle.rotation * 0.000001;
+ particle.update = 1;
}
- particle.rotation += speed * particle.r * dt;
- particle.r -= particle.rotation * coefficient;
- if (particle.r == 0.0)
- particle.r -= particle.rotation * 0.000001;
- particle.update = 1;
}
}
@@ -104,19 +107,22 @@ Item {
width: parent.width + 120
height: 100
anchors.bottom: parent.bottom
- onAffectParticle:{
- var pseudoRand = (Math.floor(particle.t*1327) % 10) + 1;
- var yslow = pseudoRand * 0.01 + 1.01;
- var xslow = pseudoRand * 0.005 + 1.0;
- if (particle.vy < 1)
- particle.vy = 0;
- else
- particle.vy = (particle.vy / yslow);
- if (particle.vx < 1)
- particle.vx = 0;
- else
- particle.vx = (particle.vx / xslow);
- particle.update = 1;
+ onAffectParticles:{
+ for (var i=0; i<particles.length; i++) {
+ var particle = particles[i];
+ var pseudoRand = (Math.floor(particle.t*1327) % 10) + 1;
+ var yslow = dt * pseudoRand * 0.5 + 1;
+ var xslow = dt * pseudoRand * 0.05 + 1;
+ if (particle.vy < 1)
+ particle.vy = 0;
+ else
+ particle.vy = (particle.vy / yslow);
+ if (particle.vx < 1)
+ particle.vx = 0;
+ else
+ particle.vx = (particle.vx / xslow);
+ particle.update = 1;
+ }
}
}
ImageParticle{
diff --git a/examples/declarative/particles/emitters/customemitter.qml b/examples/declarative/particles/emitters/customemitter.qml
index 55c3884a11..39e2d066f6 100644
--- a/examples/declarative/particles/emitters/customemitter.qml
+++ b/examples/declarative/particles/emitters/customemitter.qml
@@ -66,15 +66,18 @@ ParticleSystem{
emitRate: 120
size: 12
anchors.centerIn: parent
- onEmitParticle:{
- particle.startSize = Math.max(02,Math.min(492,Math.tan(particle.t/2)*24));
- var theta = Math.floor(Math.random() * 6.0) / 6.0;
- theta *= 2.0*Math.PI;
- theta += sys.convert(sys.petalRotation);
- particle.initialVX = petalLength * Math.cos(theta);
- particle.initialVY = petalLength * Math.sin(theta);
- particle.initialAX = particle.initialVX * -0.5;
- particle.initialAY = particle.initialVY * -0.5;
+ onEmitParticles:{
+ for (var i=0; i<particles.length; i++) {
+ var particle = particles[i];
+ particle.startSize = Math.max(02,Math.min(492,Math.tan(particle.t/2)*24));
+ var theta = Math.floor(Math.random() * 6.0) / 6.0;
+ theta *= 2.0*Math.PI;
+ theta += sys.convert(sys.petalRotation);
+ particle.initialVX = petalLength * Math.cos(theta);
+ particle.initialVY = petalLength * Math.sin(theta);
+ particle.initialAX = particle.initialVX * -0.5;
+ particle.initialAY = particle.initialVY * -0.5;
+ }
}
}
ImageParticle{