May 2019
Intermediate to advanced
542 pages
13h 37m
English
Our game will have two tanks, one at the top of the screen and one at the bottom. These will be drawn on the Scene object and be animated so that the players can move them left and right. In Chapter 6, Styling Qt Applications, you learned that animation can be done using QPropertyAnimation, but only if the property being animated belongs to a descendant of QObject. QGraphicsItem is not a QObject descendant, but the QGraphicsObject object combines both to provide us with a graphics item that we can animate.
Therefore, we'll need to build our Tank class as a subclass of QGraphicsObject:
class Tank(qtw.QGraphicsObject): BOTTOM, TOP = 0, 1 TANK_BM = b'\x18\x18\xFF\xFF\xFF\xFF\xFF\x66'
This class begins by defining two constants, ...
Read now
Unlock full access