FAQ
Q) I admit that the arrays solution for the clouds was more efficient. But do we really need three separate arrays—one for active, one for speed, and one for the sprite itself?
A) If we look at the properties/variables that various objects have, for example, Sprite
objects, we will see they are numerous. Sprites have position, color, size, rotation, and more as well. But it would be just perfect if they had active
, speed
, and perhaps some more. The problem is that the coders at SFML can't possibly predict all of the ways that we will want to use their Sprite
class. Fortunately, we can make our own classes. We could make a class called Cloud
that has a Boolean for active
and int
for speed. We can even give our Cloud
class an SFML Sprite
object. We could then simplify our cloud code even further. We will look at designing our own classes in the next chapter.