Qt基于Qml材质系统ParticleSystem使用示例

本文介绍如何使用Qt Quick Particles模块创建粒子效果。通过定义图片材质、粒子系统及发射器,实现了从底部向目标区域发射粒子的效果,并详细展示了完整的QML代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 演示效果

 1.定义图片材质

//图片材质
    ImageParticle {
        system: particleSystem;
        source: "qrc:/bubble_1.png";
    }

2.定义材质系统

 ParticleSystem {id: particleSystem}

3.使用Emitter发射器动态渲染材质

//发射器
Emitter {
        id: emitter;
        system: particleSystem;//指定材质系统
        anchors.left: parent.left;
        anchors.bottom: parent.bottom;
        width: 80;
        height: 80;
        size: 20;
        endSize: 80;
        sizeVariation: 10;
        emitRate: 20;//发射率
        lifeSpan: 4000;
        lifeSpanVariation: 200;
        velocity: TargetDirection {
            targetItem: target;
            targetX: target.width/2;
            targetY: 0;
            targetVariation: target.width/2;
            magnitude: root.height/3;
        }
    }

完整Qml源码

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Particles 2.0

Window {
    visible: true;
    width: 600;
    height: 400;
    color: "lightblue";
    id: root;
    title:"Qt基于Qml材质系统ParticleSystem使用示例"
    Rectangle {
        id: target;
        color: "transparent";//透明色
        width: parent.width/2;
        height: 100;
        anchors.top: parent.top;
        anchors.right: parent.right;
        anchors.margins: 4;
    }
    //材质系统
    ParticleSystem {id: particleSystem}
    //发射器
    Emitter {
        id: emitter;
        system: particleSystem;//指定材质系统
        anchors.left: parent.left;
        anchors.bottom: parent.bottom;
        width: 80;
        height: 80;
        size: 20;
        endSize: 80;
        sizeVariation: 10;
        emitRate: 20;//发射率
        lifeSpan: 4000;
        lifeSpanVariation: 200;
        velocity: TargetDirection {
            targetItem: target;
            targetX: target.width/2;
            targetY: 0;
            targetVariation: target.width/2;
            magnitude: root.height/3;
        }
    }
    //图片材质
    ImageParticle {
        system: particleSystem;
        source: "qrc:/bubble_1.png";
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

自由软件开发者

有你的鼓励,我会更加努力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值