我试图让我的精灵沿着X轴左右移动,同时旋转就好像滚动一样。这是我以前尝试过的;
var motionManager = CMMotionManager()
override func didMoveToView(view: SKView) {
let rotate = SKAction.rotateByAngle(0.05, duration: 1)
let rerotate = SKAction.reversedAction(rotate)
if motionManager.accelerometerAvailable {
motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler:{
data, error in
let currentX = self.steve.position.x
if data!.acceleration.x < 0 {
self.destX = currentX + CGFloat(data!.acceleration.x * 500)
//self.rolling = true
//self.steve.removeAllActions()
self.steve.runAction(rotate)
}
else if data!.acceleration.x > 0 {
self.destX = currentX + CGFloat(data!.acceleration.x * 500)
//self.rolling = true
// self.steve.removeAllActions()
self.steve.runAction(rerotate())
}
})
}
}
然而,经过几次,这种方法变得没有反应,我的精灵向左移动,并且在设备旋转时不会移动。我非常感谢我尝试完成的另一种方法。谢谢