Create Your First Component

The first component you’ll make is a health component. The health component is a way to track the number of health points an entity has remaining.

To make a component using the GameplayKit framework, you need to subclass the GKComponent superclass (which is another way of referring to the base class or parent class).

Each component represents a single “trait” or “ability” that you can add to an entity, and an entity represents one of your game objects. The nice thing about components is that you can reuse and add them to any type of entity. For example, you can create a single health component that both your player and monsters can share.

Creating the Health Component

In the Project Navigator, below the Extensions ...

Get Apple Game Frameworks and Technologies 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.