Search code examples
qtqmlparticles

How to generate particles from the center of my window? (qml)


I am working with the particle system in qml, but I want my particles originating from the center of my rectangle.

The foregoing I can tell you that it is already done, but what I do not like is that the particles emerge in disorder and without direction.
I would like the particles to spread evenly from the center to the ends, but I do not know how to do it.
If someone I could suggest some idea.
I annex my code.

Corrections, ideas or suggestions that solve my problem are accepted.

import QtQuick 2.0
import QtQuick.Particles 2.0

Rectangle {
    id: bg
    width: 360
    height: 360
    color: "black"

    ParticleSystem {
        id: particleSys
    }

    Emitter{
        id: emitter
        anchors.centerIn: parent
        height: 14; width: 16
        system: particleSys
        emitRate: 80
        lifeSpan: 4000
        lifeSpanVariation: 500
        maximumEmitted: 1000
        size: 5
        endSize: 40           

        velocity: TargetDirection{     
            targetX: 0; targetY: 0
            targetVariation: 360
            magnitude: 250
        }
    }

    ImageParticle{
        source: "images/blueBlip.png"      //My image
        system: particleSys
    }
} 

Thanks.


Solution

  • I am the person who asked the question.
    I found a solution to my question.

    To emit ordered particles you can make use of the burst() method.

    This event allows us to emit a certain number of particles from our emitter. You can manipulate it according to what you need.

    I implemented it through a Timmer:

    Timer{
        interval: 500; running: true; repeat: true
        onTriggered: particles.burst(particles.emitRate)
    }
    

    The code would look like this:

    import QtQuick 2.0
    import QtQuick.Particles 2.0
    
    Rectangle {
        id: bg
        width: 360
        height: 360
        color: "black"
    
        ParticleSystem {
            id: particleSys
        }
    
        Emitter{
            id: particles
            anchors.centerIn: parent
            height: 14; width: 16
            system: particleSys
            emitRate: 80
            lifeSpan: 4000
            lifeSpanVariation: 500
            maximumEmitted: 1000
            size: 5
            endSize: 40           
    
            velocity: TargetDirection{     
                targetX: 0; targetY: 0
                targetVariation: 360
                magnitude: 250
            }
    
            Timer{
                  interval: 500; running: true; repeat: true
                  onTriggered: particles.burst(particles.emitRate)
            }
        }
    
        ImageParticle{
            source: "images/blueBlip.png"      //My image
            system: particleSys
        }
    } 
    

    If someone knows a more efficient way or someone can improve it ... contribute your answer.
    Thanks.