O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - Keeping multiple animations in sync

Now we'll start implementing the coin class. We can use a simple QGraphicsEllipseItem object, but we'll need to animate its properties, so let's create a new Coin class and derive it from QObject and QGraphicsEllipseItem. Define two properties: opacity of the qreal type and rect of the QRect type. This is done only by the following code:

class Coin : public QObject, public QGraphicsEllipseItem{    Q_OBJECT    Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)    Q_PROPERTY(QRectF rect READ rect WRITE setRect)//...};

No function or slot was added, because we simply used built-in functions of QGraphicsItem and associated them with the properties.

If you want an item that inherits from QObject ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required