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 - Adding a jump animation

Go to the myscene.h file and add a private qreal m_jumpFactor field. Next, declare a getter, a setter, and a change signal for this field:

public:    //...    qreal jumpFactor() const;    void setJumpFactor(const qreal &jumpFactor);signals:    void jumpFactorChanged(qreal);

In the header file, we declare the jumpFactor property by adding the following code just after the Q_OBJECT macro:

Q_PROPERTY(qreal jumpFactor
           READ jumpFactor
           WRITE setjumpFactor
           NOTIFY jumpFactorChanged)

Here, qreal is the type of the property, jumpFactor is the registered name, and the following three lines register the corresponding member functions of the MyScene class in the property system. We'll need this property to make Benjamin jump, ...

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