16. QML中的一些粒子特效_qml实现的特效-程序员宅基地

技术标签: qml  特效  粒子系统  QML基础控件  

1.说明

在使用unity开发游戏时,都会涉及到一些特效的开发。实际上在QML中也提供了一些可以做特效的控件,称之为粒子系统。本篇博客主要记录一些使用粒子做特效的方式。
特效–火焰效果:
在这里插入图片描述

2. 案例汇总

2.1 案例1

效果展示:

粒子特效1

相关代码:

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
import QtQuick.Particles 2.0

ApplicationWindow {
    
    id:root
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {
    
        id:rec
        width: 300
        height: 300
        anchors.centerIn: parent
        color: "black"
        Button {
    
            text: "start"
            y: 0
            onClicked: {
     particles.start() }
        }
        Button {
    
            text: "pause"
            y: 70
            onClicked: {
     particles.pause() }
        }
        Button {
    
            text: "resume"
            y: 140
            onClicked: {
     particles.resume() }
        }
        Button {
    
            text: "stop"
            y: 210
            onClicked: {
     particles.stop() }
        }
        ParticleSystem {
    id:particles; running: false}
        ItemParticle {
    
            system: particles
            delegate: Rectangle {
    
                id:rectdel
                width: 10
                height: 10
                radius: 10
                color: "red"
            }
        }
        Emitter {
    
            system: particles
            x:100
            width: 200
            velocity: PointDirection {
     y:300; yVariation: 100 }
        }
    }
}
2.2 案例2 – 雪花特效

效果展示:

雪花特效

相关代码:

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
import QtQuick.Particles 2.0


ApplicationWindow {
    
    id:root
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {
    
        id:rec
        width: 300
        height: 300
        anchors.centerIn: parent

        ParticleSystem {
    
            anchors.fill: parent

            ImageParticle {
    
                sprites: Sprite {
    	//此处用的是sprite图像--存储了图片每一帧的不同姿态
                    name: "snow"
                    source: "qrc:/image/imgs/snowflake.png"
                    frameCount: 51
                    frameDuration: 40
                    frameDurationVariation: 8
                }
                colorVariation: 0.8
                entryEffect: ImageParticle.scale
            }
            Emitter {
    
                emitRate: 20
                lifeSpan: 3000
                velocity: PointDirection {
    y:80; yVariation: 40;}
                acceleration: PointDirection {
    y:4}
                size: 20
                sizeVariation: 10
                width: parent.width
                height: 100
            }
        }

    }
}

2.3 案例3 – 火焰特效

效果展示:

火焰特效

相关代码:

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
import QtQuick.Particles 2.0

ApplicationWindow {
    
    id:root
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {
    
        anchors.fill: parent
        color: "#222222"
        ParticleSystem {
    
            anchors.fill: parent
            ImageParticle {
    
                groups: ["smoke"]
                color: "#11111111"
                source: "qrc:/image/imgs/butterfly.png"
            }
            ImageParticle {
    
                groups: ["flame"]
                color: "#11ff400f"
                colorVariation: 0.1
                source: "qrc:/image/imgs/butterfly.png"
            }
            Emitter {
    
                anchors.centerIn: parent
                group: "flame"
                emitRate: 120
                lifeSpan: 1200
                size: 20
                endSize: 10
                sizeVariation: 10
                acceleration: PointDirection {
     y:-40 }
                velocity: AngleDirection {
     angle: 270; magnitude: 20; angleVariation: 22; magnitudeVariation: 5 }
            }
            TrailEmitter {
    
                group: "smoke"
                follow: "flame"
                emitRatePerParticle: 1
                lifeSpan: 2400
                lifeSpanVariation: 400
                size: 16
                endSize: 8
                sizeVariation: 8
                acceleration: PointDirection {
     y:-40 }
                velocity: AngleDirection {
     angle: 270; magnitude: 40; angleVariation: 22; magnitudeVariation: 5 }
            }
        }
    }
}

2.4 案例4 – 粒子组间过渡

效果展示:

粒子组过渡

相关代码:

import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
import QtQuick.Particles 2.0


ApplicationWindow {
    
    id:root
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {
    
        anchors.fill: parent
        color: "#222222"
        ParticleSystem {
    
            anchors.fill: parent

            ParticleGroup {
    
                name: "unlit"
                duration: 1000
                to: {
    "lighting": 1, "unlit": 5}
                ImageParticle {
    
                    source: "qrc:/image/imgs/butterfly.png"
                    color: "#2060160f"
                    colorVariation: 0.1
                }
                Emitter {
    
                    height: parent.height / 2
                    emitRate: 4
                    lifeSpan: 3000
                    size: 24
                    sizeVariation: 4
                    velocity: PointDirection {
    x: 120; xVariation: 80; yVariation: 50}
                    acceleration: PointDirection {
    y: 120}
                }
            }
            ParticleGroup {
    
                name: "lighting"
                duration: 200
                to: {
    "lit": 1}
            }
            ParticleGroup {
    
                name: "lit"
                duration: 2000
                TrailEmitter {
    
                    group: "flame"
                    emitRatePerParticle: 50
                    lifeSpan: 200
                    emitWidth: 8
                    emitHeight: 8
                    size: 24
                    sizeVariation: 8
                    endSize: 4
                }
            }
            ImageParticle {
    
                groups: ["flame", "lit", "lighting"]
                source: "qrc:/image/imgs/butterfly.png"
                color: "#00ff400f"
                colorVariation: 0.1
            }
        }
    }
}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/FY_13781298928/article/details/136341781

智能推荐

html怎样让文字自动换行,CSS怎么设置文字自动换行?-程序员宅基地

文章浏览阅读3k次。CSS怎么设置文字自动换行?下面本篇文章就给大家介绍css设置文字(特别是连续的数字和英文)自动换行的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。关于换行问题,正常字符的换行是比较合理的,但连续的数字和英文字符常常将容器撑大,而不换行,就挺让人头疼了,这就需要进行强制自动换行了。示例:html代码:正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space..._css 让文字根据html源码一样换行

个人联想Thinkpad X1 carbon 笔记本遇到的问题及解决办法_thinkpad x1carbon开机黑屏-程序员宅基地

文章浏览阅读214次。新买的一台联想Thinkpad X1 carbon 12代笔记本,不知道怎么搞的,突然有一天启动后会出现一段黑屏时间,然后等一段时间才会正常,非常地烦人。打电话给联想客服只提供了附近的维修地点,但那得花时间跑去啊。今天下午自己摸索终于解决问题了。没什么好办法,我开始卸载电脑上很多的软件,一是不想用了,二是想卸载的这些软件可能就是导致这个问题出现的原因,在卸载的时候看到电脑上的相关应用,但是在点开相机应用的时候竞然发现相机不能用了。怎么这么奇怪,我想到我以前确实是设置了一下相机的权限,难道是这个问题引起的。_thinkpad x1carbon开机黑屏

Krpano:打造全景漫游体验—基础(一)-程序员宅基地

文章浏览阅读577次,点赞29次,收藏8次。由于基础知识太多,篇幅太长,本文只讲解了krpano的运作机制、tour.js的讲解以及krpano各个元素的简单介绍,下一篇文章将详细讲解krpano中的动作也就是< action >元素的使用和用法。

vue 前端表格导入与导出_vue fixdata-程序员宅基地

文章浏览阅读557次。excel导入到表格表格导入与导出,文末带Blob.js和Export2Excel.js导入按钮<input type="file" @change="import(this)" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>导入方法import(obj) { _vue fixdata

Error: protect(): protection stack overflow [防护堆叠上溢] 解决方案①_r studio中保护堆栈溢出-程序员宅基地

文章浏览阅读6.4k次。在执行R代码是遇到防护堆叠上溢的error,有效方案①1、命令行到Rgui.exe的地址(cmd)2、输入Rgui.exe --max-ppsize=5000003、在打开的R中输入options("expressions"=20000)memory.limit(size=8000000)https://www.researchgate.net/post/error_protect_protection_stack_overflow_in_R..._r studio中保护堆栈溢出

ORA-01092、ORA-00704、ORA-39700 错误的处理方法_ora-01092: oracle instance terminated. disconnecti-程序员宅基地

文章浏览阅读7.6k次。场景:通过rman做一个数据库的异机恢复,进行到最关键的一步,打开数据库的时候报了错误,详细如下SQL&gt; startup mount;Oracle 例程已经启动。Total System Global Area 6797832192 bytesFixed Size 2241264 bytesVariable Size 3523218704 bytesDatabase Buffers 3254..._ora-01092: oracle instance terminated. disconnection forced ora-00704: boots

随便推点

高通平台8953 Linux DTS(Device Tree Source)设备树详解之一(背景基础知识篇)_高通提取dtb-程序员宅基地

文章浏览阅读5.8k次,点赞3次,收藏61次。本系列导航:高通平台8953 Linux DTS(Device Tree Source)设备树详解之一(背景基础知识篇)高通平台8953 Linux DTS(Device Tree Source)设备树详解之二(DTS设备树匹配过程)高通平台8953 Linux DTS(Device Tree Source)设备树详解之三(高通MSM8953 android7.1实例分析篇)一.什么是DTS?为..._高通提取dtb

ubuntu上opencv源码编译_libjasper-dev源码-程序员宅基地

文章浏览阅读301次。安装必备包sudo apt-get install build-essential cmake libjpeg-dev libtiff5-dev libjasper-dev安装gtkfor opencv3.2 and above:sudo apt-get install libgtk-3-devfor opencv2.4.x:sudo apt-get install libgtk2.0-dev安装v4l2sudo apt-get install v4l2ucp v4l-ut._libjasper-dev源码

安卓设备连接Unity Profiler进行性能分析_unity profile 手机-程序员宅基地

文章浏览阅读4.6k次,点赞2次,收藏7次。内容会持续更新,有错误的地方欢迎指正,谢谢!方式一:手机上运行游戏,以ADB方式连UnityProfiler分析游戏性能1.安卓环境:jdk、sdk:cmd(Win+R打开界面并输入cmd) 里直接输入 java 能正常输出即可 https://www.jianshu.com/p/21babde25dd5 adb:cmd 里直接输入 adb 能正常输出即可 https://www..._unity profile 手机

海思3559AV100实现8k文件编码_rk_mpi_cal_comm_getpicbuffersize-程序员宅基地

文章浏览阅读913次,点赞13次,收藏27次。有些小改动需要在common中改,都很简单就不写了,看一下就知道,另外我这边只测试了8k的一帧编码,如需连续编码视频需要再扩展一下,我这边由于公司项目安排就没再继续做了,测试出来8k文件编码的结果如下,颜色偏差是因为我的YUV和板子支持的YUV的存储顺序不一致,这里时间关系也就不调了,也算是顺利实现了芯片的8k文件编码。第二个函数是SAMPLE_VENC_CheckSensor,应该是检查镜头的分辨率支不支持要编的尺寸,这里我们先试的4k,所以也可以不管这个。_rk_mpi_cal_comm_getpicbuffersize

Android BLE 蓝牙通信库,2024年最新应届生面试销售岗位的面试问题技巧_android蓝牙通信-程序员宅基地

文章浏览阅读919次,点赞12次,收藏10次。然后根据自定义的协议,解析对应的 BeaconItem 中的 bytes,首先创建一个 BeaconParser,传入对应的 BeaconItem,然后根据协议不断读取数据, 如果协议中某个字段占 1 个字节,则调用 readByte,若占用两个字节则调用 readShort,如果要取某个字节的某个 bit 则调用 getBit。// 获取第 1 字节的第 1bit。可以在广播中携带设备的自定义数据,用于设备识别,数据广播,事件通知等,这样手机端无需连接设备就可以获取设备推送的数据。_android蓝牙通信

推荐文章

热门文章

相关标签