[英]Apportable & CoreMotion
我正在尝试让我的游戏在Android上运行。 我已经将其与Apportable的免费版本进行了移植,并且效果很好,但是我还无法实现陀螺仪功能。
CMMotionManager
被初始化,但运动更新从未开始(或至少handleDeviceMotion:
从未被调用)。 运动管理器的isAccelerometerActive
属性始终为NO,但isAccelerometerAvailable
为YES。
使用[NSOperationQueue mainQueue]
也无济于事。
这就是我初始化运动管理器的方式:
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.gyroUpdateInterval = .2;
[self.motionManager startDeviceMotionUpdatesToQueue:[[NSOperationQueue alloc] init]
withHandler:^(CMDeviceMotion *motion, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self handleDeviceMotion:motion];
});
}];
它向logcat产生以下消息:
E/Sensors ( 507): HAL:ERR open file /sys/bus/iio/devices/iio:device0/dmp_event_int_on to write with error 2
E/Sensors ( 507): HAL:ERR can't disable DMP event interrupt
我不知道这意味着什么...我正在Asus Nexus 7上测试该应用程序。
将CoreMotion与Apportable结合使用时,我需要做些特别的事情吗?
CoreMotion应该与apportable一起使用。 这是我在Nexus 7(2012)上测试过的简化的初始化和使用范例。
self.motionManager = [[CMMotionManager alloc] init];
[self.motionManager startDeviceMotionUpdates];
self.motionTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:@selector(handleDeviceMotion)
userInfo:nil
repeats:YES];
代替使用startDeviceMotionUpdatesToQueue: withHandler:
处理运动事件,尝试在handleDeviceMotion
方法中显式访问deviceMotion
属性,该方法将由重复计时器调用。
-(void) handleDeviceMotion {
CMDeviceMotion *motion = [self.motionManager deviceMotion];
// use motion data accordingly
}
而且,别忘了在完成后停止更新!
[self.motionManager stopDeviceMotionUpdates];
特别是对于这种设备运动,我们(希望)在下一次SDK更新中解决了一系列相当分层的问题。 我已经实现了偏航,俯仰和滚动,它们似乎给出了相对合理的值。 如果仍然有问题,请发送电子邮件至sdk(@)apportable.com(显然要删除家长)并提及我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.