Game Programming using Qt 5 Beginner's Guide - Second Edition
by Pavel Strakhov, Witold Wysota, Lorenz Haas
Creating objects on request
The problem with predeclaring objects directly in a QML file is that you need to know upfront how many objects you will need. More often than not, you will want to dynamically add and remove objects to your scene, for example, in an alien invasion game, where, as the player progresses, new alien saucers will be entering the game screen and other saucers will be getting shot down and destroyed. Also, the player's ship will be "producing" new bullets streaking in front of the ship, eventually running out of fuel or otherwise disappearing from the game scene. By putting a good amount of effort into the problem, you will be able to use Repeater to obtain this effect, but there is a better tool at hand.
QML offers us ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access