通过如何访问遥控器的运动和方向信息:
首先,需要使用NSNotificationCenter
来找到控制器。可能最好在应用启动时执行此操作。像这样的东西:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil];
然后我们可以在连接后使用以下代码将设备信息存储在属性中:
- (void)controllerDidConnect:(NSNotification *)notification {
self.myController = notification.object;
}
远程配置文件是微型游戏手柄配置文件的子类。可以通过添加值更改事件处理程序来跟踪运动和其他数据:
GCMicroGamepad *profile = self.myController.microGamepad
profile.valueChangedHandler= ^ (GCMicroGamepad *gamepad, GCControllerElement *element) {
if (self.myController.motion) {
NSLog(@"motion supported");
NSLog(@"gravity: %f %f %f", self.myController.motion.gravity.x, self.myController.motion.gravity.y, self.myController.motion.gravity.z);
NSLog(@"userAcc: %f %f %f", self.myController.motion.userAcceleration.x, self.myController.motion.userAcceleration.y, self.myController.motion.userAcceleration.z);
NSLog(@"rotationRate: %f %f %f", self.myController.motion.rotationRate.x, self.myController.motion.rotationRate.y, self.myController.motion.rotationRate.z);
NSLog(@"attitude: %f %f %f %f", self.myController.motion.attitude.x, self.myController.motion.attitude.y, self.myController.motion.attitude.z, self.myController.motion.attitude.w);
}
};