Class

GKState

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

Declaration

@interface GKState : NSObject

Overview

The GKState abstract class defines the features of state classes to be used with a state machine (a GKStateMachine object). You build a state machine by defining a separate GKState subclass for each state of the machine. In each state class, you use the isValidNextState: method to define which other states are valid for a machine to transition into. State classes provide a place to put state-dependent game logic, such as actions that should happen when entering or exiting a specific state, or per-frame update code that is valid only when in a specific state.

For more information about state machines, read State Machines in GameplayKit Programming Guide.

Topics

Creating a State

- init

Initializes a state object.

+ state

Creates a state object with the specified list of valid next states.

Working with State Machines

stateMachine

The state machine that owns this state object.

- isValidNextState:

Returns a Boolean value indicating whether a state machine currently in this state is allowed to transition into the specified state.

Handling State Transitions and Updates

- didEnterWithPreviousState:

Performs custom actions when a state machine transitions into this state.

- updateWithDeltaTime:

Performs custom actions when a state machine updates while in this state.

- willExitWithNextState:

Performs custom actions when a state machine transitions out of this state.

Relationships

Inherits From

See Also

State Machines

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.