0
我只是想從我的iPhone 4的Core Motion獲取一些陀螺儀數據,但總是得到roll = 0,pitch = 0和yaw = 0。 經過密集的搜索我認識到,iPhone 4沒有陀螺儀?
if (motionManager.isDeviceMotionAvailable)
{
[motionManager startDeviceMotionUpdates];
}
返回false,雖然我在iPhone 4 我必須能夠在設置陀螺儀運行呢?或者我可以做錯什麼...?
那我減少接口:
@interface GameLayer : CCLayer {
CMMotionManager *motionManager;
}
@property (nonatomic, retain) CMMotionManager *motionManager;
@end
而這正是我實現在MotionManager:
- (id) init
{
self=[super init];
if(self)
{
self.motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
if (motionManager.isDeviceMotionAvailable)
{
[motionManager startDeviceMotionUpdates];
}
else
{
NSLog(@"No motion captured");
}
[self scheduleUpdate];
}
return self;
}
,並在那裏它被稱爲循環:
- (void) update:(ccTime)delta
{
CMDeviceMotion *currentDeviceMotion = motionManager.deviceMotion;
motionManager.showsDeviceMovementDisplay = YES;
CMAttitude *currentDeviceAttitude = currentDeviceMotion.attitude;
float roll = currentDeviceAttitude.roll;
float pitch = currentDeviceAttitude.pitch;
float yaw = currentDeviceAttitude.yaw;
}
IT對我有用。檢查'motionManager'不是'nil',你確實在設備上運行,而不是在模擬器上運行。 – sch 2012-03-08 20:45:18
你如何創建你的'motionManager'?你能發佈代碼嗎? – Saphrosit 2012-03-08 20:45:55
我添加了一些代碼,我初始化了運動管理器...也許這有助於幫助我:) – clash 2012-03-08 22:45:32