Framework

GameplayKit

Architect and organize your game logic. Incorporate common gameplay behaviors such as random number generation, artificial intelligence, pathfinding, and agent behavior.

Overview

GameplayKit is an object-oriented framework that provides foundational tools and technologies for building games. GameplayKit includes tools for designing games with functional, reusable architecture, as well as technologies for building and enhancing gameplay features such as character movement and opponent behavior.

Getting Started with GameplayKit

GameplayKit covers many aspects of game design and development. For deeper discussions of the game design patterns you can leverage with GameplayKit, along with tutorials that illustrate building games with GameplayKit features, see GameplayKit Programming Guide.

Related Sample Code

Topics

Entities and Components

A general architecture for designing composable, reusable gameplay logic.

class GKEntity

An object relevant to gameplay, with functionality entirely provided by a collection of component objects.

class GKComponent

The abstract superclass for creating objects that add specific gameplay functionality to an entity.

class GKComponentSystem

Manages periodic update messages for all component objects of a specified class.

State Machines

A modular system for defining state-dependent gameplay logic.

class GKState

The abstract superclass for defining state-specific logic as part of a state machine.

class GKStateMachine

A finite-state machine—a collection of state objects that each define logic for a particular state of gameplay and rules for transitioning between states.

Spatial Partitioning

Data structures that organize the objects in a game world for quick searching by position or proximity.

class GKQuadtree

A data structure for organizing objects based on their locations in a two-dimensional space.

class GKQuadtreeNode

A helper class for managing the objects you organize in a quadtree.

class GKOctree

A data structure for organizing objects based on their locations in a three-dimensional space.

class GKOctreeNode

A helper class for managing the objects you organize in an octree.

class GKRTree

A data structure that adaptively organizes objects based on their locations in a two-dimensional space.

Strategists

A form of AI for planning moves in turn-based games. Describe your gameplay by creating classes that adopt the game model protocols, then use those classes with a strategist object to create AI players or suggest moves.

protocol GKStrategist

A general interface for objects that provide artificial intelligence for use in turn-based (and similar) games.

class GKMinmaxStrategist

An AI that chooses moves in turn-based games using a deterministic strategy.

class GKMonteCarloStrategist

An AI that chooses moves in turn-based games using a probabilistic strategy.

protocol GKGameModel

Implement this protocol to describe your gameplay model so that a strategist object can plan game moves.

protocol GKGameModelPlayer

Implement this protocol to describe a player in your turn-based game so that a strategist object can plan game moves.

protocol GKGameModelUpdate

Implement this protocol to describe a move in your turn-based game so that a strategist object can plan game moves.

Decision Trees

Define a series of questions and possible answers leading to a final action, or automatically build a predictive model based on data your provide.

class GKDecisionTree

A data structure that models a set of specific questions, their possible answers, and the actions that follow from a series of answers.

class GKDecisionNode

A node for use in manually creating decision trees, representing a specific question and possible answers, or an action that follows from answering other questions.

Pathfinding

Create graphs that model the navigability of your game world, allowing GameplayKit to plan optimal routes for game characters to follow.

class GKGraph

A collection of nodes that describes the navigability of a game world and provides pathfinding methods to search for routes through that space.

class GKObstacleGraph

A navigation graph for 2D game worlds that creates a minimal network for precise pathfinding around obstacles.

class GKMeshGraph

A navigation graph for 2D game worlds that creates a space-filling network for smooth pathfinding around obstacles.

class GKGridGraph

A navigation graph for 2D game worlds where movement is constrained to an integer grid.

class GKGraphNode

A single node in a navigation graph for use in pathfinding.

class GKGraphNode2D

A node in a navigation graph, associated with a point in continuous 2D space.

class GKGraphNode3D

A node in a navigation graph, associated with a point in continuous 3D space.

class GKGridGraphNode

A node in a navigation graph, associated with a position on a discrete two-dimensional grid.

Agents, Goals, and Behaviors

Add autonomous movement to characters and other game objects by combining high-level goals such as moving to a target, following a path, or avoiding obstacles.

class GKAgent

A component that moves a game entity according to a set of goals and realistic constraints.

class GKAgent2D

An agent that operates in a two-dimensional space.

class GKAgent3D

An agent that operates in a three-dimensional space.

class GKGoal

An influence that motivates the movement of one or more agents.

class GKBehavior

A set of goals that together influence the movement of an agent.

class GKCompositeBehavior

A set of behaviors, each of which is a set of goals, that together influence the movement of an agent.

class GKPath

A polygonal path that can be followed by an agent.

protocol GKAgentDelegate

Implement this protocol to synchronize the state of an agent with its visual representation in your game.

Obstacles

Classes that model impassable areas in a game world, for use with Pathfinding and Agents.

class GKObstacle

The abstract base class for objects representing impassable areas in a game world.

class GKCircleObstacle

A circular impassable area to be avoided by agents.

class GKSphereObstacle

A spherical impassable volume to be avoided by agents.

class GKPolygonObstacle

A polygon-shaped impassable area in a 2D game world.

Procedural Noise

Generate fields of coherent random noise, then use them to create texture images resembling natural phenomena such as clouds or wood grain, build procedural game worlds of unlimited size, and more.

class GKNoiseSource

The abstract superclass for procedural noise generators.

class GKNoise

A representation of procedural noise, generated by a noise source, that you can use to process, transform, or combine noise.

class GKNoiseMap

A sample of procedural noise data from which you can read noise values directly or create noise textures.

class GKCoherentNoiseSource

The abstract superclass for procedural noise generators that create coherent noise.

class GKBillowNoiseSource

A procedural noise generator whose output is a type of fractal coherent noise with smooth features.

class GKPerlinNoiseSource

A procedural noise generator whose output is a type of fractal coherent noise resembling natural phenomena such as clouds and terrain.

class GKRidgedNoiseSource

A procedural noise generator whose output is a type of multifractal coherent noise with sharply defined features.

class GKVoronoiNoiseSource

A procedural noise generator whose output (also called Worley noise or cellular noise) divides space into discrete cells surrounding random seed points.

class GKCylindersNoiseSource

A procedural noise generator whose output is a 3D field of concentric cylindrical shells.

class GKSpheresNoiseSource

A procedural noise generator whose output is a 3D field of concentric spherical shells.

class GKCheckerboardNoiseSource

A procedural noise generator whose output is an alternating square pattern.

class GKConstantNoiseSource

A procedural noise generator that outputs a field of a single constant value.

Randomization

Robust, flexible implementations of standard algorithms that let you add unpredictability to gameplay without compromising testability.

protocol GKRandom

The common interface for all randomization classes in (or usable with) GameplayKit.

class GKRandomSource

The superclass for all basic randomization classes in GameplayKit.

class GKARC4RandomSource

A basic random number generator implementing the ARC4 algorithm, which is suitable for most gameplay mechanics.

class GKLinearCongruentialRandomSource

A basic random number generator implementing the linear congruential generator algorithm, which is faster but less random than the default random source.

class GKMersenneTwisterRandomSource

A basic random number generator implementing the Mersenne Twister algorithm, which is more random, but slower than the default random source.

class GKRandomDistribution

A generator for random numbers that fall within a specific range and that exhibit a specific distribution over multiple samplings.

class GKGaussianDistribution

A generator for random numbers that follow a Gaussian distribution (also known as a normal distribution) across multiple samplings.

class GKShuffledDistribution

A generator for random numbers that are uniformly distributed across many samplings, but where short sequences of similar values are unlikely.

Rule Systems

Separate game design from executable code to speed up your gameplay development cycle, or implement fuzzy logic reasoning to add realistic behavior to your game.

class GKRule

A rule to be used in the context of a rule system, with a predicate to be tested and an action to be executed when the test succeeds.

class GKNSPredicateRule

A rule for use in a rule system that uses a Foundation NSPredicate object to evaluate itself.

class GKRuleSystem

A list of rules, together with a context for evaluating them and interpreting results, for use in constructing data-driven logic or fuzzy logic systems.

Xcode and SpriteKit Integration

Classes and protocols to support easy creation and editing of GameplayKit features with the SpriteKit scene editor in Xcode.

class GKScene

A container for associating GameplayKit objects with a SpriteKit scene.

protocol GKSceneRootNodeType

Identifies scene classes from other frameworks that support embedded GameplayKit information.

class GKSKNodeComponent

A component that manages a SpriteKit node.