Manages periodic update messages for all component objects of a specified class.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
GKComponent object manages periodic update messages for components in a game that uses Entity-Component architecture. Use a component system to perform per-frame logic for all components of a specific class without traversing your game’s object hierarchy to dispatch update messages.
GKComponent object manages components of a specific
GKComponent subclass. You create a component system with the
init initializer, specifying the component class it will work with. Then, you register the components used by the entities in your game with the
add methods. The component system will then forward any component-specific messages it receives to all registered instances of its component class.
The most important of the component-specific messages is the
update method. Call this method from your game’s update/render loop—that is, from a method such as
update: (SpriteKit) or
renderer: (SceneKit), or from a
CADisplay (iOS) or
CVDisplay (macOS) timer in a custom rendering engine. The component system then forwards to the
update method of all the
GKComponent subclass instances it manages, allowing those objects to perform per-frame update logic.