Search code examples
qtqmlparticlesparticle-system

Prevent ParticleSystem from running forever in qml


I'm trying to make particles effect in my app, evertything is done great except that i cannot limit the emitter and make it stop from its own without me calling the stop method of the ParticleSystem although i have set the maximumEmitted to 100, for illustration here is my code:

import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Particles 2.0

Window {
visible: true
width: 360
height: 360



ParticleSystem{
    id:par
 anchors.centerIn: parent
running: true

 ImageParticle{
     id:imagepar
     source:"../../star_white.png"
    color:"red"
 }



 Emitter{
     id:myEmit
     width:1 ; height:1
    // anchors.centerIn: parent
     size:10
     emitRate: 100
     maximumEmitted: 100
     lifeSpan: 4000
     velocity: AngleDirection{
        angle: 180
        angleVariation: 5
        magnitude: 150

    }

 }

 Gravity {
     width: parent.width
     y: 150
     angle: 90
     magnitude: 150
 }



}



}

i have tried the following to make the particles stop from its own by emitting only once but unfortunately it keeps emitting for ever

 Age {
     system: par
     once: true
  }


 Affector {
     system: par
     once: true
 }

i think i'm missing a single line of code here that will make it good to go, Any Ideas.


Solution

  • The first thing that comes to my mind:

    Emitter {
        id: myEmit
        ....
        enabled: false
        Component.onCompleted: myEmit.pulse(1000)
        ....
    }