-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjumpeffect.cpp
More file actions
28 lines (22 loc) · 825 Bytes
/
Copy pathjumpeffect.cpp
File metadata and controls
28 lines (22 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "JumpEffect.h"
#include <QGraphicsScene>
JumpEffect::JumpEffect(qreal x, qreal y) {
setPixmap(QPixmap(":/img/jump.png").scaled(40, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
setPos(x, y);
setOpacity(1.0);
// Create and start a timer to update the jump effect
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &JumpEffect::updateEffect);
timer->start(16); // Update every 16ms (~60 FPS)
}
void JumpEffect::updateEffect() {
// Move the jump effect particles upward
setPos(x(), y() - 3);
// Fade out the jump effect over time
setOpacity(opacity() - 0.1);
// Remove the jump effect after it fades out
if (opacity() <= 0) {
scene()->removeItem(this);
delete this; // Delete the jump effect object to free memory
}
}