GKComponentSystem
管理指定类的所有组件对象定期更新消息。
概括
在一个组件/实体设计方式的游戏中,GKComponentSystem对象管理周期性更新的组件,使用组件系统为特定类的所有组件执行每个帧逻辑,而不需要遍历游戏的对象层次结构来发送更新消息。
每个GKComponentSystem对象都会管理特定GKComponent的子类,可以使用initWithComponentClass: 来创建特定组件Class实例。然后注册你需要的组件通过他们的实体,可以使用addComponent: 或者addComponentWithEntity: 方法。最后GKComponentSystem就会更新你所有注册了的组件实例所发来的消息。
组件中最重要的消息就是updateWithDeltaTime: 方法,调用游戏中update/render loop相关的方法,例如Spritekit中的update:方法或SceneKit中的renderer: updateAtTime:方法,或基于CADisplayLink的timer自定义一个渲染器,GKComponentSystem会通过updateWithDeltaTime: 执行所有GKComponent子类对象中的消息,从而调用每一帧的逻辑。
Topics
创建组件系统(Creating a Component System)
- initWithComponentClass:
创建特定组件类型的组件系统。
管理组件数组(Managing a List of Components)
componentClass
所管理组件的类型。
components
组件数组。
- addComponent:
添加一个组件实例到系统中。
- addComponentWithEntity:
从一个特定实体实例中添加其组件到系统中。
- removeComponent:
从系统中删除一个特定的组件。
- removeComponentWithEntity:
从系统中删除一个实体所拥有的所有组件。
定时更新(Performing Periodic Updates)
- updateWithDeltaTime:
使系统中所有的组件进行更新。
用下标语法访问组件(Accessing Components With Subscript Syntax)
- objectAtIndexedSubscript:
通过下标返回相对应的组件实例。
实例方法(Instance Methods)
- classForGenericArgumentAtIndex:
通过下标返回指定组件的类型。
关系
继承
NSObject
默认遵守
NSFastEnumeration