0
votes

I currently have a node that I want to rotate by 90 degrees around its centre for every touch. 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)

    }
    }
1

1 Answers

0
votes

I suspect you need to set correct anchorPoint for your sprite:

sprite.anchorPoint = CGPoint(0.5, 0.5)