QML 粒子和发射器例子

本文详细介绍了一个使用Qt Quick粒子系统的示例程序,展示了如何创建粒子系统,设置粒子的发射器、大小、速度及方向,以及如何使用ImageParticle显示自定义粒子图片。

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



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;

 
    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: 190;
        sizeVariation: 10;  //  粒子大小变化
        emitRate: 20; //	每秒发射的粒子数 默认是 10
        lifeSpan: 4000; //  以毫秒为单位的粒子生存周期
        lifeSpanVariation: 200;// 发射器生存器内发射的最大粒子数
        velocity: TargetDirection {  //  粒子的方向
            targetItem: target;
            targetX: target.width;
            targetY: 0;
            targetVariation: target.width/8; // 发散度
            magnitude: root.height/3; // 速度
        }
    }

 
    ImageParticle {
        system: particleSystem;
        source: "qrc:///bubble_1.png";
    }
}
程序运行效果如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值