Fancy effects: introduce Fireworks
This commit is contained in:
committed by
Carl Schwan
parent
9d6d7789bb
commit
c2aab690b6
@@ -23,10 +23,12 @@ Item {
|
|||||||
snowTimer.start()
|
snowTimer.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
function showFireworkEffect() {
|
function showFireworksEffect() {
|
||||||
|
fireworksTimer.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Confetti
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: confettiTimer
|
id: confettiTimer
|
||||||
interval: item.effectInterval;
|
interval: item.effectInterval;
|
||||||
@@ -86,6 +88,8 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Snow
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: snowTimer
|
id: snowTimer
|
||||||
interval: item.effectInterval;
|
interval: item.effectInterval;
|
||||||
@@ -148,4 +152,134 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fireworks
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: fireworksTimer
|
||||||
|
interval: item.effectInterval;
|
||||||
|
running: false;
|
||||||
|
repeat: false;
|
||||||
|
triggeredOnStart: true;
|
||||||
|
onTriggered: {
|
||||||
|
if (item.enabled) {
|
||||||
|
fireworksInternalTimer.running = !fireworksInternalTimer.running
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: fireworksInternalTimer
|
||||||
|
interval: 300
|
||||||
|
triggeredOnStart: true
|
||||||
|
running: false
|
||||||
|
repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
customEmit(Math.random() * parent.width,
|
||||||
|
Math.random() * parent.width) // height is 0 somehow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ParticleSystem {
|
||||||
|
id: fireworksSystem
|
||||||
|
running: fireworksInternalTimer.running
|
||||||
|
onRunningChanged: {
|
||||||
|
if (running) {
|
||||||
|
opacity = 1
|
||||||
|
} else {
|
||||||
|
opacity = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Behavior on opacity {
|
||||||
|
SequentialAnimation {
|
||||||
|
NumberAnimation { duration: Kirigami.Units.longDuration }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageParticle {
|
||||||
|
id: fireworksParticleA
|
||||||
|
system: fireworksSystem
|
||||||
|
source: "qrc:///particleresources/glowdot.png"
|
||||||
|
alphaVariation: 0.1
|
||||||
|
alpha: 0.1
|
||||||
|
groups: ["a"]
|
||||||
|
opacity: fireworksSystem.opacity
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageParticle {
|
||||||
|
system: fireworksSystem
|
||||||
|
source: "qrc:///particleresources/glowdot.png"
|
||||||
|
color: "white"
|
||||||
|
alphaVariation: 0.1
|
||||||
|
alpha: 0.1
|
||||||
|
groups: ["white"]
|
||||||
|
opacity: fireworksSystem.opacity
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageParticle {
|
||||||
|
id: fireworksParticleB
|
||||||
|
system: fireworksSystem
|
||||||
|
source: "qrc:///particleresources/glowdot.png"
|
||||||
|
alphaVariation: 0.1
|
||||||
|
alpha: 0.1
|
||||||
|
groups: ["b"]
|
||||||
|
opacity: fireworksSystem.opacity
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: emitterComp
|
||||||
|
Emitter {
|
||||||
|
id: container
|
||||||
|
property int life: 2600
|
||||||
|
property real targetX: 0
|
||||||
|
property real targetY: 0
|
||||||
|
width: 1
|
||||||
|
height: 1
|
||||||
|
system: fireworksSystem
|
||||||
|
emitRate: 100
|
||||||
|
size: 16
|
||||||
|
endSize: 8
|
||||||
|
sizeVariation: 5
|
||||||
|
Timer {
|
||||||
|
interval: life
|
||||||
|
running: true
|
||||||
|
onTriggered: {
|
||||||
|
container.destroy();
|
||||||
|
var randomHue = Math.random()
|
||||||
|
fireworksParticleA.color = Qt.hsla(randomHue, 0.8, 0.5, 1)
|
||||||
|
fireworksParticleA.color = Qt.hsla(1-randomHue, 0.8, 0.5, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
velocity: AngleDirection {angleVariation:360; magnitude: 200}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function customEmit(x,y) {
|
||||||
|
var currentSize = Math.round(Math.random() * 200) + 40
|
||||||
|
var currentLifeSpan = Math.round(Math.random() * 1000) + 100
|
||||||
|
for (var i=0; i<8; i++) {
|
||||||
|
var obj = emitterComp.createObject(root);
|
||||||
|
obj.x = x
|
||||||
|
obj.y = y
|
||||||
|
obj.targetX = Math.random() * currentSize - currentSize/2 + obj.x
|
||||||
|
obj.targetY = Math.random() * currentSize - currentSize/2 + obj.y
|
||||||
|
obj.life = Math.round(Math.random() * 2400) + 200
|
||||||
|
obj.emitRate = Math.round(Math.random() * 32) + 32
|
||||||
|
obj.lifeSpan = currentLifeSpan
|
||||||
|
const group = Math.round(Math.random() * 3);
|
||||||
|
switch (group) {
|
||||||
|
case 0:
|
||||||
|
obj.group = "white";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
obj.group = "a";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
obj.group = "b";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user