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

Have a go hero - Letting the item handle Benjamin's jump

Since the scene is already a QObject, adding a property to it was easy. However, imagine that you want to create a game for two players, each controlling a separate Player item. In this case, the jump factors of two elephants need to be animated independently, so you want to make an animated property in the Player class, instead of putting it to the scene.

The QGraphicsItem item and all standard items introduced so far don't inherit  QObject and thus can't have slots or emit signals; they don't benefit from the QObject property system either. However, we can make them use QObjectAll you have to do is add QObject as a base class and add the Q_OBJECT macro:

class Player : public 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