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

智能推荐

SQL优化-索引 (三)只要建立索引就能显著提高查询速度(转)-程序员宅基地

文章浏览阅读504次。2、只要建立索引就能显著提高查询速度  事实上,我们可以发现上面的例子中,第2、3条语句完全相同,且建立索引的字段也相同;不同的仅是前者在fariqi字段上建立的是非聚合索引,后者在此字段上建立的是聚合索引,但查询速度却有着天壤之别。所以,并非是在任何字段上简单地建立索引就能提高查询速度。  从建表的语句中,我们可以看到这个有着1000万数据的表中fariqi字段有5003个不同记录。在此..._索引对查询效率非常有用,在建表时就应该建好且建完整

前端项目开发流程_前端开发流程sop-程序员宅基地

文章浏览阅读3.2w次,点赞20次,收藏180次。当前分为以下四个阶段第一阶段库/框架选型(暂定react)第二阶段简单构建优化 NPM管理包node+webpack打包第三阶段JS、CSS模块化开发第四阶段组件化开发 开发过程当中注意:前端安全XSS CSRF攻击等 后期文章中将讲述如何_前端开发流程sop

个人云电脑-推荐方案 - Parsec / Fastlink_parsec 局域网-程序员宅基地

文章浏览阅读1w次。个人云电脑-推荐方案 - Parsec / FastlinkParsec安利原文局域网游戏串流:让我们都做一回「云」玩家Parsec 是游戏串流工具中的新秀。与其他不同的是,Parsec 推荐 PC-PC 间云游戏,不论是局域网还是公网通吃,这就是 Parsec 比较厉害的地方。两台设备之间的流量不通过 Parsec 云服务器,而是 Peer to Peer,Parsec 自己宣称自己使用了很多技术来保证玩家的联机体验。但国内的家庭宽带一般都是 NAT 环境(部分运营商可以._parsec 局域网

linux之find命令,Linux基础知识之find命令详解-程序员宅基地

文章浏览阅读148次。在运维人员操作系统时,要接触大量的文件,为了避免忘记文件存放位置的尴尬,就需要我们有一种文件查找工具的帮忙,下面是两个文件查找工具的详解,locate以及find,分别分享给大家。第一款工具: Locatelocate - find files by namelocate的工作依赖于事先构建好的索引库;查找文件时,直接搜索索引库里记载的文件的位置;索引库的构建:系统自动实现(周期性任务);手动更新..._find -name -r

登录模块 用户认证 SpringSecurity +Oauth2+Jwt_spring security 6+oauth2 +jwt+密码认证-程序员宅基地

文章浏览阅读6.7k次,点赞7次,收藏87次。SpringSecurity Oauth2 jwtSpringSecurity Oauth2 jwt1 用户认证分析1.1 单点登录1.2 第三方账号登录2 认证解决方案2.1 单点登录技术方案2.2 第三方登录技术方案2.2.1 Oauth2认证流程2.2.2 Oauth2在项目的应用2.3 Spring security Oauth2认证解决方案3 Jwt令牌回顾3.1 令牌结构3.2 生成私钥公钥3.3 基于私钥生成jwt令牌3.3.1导入认证服务3.3.2 认证服务中创建测试类3.4 基于公_spring security 6+oauth2 +jwt+密码认证

【转】CentOS上安装 jdk:rpm安装和源码安装-程序员宅基地

文章浏览阅读47次。1.安装jdk-8u5-linux-x64.rpm原文链接:http://www.cnblogs.com/xsi640/p/3756995.html先下载最新的jdk版本文件名:jdk-8u5-linux-x64.rpm将文件通过winscp上传到/usr/local目录中rpm -ivh jdk-8u5-linux-x64.rpm系统会自动安装。安装完成后,..._java 下载 rpm package还是gz

随便推点

Java基础---数据类型、类型转换、字符串 基础-程序员宅基地

文章浏览阅读368次,点赞7次,收藏8次。记住常用的基本数据类型int,double熟悉位数: byte8位,int 32位等等记住特性: long需要加L,flaot需要加F,char必须是单引号且只有一个2.1类型转换数据类型转换, 即 它们之间可以变换.2.1.1默认转换按照数据的表示范围, 小范围向大范围转换,可以默认进行// 类型转换默认进行(小转大)long b = a;2.1.2强制转换通过强制转换,可以将数据转换过去,但是有可能丢失精度口诀: 小转大默认进行,大转小强制进行3.1字符串。

uniapp h5后台地址配置_uniapp配置后台ip-程序员宅基地

文章浏览阅读2.5k次。"h5" : { "sdkConfigs" : { "maps" : {} }, "router" : { "base" : "./" }, "devServer" : { "port" : 8080, "disableHostCheck" : true, "proxy" : { ..._uniapp配置后台ip

centos7日志文件_CentOS7的journalctl日志查看方法-程序员宅基地

文章浏览阅读1k次。1、概述日志管理工具journalctl是centos7上专有的日志管理工具,该工具是从message这个文件里读取信息。Systemd统一管理所有Unit的启动日志。带来的好处就是,可以只用journalctl一个命令,查看所有日志(内核日志和应用日志)。日志的配置文件是/etc/systemd/journald.conf。2、查看所有日志(默认情况下 ,只保存本次启动的日志)[root@CEN..._journalctl -b 0

Spring Boot 注入静态成员变量_静态成员变量怎么注入-程序员宅基地

文章浏览阅读535次。前言: 在属性被 static 修饰后,Spring 便不能直接对变量进行直接注入,这是因为被 static 修饰后,会被放到常量池中,而Spring 需要使用set方法进行注入,这是就需要我们手动进行配置注入成员变量第一步:在类上添加@Component注解,让Spring扫描到这个类第二步:为成员变量添加set方法,注意去掉static关键字,否则会导致注入失败第三步:在set方法上添加@Resource注解,告诉Spring自动注入这个方法/** * @author: mi_静态成员变量怎么注入

uboot移植裁剪原理和流程_uboot裁剪-程序员宅基地

文章浏览阅读657次,点赞2次,收藏8次。Uboot的剪裁移植的原理和流程_uboot裁剪

xpath爬取小猪短租信息_小猪短租爬虫xpath-程序员宅基地

文章浏览阅读1.3k次。import requestsfrom lxml import etreeimport timeheaders={ 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'_小猪短租爬虫xpath

推荐文章

热门文章

相关标签