Use Agents, Goals, and Behaviors
To give monsters some autonomy, you’ll use a combination of agents, goals, and behaviors. Consider the agent as the brains behind the entity, and the goals and behaviors as the driving forces behind its decision making.
You can create an agent for 2D space using the GKAgent2D class. Because this class is a subclass of the GKComponent class, you can use a component system to handle its updates. Using a component system works well when you have lots of entities or for games with complex object graphs (which you’ll add in Using the Navigation Graph Editor). In doing so, you guarantee that all of the entities using this component will get updated at the same time, so let’s get one added.
Creating a Component System ...
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.