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

问题描述 投票:2回答:2

我想创建一个如上所述的SKSpriteNode。我尝试过UIBezierPath,但XCode没有识别创建该类型对象的功能。我想我可能需要import的东西,但我不确定是什么。当我实施以下内容时, 我收到错误:Missing argument in call: center

但是,一旦我添加了适当的参数, 我收到错误:Extra argument 'edgeLoopFromPath' in call。 我的代码如下:

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)
ios swift sprite-kit uibezierpath skspritenode
2个回答
4
投票

我觉得你正在努力使用路径和所有这些。你想要一个圆圈,它只是一条内部没有颜色的线条。 试试这个:

let circle = SKShapeNode(circleOfRadius: 10)

circle.physicsBody = SKPhysicsBody(circleOfRadius: 10)

circle.fillColor = SKColor.clearColor()
circle.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
self.addChild(circle)

0
投票

这是我的解决方案:

 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”的名称与参数Apple lists on their official class reference的名称不同:在网站上,他们称之为bodyWithEdgeChainFromPath,这与上面的工作代码不同。

© www.soinside.com 2019 - 2024. All rights reserved.