【问题标题】:No collision-detection by using SKShapeNode with UIBezierpath使用带有 UIBezierpath 的 SKShapeNode 没有碰撞检测
【发布时间】:2014-11-24 22:12:19
【问题描述】:

我有以下 UIBezierPath,它就像一个圆圈,但中间有一个间隙:

var centerPosition = CGPointMake(self.frame.width/2, self.frame.height/2)
var aPath:UIBezierPath = UIBezierPath(arcCenter: centerPosition, radius: 75, startAngle: 0, endAngle: degreesToRadians(size), clockwise: true)
gapeCircle = SKShapeNode(path: myPath, centered: true)

现在我想使用 SKPhysicsBody 以便当一个对象与该对象的轮廓发生碰撞时,会有一个通知。但仅限于那种情况。如果对象在间隙位置“碰撞”,则不应有通知。

但我不知道如何解决这个问题。我已经尝试了多种不同的 SKPhysicsBody-initializers。唯一有效的是circleOfRadius,但它不像我希望的那样有效,因为只有当一个物体与我圈子的“非间隙”部分发生碰撞时,我才需要检查碰撞。

【问题讨论】:

    标签: swift sprite-kit collision-detection uibezierpath skphysicsbody


    【解决方案1】:

    我怀疑这是因为您没有使用封闭的 UIBezierPath。下面的代码将创建一个循环返回自身的曲线,使“C”的宽度仅为 1 pt

    var centerPosition = CGPointMake(self.frame.width/2, self.frame.height/2)
    var aPath:UIBezierPath = UIBezierPath(arcCenter: centerPosition, radius: 75, startAngle: 0, endAngle: degreesToRadians(size), clockwise: true)
    var aPath:UIBezierPath = UIBezierPath(arcCenter: centerPosition, radius: 74, startAngle: degreesToRadians(size), endAngle: 0, clockwise: false)
    gapeCircle = SKShapeNode(path: myPath, centered: true)
    

    【讨论】:

    • 非常感谢您的回答。我到家时会检查的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多