Creating a transform component

With the ability to attach and return components, let's get our first component built and added. We'll start with a simple one first. Currently, all objects have a position by default that's provided by the Object base class. Let's break this behavior into its own component.

Encapsulating transform behavior

Since we're converting an inheritance-based approach to a component-based one, the first task is to take the transform behavior out of the Object class. Currently, that consists of a single position variable and a function to both get and set that value.

Let's create a new class named TransformComponent and move this behavior into it, as follows:

#ifndef TRANSFORMCOMPONENT_H #define TRANSFORMCOMPONENT_H #include "Component.h" ...

Get Procedural Content Generation for C++ Game Development 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.