Animate objects from QList ( Using QTimer )
-
Hi everyone ! I have the QList of object which i paint in paintEvent . I am using State pattern (States: Loading,Menu) . Game is singleton , current is pointer
class State *current
, and GameWidget (inherited from QWidget) I use to draw the objects.
There is paintEvent :void GameWidget::paintEvent(QPaintEvent *) { foreach(const Object& obj,Game::Instance().current->objects()) { QPainter painter(this); painter.drawPixmap(obj.point,QPixmap(obj.pixmap)); } }
This is function from Loading state :
QList <Object> Loading::objects() { QList <Object> objects; objects.append( Object(3,3,":/images/one.jpeg") ); objects.append( Object(300,300,":/images/one.jpeg") ); return objects; }
and this is Object class for creating new objects to append in QList :
class Object { public: QPoint point; QPixmap pixmap; Object(int x,int y, QString load) { point+= QPoint(x,y); pixmap.load(load); } };
Question : How animate object ( using QTimer ) ? For example I want the first object move from ( 3 , 3 ) to (100,100) for 5 seconds.
-
Hi,
You can use the Animation Framework for that. But rather than painting on a widget since you seem to be writing a game, you should take a look at the GraphicsView Framework