【问题标题】:How to create a SKSpriteNode that is the circumference of a circle, just the outline?如何创建一个圆的圆周,只是轮廓的 SKSpriteNode?
【发布时间】:2015-02-01 04:11:10
【问题描述】:

我想创建一个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)

【问题讨论】:

  • 你应该发布你试图用来创建 UIBezierPath 的代码
  • @AbhiBeckert 代码已启动,还有错误消息。
  • 检查 skphysicsbody 类参考或让 xcode 自动完成指导你,看起来你的参数顺序错误,edgeLoopF​​romPath 应该是第一个参数 afaik

标签: ios swift sprite-kit uibezierpath skspritenode


【解决方案1】:

我觉得你在使用路径之类的东西让事情变得困难。你想要一个只有一条线的圆圈,里面没有颜色。
试试这个:

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)

【讨论】:

【解决方案2】:

这是我的解决方案:

 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,这与上面的工作代码不同。

【讨论】:

    猜你喜欢
    • 2020-01-30
    • 2014-03-08
    • 2020-05-22
    • 2019-04-19
    • 2015-04-26
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    相关资源
    最近更新 更多