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 ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition 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.