QML笔记-Particle的基本使用(粒子系统的基本使用)
目录
基本概念
粒子系统(ParticleSystem)- 管理发射器之间的共享时间线。
发射器(Emitter)- 向系统中发射逻辑粒子。
粒子画笔(ParticlePainter)- 实现粒子可视化。
其中下面的ParticlePainter是ImageParticle,他是ParticlePainter的子类
每一个例子系统都有自己独立的线程。
其中发射器可以设置例子发射的角度和频率,以及其他的东西;
博主例子
先来个静态的运行截图:
动态的运行截图:
程序结构如下:
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
id: window
visible: true
width: 800
height: 600
title: qsTr("Hello World")
Image{
id: image
source: "qrc:/img/bg.jpg"
transformOrigin: Item.Center
anchors.centerIn: parent
NumberAnimation on rotation {
from: 0
to: 360
duration: 20000
loops: Animation.Infinite
}
}
MyParticle{
id: myParticle
}
}
MyParticle.qml
import QtQuick 2.0
import QtQuick.Particles 2.0
Item {
ParticleSystem{
id: sys
}
ImageParticle{
system: sys
source: "qrc:/img/star.png"
}
Emitter{
id: startField
system: sys
emitRate: 80
lifeSpan: 2500
lifeSpanVariation: 4000
width: window.width
height: window.height
//acceleration: PointDirection { xVariation: 200; yVariation: 200; }
size: 0
endSize: 48
sizeVariation: 10
}
}
源码打包下载
https://github.com/fengfanchen/Qt/tree/master/ParticleDemoAoutQML