所以我使用此代码顺时针或逆时针旋转对象。
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first as UITouch!
let touchPosition = touch.locationInNode(self)
let newRotationDirection : rotationDirection = touchPosition.x < CGRectGetMidX(self.frame) ? .clockwise : .counterClockwise
if currentRotationDirection != newRotationDirection && currentRotationDirection != .none {
reverseRotation()
currentRotationDirection = newRotationDirection
}
else if (currentRotationDirection == .none) {
setupRotationWith(direction: newRotationDirection)
currentRotationDirection = newRotationDirection
}
}
func reverseRotation(){
let oldRotateAction = ship.actionForKey("rotate")
let newRotateAction = SKAction.reversedAction(oldRotateAction!)
ship.runAction(newRotateAction(), withKey: "rotate")
}
func stopRotation(){
ship.removeActionForKey("rotate")
}
func setupRotationWith(direction direction: rotationDirection){
let angle : CGFloat = (direction == .clockwise) ? CGFloat(M_PI) : -CGFloat(M_PI)
let rotate = SKAction.rotateByAngle(angle, duration: 2)
let repeatAction = SKAction.repeatActionForever(rotate)
ship.runAction(repeatAction, withKey: "rotate")
}
我的问题是,这会在SKSpriteNode的锚点周围产生顺时针或逆时针旋转。
但是我希望对象围绕SKSprite内部的另一个点旋转(类似于精灵图像底部的4/5)。我假设我不能使用通过CGPointMake定义的设定点,因为我希望精灵独立地在屏幕上移动,这不起作用?
有人建议吗?
答案 0 :(得分:1)
您是否尝试过将精灵的anchorPoint
属性设置为您希望精灵旋转的位置?
ship.anchorPoint = CGPoint(x: 0, y: 4/5)
这是你在找什么?