blob: 88679b3028464478cb9cc3b17ffd52e69428c23c (
plain)
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
63
64
65
66
67
68
69
70
|
#ifndef SPRITE_H
#define SPRITE_H
#include <QList>
#include <QMap>
#include <QString>
#include <QPixmap>
#include <QGraphicsPixmapItem>
#include <QElapsedTimer>
#include <QObject>
class Sprite: public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
typedef QList<QPixmap> FrameList;
explicit Sprite(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
//! Adds a frame to an animation
void addFrame(const QString &anim, QPixmap frame);
//! Adds a list of frames to an animation
void addAnimation(const QString &anim, const FrameList &frames);
//! Set current frame in the current animation
void setFrame(int frame);
//! Get current frame
int getFrame() const;
//! Change to next frame
void nextFrame();
QPixmap getFramePixmap() const;
//! Get frame count in current animation
int getFrameCount() const;
FrameList getCurrentAnimation() const;
void setAnimation(const QString &anim);
void setFrameInterval(int msecs) { m_interval = msecs; }
int frameInterval() const { return m_interval; }
virtual void advance(int phase);
signals:
//! Marks this sprite for removal
void removeMe();
protected:
//! Map of animations (i.e. running, idle, jumping, ...)
QMap<QString, FrameList> m_animations;
QString m_currentAnimation;
//! Current frame
int m_currentFrame;
//! How often frames should be changed
int m_interval;
QElapsedTimer m_timer;
};
#endif // SPRITE_H
|