沿其中心旋转SKShapeNode [英] Rotating an SKShapeNode along its center

查看:169
本文介绍了沿其中心旋转SKShapeNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an SKShapeNode (rectangle in this case) which I am trying to rotate along its center. However it is rotating along the screen's bottom left point. Since I cannot set an anchor point for SKShapeNode, how can I achieve my requirement (to rotate the shape along its centre). This is the code I'm trying.

    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)

推荐答案

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

Did you look at the SKShapeNode documentation : https://developer.apple.com/library/IOs/documentation/SpriteKit/Reference/SKShapeNode_Ref/index.html

尝试使用:

shapeNodeWithPath:centered:

为居中选择YES。


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

If YES, the path is translated so that the center of the path’s bounding box is at the node’s origin; otherwise the path is relative to the node’s origin.

这篇关于沿其中心旋转SKShapeNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆