-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQGraphicsAnimatedSprite.h
More file actions
62 lines (45 loc) · 1.63 KB
/
QGraphicsAnimatedSprite.h
File metadata and controls
62 lines (45 loc) · 1.63 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef QGRAPHICSANIMATEDSPRITE_H
#define QGRAPHICSANIMATEDSPRITE_H
#include <QGraphicsObject>
#include <QTime>
class QGraphicsAnimatedSprite : public QGraphicsObject
{
public:
// ctor
QGraphicsAnimatedSprite(QImage& spritesheet);
// dtor
~QGraphicsAnimatedSprite();
// Override paint event from QGraphicsObject
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
// Override boundingRect calculation from QGraphicsObject
// @note: Miscalculating boundingRect results in rendering glitches
QRectF boundingRect() const;
// Timer event for animation
void timerEvent(QTimerEvent *evt);
// Set whether or not to enable frame reverse (animation goes 1==>10 10==>1 1==>10.. instead of 1==>10 1==>10 1==>10)
void setFrameReversion(bool reverse);
// Set the number of lines and columns of the sheet
void setSheetSize(int lines, int columns);
// Set the size of one element of the sheet
void setElementSize(int width, int height);
// Set the animation frames to loop
void setAnimationFrames(int start_col, int start_line, int end_col, int end_line);
// Set time between each frame (100 = 100ms between each frame)
void setSpeed(int timeMs);
protected:
QImage mSpriteSheet;
int mTimerId;
int mCurrentColumn;
int mCurrentLine;
bool mReverseFrame;
bool mReverseFrameEnabled;
int mAnimationStartCol;
int mAnimationStartLine;
int mAnimationEndCol;
int mAnimationEndLine;
int mSheetLines;
int mSheetColumns;
int mElementWidth;
int mElementHeight;
};
#endif // QGRAPHICSANIMATEDSPRITE_H