如何知道手机何时向相反方向倾斜以改变精灵方向?
这是读取手机加速度计并告诉精灵移动位置和速度的代码
- (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);
}