简体   繁体   English

适用和CoreMotion

[英]Apportable & CoreMotion

I'm trying to get my game working on Android. 我正在尝试让我的游戏在Android上运行。 I've ported it with the free version of Apportable and it works quite well, but I haven't been able to implement the gyroscope feature. 我已经将其与Apportable的免费版本进行了移植,并且效果很好,但是我还无法实现陀螺仪功能。

CMMotionManager gets initialized but the motion updates never start (or at least handleDeviceMotion: never gets called). CMMotionManager被初始化,但运动更新从未开始(或至少handleDeviceMotion:从未被调用)。 The motion manager's isAccelerometerActive property is always NO, but isAccelerometerAvailable is YES. 运动管理器的isAccelerometerActive属性始终为NO,但isAccelerometerAvailable为YES。

Using [NSOperationQueue mainQueue] doesn't help either. 使用[NSOperationQueue mainQueue]也无济于事。

This is how I initialize the motion manager: 这就是我初始化运动管理器的方式:

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];
                                                    });
                                                }];

It produces the following message to logcat: 它向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

I have no idea what this means... I'm testing the app on Asus Nexus 7. 我不知道这意味着什么...我正在Asus Nexus 7上测试该应用程序。

Is there something special I need to do to use CoreMotion with Apportable? 将CoreMotion与Apportable结合使用时,我需要做些特别的事情吗?

Edit: Here's a simple test project I created to demonstrate the issue. 编辑: 这是我创建一个简单的测试项目,以演示该问题。

CoreMotion should work with apportable. CoreMotion应该与apportable一起使用。 Here is a simplified initialization and usage paradigm that I've tested on a Nexus 7 (2012). 这是我在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];

Instead of using startDeviceMotionUpdatesToQueue: withHandler: to process the motion events, try explicitly accessing the deviceMotion property in a handleDeviceMotion method which will be called by the repeating timer. 代替使用startDeviceMotionUpdatesToQueue: withHandler:处理运动事件,尝试在handleDeviceMotion方法中显式访问deviceMotion属性,该方法将由重复计时器调用。

-(void) handleDeviceMotion {
    CMDeviceMotion *motion = [self.motionManager deviceMotion];
    // use motion data accordingly
}    

And don't forget to stop updates when you're done! 而且,别忘了在完成后停止更新!

[self.motionManager stopDeviceMotionUpdates];

For this sort of device motion in particular, we had a fairly layered series of issues that I've (hopefully) resolved with the next SDK update. 特别是对于这种设备运动,我们(希望)在下一次SDK更新中解决了一系列相当分层的问题。 I've implemented yaw, pitch, and roll, and they seem to give relatively sane values. 我已经实现了偏航,俯仰和滚动,它们似乎给出了相对合理的值。 If you're still having issues, email sdk(@)apportable.com (delete the parens obviously) and mention me. 如果仍然有问题,请发送电子邮件至sdk(@)apportable.com(显然要删除家长)并提及我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM