如何在粒子中显示不同的图像?

时间:2017-06-20 19:11:13

标签: image qml particle-system

我希望发射粒子但是使用我的阵列中的图像 我在代码中做了修改。现在的错误显然是在函数getImage()中,它可以通过我的所有数组获取每个图像的每个路径,但在ImageParticle中它只能设法识别单个路径。
结果:发射粒子,但只识别矩阵中二十个图像 有谁知道我做错了吗?

import QtQuick 2.0
import QtQuick.Particles 2.0    

Rectangle {
    id: bg
    width: 1920         
    height: 1080         
    color: "black"

    ParticleSystem {
        id: particleSys
    }            

    Emitter{
        id: particles
        anchors.centerIn: parent
        height: 1; width: 1
        system: particleSys
        emitRate: 30
        lifeSpan: 4000
        lifeSpanVariation: 500
        maximumEmitted: 1000
        size: 5
        endSize: 200           

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

    property var picturesList: [
        "images/Image1.png", "images/Image2.png", "images/Image3.png", "images/Image4.png", "images/Image5.png", "images/Image6.png", "images/Image7.png", "images/Image8.png", "images/Image9.png", "images/Image10.png",
        "images/Image11.png", "images/Image12.png", "images/Image13.png", "images/Image14.png", "images/Image15.png", "images/Image16.png", "images/Image17.png", "images/Image18.png", "images/Image19.png", "images/Image20.png"
    ]

    function getImage(arr){
        var flag = "";
        for(var i = 0; i < arr.length ; i++){                
            flag = arr[i];
            //console.log("Position: " + arr[i] + " flag: " + flag )
        }
        return flag;
    }

    ImageParticle{
        property var link: getImage(picturesList)
        source:  link
        system: particleSys
    }    
} 

0 个答案:

没有答案