Chapter    8

Colors and Collisions

By now, you’ve implemented quite a large part of the Painter game. You’ve seen how to define game object classes by using the class mechanism. By using classes, you gain more control over how game objects are structured and how to create game objects of a certain type. Each class is defined in its own Swift file. That way, when you need a cannon or a ball with the same behavior in a future game you’re working on, you can simply copy these files and create instances of these game objects in your game.

When you look more closely at the definition of a class, you can see that a class defines the internal structure of an object (which properties it consists of) as well as methods that manipulate this object in some ...

Get Swift Game Programming for Absolute Beginners 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.