add svg sprite source
[blok] / blokitem / normalblokitem.cpp
1 #include "normalblokitem.h"
2 #include <QDebug>
3
4 NormalBlokItem::NormalBlokItem(int width, int height,QObject *parent) :
5         BlokItem(width,height,parent)
6 {
7
8     mAnimationTimeLine = new QTimeLine;
9     mAnimationTimeLine->setFrameRange(0,10);
10     setBrush(QBrush(QPixmap(":sprites/normal_block.png")));
11
12     connect(mAnimationTimeLine,SIGNAL(frameChanged(int)),this,SLOT(anim(int)));
13
14 }
15
16 void NormalBlokItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
17 {
18
19
20
21     mAnimationTimeLine->start();
22
23     setBrush(Qt::white);
24     QPen pen;
25     pen.setColor(Qt::transparent);
26     setPen(pen);
27
28 }
29
30 void NormalBlokItem::anim(int frame)
31 {
32     qDebug()<<"anim";
33
34     QColor c= brush().color();
35     int alpha = c.alpha();
36
37     alpha-= 255/9;
38
39     qDebug()<<alpha;
40     if ( alpha <=0)
41     {
42         qDebug()<<"remove";
43         PhysicsScene * s = qobject_cast<PhysicsScene*>(scene());
44         s->world()->DestroyBody(body());
45         s->removeItem(this);
46         return;
47     }
48
49     c.setAlpha(alpha);
50     setBrush(QBrush(c));
51
52 }