Optimization

Let us now take a look at some of the optimizations we can perform to speed up the scene.

A binary space partition tree

The scene constantly keeps record of the position of the item in its internal binary space partition tree. Thus, on every move of an item, the scene has to update the tree, an operation that can become quite time-and memory-consuming. This is especially true of scenes with a large number of animated items. On the other hand, the tree enables you to find an item (for example, with items() or itemAt()) incredibly fast even if you have thousands of items.

So when you do not need any positional information about the items—this also includes collision detection—you can disable the index function by calling setItemIndexMethod(QGraphicsScene::NoIndex) ...

Get Game Programming Using Qt now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.