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 – Animating a cube

Try modifying the code to make the cube animated. To do that, have the scene inherit QObject, add an angle property of the float type to it (remember about the Q_OBJECT macro). Then, modify one of the glRotatef() lines to use the angle value instead of a constant value. Put the following code in main(), right before calling app.exec():

QPropertyAnimation animation(&scene, "angle");animation.setStartValue(0);animation.setEndValue(359);animation.setDuration(5000);animation.setLoopCount(-1);animation.start();

Remember to put a call to window()->update() in the setter for the angle property so that the scene is redrawn.

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