QT粒子效果4
import QtQuick 2.6
import QtQuick.Particles 2.0
/*
* 作者: yubo
* 功能: 指標粒子發射器
* 描述: 支援依照形狀進行發射粒子,粒子發射方向和數量以及生命週期可控制,適用於對某個圖片進行使用
* 日期: 2018-07-12
*/
Item {
// 發射器發射寬度
property real senderWidth: 0
// 發射器發射高度
property real senderHeight: 0
// 發射器自身角度
property alias senderRotation: sender.rotation
// 發射器X座標
property real senderX: 0
// 發射器Y座標
property real senderY: 0
// 發射器原點X座標
property real senderOriginX: 0
// 發射器原點Y座標
property real senderOriginY: 0
// 發射器旋轉角度
property real senderAngle: 0
// 發起器遮罩形狀圖片資源
property string maskShapeImage: ""
// 粒子圖片資源
property string particlesImage: "qrc:/Image/Theme2/CentralPanel/potS.png"
// 發射器發射粒子X軸寬度
property real senderDirectX: 30
// 發射器發射粒子Y軸高度
property real senderDirectY: -10
// 發射器發射粒子X寬度變化
property real senderVariationX: 20
// 發射器發射粒子Y高度變化
property real senderVariationY: 10
// 粒子顏色
property string particlesColor: "#cde0ff"
// 粒子大小
property real particleSize: 5
// 粒子發射速率
property real particleEmitRate: 20
// 粒子生命週期
property real particleLifeSpan: 2000 - Car.speed / 220 * 1000
Timer {
running: true
repeat: true
interval: 1000 * 60 * 60 * 5
onTriggered: {
particles.reset();
}
}
ParticleSystem {
id: particles
}
ImageParticle {
system: particles
groups: ["A"]
source: particlesImage
color: particlesColor
colorVariation: 0
Behavior on color { ColorAnimation { duration: 1000 } }
}
ImageParticle {
groups: ["B"]
system: particles
source: "qrc:///particleresources/star.png"
color: "#cde0ff"
}
Emitter {
id: sender
x: senderX
y: senderY
width: senderWidth
height: senderHeight
group: "A"
rotation: senderRotation
transform: Rotation {
id: senderRotation
origin.x: senderOriginX
origin.y: senderOriginY
angle: senderAngle
}
system: particles
emitRate: particleEmitRate
lifeSpan: particleLifeSpan
lifeSpanVariation: 500
size: particleSize
sizeVariation: 5
endSize: 1
shape: MaskShape { source: maskShapeImage }
acceleration: PointDirection { x: senderDirectX; xVariation: senderVariationX; y: senderDirectY; yVariation: senderVariationY }
}
Emitter {
x: senderX
y: senderY
width: senderWidth
height: senderHeight
group: "B"
rotation: sender.rotation
transform: Rotation {
origin.x: senderOriginX
origin.y: senderOriginY
angle: senderAngle
}
system: particles
emitRate: particleEmitRate - 10
lifeSpan: particleLifeSpan
lifeSpanVariation: 500
size: particleSize + 30
sizeVariation: 5
endSize: 1
shape: MaskShape { source: maskShapeImage }
acceleration: PointDirection { x: senderDirectX; xVariation: senderVariationX; y: senderDirectY; yVariation: senderVariationY }
}
}