沿其中心旋转SKShapeNode

Bij*_*raj 5 ios sprite-kit skshapenode swift

我有一个SKShapeNode(在这种情况下是矩形),我试图沿着它的中心旋转.然而,它沿着屏幕的左下角旋转.由于我无法为SKShapeNode设置锚点,如何实现我的要求(沿着中心旋转形状).这是我正在尝试的代码.

    let rectangle = SKShapeNode()
    rectangle.path = UIBezierPath(rect: CGRectMake(view.frame.width/4, view.frame.height/2, view.frame.width/2, view.frame.width/2)).CGPath
    rectangle.fillColor = UIColor.yellowColor()
    rectangle.strokeColor = UIColor.yellowColor()

    let oneRevolution = SKAction.rotateByAngle(360, duration: 100.0)
    let repeat = SKAction.repeatActionForever(oneRevolution)
    rectangle.runAction(repeat)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Kai*_*zay 5

您是否查看了SKShapeNode文档:https://developer.apple.com/library/IOs/documentation/SpriteKit/Reference/SKShapeNode_Ref/index.html

尝试使用:

shapeNodeWithPath:centered:
Run Code Online (Sandbox Code Playgroud)

选择"是"进行居中.

如果是,则转换路径,使路径边界框的中心位于节点的原点; 否则路径相对于节点的原点.