跟踪Motion Cocos2d 3.0

时间:2014-05-06 03:38:09

标签: cocos2d-iphone accelerometer

如何知道手机何时向相反方向倾斜以改变精灵方向?

这是读取手机加速度计并告诉精灵移动位置和速度的代码

- (void)update:(CCTime)delta {

accelerometerData = _motionManager.accelerometerData;
CMAcceleration acceleration = accelerometerData.acceleration;

CGFloat newXPosition = MainSprite.position.x + acceleration.y * 1000 * delta;
newXPosition = clampf(newXPosition, 0, self.contentSize.width);
MainSprite.position = CGPointMake(newXPosition, MainSprite.position.y); 

}

0 个答案:

没有答案