Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何创建一个圆的圆周,只是轮廓?_Ios_Swift_Sprite Kit_Uibezierpath_Skspritenode - Fatal编程技术网

Ios 如何创建一个圆的圆周,只是轮廓?

Ios 如何创建一个圆的圆周,只是轮廓?,ios,swift,sprite-kit,uibezierpath,skspritenode,Ios,Swift,Sprite Kit,Uibezierpath,Skspritenode,我想如上所述创建一个SKSpriteNode。我尝试过UIBezierPath,但XCode没有识别用于创建该类型对象的函数。我想我可能需要进口一些东西,但我不确定是什么。 当我实现以下内容时,我得到一个错误:call:center中缺少参数 然而,一旦我添加了适当的参数,我就会得到错误:调用中的额外参数'edgeLoopFromPath'。 我的代码如下: let circlePath: UIBezierPath = UIBezierPath(arcCenter: CGPointMake(se

我想如上所述创建一个SKSpriteNode。我尝试过UIBezierPath,但XCode没有识别用于创建该类型对象的函数。我想我可能需要进口一些东西,但我不确定是什么。 当我实现以下内容时,我得到一个错误:call:center中缺少参数

然而,一旦我添加了适当的参数,我就会得到错误:调用中的额外参数'edgeLoopFromPath'。 我的代码如下:

let circlePath: UIBezierPath = UIBezierPath(arcCenter: CGPointMake(self.frame.midX, self.frame.midY), radius: self.frame.height / 2, startAngle: 0, endAngle: 360, clockwise: true)
let confinCircle: SKPhysicsBody = SKPhysicsBody(center: CGPointMake(self.frame.midX, self.frame.midY), edgeLoopFromPath: circlePath)

我觉得你在用路径之类的东西让事情变得艰难。您想要一个圆圈,它只是一条内部没有颜色的线。请尝试以下操作:

以下是我的解决方案:

 let circlePath: UIBezierPath = UIBezierPath(arcCenter: CGPointMake(self.frame.midX, self.frame.midY), radius: self.frame.height / 2, startAngle: 0, endAngle: 360, clockwise: true)
 confiningCircle.physicsBody = SKPhysicsBody(edgeChainFromPath: circlePath.CGPath)
 self.addChild(confiningCircle)
有趣的是,参数edgeChainFromPath的名称与参数的名称不同:
在网站上,他们称之为bodyWithEdgeChainFromPath,这与上面的工作代码不同。

您应该发布您试图用于创建UIBezierPath@AbhiBeckert代码已启动,并显示错误消息。请检查skphysicsbody类引用或让xcode自动完成指导您,看起来你的参数顺序不对,edgeLoopFromPath应该是第一个参数,但是形状节点很慢。我需要一个物理体。我解决了我的问题,稍后我会发布答案,但我需要物理体也是空心的。我在这里找到了接近解决方案的东西::
 let circlePath: UIBezierPath = UIBezierPath(arcCenter: CGPointMake(self.frame.midX, self.frame.midY), radius: self.frame.height / 2, startAngle: 0, endAngle: 360, clockwise: true)
 confiningCircle.physicsBody = SKPhysicsBody(edgeChainFromPath: circlePath.CGPath)
 self.addChild(confiningCircle)