QML笔记-Particle的基本使用(粒子系统的基本使用)
发布日期:2021-06-30 11:01:28 浏览次数:2 分类:技术文章

本文共 1580 字,大约阅读时间需要 5 分钟。

目录

 

 


 

基本概念

粒子系统(ParticleSystem)- 管理发射器之间的共享时间线。

发射器(Emitter)- 向系统中发射逻辑粒子。
粒子画笔(ParticlePainter)- 实现粒子可视化。
其中下面的ParticlePainter是ImageParticle,他是ParticlePainter的子类

 

每一个例子系统都有自己独立的线程。

其中发射器可以设置例子发射的角度和频率,以及其他的东西;

 

博主例子

先来个静态的运行截图:

动态的运行截图:

程序结构如下:

main.cpp

#include 
#include
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.9import QtQuick.Window 2.2Window {    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.0import QtQuick.Particles 2.0Item {    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://it1995.blog.csdn.net/article/details/90368589 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:MySQL笔记-左连接的使用(left join有关联的多表查询)
下一篇:QML笔记-在背景图中添加NumberAnimation使得界面效果更佳(小技巧)

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年05月03日 05时29分12秒