ios - 绕中心旋转节点

标签 ios swift sprite-kit

我目前有一个节点,每次触摸时我都希望它绕其中心旋转 90 度。我已经设法使用下面的代码旋转它,但不是围绕它的中心。如果有人有办法解决这个问题,我将非常感激。

  override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

    let touch = touches.first as! UITouch
    let touchLocation = touch.locationInNode(self)

    if sprite.frame.contains(touchLocation) {

    let rotate = SKAction.rotateByAngle(1.57, duration: 0.1)
    sprite.runAction(rotate)

    }
    }

最佳答案

我怀疑你需要为你的 Sprite 设置正确的 anchor :

sprite.anchorPoint = CGPoint(0.5, 0.5)

关于ios - 绕中心旋转节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31691490/

相关文章:

swift - 缩放SKSpriteNode

ios - 旧金山字体 + SpriteKit

ios - 无法滚动到 UIScrollView 中嵌入的 UITableView 的顶部

ios - 如何从触摸点呈现 ViewController?

ios - 如何在 ios 的 Swift 语言中正确安排动画顺序?

ios - 从麦克风录音和处理(PCM?)文件的示例

ios - 引入障碍物时 GKObstacleGraph 找不到路径

ios - 使用“performSelector”返回非id结果

ios - UITableView 中的 MFMessageComposeViewController (Swift)

ios - 出现键盘时缩小 UIWebView