如何在粒子系统发射器中发射一个又一个粒子

问题描述 投票:0回答:1

我只想一次只发出一张图像,每次发出后我希望下一个是第二张图像。 我找不到任何解决方案。 也许我应该使用一些计时器,但我不确定在哪里。

Window {
    width: 300
    height: 300
    Rectangle {
        anchors.fill: parent

        ParticleSystem {
            id: xy
            anchors.centerIn: parent
            Age {
                system: notes
                anchors.fill: parent
                once: true
                lifeLeft: 1000
                advancePosition: false
            }
            ImageParticle {
                groups: ["x"]
                source: "images/x.png"

            }
            ImageParticle {
                groups: ["y"]
                source: "images/y.png"
            }

            Emitter {
                group: "y"
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                velocity: AngleDirection {
                    angle: 270
                    angleVariation: 35
                    magnitude: 20
                }
                lifeSpan: 5000
                emitRate: 2
                size: 8
                endSize: 15

            }
            Emitter {
                group: "x"
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                velocity: AngleDirection {
                    angle: 270
                    angleVariation: 35
                    magnitude: 20
                }
                lifeSpan: 5000
                emitRate: 2
                size: 6
                endSize: 13
            }
        }

            Age {
                system: xy
                anchors.fill: parent
                once: true
                lifeLeft: 1000
                advancePosition: false
            }
        }
}

提前感谢您的回答。

文档:

qt qml qt-quick qqmlcomponent
1个回答
0
投票

因为您想要对

Emitters
何时发射进行细粒度控制,所以我建议关闭自动发射器,然后通过设置
emitRate: 0
,您可以对相应的
Emitter.burst()
方法进行交替调用。在以下示例中,我使用
Timer
来安排此类调用:

    Timer {
        property int c: 0
        interval: 100
        repeat: true
        running: true
        onTriggered: {
            if (++c % 2 == 0)
                emx.burst(1);
            else
                emy.burst(1);
        }
    }
    Rectangle {
        anchors.fill: parent
        ParticleSystem {
            id: ps
            anchors.centerIn: parent
            property int c: 0
            ImageParticle {
                groups: ["x"]
                source: "images/x.svg"
            }
            ImageParticle {
                groups: ["y"]
                source: "images/y.svg"
            }
            Emitter {
                id: emx
                group: "x"
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                velocity: AngleDirection {
                    angle: 270
                    angleVariation: 35
                    magnitude: 100
                }
                lifeSpan: 1000
                emitRate: 0
                size: 8
                endSize: 15
            }
            Emitter {
                id: emy
                group: "y"
                anchors.bottom: parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                velocity: AngleDirection {
                    angle: 270
                    angleVariation: 35
                    magnitude: 100
                }
                lifeSpan: 1000
                emitRate: 0
                size: 6
                endSize: 13
            }
        }
    }

您可以在线尝试!

© www.soinside.com 2019 - 2024. All rights reserved.