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

The playing field

Since we will have to do some work on the scene, we subclass QGraphicsScene and name the new class MyScene. There, we implement one part of the game logic. This is convenient since QGraphicsScene inherits QObject and thus we can use Qt's signal and slot mechanism.

The scene creates the  environment in which our elephant will be walking and jumping. Overall, we have a view fixed in size holding a scene, which is exactly as big as the view. We do not take size changes of the view into account, since they will complicate the example too much.

All animations inside the playing field are done by moving the items, not the scene. So we have to distinguish between the view's, or rather the scene's, width and the width of the elephant's ...

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