Sprite kit 用CoreMotion移动SKSpriteNode

Sprite kit 用CoreMotion移动SKSpriteNode,sprite-kit,gravity,core-motion,skspritenode,cmmotionmanager,Sprite Kit,Gravity,Core Motion,Skspritenode,Cmmotionmanager,我有一个代表用户的SKSpriteNode,我希望这个节点随着用户的移动而移动,如果用户行走,那么节点会朝着相同的方向移动 起始位置是视图的中心,我认为可以使用CMMotionManager iOS 7中的旋转率、用户加速度和重力来实现这一点,但我不知道我是否错了,或者我应该对这些值进行哪些操作 如果有人能帮助我,我很感激 谢谢。现在,我很忙 if ([self.motionManager isDeviceMotionAvailable] == YES) { [self.

我有一个代表用户的SKSpriteNode,我希望这个节点随着用户的移动而移动,如果用户行走,那么节点会朝着相同的方向移动

起始位置是视图的中心,我认为可以使用CMMotionManager iOS 7中的旋转率、用户加速度和重力来实现这一点,但我不知道我是否错了,或者我应该对这些值进行哪些操作

如果有人能帮助我,我很感激

谢谢。

现在,我很忙

if ([self.motionManager isDeviceMotionAvailable] == YES) {
            [self.motionManager startDeviceMotionUpdatesToQueue:self.queueMotion withHandler:^(CMDeviceMotion *motion, NSError *error) {
                self.xpos = motion.userAcceleration.x * motion.gravity.x * motion.rotationRate.x;
                self.ypos = motion.userAcceleration.y * motion.gravity.y * motion.rotationRate.y;

                [self performSelectorOnMainThread:@selector(updatePosition:) withObject:nil waitUntilDone:YES];
            }];
        }

然后我将这些x和y坐标添加到SKSpriteNode位置,并将SKSpriteNode移动到最终位置。我得到的是,当我行走时,SKSpriteNode不会移动,但如果我用力加速,它会移动,但只是片刻,如果我以恒定速度行走,它不会移动。

你能展示你迄今为止所做的尝试吗,这给了你什么结果?你可以在这里找到一个很好的使用SpriteKit加速度计的教程: