ios – 沿着中心旋转SKShapeNode

ios – 沿着中心旋转SKShapeNode,第1张

概述我有一个SKShapeNode(在这种情况下是矩形),我试图沿着它的中心旋转.然而,它沿着屏幕的左下角旋转.由于我无法为SKShapeNode设置锚点,如何实现我的要求(沿着中心旋转形状).这是我正在尝试的代码. let rectangle = SKShapeNode() rectangle.path = UIBezierPath(rect: CGRectMake(view.frame.w 我有一个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)
解决方法 您是否看过SKShapeNode文档: https://developer.apple.com/library/IOs/documentation/SpriteKit/Reference/SKShapeNode_Ref/index.html

尝试使用:

shapeNodeWithPath:centered:

选择“是”进行居中.

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.

总结

以上是内存溢出为你收集整理的ios – 沿着中心旋转SKShapeNode全部内容,希望文章能够帮你解决ios – 沿着中心旋转SKShapeNode所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1072424.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存