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 ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.