简体   繁体   English

围绕中心旋转节点

[英]rotate node around center

I currently have a node that I want to rotate by 90 degrees around its centre for every touch. 我目前有一个节点,希望每次触摸都围绕其中心旋转90度。 I've managed to rotate it using the code below, but not around its centre. 我设法使用下面的代码旋转了它,但是没有绕它的中心旋转。 If anyone has a way to fix this I'd really appreciate it. 如果有人能解决此问题,我将非常感激。

  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)

    }
    }

我怀疑您需要为您的精灵设置正确的anchorPoint:

sprite.anchorPoint = CGPoint(0.5, 0.5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM