forked from kn0w0n3/Super_Mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstairblock.cpp
39 lines (32 loc) · 876 Bytes
/
stairblock.cpp
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
/*
* Author: equati0n
* Date: December 2016
*/
#include "stairblock.h"
#include <QPainter>
StairBlock::StairBlock( int length, QGraphicsItem *parent)
:QGraphicsItem(parent),mCurrentFrame(0), mLength(length)
{
setFlag(ItemClipsToShape);
mPixmap = QPixmap(":images/stairblock.png");
}
void StairBlock::nextFrame() {
mCurrentFrame += 48;
if (mCurrentFrame >= 768 ) {
mCurrentFrame = 0;
}
}
QRectF StairBlock::boundingRect() const {
return QRectF(0,0,48*mLength,48);
}
void StairBlock::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(widget);
Q_UNUSED(option);
for(int i = 0; i < 48*mLength; ++i) {
painter->drawPixmap(i*48,0, mPixmap, mCurrentFrame, 0,48, 48);
}
setTransformOriginPoint(boundingRect().center());
}
int StairBlock::type() const {
return Type;
}